http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/CreateConfigurationWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/CreateConfigurationWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/CreateConfigurationWebRequest.java new file mode 100644 index 0000000..884eb7b --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/CreateConfigurationWebRequest.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.funtest.server.api.cluster; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ClusterConfigParams; +import org.apache.ambari.funtest.server.ConnectionParams; + +import java.util.HashMap; +import java.util.Map; + +public class CreateConfigurationWebRequest extends AmbariHttpWebRequest { + private String clusterName; + private String configType; + private String configTag; + private Map<String, String> properties; + private static String pathFormat = "/api/v1/clusters/%s/configurations"; + + public CreateConfigurationWebRequest(ConnectionParams serverParams, ClusterConfigParams configParams) { + super(serverParams); + this.clusterName = configParams.getClusterName(); + this.configType = configParams.getConfigType(); + this.configTag = configParams.getConfigTag(); + this.properties = new HashMap<>(configParams.getProperties()); + } + + public String getClusterName() { return this.clusterName; } + + public String getConfigType() { return this.configType; } + + public String getConfigTag() { return this.configTag; } + + @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); + } + + /** + * Gets the request data. + * + * @return - Request data. + */ + @Override + protected String getRequestData() { + /** + * {"type": "core-site", "tag": "version1363902625", "properties" : { "fs.default.name" : "localhost:8020"}} + */ + JsonObject jsonPropertiesObj = new JsonObject(); + for (Map.Entry<String, String> property : properties.entrySet()) { + jsonPropertiesObj.addProperty(property.getKey(), property.getValue()); + } + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("type", configType); + jsonObject.addProperty("tag", configTag); + jsonObject.add("properties", jsonPropertiesObj); + Gson gson = new Gson(); + return gson.toJson(jsonObject); + } +}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetAllClustersWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetAllClustersWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetAllClustersWebRequest.java new file mode 100644 index 0000000..4b916d1 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetAllClustersWebRequest.java @@ -0,0 +1,53 @@ +/* + * 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.funtest.server.api.cluster; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * Gets all the clusters. + */ +public class GetAllClustersWebRequest extends AmbariHttpWebRequest { + private static String pathFormat = "/api/v1/clusters"; + + public GetAllClustersWebRequest(ConnectionParams params) { + super(params); + } + + /** + * Gets the REST API method. + * + * @return - GET. + */ + @Override + public String getHttpMethod() { + return "GET"; + } + + /** + * Get REST API path fragment for construction full URI. + * + * @return - REST API path + */ + @Override + protected String getApiPath() { + return pathFormat; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetClusterWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetClusterWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetClusterWebRequest.java new file mode 100644 index 0000000..49b0687 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetClusterWebRequest.java @@ -0,0 +1,49 @@ +/* + * 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.funtest.server.api.cluster; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +public class GetClusterWebRequest extends AmbariHttpWebRequest { + private String clusterName; + private static String pathFormat = "/api/v1/clusters/%s"; + + public GetClusterWebRequest(ConnectionParams params, String clusterName) { + super(params); + this.clusterName = clusterName; + } + + public String getClusterName() { return this.clusterName; } + + @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); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetRequestStatusWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetRequestStatusWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetRequestStatusWebRequest.java new file mode 100644 index 0000000..e2cf8ae --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/cluster/GetRequestStatusWebRequest.java @@ -0,0 +1,78 @@ +/* + * 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.funtest.server.api.cluster; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * Gets the status of a request by request id. For example: + * curl --user admin:admin -i -X GET http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/requests/9 + * curl --user admin:admin -i -X GET http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/requests/9/tasks/101 + * + * Response: + * { + * "href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/requests/9/tasks/101", + * "Tasks" : { + * ... + * "status" : "COMPLETED", + * ... + * } + * } + */ +public class GetRequestStatusWebRequest extends AmbariHttpWebRequest { + private String clusterName; + private int requestId; + private int taskId; + private static String pathFormat = "/api/v1/clusters/%s/requests/%d"; + private static String pathFormatWithTask = "/api/v1/clusters/%s/requests/%d/tasks/%d"; + + public GetRequestStatusWebRequest(ConnectionParams params, String clusterName, int requestId) { + this(params, clusterName, requestId, -1); + } + + public GetRequestStatusWebRequest(ConnectionParams params, String clusterName, int requestId, int taskId) { + super(params); + this.clusterName = clusterName; + this.requestId = requestId; + this.taskId = taskId; + } + + public String getClusterName() { return this.clusterName; } + + public int getRequestId() { return this.requestId; } + + @Override + public String getHttpMethod() { + return "GET"; + } + + /** + * Get REST API path fragment for construction full URI. + * + * @return - REST API path + */ + @Override + protected String getApiPath() { + if (taskId != -1) + return String.format(pathFormatWithTask, clusterName, requestId, taskId); + + return String.format(pathFormat, clusterName, requestId); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/AddHostWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/AddHostWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/AddHostWebRequest.java new file mode 100644 index 0000000..70b0642 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/AddHostWebRequest.java @@ -0,0 +1,63 @@ +/* + * 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.funtest.server.api.host; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * Adds a host to an existing cluster. + */ +public class AddHostWebRequest extends AmbariHttpWebRequest { + private String clusterName = null; + private String hostName = null; + private static String pathFormat = "/api/v1/clusters/%s/hosts/%s"; + + /** + * Adds the specified host to an existing cluster. + * + * @param params - Ambari connection information. + * @param clusterName - Existing cluster name. + * @param hostName - New host name. Host must have been registered previously using RegisterHostWebRequest. + */ + public AddHostWebRequest(ConnectionParams params, String clusterName, String hostName) { + super(params); + this.clusterName = clusterName; + this.hostName = hostName; + } + + public String getClusterName() { return this.clusterName; } + + 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, clusterName, hostName); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetHostWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetHostWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetHostWebRequest.java new file mode 100644 index 0000000..d4fa154 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetHostWebRequest.java @@ -0,0 +1,56 @@ +/* + * 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.funtest.server.api.host; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * Gets the host identitied by the cluster name and host name. + */ +public class GetHostWebRequest extends AmbariHttpWebRequest { + private String clusterName = null; + private String hostName = null; + private static String pathFormat = "/api/v1/clusters/%s/hosts/%s"; + + public GetHostWebRequest(ConnectionParams params, String clusterName, String hostName) { + super(params); + this.clusterName = clusterName; + this.hostName = hostName; + } + + public String getClusterName() { return this.clusterName; } + + public String getHostName() { return this.hostName; } + + @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); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetRegisteredHostWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetRegisteredHostWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetRegisteredHostWebRequest.java new file mode 100644 index 0000000..95c2168 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/GetRegisteredHostWebRequest.java @@ -0,0 +1,59 @@ +/* + * 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.funtest.server.api.host; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * Gets a host that was previously registered with Ambari. Use this + * method to verify if a host was registered. + */ +public class GetRegisteredHostWebRequest extends AmbariHttpWebRequest { + private String hostName = null; + private static String pathFormat = "/api/v1/hosts/%s"; + + /** + * Gets the host information for a registered host. + * + * @param params - Ambari server connection information. + * @param hostName - Name of the registered host. + */ + public GetRegisteredHostWebRequest(ConnectionParams params, String hostName) { + super(params); + this.hostName = hostName; + } + + public String getHostName() { return this.hostName; } + + @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, hostName); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/RegisterHostWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/RegisterHostWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/RegisterHostWebRequest.java new file mode 100644 index 0000000..1a50b64 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/host/RegisterHostWebRequest.java @@ -0,0 +1,59 @@ +/* + * 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.funtest.server.api.host; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * 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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/AddServiceWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/AddServiceWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/AddServiceWebRequest.java new file mode 100644 index 0000000..43f4109 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/AddServiceWebRequest.java @@ -0,0 +1,98 @@ +/* + * 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.funtest.server.api.service; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * 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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/DeleteServiceWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/DeleteServiceWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/DeleteServiceWebRequest.java new file mode 100644 index 0000000..f1adaa9 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/DeleteServiceWebRequest.java @@ -0,0 +1,67 @@ +/* + * 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.funtest.server.api.service; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * 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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/GetServiceWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/GetServiceWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/GetServiceWebRequest.java new file mode 100644 index 0000000..cf8f280 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/GetServiceWebRequest.java @@ -0,0 +1,67 @@ +/* + * 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.funtest.server.api.service; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * 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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/InstallServiceWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/InstallServiceWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/InstallServiceWebRequest.java new file mode 100644 index 0000000..0837066 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/InstallServiceWebRequest.java @@ -0,0 +1,39 @@ +/* + * 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.funtest.server.api.service; + +import org.apache.ambari.funtest.server.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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/SetServiceStateWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/SetServiceStateWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/SetServiceStateWebRequest.java new file mode 100644 index 0000000..a6c2530 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/SetServiceStateWebRequest.java @@ -0,0 +1,97 @@ +/* + * 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.funtest.server.api.service; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; +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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StartServiceWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StartServiceWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StartServiceWebRequest.java new file mode 100644 index 0000000..d33db00 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StartServiceWebRequest.java @@ -0,0 +1,38 @@ +/* + * 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.funtest.server.api.service; + +import org.apache.ambari.funtest.server.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-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StopServiceWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StopServiceWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StopServiceWebRequest.java new file mode 100644 index 0000000..d40e8b6 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/service/StopServiceWebRequest.java @@ -0,0 +1,38 @@ +/* + * 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.funtest.server.api.service; + +import org.apache.ambari.funtest.server.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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/AddServiceComponentWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/AddServiceComponentWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/AddServiceComponentWebRequest.java new file mode 100644 index 0000000..3ff4201 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/AddServiceComponentWebRequest.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.funtest.server.api.servicecomponent; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * 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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/GetServiceComponentWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/GetServiceComponentWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/GetServiceComponentWebRequest.java new file mode 100644 index 0000000..3f96c1c --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/GetServiceComponentWebRequest.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.funtest.server.api.servicecomponent; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +/** + * 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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/SetServiceComponentStateWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/SetServiceComponentStateWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponent/SetServiceComponentStateWebRequest.java new file mode 100644 index 0000000..f74fcea --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/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.funtest.server.api.servicecomponent; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; +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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/AddServiceComponentHostWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/AddServiceComponentHostWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/AddServiceComponentHostWebRequest.java new file mode 100644 index 0000000..2bd3960 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/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.funtest.server.api.servicecomponenthost; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/BulkAddServiceComponentHostsWebRequest.java new file mode 100644 index 0000000..82b4b93 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/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.funtest.server.api.servicecomponenthost; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; + +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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/BulkSetServiceComponentHostStateWebRequest.java new file mode 100644 index 0000000..81b920a --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/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.funtest.server.api.servicecomponenthost; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.ConnectionParams; +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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/GetServiceComponentHostWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/GetServiceComponentHostWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/GetServiceComponentHostWebRequest.java new file mode 100644 index 0000000..b9a126e --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/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.funtest.server.api.servicecomponenthost; + +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.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-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/api/servicecomponenthost/SetServiceComponentHostStateWebRequest.java new file mode 100644 index 0000000..e758904 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/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.funtest.server.api.servicecomponenthost; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.AmbariHttpWebRequest; +import org.apache.ambari.funtest.server.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-funtest/src/test/java/org/apache/ambari/funtest/server/orm/InMemoryDefaultTestModule.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/orm/InMemoryDefaultTestModule.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/orm/InMemoryDefaultTestModule.java new file mode 100644 index 0000000..7b49611 --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/orm/InMemoryDefaultTestModule.java @@ -0,0 +1,88 @@ +package org.apache.ambari.funtest.server.orm; + +/** + * 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. + */ + +import java.io.File; +import java.util.Collections; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +import org.apache.ambari.server.configuration.Configuration; +import org.apache.ambari.server.controller.ControllerModule; +import org.springframework.beans.factory.config.BeanDefinition; + +import com.google.inject.AbstractModule; + +public class InMemoryDefaultTestModule extends AbstractModule { + + /** + * Saves all {@link ControllerModule} logic, but changes bean discovery mechanism. + * In this implementation scan for {@link org.apache.ambari.server.EagerSingleton} + * and {@link org.apache.ambari.server.StaticallyInject} and + * {@link org.apache.ambari.server.AmbariService} annotations will not be run for every test. + */ + private static class BeanDefinitionsCachingTestControllerModule extends ControllerModule { + + // Access should be synchronised to allow concurrent test runs. + private static final AtomicReference<Set<BeanDefinition>> foundBeanDefinitions + = new AtomicReference<Set<BeanDefinition>>(null); + + public BeanDefinitionsCachingTestControllerModule(Properties properties) throws Exception { + super(properties); + } + + @Override + protected Set<BeanDefinition> bindByAnnotation(Set<BeanDefinition> beanDefinitions) { + Set<BeanDefinition> newBeanDefinitions = super.bindByAnnotation(foundBeanDefinitions.get()); + foundBeanDefinitions.compareAndSet(null, Collections.unmodifiableSet(newBeanDefinitions)); + return null; + } + } + + Properties properties = new Properties(); + + @Override + protected void configure() { + String stacks = "src/test/resources/stacks"; + String version = "src/test/resources/version"; + String sharedResourcesDir = "src/test/resources/"; + if (System.getProperty("os.name").contains("Windows")) { + stacks = ClassLoader.getSystemClassLoader().getResource("stacks").getPath(); + version = new File(new File(ClassLoader.getSystemClassLoader().getResource("").getPath()).getParent(), "version").getPath(); + sharedResourcesDir = ClassLoader.getSystemClassLoader().getResource("").getPath(); + } + + properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory"); + properties.setProperty(Configuration.METADATA_DIR_PATH, stacks); + properties.setProperty(Configuration.SERVER_VERSION_FILE, version); + properties.setProperty(Configuration.OS_VERSION_KEY, "centos6"); + properties.setProperty(Configuration.SHARED_RESOURCES_DIR_KEY, sharedResourcesDir); + + try { + install(new BeanDefinitionsCachingTestControllerModule(properties)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Properties getProperties() { + return properties; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/ffb4d3b8/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/DeleteServiceTest.java new file mode 100644 index 0000000..3f38acf --- /dev/null +++ b/ambari-funtest/src/test/java/org/apache/ambari/funtest/server/tests/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.funtest.server.tests; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import org.apache.ambari.funtest.server.ConnectionParams; +import org.apache.ambari.funtest.server.WebResponse; +import org.apache.ambari.funtest.server.api.service.DeleteServiceWebRequest; +import org.apache.ambari.funtest.server.api.service.GetServiceWebRequest; +import org.apache.ambari.funtest.server.api.service.StopServiceWebRequest; +import org.apache.ambari.funtest.server.utils.ClusterUtils; +import org.apache.ambari.funtest.server.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
