You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2015/12/15 07:01:59 UTC
[02/31] ambari git commit: AMBARI-14370. Move functional tests from
ambari-server project to a separate project ambari-funtest (Nahappan
Somasundaram via smohanty)
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/host/RegisterHostWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/host/RegisterHostWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/host/RegisterHostWebRequest.java
deleted file mode 100644
index 86ae9c5..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/host/RegisterHostWebRequest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.host;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-/**
- * Registers a host with Ambari. A host must
- * be registered before it can be added to a cluster.
- */
-public class RegisterHostWebRequest extends AmbariHttpWebRequest {
- private String hostName = null;
- private static String pathFormat = "/agent/v1/register/%s";
-
- /**
- * Registers a new host with Ambari.
- *
- * @param params - Ambari server connection information.
- * @param hostName - Host name to be newly registered.
- */
- public RegisterHostWebRequest(ConnectionParams params, String hostName) {
- super(params);
- this.hostName = hostName;
- }
-
- public String getHostName() { return this.hostName; }
-
- @Override
- public String getHttpMethod() {
- return "POST";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, hostName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/AddServiceWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/AddServiceWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/AddServiceWebRequest.java
deleted file mode 100644
index d27afbc..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/AddServiceWebRequest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-/**
- * Adds a service to the specified cluster. The service name is sent in the request data.
- */
-public class AddServiceWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private static String pathFormat = "/api/v1/clusters/%s/services";
-
- /**
- * Add serviceName to the cluster clusterName
- *
- * @param params - Ambari server connection information
- * @param clusterName - Existing name of a cluster.
- * @param serviceName - Service name to be added.
- */
- public AddServiceWebRequest(ConnectionParams params, String clusterName, String serviceName) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- }
-
- /**
- * Gets the cluster name.
- * @return
- */
- public String getClusterName() { return this.clusterName; }
-
- /**
- * Gets the service name to be added.
- *
- * @return
- */
- public String getServiceName() { return this.serviceName; }
-
- /**
- * Gets the REST API method to use.
- *
- * @return - POST.
- */
- @Override
- public String getHttpMethod() {
- return "POST";
- }
-
- /**
- * Gets the API fragment to be added to the server URL.
- * @return
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName);
- }
-
- /**
- * Constructs the request data.
- *
- * @return - Request data.
- */
- @Override
- protected String getRequestData() {
- /**
- * {
- * "ServiceInfo" : {
- * "service_name" : serviceName
- * }
- * }
- */
- JsonObject jsonServiceInfoObj;
- jsonServiceInfoObj = createJsonObject("ServiceInfo", createJsonObject("service_name", serviceName));
- Gson gson = new Gson();
- return gson.toJson(jsonServiceInfoObj);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/DeleteServiceWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/DeleteServiceWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/DeleteServiceWebRequest.java
deleted file mode 100644
index 50d02ac..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/DeleteServiceWebRequest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-/**
- * Deletes the specified service from the specified cluster.
- */
-public class DeleteServiceWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private static String pathFormat = "/api/v1/clusters/%s/services/%s";
-
- /**
- * Deletes a service from a cluster.
- *
- * @param params - Ambari server connection information
- * @param clusterName - Cluster from where the service is to be deleted.
- * @param serviceName - Service to be deleted.
- */
- public DeleteServiceWebRequest(ConnectionParams params, String clusterName, String serviceName) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- }
-
- public String getClusterName() {
- return this.clusterName;
- }
-
- public String getHostName() {
- return this.serviceName;
- }
-
- @Override
- public String getHttpMethod() {
- return "DELETE";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, serviceName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/GetServiceWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/GetServiceWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/GetServiceWebRequest.java
deleted file mode 100644
index 69f2fc5..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/GetServiceWebRequest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-/**
- * Gets the specified service from the specified cluster.
- */
-public class GetServiceWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private static String pathFormat = "/api/v1/clusters/%s/services/%s";
-
- /**
- * Gets a service from a cluster.
- *
- * @param params - Ambari server connection information
- * @param clusterName - Cluster from where the service is to be deleted.
- * @param serviceName - Service to be deleted.
- */
- public GetServiceWebRequest(ConnectionParams params, String clusterName, String serviceName) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- }
-
- public String getClusterName() {
- return this.clusterName;
- }
-
- public String getHostName() {
- return this.serviceName;
- }
-
- @Override
- public String getHttpMethod() {
- return "GET";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, serviceName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/InstallServiceWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/InstallServiceWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/InstallServiceWebRequest.java
deleted file mode 100644
index 662b905..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/InstallServiceWebRequest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.state.State;
-
-/**
- * Installs a service.
- */
-public class InstallServiceWebRequest extends SetServiceStateWebRequest {
-
- /**
- * Updates the state of the specified service to INSTALLED.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster name.
- * @param serviceName - Service to be installed.
- */
- public InstallServiceWebRequest(ConnectionParams params, String clusterName, String serviceName) {
- super(params, clusterName, serviceName, State.INSTALLED, "Install service");
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/SetServiceStateWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/SetServiceStateWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/SetServiceStateWebRequest.java
deleted file mode 100644
index 5a5d3e6..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/SetServiceStateWebRequest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-import org.apache.ambari.server.state.State;
-
-/**
- * Updates the state of a service in a cluster.
- */
-public class SetServiceStateWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private State serviceState;
- private String requestContext;
- private static String pathFormat = "/api/v1/clusters/%s/services/%s";
-
- /**
- * Updates the state of the specified service in the specified cluster.
- *
- * @param params - Ambari connection information.
- * @param clusterName - Existing cluster name.
- * @param serviceName - Service name whose state is to be updated.
- * @param serviceState - New service state.
- * @param requestContext - Comments or remarks.
- */
- public SetServiceStateWebRequest(ConnectionParams params, String clusterName, String serviceName, State serviceState,
- String requestContext) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- this.serviceState = serviceState;
- this.requestContext = requestContext;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getHostName() { return this.serviceName; }
-
- public State getServiceState() { return this.serviceState; }
-
- public String getRequestContext() { return this.requestContext; }
-
- @Override
- public String getHttpMethod() {
- return "PUT";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, serviceName);
- }
-
- /**
- * Constructs the request data.
- *
- * @return - Request data.
- */
- @Override
- protected String getRequestData() {
- /**
- * {
- * "RequestInfo" : {"context" : requestContext},
- * "Body" : {"ServiceInfo" : {"state" : serviceState}}
- * }
- */
- JsonObject jsonObject = new JsonObject();
- jsonObject.add("RequestInfo", createJsonObject("context", requestContext));
- jsonObject.add("Body", createJsonObject("ServiceInfo", createJsonObject("state", serviceState.toString())));
- Gson gson = new Gson();
- return gson.toJson(jsonObject);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StartServiceWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StartServiceWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StartServiceWebRequest.java
deleted file mode 100644
index 26f5bc3..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StartServiceWebRequest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.state.State;
-
-/**
- * Starts a service by updating it's state to STARTED.
- */
-public class StartServiceWebRequest extends SetServiceStateWebRequest {
- /**
- * Updates the state of the specified service to STARTED.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster name.
- * @param serviceName - Service to be started.
- */
- public StartServiceWebRequest(ConnectionParams params, String clusterName, String serviceName) {
- super(params, clusterName, serviceName, State.STARTED, "Start service");
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StopServiceWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StopServiceWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StopServiceWebRequest.java
deleted file mode 100644
index 8c2d968..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/service/StopServiceWebRequest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.service;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.state.State;
-
-/**
- * Stop a service by updating it's state to INSTALLED.
- */
-public class StopServiceWebRequest extends SetServiceStateWebRequest {
- /**
- * Updates the state of the specified service to INSTALLED.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster name.
- * @param serviceName - Service to be stopped.
- */
- public StopServiceWebRequest(ConnectionParams params, String clusterName, String serviceName) {
- super(params, clusterName, serviceName, State.INSTALLED, "Stop service");
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/AddServiceComponentWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/AddServiceComponentWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/AddServiceComponentWebRequest.java
deleted file mode 100644
index 48a7b0d..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/AddServiceComponentWebRequest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponent;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-/**
- * Adds a component to a service.
- */
-public class AddServiceComponentWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private String componentName;
- private static String pathFormat = "/api/v1/clusters/%s/services/%s/components/%s";
-
- /**
- * Adds the specified service component to the specified service.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster name.
- * @param serviceName - Existing service name.
- * @param componentName - Component to be added to a service.
- */
- public AddServiceComponentWebRequest(ConnectionParams params, String clusterName, String serviceName,
- String componentName) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- this.componentName = componentName;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getServiceName() { return this.serviceName; }
-
- public String getComponentName() { return this.componentName; }
-
- @Override
- public String getHttpMethod() {
- return "POST";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, serviceName, componentName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/GetServiceComponentWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/GetServiceComponentWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/GetServiceComponentWebRequest.java
deleted file mode 100644
index abd35c1..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/GetServiceComponentWebRequest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponent;
-
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-/**
- * Gets a component to a service.
- */
-public class GetServiceComponentWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private String componentName;
- private static String pathFormat = "/api/v1/clusters/%s/services/%s/components/%s";
-
- /**
- * Gets the specified service component to the specified service.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster name.
- * @param serviceName - Existing service name.
- * @param componentName - Component to be added to a service.
- */
- public GetServiceComponentWebRequest(ConnectionParams params, String clusterName, String serviceName,
- String componentName) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- this.componentName = componentName;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getServiceName() { return this.serviceName; }
-
- public String getComponentName() { return this.componentName; }
-
- @Override
- public String getHttpMethod() {
- return "GET";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, serviceName, componentName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/SetServiceComponentStateWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/SetServiceComponentStateWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/SetServiceComponentStateWebRequest.java
deleted file mode 100644
index df7707b..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/SetServiceComponentStateWebRequest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponent;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-import org.apache.ambari.server.state.State;
-
-public class SetServiceComponentStateWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String serviceName;
- private String componentName;
- private State componentState;
- private String requestContext;
- private static String pathFormat = "/api/v1/clusters/%s/services/%s";
-
- public SetServiceComponentStateWebRequest(ConnectionParams params, String clusterName, String serviceName,
- String componentName, State componentState, String requestContext) {
- super(params);
- this.clusterName = clusterName;
- this.serviceName = serviceName;
- this.componentName = componentName;
- this.componentState = componentState;
- this.requestContext = requestContext;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getServiceName() { return this.serviceName; }
-
- public State getComponentState() { return this.componentState; }
-
- public String getRequestContext() { return this.requestContext; }
-
- @Override
- public String getHttpMethod() {
- return "PUT";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, serviceName, componentName);
- }
-
- /**
- * Constructs the request data.
- *
- * @return - Request data.
- */
- @Override
- protected String getRequestData() {
- /**
- * {
- * "RequestInfo" : {"context" : requestContext},
- * "Body" : {"ServiceComponentInfo" : {"state" : componentState}}
- * }
- */
- JsonObject jsonObject = new JsonObject();
- jsonObject.add("RequestInfo", createJsonObject("context", requestContext));
- jsonObject.add("Body", createJsonObject("ServiceComponentInfo", createJsonObject("state", componentState.toString())));
- Gson gson = new Gson();
- return gson.toJson(jsonObject);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/AddServiceComponentHostWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/AddServiceComponentHostWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/AddServiceComponentHostWebRequest.java
deleted file mode 100644
index cd0fe0a..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/AddServiceComponentHostWebRequest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponenthost;
-
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-
-/**
- * Adds a service component to a host.
- */
-public class AddServiceComponentHostWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String hostName;
- private String componentName;
- private static String pathFormat = "/api/v1/clusters/%s/hosts/%s/host_components/%s";
-
- /**
- * Adds the specified service component to the specified host.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster.
- * @param hostName - Existing host.
- * @param componentName - Component to be added to hostName.
- */
- public AddServiceComponentHostWebRequest(ConnectionParams params, String clusterName, String hostName,
- String componentName) {
- super(params);
- this.clusterName = clusterName;
- this.hostName = hostName;
- this.componentName = componentName;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getHostName() { return this.hostName; }
-
- public String getComponentName() { return this.componentName; }
-
- @Override
- public String getHttpMethod() {
- return "POST";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, hostName, componentName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java
deleted file mode 100644
index bacabb8..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponenthost;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * Bulk add a set of components on multiple hosts.
- * Replaces multiple calls to AddServiceComponentHostWebRequest
- */
-public class BulkAddServiceComponentHostsWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private List<String> hostNames;
- private List<String> componentNames;
- private static String pathFormat = "/api/v1/clusters/%s/hosts";
-
- /**
- * Adds multiple componenents to multiple hosts.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster.
- * @param hostNames - Hosts on which components are to be added.
- * @param componentNames - Components to be added.
- */
- public BulkAddServiceComponentHostsWebRequest(ConnectionParams params, String clusterName, List<String> hostNames,
- List<String> componentNames) {
- super(params);
- this.clusterName = clusterName;
- this.hostNames = new ArrayList<>(hostNames);
- this.componentNames = new ArrayList<>(componentNames);
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public List<String> getHostNames() { return Collections.unmodifiableList(this.hostNames); }
-
- public List<String> getComponentNames() { return Collections.unmodifiableList(this.componentNames); }
-
- @Override
- public String getHttpMethod() {
- return "POST";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName);
- }
-
- /**
- * Constructs the request data.
- *
- * @return - Request data.
- */
- @Override
- protected String getRequestData() {
- /**
- * {
- * "RequestInfo" : {
- * "query":"Hosts/host_name.in(host1,host2)"
- * },
- * "Body" : {
- * "host_components": [
- * {
- * "HostRoles" : { "component_name" : "HIVE_CLIENT" }
- * },
- * {
- * "HostRoles" : { "component_name" : "TEZ_CLIENT" }
- * }
- * ]
- * }
- */
- JsonObject jsonObject = new JsonObject();
- JsonArray hostRoles = new JsonArray();
-
- jsonObject.add("RequestInfo", createJsonObject("query", String.format("Hosts/host_name.in(%s)", toCsv(hostNames))));
-
- for (String componentName : componentNames) {
- hostRoles.add(createJsonObject("HostRoles", createJsonObject("component_name", componentName)));
- }
-
- jsonObject.add("Body", createJsonObject("host_components", hostRoles));
-
- Gson gson = new Gson();
- return gson.toJson(jsonObject);
- }
-
- private static String toCsv(List<String> list) {
- StringBuilder sb = new StringBuilder();
-
- for (String item : list) {
- sb.append(String.format("%s,", item));
- }
-
- sb.deleteCharAt(sb.length() - 1);
-
- return sb.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java
deleted file mode 100644
index 6634373..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponenthost;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-import org.apache.ambari.server.state.State;
-
-/**
- * Updates the state of the specified set of components.
- */
-public class BulkSetServiceComponentHostStateWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private State currentState;
- private State desiredState;
-
- private static String pathFormat = "/api/v1/clusters/%s/host_components?HostRoles/state=%s";
-
- /**
- * Updates the state of multiple components in a cluster.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster name.
- * @param currentState - Desired state.
- * @param desiredState - Current state.
- */
- public BulkSetServiceComponentHostStateWebRequest(ConnectionParams params, String clusterName, State currentState,
- State desiredState) {
- super(params);
- this.clusterName = clusterName;
- this.currentState = currentState;
- this.desiredState = desiredState;
- }
-
- @Override
- public String getHttpMethod() {
- return "PUT";
- }
-
- public State getCurrentState() { return this. currentState; }
-
- public State getDesiredState() { return this.desiredState; }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, this.currentState);
- }
-
- /**
- * Constructs the request data.
- *
- * @return - Request data.
- */
- @Override
- protected String getRequestData() {
- /**
- * {
- * "HostRoles" : { "state" : "INSTALLED" }
- * }
- */
- JsonObject jsonObject = new JsonObject();
-
- jsonObject.add("HostRoles", createJsonObject("state", desiredState.toString()));
-
- Gson gson = new Gson();
- return gson.toJson(jsonObject);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/GetServiceComponentHostWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/GetServiceComponentHostWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/GetServiceComponentHostWebRequest.java
deleted file mode 100644
index 15d1441..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/GetServiceComponentHostWebRequest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponenthost;
-
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-
-/**
- * Gets a service component to a host.
- */
-public class GetServiceComponentHostWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String hostName;
- private String componentName;
- private static String pathFormat = "/api/v1/clusters/%s/hosts/%s/host_components/%s";
-
- /**
- * Gets the specified service component to the specified host.
- *
- * @param params - Ambari server connection information.
- * @param clusterName - Existing cluster.
- * @param hostName - Existing host.
- * @param componentName - Component to be added to hostName.
- */
- public GetServiceComponentHostWebRequest(ConnectionParams params, String clusterName, String hostName,
- String componentName) {
- super(params);
- this.clusterName = clusterName;
- this.hostName = hostName;
- this.componentName = componentName;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getHostName() { return this.hostName; }
-
- public String getComponentName() { return this.componentName; }
-
- @Override
- public String getHttpMethod() {
- return "GET";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, hostName, componentName);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java
deleted file mode 100644
index 8534a00..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.api.servicecomponenthost;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.AmbariHttpWebRequest;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.state.State;
-
-public class SetServiceComponentHostStateWebRequest extends AmbariHttpWebRequest {
- private String clusterName;
- private String hostName;
- private String componentName;
- private State componentState;
- private String requestContext;
- private static String pathFormat = "/api/v1/clusters/%s/hosts/%s/host_components/%s";
-
- public SetServiceComponentHostStateWebRequest(ConnectionParams params, String clusterName, String hostName,
- String componentName, State componentState, String requestContext) {
- super(params);
- this.clusterName = clusterName;
- this.hostName = hostName;
- this.componentName = componentName;
- this.componentState = componentState;
- this.requestContext = requestContext;
- }
-
- public String getClusterName() { return this.clusterName; }
-
- public String getHostName() { return this.hostName; }
-
- public State getComponentState() { return this.componentState; }
-
- public String getRequestContext() { return this.requestContext; }
-
- @Override
- public String getHttpMethod() {
- return "PUT";
- }
-
- /**
- * Get REST API path fragment for construction full URI.
- *
- * @return - REST API path
- */
- @Override
- protected String getApiPath() {
- return String.format(pathFormat, clusterName, hostName, componentName);
- }
-
- /**
- * Constructs the request data.
- *
- * @return - Request data.
- */
- @Override
- protected String getRequestData() {
- /**
- * {
- * "RequestInfo" : {"context" : requestContext},
- * "Body" : {"HostRoles" : {"state" : componentState}}
- * }
- */
- String content;
- JsonObject jsonObject = new JsonObject();
- jsonObject.add("RequestInfo", createJsonObject("context", requestContext));
- jsonObject.add("Body", createJsonObject("HostRoles", createJsonObject("state", componentState.toString())));
- Gson gson = new Gson();
- content = gson.toJson(jsonObject);
- return content;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/DeleteServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/DeleteServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/DeleteServiceTest.java
deleted file mode 100644
index f7bd333..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/DeleteServiceTest.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.server;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.WebResponse;
-import org.apache.ambari.server.functionaltests.api.service.DeleteServiceWebRequest;
-import org.apache.ambari.server.functionaltests.api.service.GetServiceWebRequest;
-import org.apache.ambari.server.functionaltests.api.service.StopServiceWebRequest;
-import org.apache.ambari.server.functionaltests.utils.ClusterUtils;
-import org.apache.ambari.server.functionaltests.utils.RestApiUtils;
-import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
-import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
-import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
-import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
-import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntityPK;
-import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntityPK;
-import org.apache.ambari.server.state.State;
-
-import org.apache.commons.httpclient.HttpStatus;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * Simple test that starts the local ambari server,
- * tests it's status and shuts down the server.
- */
-@Ignore
-public class DeleteServiceTest extends ServerTestBase {
- /**
- * Set up a test cluster with a service, a host and a few components.
- * Attempt to delete the service. Verify the state of the DB.
- *
- * @throws Exception
- */
- @Test
- public void testDeleteService() throws Exception {
- String clusterName = "c1";
- String serviceName = "HDFS";
- ConnectionParams params = new ConnectionParams();
-
- params.setServerName("localhost");
- params.setServerApiPort(serverPort);
- params.setServerAgentPort(serverAgentPort);
- params.setUserName("admin");
- params.setPassword("admin");
-
- ClusterUtils clusterUtils = injector.getInstance(ClusterUtils.class);
- clusterUtils.createSampleCluster(params);
-
- /**
- * Verify the status of the service
- */
- JsonElement jsonResponse = RestApiUtils.executeRequest(new GetServiceWebRequest(params, clusterName, serviceName));
- assertTrue(!jsonResponse.isJsonNull());
- JsonObject jsonServiceInfoObj = jsonResponse.getAsJsonObject().get("ServiceInfo").getAsJsonObject();
- String cluster_name = jsonServiceInfoObj.get("cluster_name").getAsString();
- assertEquals(cluster_name, clusterName);
-
- String service_name = jsonServiceInfoObj.get("service_name").getAsString();
- assertEquals(service_name, serviceName);
-
- /**
- * Check the following:
- * ClusterServiceDAO
- * ServiceDesiredStateDAO
- * ServiceComponentDesiredStateDAO
- * HostComponentStateDAO
- * HostComponentDesiredStateDAO
- */
-
- /**
- * Stop the service
- */
-
- jsonResponse = RestApiUtils.executeRequest(new StopServiceWebRequest(params, clusterName, serviceName));
-
- /**
- * clusterservice table
- */
- ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
- List<ClusterServiceEntity> clusterServiceEntities = clusterServiceDAO.findAll();
- assertEquals(clusterServiceEntities.size(), 1); // Only one service in the sample cluster (HDFS)
- assertEquals(clusterServiceEntities.get(0).getServiceName(), serviceName); // Verify the only service name
-
- ClusterServiceEntity clusterServiceEntity = clusterServiceEntities.get(0);
- long clusterId = clusterServiceEntity.getClusterId();
-
- /**
- * servicedesiredstate table
- */
- ServiceDesiredStateDAO serviceDesiredStateDAO = injector.getInstance(ServiceDesiredStateDAO.class);
- List<ServiceDesiredStateEntity> serviceDesiredStateEntities = serviceDesiredStateDAO.findAll();
- assertEquals(serviceDesiredStateEntities.size(), 1);
- ServiceDesiredStateEntity serviceDesiredStateEntity = serviceDesiredStateEntities.get(0);
- assertEquals(serviceDesiredStateEntity.getServiceName(), serviceName);
- assertEquals(serviceDesiredStateEntity.getDesiredState(), State.INSTALLED);
-
- /**
- * servicecomponentdesiredstate table
- */
- ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
- List<ServiceComponentDesiredStateEntity> serviceComponentDesiredStateEntities = serviceComponentDesiredStateDAO.findAll();
- assertEquals(serviceComponentDesiredStateEntities.size(), 3); // NAMENODE, SECONDARY_NAMENODE, DATANODE.
- for (ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity : serviceComponentDesiredStateEntities) {
- assertEquals(serviceComponentDesiredStateEntity.getDesiredState(), State.INSTALLED);
- }
-
- /**
- * hostcomponentstate table
- */
- HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
- List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
- assertEquals(hostComponentStateEntities.size(), 3);
-
- /**
- * hostcomponentdesiredstate table
- */
- HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);
- List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
- assertEquals(hostComponentDesiredStateEntities.size(), 3);
-
- /**
- * Delete the service
- */
- jsonResponse = RestApiUtils.executeRequest(new DeleteServiceWebRequest(params, clusterName, serviceName));
-
- WebResponse webResponse = new GetServiceWebRequest(params, clusterName, serviceName).getResponse();
- assertEquals(webResponse.getStatusCode(), HttpStatus.SC_NOT_FOUND);
-
- /**
- * ClusterServiceDAO - the service entry should have been removed.
- */
- clusterServiceEntity = clusterServiceDAO.findByClusterAndServiceNames(clusterName, serviceName);
- assertTrue(clusterServiceEntity == null);
-
- /**
- * ServiceDesiredStateDAO - the service entry should have been removed.
- */
- ServiceDesiredStateEntityPK serviceDesiredStateEntityPK = injector.getInstance(ServiceDesiredStateEntityPK.class);
- serviceDesiredStateEntityPK.setClusterId(clusterId);
- serviceDesiredStateEntityPK.setServiceName(serviceName);
- serviceDesiredStateEntity = serviceDesiredStateDAO.findByPK(serviceDesiredStateEntityPK);
- assertTrue(serviceDesiredStateEntity == null);
-
- /**
- * ServiceComponentDesiredStateDAO
- */
- ServiceComponentDesiredStateEntityPK serviceComponentDesiredStateEntityPK = injector.getInstance(ServiceComponentDesiredStateEntityPK.class);
- ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByPK(serviceComponentDesiredStateEntityPK);
- assertTrue(serviceComponentDesiredStateEntity == null);
-
- /**
- * HostComponentStateDAO
- */
- hostComponentStateEntities = hostComponentStateDAO.findByService(serviceName);
- assertEquals(hostComponentStateEntities.size(), 0);
-
-
- /**
- * HostComponentDesiredStateDAO
- */
- hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
- assertEquals(hostComponentDesiredStateEntities.size(), 0);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/LocalAmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/LocalAmbariServer.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/LocalAmbariServer.java
deleted file mode 100644
index 24b4ccf..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/LocalAmbariServer.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.server;
-
-import com.google.inject.Inject;
-import com.google.inject.persist.PersistService;
-import org.apache.ambari.server.controller.AmbariServer;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import com.google.inject.Injector;
-
-/**
-* Wrap AmbariServer as a testable unit.
-*/
-public class LocalAmbariServer implements Runnable {
-
- private static Log LOG = LogFactory.getLog(AmbariServer.class);
-
- /**
- * Actual ambari server instance.
- */
- private AmbariServer ambariServer = null;
-
- @Inject
- private Injector injector;
-
- public LocalAmbariServer() {}
-
- /**
- * Thread entry point.
- */
- @Override
- public void run(){
- try {
- startServer();
- }
- catch (Exception ex) {
- LOG.info("Exception received ", ex);
- throw new RuntimeException(ex);
- }
- }
-
- /**
- * Configures the Guice injector to use the in-memory test DB
- * and attempts to start an instance of AmbariServer.
- *
- * @throws Exception
- */
- private void startServer() throws Exception {
- try {
- LOG.info("Attempting to start ambari server...");
-
- AmbariServer.setupProxyAuth();
- injector.getInstance(GuiceJpaInitializer.class);
- ambariServer = injector.getInstance(AmbariServer.class);
- ambariServer.initViewRegistry();
- ambariServer.run();
- } catch (InterruptedException ex) {
- LOG.info(ex);
- } catch (Throwable t) {
- LOG.error("Failed to run the Ambari Server", t);
- stopServer();
- throw t;
- }
- }
-
- /**
- * Attempts to stop the test AmbariServer instance.
- * @throws Exception
- */
- public void stopServer() throws Exception {
- LOG.info("Stopping ambari server...");
-
- if (ambariServer != null) {
- ambariServer.stop();
- }
-
- if (injector != null) {
- injector.getInstance(PersistService.class).stop();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/ServerTestBase.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/ServerTestBase.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/ServerTestBase.java
deleted file mode 100644
index a6d953a..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/ServerTestBase.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.server;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.junit.After;
-import org.junit.Before;
-
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * Base test infrastructure.
- */
-public class ServerTestBase {
- /**
- * Run the ambari server on a thread.
- */
- protected Thread serverThread = null;
-
- /**
- * Instance of the local ambari server, which wraps the actual
- * ambari server with test configuration.
- */
- protected LocalAmbariServer server = null;
-
- /**
- * Server port
- */
- protected static int serverPort = 9995;
-
- /**
- * Server agent port
- */
- protected static int serverAgentPort = 9000;
-
- /**
- * Guice injector using an in-memory DB.
- */
- protected Injector injector = null;
-
- /**
- * Server URL
- */
- protected static String SERVER_URL_FORMAT = "http://localhost:%d";
-
- /**
- * Start our local server on a thread so that it does not block.
- *
- * @throws Exception
- */
- @Before
- public void setup() throws Exception {
- InMemoryDefaultTestModule testModule = new InMemoryDefaultTestModule();
- Properties properties = testModule.getProperties();
- properties.setProperty(Configuration.AGENT_USE_SSL, "false");
- properties.setProperty(Configuration.CLIENT_API_PORT_KEY, Integer.toString(serverPort));
- properties.setProperty(Configuration.SRVR_ONE_WAY_SSL_PORT_KEY, Integer.toString(serverAgentPort));
- String tmpDir = System.getProperty("java.io.tmpdir");
- testModule.getProperties().setProperty(Configuration.SRVR_KSTR_DIR_KEY, tmpDir);
- injector = Guice.createInjector(testModule);
- server = injector.getInstance(LocalAmbariServer.class);
- serverThread = new Thread(server);
- serverThread.start();
- waitForServer();
- }
-
- /**
- * Waits for the local server until it is ready to accept requests.
- *
- * @throws Exception
- */
- private void waitForServer() throws Exception {
- int count = 1;
-
- while (!isServerUp()) {
- serverThread.join(count * 10000); // Give a few seconds for the ambari server to start up
- //count += 1; // progressive back off
- //count *= 2; // exponential back off
- }
- }
-
- /**
- * Attempt to query the server for the stack. If the server is up,
- * we will get a response. If not, an exception will be thrown.
- *
- * @return - True if the local server is responsive to queries.
- * False, otherwise.
- */
- private boolean isServerUp() {
- String apiPath = "/api/v1/stacks";
-
- String apiUrl = String.format(SERVER_URL_FORMAT, serverPort) + apiPath;
- HttpClient httpClient = new HttpClient();
- GetMethod getMethod = new GetMethod(apiUrl);
-
- try {
- int statusCode = httpClient.executeMethod(getMethod);
- String response = getMethod.getResponseBodyAsString();
-
- return true;
- } catch (IOException ex) {
-
- } finally {
- getMethod.releaseConnection();
- }
-
- return false;
- }
-
- /**
- * Shut down the local server.
- *
- * @throws Exception
- */
- @After
- public void teardown() throws Exception {
- if (serverThread != null) {
- serverThread.interrupt();
- }
- if (server != null) {
- server.stopServer();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/StartStopServerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/StartStopServerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/StartStopServerTest.java
deleted file mode 100644
index 55806f4..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/StartStopServerTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.server;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
-
-import java.io.StringReader;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonArray;
-
-import java.io.IOException;
-
-import org.apache.http.HttpStatus;
-
-/**
- * Simple test that starts the local ambari server,
- * tests it's status and shuts down the server.
- */
-@Ignore
-public class StartStopServerTest extends ServerTestBase {
- /**
- * Waits for the ambari server to startup and then checks it's
- * status by querying /api/v1/stacks (does not touch the DB)
- */
- @Test
- public void testServerStatus() throws IOException {
- /**
- * Query the ambari server for the list of stacks.
- * A successful GET returns the list of stacks.
- * We should get a json like:
- * {
- * "href" : "http://localhost:9995/api/v1/stacks",
- * "items" : [
- * {
- * "href" : "http://localhost:9995/api/v1/stacks/HDP",
- * "Stacks" : {
- * "stack_name" : "HDP"
- * }
- * }
- * ]
- * }
- */
-
- /**
- * Test URL for GETting the status of the ambari server
- */
- String stacksPath = "/api/v1/stacks";
- String stacksUrl = String.format(SERVER_URL_FORMAT, serverPort) + stacksPath;
- HttpClient httpClient = new HttpClient();
- GetMethod getMethod = new GetMethod(stacksUrl);
-
- try {
- int statusCode = httpClient.executeMethod(getMethod);
-
- assertTrue (statusCode == HttpStatus.SC_OK); // HTTP status code 200
-
- String responseBody = getMethod.getResponseBodyAsString();
-
- assertTrue(responseBody != null); // Make sure response body is valid
-
- JsonElement jsonElement = new JsonParser().parse(new JsonReader(new StringReader(responseBody)));
-
- assertTrue (jsonElement != null); // Response was a JSON string
-
- JsonObject jsonObject = jsonElement.getAsJsonObject();
-
- assertTrue (jsonObject.has("items")); // Should have "items" entry
-
- JsonArray stacksArray = jsonObject.get("items").getAsJsonArray();
-
- assertTrue (stacksArray.size() > 0); // Should have at least one stack
-
- } finally {
- getMethod.releaseConnection();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/ClusterUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/ClusterUtils.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/ClusterUtils.java
deleted file mode 100644
index 8361bf1..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/ClusterUtils.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.utils;
-
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import org.apache.ambari.server.actionmanager.HostRoleStatus;
-import org.apache.ambari.server.functionaltests.api.ClusterConfigParams;
-import org.apache.ambari.server.functionaltests.api.ConnectionParams;
-import org.apache.ambari.server.functionaltests.api.WebRequest;
-import org.apache.ambari.server.functionaltests.api.WebResponse;
-import org.apache.ambari.server.functionaltests.api.cluster.*;
-import org.apache.ambari.server.functionaltests.api.host.AddHostWebRequest;
-import org.apache.ambari.server.functionaltests.api.host.RegisterHostWebRequest;
-import org.apache.ambari.server.functionaltests.api.service.AddServiceWebRequest;
-import org.apache.ambari.server.functionaltests.api.service.InstallServiceWebRequest;
-import org.apache.ambari.server.functionaltests.api.service.StartServiceWebRequest;
-import org.apache.ambari.server.functionaltests.api.servicecomponent.AddServiceComponentWebRequest;
-import org.apache.ambari.server.functionaltests.api.servicecomponenthost.BulkAddServiceComponentHostsWebRequest;
-import org.apache.ambari.server.functionaltests.api.servicecomponenthost.BulkSetServiceComponentHostStateWebRequest;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.State;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-public class ClusterUtils {
-
- @Inject
- private Injector injector;
-
- public void createSampleCluster(ConnectionParams serverParams) throws Exception {
- WebResponse response = null;
- JsonElement jsonResponse;
- String clusterName = "c1";
- String hostName = "host1";
- String clusterVersion = "HDP-2.2.0";
-
- /**
- * Register a host
- */
- if (injector == null) {
- jsonResponse = RestApiUtils.executeRequest(new RegisterHostWebRequest(serverParams, hostName));
- }
- else {
- /**
- * Hack: Until we figure out how to get the agent servlet going,
- * register a host directly using the Clusters class.
- */
- Clusters clusters = injector.getInstance(Clusters.class);
- clusters.addHost(hostName);
- Host host1 = clusters.getHost(hostName);
- Map<String, String> hostAttributes = new HashMap<String, String>();
- hostAttributes.put("os_family", "redhat");
- hostAttributes.put("os_release_version", "6.3");
- host1.setHostAttributes(hostAttributes);
- host1.persist();
- }
-
- /**
- * Create a cluster
- */
- jsonResponse = RestApiUtils.executeRequest(new CreateClusterWebRequest(serverParams, clusterName, clusterVersion));
-
- /**
- * Add the registered host to the new cluster
- */
- jsonResponse = RestApiUtils.executeRequest(new AddHostWebRequest(serverParams, clusterName, hostName));
-
- /**
- * Create and add a configuration to our cluster
- */
-
- String configType = "test-hadoop-env";
- String configTag = "version1";
- ClusterConfigParams configParams = new ClusterConfigParams();
- configParams.setClusterName(clusterName);
- configParams.setConfigType(configType);
- configParams.setConfigTag(configTag);
- configParams.setProperties(new HashMap<String, String>() {{
- put("fs.default.name", "localhost:9995");
- }});
-
- jsonResponse = RestApiUtils.executeRequest(new CreateConfigurationWebRequest(serverParams, configParams));
-
- /**
- * Apply the desired configuration to our cluster
- */
- jsonResponse = RestApiUtils.executeRequest(new AddDesiredConfigurationWebRequest(serverParams, configParams));
-
- /**
- * Add a service to the cluster
- */
-
- String serviceName = "HDFS";
- jsonResponse = RestApiUtils.executeRequest(new AddServiceWebRequest(serverParams, clusterName, serviceName));
-
- String [] componentNames = new String [] {"NAMENODE", "DATANODE", "SECONDARY_NAMENODE"};
-
- /**
- * Add components to the service
- */
- for (String componentName : componentNames) {
- jsonResponse = RestApiUtils.executeRequest(new AddServiceComponentWebRequest(serverParams, clusterName,
- serviceName, componentName));
- }
-
- /**
- * Install the service
- */
- jsonResponse = RestApiUtils.executeRequest(new InstallServiceWebRequest(serverParams, clusterName, serviceName));
-
- /**
- * Add components to the host
- */
-
- jsonResponse = RestApiUtils.executeRequest(new BulkAddServiceComponentHostsWebRequest(serverParams, clusterName,
- Arrays.asList(hostName), Arrays.asList(componentNames)));
-
- /**
- * Install the service component hosts
- */
- jsonResponse = RestApiUtils.executeRequest(new BulkSetServiceComponentHostStateWebRequest(serverParams,
- clusterName, State.INIT, State.INSTALLED));
- int requestId = parseRequestId(jsonResponse);
- RequestStatusPoller.poll(serverParams, clusterName, requestId);
-
- /**
- * Start the service component hosts
- */
-
- jsonResponse = RestApiUtils.executeRequest(new BulkSetServiceComponentHostStateWebRequest(serverParams,
- clusterName, State.INSTALLED, State.STARTED));
- requestId = parseRequestId(jsonResponse);
- RequestStatusPoller.poll(serverParams, clusterName, requestId);
-
- /**
- * Start the service
- */
- //jsonResponse = RestApiUtils.executeRequest(new StartServiceWebRequest(serverParams, clusterName, serviceName));
- }
-
- /**
- * Parses a JSON response string for { "Requests" : { "id" : "2" } }
- *
- * @param jsonResponse
- * @return - request id
- * @throws IllegalArgumentException
- */
- private static int parseRequestId(JsonElement jsonResponse) throws IllegalArgumentException {
- if (jsonResponse.isJsonNull()) {
- throw new IllegalArgumentException("jsonResponse with request id expected.");
- }
-
- JsonObject jsonObject = jsonResponse.getAsJsonObject();
- int requestId = jsonObject.get("Requests").getAsJsonObject().get("id").getAsInt();
- return requestId;
- }
-}
-
-/**
- * Polls the status of a service component host request.
- */
-class RequestStatusPoller implements Runnable {
- private HostRoleStatus hostRoleStatus;
- private ConnectionParams serverParams;
- private String clusterName;
- private int requestId;
-
- public RequestStatusPoller(ConnectionParams serverParams, String clusterName, int requestId) {
- this.hostRoleStatus = HostRoleStatus.IN_PROGRESS;
- this.serverParams = serverParams;
- this.clusterName = clusterName;
- this.requestId = requestId;
- }
-
- public HostRoleStatus getHostRoleStatus() {
- return this.hostRoleStatus;
- }
-
- public static boolean poll(ConnectionParams serverParams, String clusterName, int requestId) throws Exception {
- RequestStatusPoller poller = new RequestStatusPoller(serverParams, clusterName, requestId);
- Thread pollerThread = new Thread(poller);
- pollerThread.start();
- pollerThread.join();
- if (poller.getHostRoleStatus() == HostRoleStatus.COMPLETED)
- return true;
-
- return false;
- }
-
- @Override
- public void run() {
- int retryCount = 5;
- while (true) {
- JsonElement jsonResponse;
-
- try {
- WebRequest webRequest = new GetRequestStatusWebRequest(serverParams, clusterName, requestId);
- jsonResponse = RestApiUtils.executeRequest(webRequest);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- if (!jsonResponse.isJsonNull()) {
- JsonObject jsonObj = jsonResponse.getAsJsonObject();
- JsonObject jsonRequestsObj = jsonObj.getAsJsonObject("Requests");
- String requestStatus = jsonRequestsObj.get("request_status").getAsString();
- hostRoleStatus = HostRoleStatus.valueOf(requestStatus);
-
- if (hostRoleStatus == HostRoleStatus.COMPLETED ||
- hostRoleStatus == HostRoleStatus.ABORTED ||
- hostRoleStatus == HostRoleStatus.TIMEDOUT ||
- retryCount == 0)
- break;
- }
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException ex) {
- break;
- }
-
- retryCount--;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/RestApiUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/RestApiUtils.java b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/RestApiUtils.java
deleted file mode 100644
index 1cb0f31..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/RestApiUtils.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.functionaltests.utils;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.stream.JsonReader;
-import org.apache.ambari.server.functionaltests.api.WebRequest;
-import org.apache.ambari.server.functionaltests.api.WebResponse;
-import org.apache.commons.httpclient.HttpStatus;
-
-import java.io.StringReader;
-
-/**
- * Helper that executes a web request object and evaluates the response code.
- */
-public class RestApiUtils {
- /**
- * Executes a web request and throws an exception if the status code is incorrect.
- *
- * @param request
- * @return
- * @throws Exception
- */
- public static JsonElement executeRequest(WebRequest request) throws Exception {
- WebResponse response = request.getResponse();
- int responseCode = response.getStatusCode();
- String responseBody = response.getContent();
-
- if (responseCode != HttpStatus.SC_OK && responseCode != HttpStatus.SC_CREATED && responseCode != HttpStatus.SC_ACCEPTED) {
- throw new RuntimeException(String.format("%d:%s", responseCode, responseBody));
- }
-
- return new JsonParser().parse(new JsonReader(new StringReader(responseBody)));
- }
-}