ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject [1/2] ambari git commit: AMBARI-13956. Add functional test infrastructure commands to perform API calls (Nahappan Somasundaram)
Date Tue, 24 Nov 2015 23:37:28 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk aa465686f -> b5e8a3bf8


http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e8a3bf/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
new file mode 100644
index 0000000..df7707b
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponent/SetServiceComponentStateWebRequest.java
@@ -0,0 +1,87 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..cd0fe0a
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/AddServiceComponentHostWebRequest.java
@@ -0,0 +1,69 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..bacabb8
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java
@@ -0,0 +1,127 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..6634373
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java
@@ -0,0 +1,91 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..15d1441
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/GetServiceComponentHostWebRequest.java
@@ -0,0 +1,69 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..8534a00
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java
@@ -0,0 +1,89 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..f7bd333
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/DeleteServiceTest.java
@@ -0,0 +1,197 @@
+/*
+ * 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/b5e8a3bf/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
index ceadbc2..24b4ccf 100644
--- 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
@@ -18,15 +18,13 @@
 
 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.Guice;
 import com.google.inject.Injector;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.configuration.Configuration;
 
 /**
 * Wrap AmbariServer as a testable unit.
@@ -40,20 +38,10 @@ public class LocalAmbariServer implements Runnable {
    */
   private AmbariServer ambariServer = null;
 
-  private Injector injector = null;
+  @Inject
+  private Injector injector;
 
-  private InMemoryDefaultTestModule module = null;
-
-  /**
-   * Default constructor using the default implementation of InMemoryDefaultTestModule.
-   */
-  public LocalAmbariServer() { this.module = new InMemoryDefaultTestModule(); }
-
-  /**
-   * Overloaded constructor for sub-classed InMemoryDefaultTestModule implementations.
-   * @param module
-   */
-  public LocalAmbariServer(InMemoryDefaultTestModule module) { this.module = module; }
+  public LocalAmbariServer() {}
 
   /**
    * Thread entry point.
@@ -76,16 +64,6 @@ public class LocalAmbariServer implements Runnable {
    * @throws Exception
    */
   private void startServer() throws Exception {
-    /**
-     * Specify the temp folder as the source for certificate keys.
-     * Without this, the CertificateManager will generate the keys
-     * in the current folder (ambari-server) causing issues with
-     * rat check.
-     */
-    String tmpDir = System.getProperty("java.io.tmpdir");
-    this.module.getProperties().setProperty(Configuration.SRVR_KSTR_DIR_KEY, tmpDir);
-    injector = Guice.createInjector(this.module);
-
     try {
       LOG.info("Attempting to start ambari server...");
 
@@ -99,6 +77,7 @@ public class LocalAmbariServer implements Runnable {
     } catch (Throwable t) {
       LOG.error("Failed to run the Ambari Server", t);
       stopServer();
+      throw t;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e8a3bf/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
new file mode 100644
index 0000000..a6d953a
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/server/ServerTestBase.java
@@ -0,0 +1,146 @@
+/*
+ * 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/b5e8a3bf/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
index c49a01e..55806f4 100644
--- 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
@@ -18,15 +18,9 @@
 
 package org.apache.ambari.server.functionaltests.server;
 
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.util.Properties;
-
 import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.httpclient.HttpClient;
@@ -40,7 +34,6 @@ import com.google.gson.JsonObject;
 import com.google.gson.JsonArray;
 
 import java.io.IOException;
-import java.text.MessageFormat;
 
 import org.apache.http.HttpStatus;
 
@@ -49,63 +42,7 @@ import org.apache.http.HttpStatus;
  * tests it's status and shuts down the server.
  */
 @Ignore
-public class StartStopServerTest {
-  /**
-   * Run the ambari server on a thread.
-   */
-  private Thread serverThread = null;
-
-  /**
-   * Instance of the local ambari server, which wraps the actual
-   * ambari server with test configuration.
-   */
-  private LocalAmbariServer server = null;
-
-  /**
-   * Server port
-   */
-  private static int serverPort = 9995;
-
-  /**
-   * Server URL
-   */
-  private static String SERVER_URL_FORMAT = "http://localhost:%d";
-
-  /**
-   * Test URL for GETting the status of the ambari server
-   */
-  private static String stacksPath = "/api/v1/stacks";
-
-  /**
-   * 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));
-    server = new LocalAmbariServer(testModule);
-    serverThread = new Thread(server);
-    serverThread.start();
-    serverThread.join(20000);     // Give a few seconds for the ambari server to start up
-  }
-
-  /**
-   * Shut down our local server.
-   * @throws Exception
-   */
-  @After
-  public void teardown() throws Exception {
-    if (serverThread != null) {
-      serverThread.interrupt();
-    }
-    if (server != null) {
-      server.stopServer();
-    }
-  }
-
+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)
@@ -129,6 +66,10 @@ public class StartStopServerTest {
      * }
      */
 
+    /**
+     * 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);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e8a3bf/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
new file mode 100644
index 0000000..8361bf1
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/ClusterUtils.java
@@ -0,0 +1,247 @@
+/*
+ * 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/b5e8a3bf/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
new file mode 100644
index 0000000..1cb0f31
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/functionaltests/utils/RestApiUtils.java
@@ -0,0 +1,52 @@
+/*
+ * 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)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e8a3bf/ambari-server/src/test/resources/stacks/HDP/2.1.1/role_command_order.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.1.1/role_command_order.json b/ambari-server/src/test/resources/stacks/HDP/2.1.1/role_command_order.json
index 656bb63..faaee6e 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.1.1/role_command_order.json
+++ b/ambari-server/src/test/resources/stacks/HDP/2.1.1/role_command_order.json
@@ -3,7 +3,7 @@
   "_comment" : "blockedRole-blockedCommand: [blockerRole1-blockerCommand1, blockerRole2-blockerCommand2, ...]",
   "general_deps" : {
     "_comment" : "dependencies for all cases",
-    "HBASE_MASTER-START": ["ZOOKEEPER_SERVER-START, ZOOKEEPER_SERVER-START"],
+    "HBASE_MASTER-START": ["ZOOKEEPER_SERVER-START"],
     "OOZIE_SERVER-START": ["JOBTRACKER-START", "TASKTRACKER-START"],
     "WEBHCAT_SERVER-START": ["TASKTRACKER-START", "HIVE_SERVER-START"],
     "HIVE_METASTORE-START": ["MYSQL_SERVER-START"],

http://git-wip-us.apache.org/repos/asf/ambari/blob/b5e8a3bf/ambari-server/src/test/resources/stacks/HDP/2.2.0/role_command_order.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/stacks/HDP/2.2.0/role_command_order.json b/ambari-server/src/test/resources/stacks/HDP/2.2.0/role_command_order.json
index 656bb63..faaee6e 100644
--- a/ambari-server/src/test/resources/stacks/HDP/2.2.0/role_command_order.json
+++ b/ambari-server/src/test/resources/stacks/HDP/2.2.0/role_command_order.json
@@ -3,7 +3,7 @@
   "_comment" : "blockedRole-blockedCommand: [blockerRole1-blockerCommand1, blockerRole2-blockerCommand2, ...]",
   "general_deps" : {
     "_comment" : "dependencies for all cases",
-    "HBASE_MASTER-START": ["ZOOKEEPER_SERVER-START, ZOOKEEPER_SERVER-START"],
+    "HBASE_MASTER-START": ["ZOOKEEPER_SERVER-START"],
     "OOZIE_SERVER-START": ["JOBTRACKER-START", "TASKTRACKER-START"],
     "WEBHCAT_SERVER-START": ["TASKTRACKER-START", "HIVE_SERVER-START"],
     "HIVE_METASTORE-START": ["MYSQL_SERVER-START"],


Mime
View raw message