You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2017/12/26 14:10:06 UTC
ambari git commit: AMBARI-22249. Add service group
dependencies.(vbrodetskyi)
Repository: ambari
Updated Branches:
refs/heads/branch-feature-AMBARI-14714 6a7f5b1bc -> 765fb1c1a
AMBARI-22249. Add service group dependencies.(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/765fb1c1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/765fb1c1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/765fb1c1
Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 765fb1c1affb0d83e9cf51d2a52627fccb8b6d71
Parents: 6a7f5b1
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Tue Dec 26 16:09:38 2017 +0200
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Tue Dec 26 16:09:38 2017 +0200
----------------------------------------------------------------------
.../server/api/services/ServiceGroupKey.java | 10 +
.../ServiceGroupDependencyRequest.java | 35 +-
.../ServiceGroupDependencyResponse.java | 37 +-
.../ServiceGroupDependencyResourceProvider.java | 109 ++--
.../entities/ServiceGroupDependencyEntity.java | 8 +
.../ambari/server/state/ServiceGroupImpl.java | 4 +-
...viceGroupDependencyResourceProviderTest.java | 527 +++++++++++++++++++
7 files changed, 668 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceGroupKey.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceGroupKey.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceGroupKey.java
index 9389f0c..bb8ca83 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceGroupKey.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceGroupKey.java
@@ -27,6 +27,8 @@ public class ServiceGroupKey {
private String clusterName;
private String serviceGroupName;
+ private Long dependencyId;
+
@JsonProperty("cluster_name")
public String getClusterName() {
return clusterName;
@@ -61,6 +63,14 @@ public class ServiceGroupKey {
this.serviceGroupId = serviceGroupId;
}
+ public Long getDependencyId() {
+ return dependencyId;
+ }
+
+ public void setDependencyId(Long dependencyId) {
+ this.dependencyId = dependencyId;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyRequest.java
index 9f4eea3..f7cd738 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyRequest.java
@@ -22,12 +22,17 @@ public class ServiceGroupDependencyRequest {
private String clusterName; // REF
private String serviceGroupName; // GET/CREATE/UPDATE/DELETE
- private Long dependencyServiceGroupId;
+ private String dependentServiceGroupClusterName;
+ private String dependentServiceGroupName;
+ private Long dependencyId;
- public ServiceGroupDependencyRequest(String clusterName, String serviceGroupName, Long dependencyServiceGroupId) {
+ public ServiceGroupDependencyRequest(String clusterName, String serviceGroupName, String dependentServiceGroupClusterName,
+ String dependentServiceGroupName, Long dependencyId) {
this.clusterName = clusterName;
this.serviceGroupName = serviceGroupName;
- this.dependencyServiceGroupId = dependencyServiceGroupId;
+ this.dependentServiceGroupName = dependentServiceGroupName;
+ this.dependentServiceGroupClusterName = dependentServiceGroupClusterName;
+ this.dependencyId = dependencyId;
}
/**
@@ -58,12 +63,28 @@ public class ServiceGroupDependencyRequest {
this.serviceGroupName = serviceGroupName;
}
- public Long getDependencyServiceGroupId() {
- return dependencyServiceGroupId;
+ public Long getDependencyId() {
+ return dependencyId;
}
- public void setDependencyServiceGroupId(Long dependencyServiceGroupId) {
- this.dependencyServiceGroupId = dependencyServiceGroupId;
+ public void setDependencyId(Long dependencyId) {
+ this.dependencyId = dependencyId;
+ }
+
+ public String getDependentServiceGroupName() {
+ return dependentServiceGroupName;
+ }
+
+ public void setDependentServiceGroupName(String dependentServiceGroupName) {
+ this.dependentServiceGroupName = dependentServiceGroupName;
+ }
+
+ public String getDependentServiceGroupClusterName() {
+ return dependentServiceGroupClusterName;
+ }
+
+ public void setDependentServiceGroupClusterName(String dependentServiceGroupClusterName) {
+ this.dependentServiceGroupClusterName = dependentServiceGroupClusterName;
}
public String toString() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyResponse.java
index 1a4b4ed..efa36f4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupDependencyResponse.java
@@ -26,6 +26,7 @@ public class ServiceGroupDependencyResponse {
private Long serviceGroupId;
private Long dependencyClusterId;
private Long dependencyGroupId;
+ private Long dependencyId;
private String clusterName;
private String serviceGroupName;
private String dependencyGroupName;
@@ -33,7 +34,7 @@ public class ServiceGroupDependencyResponse {
public ServiceGroupDependencyResponse(Long clusterId, String clusterName, Long serviceGroupId, String serviceGroupName,
Long dependencyClusterId, String dependencyClusterName,
- Long dependencyGroupId, String dependencyGroupName) {
+ Long dependencyGroupId, String dependencyGroupName, Long dependencyId) {
this.clusterId = clusterId;
this.serviceGroupId = serviceGroupId;
this.clusterName = clusterName;
@@ -42,6 +43,7 @@ public class ServiceGroupDependencyResponse {
this.dependencyGroupName = dependencyGroupName;
this.dependencyClusterId = dependencyClusterId;
this.dependencyClusterName = dependencyClusterName;
+ this.dependencyId = dependencyId;
}
/**
@@ -132,29 +134,38 @@ public class ServiceGroupDependencyResponse {
this.dependencyClusterName = dependencyClusterName;
}
+ public Long getDependencyId() {
+ return dependencyId;
+ }
+
+ public void setDependencyId(Long dependencyId) {
+ this.dependencyId = dependencyId;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (!(o instanceof ServiceGroupDependencyResponse)) return false;
- ServiceGroupResponse that = (ServiceGroupResponse) o;
+ ServiceGroupDependencyResponse that = (ServiceGroupDependencyResponse) o;
- if (clusterId != null ?
- !clusterId.equals(this.clusterId) : this.clusterId != null) {
+ if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
+ if (dependencyGroupId != null ? !dependencyGroupId.equals(that.dependencyGroupId) : that.dependencyGroupId != null)
return false;
- }
- if (clusterName != null ?
- !clusterName.equals(this.clusterName) : this.clusterName != null) {
+ if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : that.serviceGroupId != null)
return false;
- }
- if (serviceGroupName != null ?
- !serviceGroupName.equals(this.serviceGroupName) : this.serviceGroupName != null) {
- return false;
- }
return true;
}
+ @Override
+ public int hashCode() {
+ int result = clusterId != null ? clusterId.hashCode() : 0;
+ result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() : 0);
+ result = 31 * result + (dependencyGroupId != null ? dependencyGroupId.hashCode() : 0);
+ return result;
+ }
+
/**
* Interface to help correct Swagger documentation generation
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProvider.java
index aac7102..e19e6e3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProvider.java
@@ -74,10 +74,11 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
public static final String SERVICE_GROUP_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "cluster_name";
public static final String SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_group_id";
public static final String SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_group_name";
- public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependency_cluster_id";
- public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependency_cluster_name";
- public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependency_service_group_id";
- public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependency_service_group_name";
+ public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependent_cluster_id";
+ public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependent_cluster_name";
+ public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependent_service_group_id";
+ public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependent_service_group_name";
+ public static final String SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "dependency_id";
protected ObjectMapper mapper = new ObjectMapper();;
@@ -85,7 +86,7 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
new HashSet<String>(Arrays.asList(new String[]{
SERVICE_GROUP_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID,
SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID,
- SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID}));
+ SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID}));
private static Gson gson = StageUtils.getGson();
@@ -105,15 +106,16 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID);
PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID);
PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID);
- PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_ID_PROPERTY_ID);
- PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID);
- PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID);
- PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID);
+ PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_ID_PROPERTY_ID);
+ PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_NAME_PROPERTY_ID);
+ PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_ID_PROPERTY_ID);
+ PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_NAME_PROPERTY_ID);
+ PROPERTY_IDS.add(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID);
// keys
KEY_PROPERTY_IDS.put(Resource.Type.Cluster, SERVICE_GROUP_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID);
KEY_PROPERTY_IDS.put(Resource.Type.ServiceGroup, SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID);
- KEY_PROPERTY_IDS.put(Resource.Type.ServiceGroupDependency, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID);
+ KEY_PROPERTY_IDS.put(Resource.Type.ServiceGroupDependency, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID);
}
private Clusters clusters;
@@ -167,10 +169,11 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
resource.setProperty(SERVICE_GROUP_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID, response.getClusterName());
resource.setProperty(SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID, response.getServiceGroupId());
resource.setProperty(SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID, response.getServiceGroupName());
- resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_ID_PROPERTY_ID, response.getDependencyClusterId());
- resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID, response.getDependencyClusterName());
- resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID, response.getDependencyGroupId());
- resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID, response.getDependencyGroupName());
+ resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_ID_PROPERTY_ID, response.getDependencyClusterId());
+ resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_NAME_PROPERTY_ID, response.getDependencyClusterName());
+ resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_ID_PROPERTY_ID, response.getDependencyGroupId());
+ resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_NAME_PROPERTY_ID, response.getDependencyGroupName());
+ resource.setProperty(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID, response.getDependencyId());
associatedResources.add(resource);
}
@@ -210,14 +213,16 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
response.getServiceGroupId(), requestedIds);
setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID,
response.getServiceGroupName(), requestedIds);
- setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_ID_PROPERTY_ID,
+ setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_ID_PROPERTY_ID,
response.getDependencyClusterId(), requestedIds);
- setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID,
+ setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_NAME_PROPERTY_ID,
response.getDependencyClusterName(), requestedIds);
- setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID,
+ setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_ID_PROPERTY_ID,
response.getDependencyGroupId(), requestedIds);
- setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID,
+ setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_NAME_PROPERTY_ID,
response.getDependencyGroupName(), requestedIds);
+ setResourceProperty(resource, SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID,
+ response.getDependencyId(), requestedIds);
resources.add(resource);
}
return resources;
@@ -253,7 +258,7 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
notifyDelete(Resource.Type.ServiceGroupDependency, predicate);
for(ServiceGroupDependencyRequest svgReq : requests) {
deleteStatusMetaData.addDeletedKey("cluster_name: " + svgReq.getClusterName() + ", " + " service_group_name: " + svgReq.getServiceGroupName()
- + " dependency_service_group_id: " + svgReq.getDependencyServiceGroupId());
+ + " dependency_id: " + svgReq.getDependencyId());
}
return getRequestStatus(null, null, deleteStatusMetaData);
}
@@ -288,9 +293,12 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
private ServiceGroupDependencyRequest getRequest(Map<String, Object> properties) {
String clusterName = (String) properties.get(SERVICE_GROUP_DEPENDENCY_CLUSTER_NAME_PROPERTY_ID);
String serviceGroupName = (String) properties.get(SERVICE_GROUP_DEPENDENCY_SERVICE_GROUP_NAME_PROPERTY_ID);
- String strdependencyServiceGroupId = (String)properties.get(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_SERVICE_GROUP_ID_PROPERTY_ID);
- Long dependencyServiceGroupId = strdependencyServiceGroupId == null ? null : Long.valueOf(strdependencyServiceGroupId);
- ServiceGroupDependencyRequest svcRequest = new ServiceGroupDependencyRequest(clusterName, serviceGroupName, dependencyServiceGroupId);
+ String dependentServiceGroupClusterName = (String) properties.get(SERVICE_GROUP_DEPENDENCY_DEPENDENT_CLUSTER_NAME_PROPERTY_ID);
+ String dependentServiceGroupName = (String) properties.get(SERVICE_GROUP_DEPENDENCY_DEPENDENT_SERVICE_GROUP_NAME_PROPERTY_ID);
+ String strdependencyId = (String)properties.get(SERVICE_GROUP_DEPENDENCY_DEPENDENCY_ID_PROPERTY_ID);
+ Long dependencyId = strdependencyId == null ? null : Long.valueOf(strdependencyId);
+ ServiceGroupDependencyRequest svcRequest = new ServiceGroupDependencyRequest(clusterName, serviceGroupName, dependentServiceGroupClusterName,
+ dependentServiceGroupName, dependencyId);
return svcRequest;
}
@@ -312,9 +320,17 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
Set<ServiceGroupDependencyResponse> createdServiceGroupDependencies = new HashSet<>();
for (ServiceGroupDependencyRequest request : requests) {
Cluster cluster = clusters.getCluster(request.getClusterName());
+ String dependentServiceGroupClusterName = request.getClusterName();
+
+ //find dependent service group
+ if (StringUtils.isNotEmpty(request.getDependentServiceGroupClusterName())) {
+ dependentServiceGroupClusterName = request.getDependentServiceGroupClusterName();
+ }
+ Cluster dependentServiceGroupCluster = clusters.getCluster(dependentServiceGroupClusterName);
+ ServiceGroup serviceGroup = dependentServiceGroupCluster.getServiceGroup(request.getDependentServiceGroupName());
// Already checked that service group does not exist
- cluster.addServiceGroupDependency(request.getServiceGroupName(), request.getDependencyServiceGroupId());
+ cluster.addServiceGroupDependency(request.getServiceGroupName(), serviceGroup.getServiceGroupId());
createdServiceGroupDependencies.addAll(cluster.getServiceGroup(request.getServiceGroupName()).getServiceGroupDependencyResponses());
}
return createdServiceGroupDependencies;
@@ -393,18 +409,20 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
" dependencies, so nothing to remove.");
} else {
boolean dependencyAvailable = false;
+ long dependentServiceGroupId = 0L;
for (ServiceGroupKey dependencyServiceGroupKey : dependencyServiceGroupKeys) {
- if (dependencyServiceGroupKey.getServiceGroupId() == serviceGroupDependencyRequest.getDependencyServiceGroupId()) {
+ if (dependencyServiceGroupKey.getDependencyId() == serviceGroupDependencyRequest.getDependencyId()) {
dependencyAvailable = true;
+ dependentServiceGroupId = dependencyServiceGroupKey.getServiceGroupId();
}
}
if (!dependencyAvailable) {
throw new AmbariException("Servcie group name " + serviceGroupDependencyRequest.getServiceGroupName() + " has no" +
- "dependency with id=" + serviceGroupDependencyRequest.getDependencyServiceGroupId() + ", so nothing to remove.");
+ "dependency with id=" + serviceGroupDependencyRequest.getDependencyId() + ", so nothing to remove.");
}
serviceGroup.getCluster().deleteServiceGroupDependency(serviceGroupDependencyRequest.getServiceGroupName(),
- serviceGroupDependencyRequest.getDependencyServiceGroupId());
+ dependentServiceGroupId);
}
}
}
@@ -417,26 +435,37 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
for (ServiceGroupDependencyRequest request : requests) {
final String clusterName = request.getClusterName();
final String serviceGroupName = request.getServiceGroupName();
- final Long dependencyServiceGroupId = request.getDependencyServiceGroupId();
+ String dependentServiceGroupClusterName = request.getDependentServiceGroupClusterName();
+ final String dependentServiceGroupName = request.getDependentServiceGroupName();
- Validate.notNull(clusterName, "Cluster name should be provided when creating a service group");
+ Validate.notNull(clusterName, "Cluster name should be provided when creating a service group dependency");
+ Validate.notNull(serviceGroupName, "Service group name should be provided when creating a service group dependency");
+ Validate.notNull(dependentServiceGroupName, "Dependent service group name should be provided when creating a service group dependency");
// validating service group dependencies
- if (dependencyServiceGroupId == null) {
- throw new AmbariException("Service group name id has is null!");
+ Long dependentServiceGroupId = null;
+ if (StringUtils.isEmpty(dependentServiceGroupName)) {
+
+ throw new AmbariException("Dependent Service group name is null or empty!");
+
} else {
- boolean dependencyServiceGroupAvailable = false;
- for (Cluster cl : clusters.getClusters().values()) {
- if (cl.getServiceGroupsById().containsKey(dependencyServiceGroupId)) {
- dependencyServiceGroupAvailable = true;
+
+ try {
+ if (StringUtils.isEmpty(dependentServiceGroupClusterName)) {
+ dependentServiceGroupClusterName = clusterName;
}
+ Cluster cluster = clusters.getCluster(dependentServiceGroupClusterName);
+
+ ServiceGroup dependentServiceGroup = cluster.getServiceGroup(dependentServiceGroupName);
+ dependentServiceGroupId = dependentServiceGroup.getServiceGroupId();
+ } catch (ClusterNotFoundException e) {
+ throw new ParentObjectNotFoundException("Attempted to add a service group dependency to a cluster which doesn't exist", e);
+ } catch (ServiceGroupNotFoundException e) {
+ throw new AmbariException(String.format("Unable to find dependent service group %s in cluster %s",
+ dependentServiceGroupName, dependentServiceGroupClusterName), e);
}
- if (!dependencyServiceGroupAvailable) {
- throw new AmbariException("Service group with id=" + dependencyServiceGroupId + " is not available.");
- }
- }
- Validate.notEmpty(serviceGroupName, "Service group name should be provided when adding a service group dependency");
+ }
if (LOG.isDebugEnabled()) {
LOG.debug("Received a createServiceGroupDependency request" +
@@ -460,7 +489,7 @@ public class ServiceGroupDependencyResourceProvider extends AbstractControllerRe
Set<ServiceGroupKey> dependencies = sg.getServiceGroupDependencies();
if (dependencies != null) {
for (ServiceGroupKey serviceGroupKey : dependencies) {
- if (serviceGroupKey.getServiceGroupId() == dependencyServiceGroupId) {
+ if (serviceGroupKey.getServiceGroupId() == dependentServiceGroupId) {
throw new AmbariException("Service group " + serviceGroupName + " already have dependency for service group "
+ serviceGroupKey.getServiceGroupName());
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupDependencyEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupDependencyEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupDependencyEntity.java
index ee0beeb..4c1b5d3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupDependencyEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupDependencyEntity.java
@@ -92,6 +92,14 @@ public class ServiceGroupDependencyEntity {
this.serviceGroupDependency = serviceGroupDependency;
}
+ public Long getServiceGroupDependencyId() {
+ return serviceGroupDependencyId;
+ }
+
+ public void setServiceGroupDependencyId(Long serviceGroupDependencyId) {
+ this.serviceGroupDependencyId = serviceGroupDependencyId;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupImpl.java
index 914b65a..dcc8433 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupImpl.java
@@ -42,7 +42,6 @@ import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import com.google.inject.persist.Transactional;
-
public class ServiceGroupImpl implements ServiceGroup {
private static final Logger LOG = LoggerFactory.getLogger(ServiceGroupImpl.class);
@@ -159,7 +158,7 @@ public class ServiceGroupImpl implements ServiceGroup {
if (getServiceGroupDependencies() != null) {
for (ServiceGroupKey sgk : getServiceGroupDependencies()) {
responses.add(new ServiceGroupDependencyResponse(cluster.getClusterId(), cluster.getClusterName(),
- serviceGroupId, serviceGroupName, sgk.getClusterId(), sgk.getClusterName(), sgk.getServiceGroupId(), sgk.getServiceGroupName()));
+ serviceGroupId, serviceGroupName, sgk.getClusterId(), sgk.getClusterName(), sgk.getServiceGroupId(), sgk.getServiceGroupName(), sgk.getDependencyId()));
}
}
return responses;
@@ -203,6 +202,7 @@ public class ServiceGroupImpl implements ServiceGroup {
serviceGroupKey.setServiceGroupId(serviceGroupDependencId);
serviceGroupKey.setClusterName(clusterName);
serviceGroupKey.setClusterId(clusterId);
+ serviceGroupKey.setDependencyId(sgde.getServiceGroupDependencyId());
serviceGroupDependenciesList.add(serviceGroupKey);
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/765fb1c1/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java
new file mode 100644
index 0000000..bed3689
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java
@@ -0,0 +1,527 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.controller.internal;
+
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.persistence.EntityManager;
+
+import org.apache.ambari.server.H2DatabaseCleaner;
+import org.apache.ambari.server.actionmanager.ActionDBAccessor;
+import org.apache.ambari.server.actionmanager.ActionManager;
+import org.apache.ambari.server.actionmanager.HostRoleCommand;
+import org.apache.ambari.server.actionmanager.StageFactory;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.ClusterRequest;
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
+import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.ServiceComponentHostRequest;
+import org.apache.ambari.server.controller.ServiceComponentRequest;
+import org.apache.ambari.server.controller.ServiceGroupDependencyRequest;
+import org.apache.ambari.server.controller.ServiceGroupDependencyResponse;
+import org.apache.ambari.server.controller.ServiceRequest;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
+import org.apache.ambari.server.orm.dao.HostDAO;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
+import org.apache.ambari.server.orm.dao.ServiceGroupDAO;
+import org.apache.ambari.server.orm.dao.TopologyHostInfoDAO;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.security.TestAuthenticationFactory;
+import org.apache.ambari.server.stack.StackManagerMock;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.SecurityType;
+import org.apache.ambari.server.state.ServiceComponentFactory;
+import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.ServiceGroup;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
+import org.apache.ambari.server.topology.TopologyManager;
+import org.apache.ambari.server.utils.EventBusSynchronizer;
+import org.apache.ambari.server.utils.StageUtils;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+
+public class ServiceGroupDependencyResourceProviderTest {
+
+ private static final String SERVICE_GROUP_NAME_CORE = "CORE";
+ private static final String SERVICE_GROUP_NAME_TEST = "TEST";
+
+ private static AmbariManagementController controller;
+ private static Clusters clusters;
+ private ActionDBAccessor actionDB;
+ private static Injector injector;
+ private ServiceFactory serviceFactory;
+ private ServiceComponentFactory serviceComponentFactory;
+ private ServiceComponentHostFactory serviceComponentHostFactory;
+ private static AmbariMetaInfo ambariMetaInfo;
+ private EntityManager entityManager;
+ private static Properties backingProperties;
+ private Configuration configuration;
+ private ConfigHelper configHelper;
+ private ConfigGroupFactory configGroupFactory;
+ private OrmTestHelper helper;
+ private StageFactory stageFactory;
+ private HostDAO hostDAO;
+ private ServiceGroupDAO serviceGroupDAO;
+ private ClusterServiceDAO serviceDAO;
+ private TopologyHostInfoDAO topologyHostInfoDAO;
+ private HostRoleCommandDAO hostRoleCommandDAO;
+ private StackManagerMock stackManagerMock;
+ private RepositoryVersionDAO repositoryVersionDAO;
+
+ RepositoryVersionEntity repositoryVersion206;
+
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
+ backingProperties = module.getProperties();
+ injector = Guice.createInjector(module);
+ H2DatabaseCleaner.resetSequences(injector);
+ injector.getInstance(GuiceJpaInitializer.class);
+ ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+ ambariMetaInfo.init();
+ clusters = injector.getInstance(Clusters.class);
+ controller = injector.getInstance(AmbariManagementController.class);
+ TopologyManager topologyManager = injector.getInstance(TopologyManager.class);
+ StageUtils.setTopologyManager(topologyManager);
+ Configuration configuration = injector.getInstance(Configuration.class);
+ StageUtils.setConfiguration(configuration);
+ ActionManager.setTopologyManager(topologyManager);
+
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
+ }
+
+ @Before
+ public void setup() throws Exception {
+ EventBusSynchronizer.synchronizeAmbariEventPublisher(injector);
+
+ entityManager = injector.getProvider(EntityManager.class).get();
+ actionDB = injector.getInstance(ActionDBAccessor.class);
+ serviceFactory = injector.getInstance(ServiceFactory.class);
+ serviceComponentFactory = injector.getInstance(
+ ServiceComponentFactory.class);
+ serviceComponentHostFactory = injector.getInstance(
+ ServiceComponentHostFactory.class);
+ configuration = injector.getInstance(Configuration.class);
+ configHelper = injector.getInstance(ConfigHelper.class);
+ configGroupFactory = injector.getInstance(ConfigGroupFactory.class);
+ helper = injector.getInstance(OrmTestHelper.class);
+ stageFactory = injector.getInstance(StageFactory.class);
+ hostDAO = injector.getInstance(HostDAO.class);
+ serviceGroupDAO = injector.getInstance(ServiceGroupDAO.class);
+ serviceDAO = injector.getInstance(ClusterServiceDAO.class);
+ topologyHostInfoDAO = injector.getInstance(TopologyHostInfoDAO.class);
+ hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+ stackManagerMock = (StackManagerMock) ambariMetaInfo.getStackManager();
+ EasyMock.replay(injector.getInstance(AuditLogger.class));
+
+ repositoryVersion206 = helper.getOrCreateRepositoryVersion(
+ new StackId("HDP-2.0.6"), "2.0.6-1234");
+
+
+
+ repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
+ }
+
+ @After
+ public void teardown() {
+ actionDB = null;
+ EasyMock.reset(injector.getInstance(AuditLogger.class));
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
+ }
+
+ private static String getUniqueName() {
+ return UUID.randomUUID().toString();
+ }
+
+ private void setOsFamily(Host host, String osFamily, String osVersion) {
+ Map<String, String> hostAttributes = new HashMap<>();
+ hostAttributes.put("os_family", osFamily);
+ hostAttributes.put("os_release_version", osVersion);
+
+ host.setHostAttributes(hostAttributes);
+ }
+
+ private void addHost(String hostname) throws Exception {
+ addHostToCluster(hostname, null);
+ }
+
+ private void addHostToCluster(String hostname, String clusterName) throws Exception {
+
+ if (!clusters.hostExists(hostname)) {
+ clusters.addHost(hostname);
+ setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
+ clusters.getHost(hostname).setState(HostState.HEALTHY);
+ }
+
+ if (null != clusterName) {
+ clusters.mapHostToCluster(hostname, clusterName);
+ }
+ }
+
+
+ /**
+ * Creates a Cluster object, along with its corresponding ClusterVersion based on the stack.
+ * @param clusterName Cluster name
+ * @throws Exception
+ */
+ private void createCluster(String clusterName) throws Exception{
+ ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(), SecurityType.NONE, "HDP-0.1", null);
+ controller.createCluster(r);
+ }
+
+ private void createService(String clusterName, String serviceGroupName, String serviceName, State desiredState) throws Exception {
+ createService(clusterName, serviceGroupName, serviceName, repositoryVersion206, desiredState);
+ }
+
+ private void createService(String clusterName, String serviceGroupName, String serviceName,
+ RepositoryVersionEntity repositoryVersion, State desiredState
+ )
+ throws Exception {
+ String dStateStr = null;
+ if (desiredState != null) {
+ dStateStr = desiredState.toString();
+ }
+
+ ServiceRequest r1 = new ServiceRequest(clusterName, serviceGroupName, serviceName,
+ repositoryVersion.getId(), dStateStr,
+ null);
+
+ ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, Collections.singleton(r1));
+ }
+
+ private void createServiceComponent(String clusterName,
+ String serviceGroupName, String serviceName, String componentName, State desiredState
+ )
+ throws Exception {
+ String dStateStr = null;
+ if (desiredState != null) {
+ dStateStr = desiredState.toString();
+ }
+ ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName,
+ serviceName, componentName, dStateStr);
+ ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r));
+ }
+
+ private void createServiceComponentHost(String clusterName,
+ String serviceGroupName, String serviceName, String componentName, String hostname,
+ State desiredState
+ ) throws Exception {
+ String dStateStr = null;
+ if (desiredState != null) {
+ dStateStr = desiredState.toString();
+ }
+ ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName,
+ serviceName, componentName, hostname, dStateStr);
+ controller.createHostComponents(Collections.singleton(r));
+ }
+
+
+ private long installService(String clusterName, String serviceGroupName, String serviceName, boolean runSmokeTests, boolean reconfigureClients)
+ throws Exception {
+ return installService(clusterName, serviceGroupName, serviceName, runSmokeTests, reconfigureClients, null, null);
+ }
+
+
+ /**
+ * Allows to set maintenanceStateHelper. For use when there is anything to test
+ * with maintenance mode.
+ */
+ private long installService(String clusterName, String serviceGroupName, String serviceName,
+ boolean runSmokeTests, boolean reconfigureClients,
+ MaintenanceStateHelper maintenanceStateHelper,
+ Map<String, String> mapRequestPropsInput
+ )
+ throws Exception {
+
+ ServiceRequest r = new ServiceRequest(clusterName, serviceGroupName, serviceName, repositoryVersion206.getId(),
+ State.INSTALLED.toString(), null);
+
+ Set<ServiceRequest> requests = new HashSet<>();
+ requests.add(r);
+
+ Map<String, String> mapRequestProps = new HashMap<>();
+ mapRequestProps.put("context", "Called from a test");
+ if(mapRequestPropsInput != null) {
+ mapRequestProps.putAll(mapRequestPropsInput);
+ }
+
+ RequestStatusResponse resp = ServiceResourceProviderTest.updateServices(controller, requests,
+ mapRequestProps, runSmokeTests, reconfigureClients, maintenanceStateHelper);
+
+ Assert.assertEquals(State.INSTALLED,
+ clusters.getCluster(clusterName).getService(serviceName)
+ .getDesiredState());
+
+ if (resp != null) {
+ // manually change live state to stopped as no running action manager
+ List<HostRoleCommand> commands = actionDB.getRequestTasks(resp.getRequestId());
+ for (HostRoleCommand cmd : commands) {
+ clusters.getCluster(clusterName).getService(serviceName).getServiceComponent(cmd.getRole().name())
+ .getServiceComponentHost(cmd.getHostName()).setState(State.INSTALLED);
+ }
+ return resp.getRequestId();
+ } else {
+ return -1;
+ }
+ }
+
+
+ private Cluster setupClusterWithHosts(String clusterName, String stackId, List<String> hosts,
+ String osType) throws Exception {
+ ClusterRequest r = new ClusterRequest(null, clusterName, stackId, null);
+ controller.createCluster(r);
+ Cluster c1 = clusters.getCluster(clusterName);
+ for (String host : hosts) {
+ addHostToCluster(host, clusterName);
+ }
+ return c1;
+ }
+
+ private Cluster createDefaultCluster(String clusterName) throws Exception {
+ // !!! weird, but the assertions are banking on alphabetical order
+ final String host1 = "a" + getUniqueName();
+ final String host2 = "b" + getUniqueName();
+ final String host3 = "c" + getUniqueName();
+
+ setupClusterWithHosts(clusterName, "HDP-2.0.6", Arrays.asList(host1, host2, host3), "centos6");
+
+ Cluster cluster = clusters.getCluster(clusterName);
+ cluster.setDesiredStackVersion(new StackId("HDP-2.0.6"));
+ cluster.setCurrentStackVersion(new StackId("HDP-2.0.6"));
+
+ RepositoryVersionEntity repositoryVersion = repositoryVersion206;
+
+ ServiceGroup serviceGroupCore = cluster.addServiceGroup(SERVICE_GROUP_NAME_CORE);
+ ServiceGroup serviceGroupTest = cluster.addServiceGroup(SERVICE_GROUP_NAME_TEST);
+
+
+ return cluster;
+ }
+
+
+
+ @Test
+ public void testDefaultRequestForServiceGroupDependencyCreation() throws Exception {
+ final String cluster1 = getUniqueName();
+
+ Cluster cluster = createDefaultCluster(cluster1);
+
+ ServiceGroup serviceGroupCore = cluster.getServiceGroup(SERVICE_GROUP_NAME_CORE);
+ ServiceGroup serviceGroupTest = cluster.getServiceGroup(SERVICE_GROUP_NAME_TEST);
+
+ Set<ServiceGroupDependencyRequest> requests = new HashSet<>();
+ ServiceGroupDependencyRequest request = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ cluster1, serviceGroupTest.getServiceGroupName(), null);
+ requests.add(request);
+
+ ServiceGroupDependencyResourceProvider serviceGroupDependencyResourceProvider = new ServiceGroupDependencyResourceProvider(controller);
+ Set<ServiceGroupDependencyResponse> responses = serviceGroupDependencyResourceProvider.createServiceGroupDependencies(requests);
+
+ Assert.assertEquals(responses.size(), 1);
+
+ ServiceGroupDependencyResponse serviceGroupDependencyResponse = responses.iterator().next();
+
+ Assert.assertEquals(serviceGroupDependencyResponse.getServiceGroupName(), serviceGroupCore.getServiceGroupName());
+ Assert.assertEquals(serviceGroupDependencyResponse.getDependencyGroupName(), serviceGroupTest.getServiceGroupName());
+ Assert.assertEquals(serviceGroupDependencyResponse.getClusterName(), cluster1);
+ Assert.assertEquals(serviceGroupDependencyResponse.getDependencyClusterName(), cluster1);
+ }
+
+
+
+ @Test
+ public void testRequestWithInvalidServiceGroupName() throws Exception {
+ final String cluster1 = getUniqueName();
+
+ Cluster cluster = createDefaultCluster(cluster1);
+
+ ServiceGroup serviceGroupCore = cluster.getServiceGroup(SERVICE_GROUP_NAME_CORE);
+
+
+ Set<ServiceGroupDependencyRequest> requests = new HashSet<>();
+ ServiceGroupDependencyRequest request = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ cluster1, "invalid_service_group", null);
+ requests.add(request);
+
+ ServiceGroupDependencyResourceProvider serviceGroupDependencyResourceProvider = new ServiceGroupDependencyResourceProvider(controller);
+ boolean isFailed = false;
+ Exception exception = null;
+ try {
+ Set<ServiceGroupDependencyResponse> responses = serviceGroupDependencyResourceProvider.createServiceGroupDependencies(requests);
+ } catch (Exception e) {
+ isFailed = true;
+ exception = e;
+ }
+
+ Assert.assertTrue(isFailed);
+ Assert.assertTrue(exception.getMessage().contains("Unable to find dependent service group"));
+
+ }
+
+ @Test
+ public void testRequestWithInvalidClusterName() throws Exception {
+ final String cluster1 = getUniqueName();
+
+ Cluster cluster = createDefaultCluster(cluster1);
+
+ ServiceGroup serviceGroupCore = cluster.getServiceGroup(SERVICE_GROUP_NAME_CORE);
+ ServiceGroup serviceGroupTest = cluster.getServiceGroup(SERVICE_GROUP_NAME_TEST);
+
+
+ Set<ServiceGroupDependencyRequest> requests = new HashSet<>();
+ ServiceGroupDependencyRequest request = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ "invalid_cluster_name", serviceGroupTest.getServiceGroupName(), null);
+ requests.add(request);
+
+ ServiceGroupDependencyResourceProvider serviceGroupDependencyResourceProvider = new ServiceGroupDependencyResourceProvider(controller);
+ boolean isFailed = false;
+ Exception exception = null;
+ try {
+ Set<ServiceGroupDependencyResponse> responses = serviceGroupDependencyResourceProvider.createServiceGroupDependencies(requests);
+ } catch (Exception e) {
+ isFailed = true;
+ exception = e;
+ }
+
+ Assert.assertTrue(isFailed);
+ Assert.assertTrue(exception.getMessage().contains("Cluster not found"));
+
+ }
+
+
+ @Test
+ public void testDeleteRequestForServiceDependency() throws Exception {
+ final String cluster1 = getUniqueName();
+
+ Cluster cluster = createDefaultCluster(cluster1);
+
+ ServiceGroup serviceGroupCore = cluster.getServiceGroup(SERVICE_GROUP_NAME_CORE);
+ ServiceGroup serviceGroupTest = cluster.getServiceGroup(SERVICE_GROUP_NAME_TEST);
+
+ Set<ServiceGroupDependencyRequest> requests = new HashSet<>();
+ ServiceGroupDependencyRequest request = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ cluster1, serviceGroupTest.getServiceGroupName(), null);
+ requests.add(request);
+
+ ServiceGroupDependencyResourceProvider serviceGroupDependencyResourceProvider = new ServiceGroupDependencyResourceProvider(controller);
+ Set<ServiceGroupDependencyResponse> responses = serviceGroupDependencyResourceProvider.createServiceGroupDependencies(requests);
+
+ Assert.assertEquals(responses.size(), 1);
+
+ ServiceGroupDependencyResponse serviceGroupDependencyResponse = responses.iterator().next();
+
+ Assert.assertEquals(serviceGroupDependencyResponse.getServiceGroupName(), serviceGroupCore.getServiceGroupName());
+ Assert.assertEquals(serviceGroupDependencyResponse.getDependencyGroupName(), serviceGroupTest.getServiceGroupName());
+ Assert.assertEquals(serviceGroupDependencyResponse.getClusterName(), cluster1);
+ Assert.assertEquals(serviceGroupDependencyResponse.getDependencyClusterName(), cluster1);
+
+
+ Set<ServiceGroupDependencyRequest> deleteRequests = new HashSet<>();
+ ServiceGroupDependencyRequest deleteRequest = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ null, null, serviceGroupDependencyResponse.getDependencyId());
+ deleteRequests.add(deleteRequest);
+
+ serviceGroupDependencyResourceProvider.deleteServiceGroupDependencies(deleteRequests);
+ ServiceGroup updatedCoreServiceGroup = cluster.getServiceGroup(SERVICE_GROUP_NAME_CORE);
+
+ Assert.assertTrue(updatedCoreServiceGroup.getServiceGroupDependencies().isEmpty());
+
+ }
+
+ @Test
+ public void testGetRequestForServiceDependencyCreation() throws Exception {
+ final String cluster1 = getUniqueName();
+
+ Cluster cluster = createDefaultCluster(cluster1);
+
+ ServiceGroup serviceGroupCore = cluster.getServiceGroup(SERVICE_GROUP_NAME_CORE);
+ ServiceGroup serviceGroupTest = cluster.getServiceGroup(SERVICE_GROUP_NAME_TEST);
+
+ Set<ServiceGroupDependencyRequest> requests = new HashSet<>();
+ ServiceGroupDependencyRequest request = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ cluster1, serviceGroupTest.getServiceGroupName(), null);
+ requests.add(request);
+
+ ServiceGroupDependencyResourceProvider serviceGroupDependencyResourceProvider = new ServiceGroupDependencyResourceProvider(controller);
+ Set<ServiceGroupDependencyResponse> responses = serviceGroupDependencyResourceProvider.createServiceGroupDependencies(requests);
+
+ Assert.assertEquals(responses.size(), 1);
+
+ ServiceGroupDependencyResponse serviceGroupDependencyResponse = responses.iterator().next();
+
+ Assert.assertEquals(serviceGroupDependencyResponse.getServiceGroupName(), serviceGroupCore.getServiceGroupName());
+ Assert.assertEquals(serviceGroupDependencyResponse.getDependencyGroupName(), serviceGroupTest.getServiceGroupName());
+ Assert.assertEquals(serviceGroupDependencyResponse.getClusterName(), cluster1);
+ Assert.assertEquals(serviceGroupDependencyResponse.getDependencyClusterName(), cluster1);
+
+
+ Set<ServiceGroupDependencyRequest> getRequests = new HashSet<>();
+ ServiceGroupDependencyRequest getRequest = new ServiceGroupDependencyRequest(cluster1, serviceGroupCore.getServiceGroupName(),
+ null, null, serviceGroupDependencyResponse.getDependencyId());
+
+ Set<ServiceGroupDependencyResponse> getResponses = serviceGroupDependencyResourceProvider.getServiceGroupDependencies(getRequests);
+
+ Assert.assertEquals(responses.size(), 1);
+
+ ServiceGroupDependencyResponse getServiceGroupDependencyResponse = responses.iterator().next();
+ Assert.assertEquals(getServiceGroupDependencyResponse.getClusterName(), cluster1);
+ Assert.assertEquals(getServiceGroupDependencyResponse.getDependencyClusterName(), cluster1);
+ Assert.assertEquals(getServiceGroupDependencyResponse.getServiceGroupName(), serviceGroupCore.getServiceGroupName());
+ Assert.assertEquals(getServiceGroupDependencyResponse.getDependencyGroupName(), serviceGroupTest.getServiceGroupName());
+ }
+
+
+}