diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupRequest.java index 38fba97b0f2..b9f94cecac0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupRequest.java @@ -23,10 +23,12 @@ public class ServiceGroupRequest { private String clusterName; // REF private String serviceGroupName; // GET/CREATE/UPDATE/DELETE + private String version; // Associated stack version info - public ServiceGroupRequest(String clusterName, String serviceGroupName) { + public ServiceGroupRequest(String clusterName, String serviceGroupName, String version) { this.clusterName = clusterName; this.serviceGroupName = serviceGroupName; + this.version = version; } /** @@ -57,9 +59,25 @@ public void setServiceGroupName(String serviceGroupName) { this.serviceGroupName = serviceGroupName; } + /** + * @return the servicegroup version + */ + public String getVersion() { + return version; + } + + /** + * @param version the servicegroup version to set + */ + public void setVersion(String version) { + this.version = version; + } + @Override public String toString() { - return String.format("clusterName=%s, serviceGroupName=%s", clusterName, serviceGroupName); + StringBuilder sb = new StringBuilder(); + sb.append("clusterName=").append(clusterName).append(", serviceGroupName=").append(serviceGroupName).append(", version=").append(version); + return sb.toString(); } @Override @@ -73,12 +91,11 @@ public boolean equals(Object obj) { ServiceGroupRequest other = (ServiceGroupRequest) obj; - return Objects.equals(clusterName, other.clusterName) && - Objects.equals(serviceGroupName, other.serviceGroupName); + return Objects.equals(clusterName, other.clusterName) && Objects.equals(serviceGroupName, other.serviceGroupName) && Objects.equals(version, other.version); } @Override public int hashCode() { - return Objects.hash(clusterName, serviceGroupName); + return Objects.hash(clusterName, serviceGroupName, version); } } \ No newline at end of file diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupResponse.java index 6b7c32fa547..afd7f248b61 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupResponse.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceGroupResponse.java @@ -18,6 +18,8 @@ package org.apache.ambari.server.controller; +import java.util.Objects; + import io.swagger.annotations.ApiModelProperty; public class ServiceGroupResponse { @@ -26,12 +28,15 @@ public class ServiceGroupResponse { private Long serviceGroupId; private String clusterName; private String serviceGroupName; + private String version; - public ServiceGroupResponse(Long clusterId, String clusterName, Long serviceGroupId, String serviceGroupName) { + public ServiceGroupResponse(Long clusterId, String clusterName, Long serviceGroupId, String serviceGroupName, String version) { this.clusterId = clusterId; this.serviceGroupId = serviceGroupId; this.clusterName = clusterName; this.serviceGroupName = serviceGroupName; + this.version = version; + } /** @@ -90,27 +95,28 @@ public void setServiceGroupName(String serviceGroupName) { this.serviceGroupName = serviceGroupName; } + /** + * @return the servicegroup version (stackName-stackVersion) + */ + public String getVersion() { + return version; + } + + /** + * @param version the servicegroup version (stackName-stackVersion) + */ + public void setVersion(String version) { + this.version = version; + } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ServiceGroupResponse that = (ServiceGroupResponse) o; - - if (clusterId != null ? - !clusterId.equals(that.clusterId) : that.clusterId != null) { - return false; - } - if (clusterName != null ? - !clusterName.equals(that.clusterName) : that.clusterName != null) { - return false; - } - if (serviceGroupName != null ? - !serviceGroupName.equals(that.serviceGroupName) : that.serviceGroupName != null) { - return false; - } - - return true; + ServiceGroupResponse other = (ServiceGroupResponse) o; + + return Objects.equals(clusterId, other.clusterId) && Objects.equals(clusterName, other.clusterName) && Objects.equals(serviceGroupName, other.serviceGroupName) && Objects.equals(version, other.version); } /** diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java index 8d92dd164d1..11cb2dd7e8d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java @@ -219,7 +219,7 @@ public void setRequiredDeleteAuthorizations(Set requiredDelet */ @Override public RequestStatus createResources(Request request) - throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { + throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException, IllegalArgumentException { Authentication authentication = AuthorizationHelper.getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java index e8bece58ca4..ee87b1b31f0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java @@ -54,6 +54,7 @@ import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.ServiceGroup; +import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.utils.StageUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; @@ -78,6 +79,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv public static final String SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "cluster_name"; public static final String SERVICE_GROUP_SERVICE_GROUP_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_group_id"; public static final String SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_group_name"; + public static final String SERVICE_GROUP_VERSION_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "version"; private static Set pkPropertyIds = @@ -103,10 +105,12 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv PROPERTY_IDS.add(SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID); PROPERTY_IDS.add(SERVICE_GROUP_SERVICE_GROUP_ID_PROPERTY_ID); PROPERTY_IDS.add(SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID); + PROPERTY_IDS.add(SERVICE_GROUP_VERSION_PROPERTY_ID); // keys KEY_PROPERTY_IDS.put(Resource.Type.Cluster, SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID); KEY_PROPERTY_IDS.put(Resource.Type.ServiceGroup, SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID); + KEY_PROPERTY_IDS.put(Resource.Type.Stack, SERVICE_GROUP_VERSION_PROPERTY_ID); } private Clusters clusters; @@ -136,7 +140,7 @@ protected RequestStatus createResourcesAuthorized(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, - NoSuchParentResourceException { + NoSuchParentResourceException, IllegalArgumentException{ final Set requests = new HashSet<>(); for (Map propertyMap : request.getProperties()) { @@ -145,7 +149,7 @@ protected RequestStatus createResourcesAuthorized(Request request) Set createServiceGroups = null; createServiceGroups = createResources(new Command>() { @Override - public Set invoke() throws AmbariException, AuthorizationException { + public Set invoke() throws AmbariException, AuthorizationException, IllegalArgumentException { return createServiceGroups(requests); } }); @@ -160,6 +164,7 @@ public Set invoke() throws AmbariException, AuthorizationE resource.setProperty(SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID, response.getClusterName()); resource.setProperty(SERVICE_GROUP_SERVICE_GROUP_ID_PROPERTY_ID, response.getServiceGroupId()); resource.setProperty(SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID, response.getServiceGroupName()); + resource.setProperty(SERVICE_GROUP_VERSION_PROPERTY_ID, response.getVersion()); associatedResources.add(resource); } @@ -199,6 +204,8 @@ public Set invoke() throws AmbariException { response.getServiceGroupId(), requestedIds); setResourceProperty(resource, SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID, response.getServiceGroupName(), requestedIds); + setResourceProperty(resource, SERVICE_GROUP_VERSION_PROPERTY_ID, + response.getVersion(), requestedIds); resources.add(resource); } return resources; @@ -268,13 +275,14 @@ protected Set getPKPropertyIds() { private ServiceGroupRequest getRequest(Map properties) { String clusterName = (String) properties.get(SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID); String serviceGroupName = (String) properties.get(SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID); - ServiceGroupRequest svcRequest = new ServiceGroupRequest(clusterName, serviceGroupName); + String version = (String) properties.get(SERVICE_GROUP_VERSION_PROPERTY_ID); + ServiceGroupRequest svcRequest = new ServiceGroupRequest(clusterName, serviceGroupName, version); return svcRequest; } // Create services from the given request. public synchronized Set createServiceGroups(Set requests) - throws AmbariException, AuthorizationException { + throws AmbariException, AuthorizationException, IllegalArgumentException { if (requests.isEmpty()) { LOG.warn("Received an empty requests set"); @@ -291,7 +299,7 @@ public synchronized Set createServiceGroups(Set requests, Clusters clusters) - throws AuthorizationException, AmbariException { + throws AuthorizationException, AmbariException, IllegalArgumentException { AmbariMetaInfo ambariMetaInfo = getManagementController().getAmbariMetaInfo(); Map> serviceGroupNames = new HashMap<>(); @@ -397,13 +405,25 @@ private void validateCreateRequests(Set requests, Clusters for (ServiceGroupRequest request : requests) { final String clusterName = request.getClusterName(); final String serviceGroupName = request.getServiceGroupName(); + String version = request.getVersion(); + //TODO: This should not happen, after UI changes the code, this check should be removed + if (StringUtils.isBlank(version)) { + try { + Cluster cluster = clusters.getCluster(clusterName); + StackId stackId = cluster.getCurrentStackVersion(); + request.setVersion(stackId.getStackId()); + } catch (ClusterNotFoundException e) { + throw new ParentObjectNotFoundException("Cluster " + clusterName + " does not exist: ", e); + } + } Validate.notNull(clusterName, "Cluster name should be provided when creating a service group"); Validate.notEmpty(serviceGroupName, "Service group name should be provided when creating a service group"); + Validate.notEmpty(request.getVersion(), "Stack version should be provided when creating a service group"); if (LOG.isDebugEnabled()) { LOG.debug("Received a createServiceGroup request" + - ", clusterName=" + clusterName + ", serviceGroupName=" + serviceGroupName + ", request=" + request); + ", clusterName=" + clusterName + ", serviceGroupName=" + serviceGroupName + ", version=" + version + ", request=" + request); } if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, @@ -422,12 +442,14 @@ private void validateCreateRequests(Set requests, Clusters } serviceGroupNames.get(clusterName).add(serviceGroupName); + // TODO: Validate stack version Cluster cluster; try { cluster = clusters.getCluster(clusterName); } catch (ClusterNotFoundException e) { throw new ParentObjectNotFoundException("Attempted to add a service group to a cluster which doesn't exist", e); } + try { ServiceGroup sg = cluster.getServiceGroup(serviceGroupName); if (sg != null) { diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java index 7d03e443ea6..48b7664b802 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java @@ -19,6 +19,7 @@ package org.apache.ambari.server.orm.entities; import java.util.List; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; @@ -31,6 +32,7 @@ import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.TableGenerator; @@ -70,6 +72,13 @@ public class ServiceGroupEntity { @Column(name = "service_group_name", nullable = false, insertable = true, updatable = true) private String serviceGroupName; + /** + * Unidirectional one-to-one association to {@link StackEntity} + */ + @OneToOne + @JoinColumn(name = "stack_id", unique = false, nullable = false, insertable = true, updatable = true) + private StackEntity stack; + @ManyToOne @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false) private ClusterEntity clusterEntity; @@ -96,7 +105,6 @@ public void setServiceGroupId(Long serviceGroupId) { this.serviceGroupId = serviceGroupId; } - public String getServiceGroupName() { return serviceGroupName; } @@ -105,6 +113,14 @@ public void setServiceGroupName(String serviceGroupName) { this.serviceGroupName = serviceGroupName; } + public StackEntity getStack() { + return stack; + } + + public void setStack(StackEntity stack) { + this.stack = stack; + } + public List getDependencies() { return dependencies; } @@ -131,15 +147,15 @@ public boolean equals(Object o) { if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false; if (serviceGroupName != null ? !serviceGroupName.equals(that.serviceGroupName) : that.serviceGroupName != null) return false; + if (Long.valueOf(stack.getStackId()) != Long.valueOf(((ServiceGroupEntity) o).getStack().getStackId())) + return false; return true; } @Override public int hashCode() { - int result = clusterId != null ? clusterId.intValue() : 0; - result = 31 * result + (serviceGroupName != null ? serviceGroupName.hashCode() : 0); - return result; + return Objects.hash(serviceGroupId, clusterId, serviceGroupName, stack); } public ClusterEntity getClusterEntity() { diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java index 8ec5c3a6dd6..79d5844c3dc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java @@ -95,7 +95,9 @@ Service addDependencyToService(String serviceGroupName, String serviceName, * @return * @throws AmbariException */ - ServiceGroup addServiceGroup(String serviceGroupName) throws AmbariException; + ServiceGroup addServiceGroup(String serviceGroupName, String version) throws AmbariException; + + ServiceGroup addServiceGroup(String serviceGroupName, StackId stackId) throws AmbariException; /** * Add service group dependency to the service group diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroup.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroup.java index fcd4c893d5d..dce2337c68d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroup.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroup.java @@ -46,6 +46,8 @@ public interface ServiceGroup { Set getServiceGroupDependencyResponses(); + StackId getStackId(); + void debugDump(StringBuilder sb); void refresh(); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupFactory.java index 3c5e956ec1d..59e3f40bfc1 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceGroupFactory.java @@ -29,6 +29,7 @@ public interface ServiceGroupFactory { ServiceGroup createNew(Cluster cluster, @Assisted("serviceGroupName") String serviceGroupName, + @Assisted("stackId") StackId stackId, @Assisted("serviceGroupDependencies") Set serviceGroupDependencies); ServiceGroup createExisting(Cluster cluster, ServiceGroupEntity serviceGroupEntity); 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 dcc84337e46..5ada744eaed 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 @@ -31,10 +31,12 @@ import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.orm.dao.ClusterDAO; import org.apache.ambari.server.orm.dao.ServiceGroupDAO; +import org.apache.ambari.server.orm.dao.StackDAO; import org.apache.ambari.server.orm.entities.ClusterEntity; import org.apache.ambari.server.orm.entities.ServiceGroupDependencyEntity; import org.apache.ambari.server.orm.entities.ServiceGroupEntity; import org.apache.ambari.server.orm.entities.ServiceGroupEntityPK; +import org.apache.ambari.server.orm.entities.StackEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,19 +53,23 @@ public class ServiceGroupImpl implements ServiceGroup { private final Cluster cluster; private final ClusterDAO clusterDAO; + private final StackDAO stackDAO; private final ServiceGroupDAO serviceGroupDAO; private final AmbariEventPublisher eventPublisher; private final Clusters clusters; private Long serviceGroupId; private String serviceGroupName; + private StackId stackId; private Set serviceGroupDependencies; @AssistedInject public ServiceGroupImpl(@Assisted Cluster cluster, @Assisted("serviceGroupName") String serviceGroupName, + @Assisted("stackId") StackId stackId, @Assisted("serviceGroupDependencies") Set serviceGroupDependencies, ClusterDAO clusterDAO, + StackDAO stackDAO, ServiceGroupDAO serviceGroupDAO, AmbariEventPublisher eventPublisher, Clusters clusters) throws AmbariException { @@ -71,16 +77,18 @@ public ServiceGroupImpl(@Assisted Cluster cluster, this.cluster = cluster; this.clusters = clusters; this.clusterDAO = clusterDAO; + this.stackDAO = stackDAO; this.serviceGroupDAO = serviceGroupDAO; this.eventPublisher = eventPublisher; this.serviceGroupName = serviceGroupName; + this.stackId = stackId; ServiceGroupEntity serviceGroupEntity = new ServiceGroupEntity(); serviceGroupEntity.setClusterId(cluster.getClusterId()); serviceGroupEntity.setServiceGroupId(serviceGroupId); serviceGroupEntity.setServiceGroupName(serviceGroupName); - + serviceGroupEntity.setStack(stackDAO.find(stackId)); if (serviceGroupDependencies == null) { this.serviceGroupDependencies = new HashSet<>(); } else { @@ -96,17 +104,21 @@ public ServiceGroupImpl(@Assisted Cluster cluster, public ServiceGroupImpl(@Assisted Cluster cluster, @Assisted ServiceGroupEntity serviceGroupEntity, ClusterDAO clusterDAO, + StackDAO stackDAO, ServiceGroupDAO serviceGroupDAO, AmbariEventPublisher eventPublisher, Clusters clusters) throws AmbariException { this.cluster = cluster; this.clusters = clusters; this.clusterDAO = clusterDAO; + this.stackDAO = stackDAO; this.serviceGroupDAO = serviceGroupDAO; this.eventPublisher = eventPublisher; this.serviceGroupId = serviceGroupEntity.getServiceGroupId(); this.serviceGroupName = serviceGroupEntity.getServiceGroupName(); + StackEntity stack = serviceGroupEntity.getStack(); + this.stackId = new StackId(stack.getStackName(), stack.getStackVersion()); this.serviceGroupDependencies = getServiceGroupDependencies(serviceGroupEntity.getServiceGroupDependencies()); this.serviceGroupEntityPK = getServiceGroupEntityPK(serviceGroupEntity); @@ -135,6 +147,11 @@ public long getClusterId() { return cluster.getClusterId(); } + @Override + public StackId getStackId() { + return stackId; + } + @Override public Set getServiceGroupDependencies() { return serviceGroupDependencies; @@ -148,7 +165,7 @@ public void setServiceGroupDependencies(Set serviceGroupDepende @Override public ServiceGroupResponse convertToResponse() { ServiceGroupResponse r = new ServiceGroupResponse(cluster.getClusterId(), - cluster.getClusterName(), getServiceGroupId(), getServiceGroupName()); + cluster.getClusterName(), getServiceGroupId(), getServiceGroupName(), stackId.getStackId()); return r; } @@ -216,8 +233,10 @@ public Cluster getCluster() { @Override public void debugDump(StringBuilder sb) { - sb.append("ServiceGroup={ serviceGroupName=" + getServiceGroupName() + ", clusterName=" - + cluster.getClusterName() + ", clusterId=" + cluster.getClusterId() + "}"); + sb.append("ServiceGroup={ serviceGroupName=").append(getServiceGroupName()) + .append(", clusterName=").append(cluster.getClusterName()).append(", clusterId=") + .append(cluster.getClusterId()).append(", stackId=").append(getStackId()); + sb.append("}"); } /** @@ -254,10 +273,9 @@ protected ServiceGroupEntity persistEntities(ServiceGroupEntity serviceGroupEnti @Override @Transactional public void refresh() { - ServiceGroupEntityPK pk = new ServiceGroupEntityPK(); - pk.setClusterId(getClusterId()); - pk.setServiceGroupId(getServiceGroupId()); - ServiceGroupEntity serviceGroupEntity = serviceGroupDAO.findByPK(pk); + serviceGroupEntityPK.setClusterId(getClusterId()); + serviceGroupEntityPK.setServiceGroupId(getServiceGroupId()); + ServiceGroupEntity serviceGroupEntity = serviceGroupDAO.findByPK(serviceGroupEntityPK); serviceGroupDAO.refresh(serviceGroupEntity); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java index 6861816a811..9b0390faba5 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java @@ -1018,13 +1018,17 @@ public void addServiceGroup(ServiceGroup serviceGroup) { } @Override - public ServiceGroup addServiceGroup(String serviceGroupName) throws AmbariException { + public ServiceGroup addServiceGroup(String serviceGroupName, String version) throws AmbariException { + return addServiceGroup(serviceGroupName, new StackId(version)); + } + + @Override + public ServiceGroup addServiceGroup(String serviceGroupName, StackId stackId) throws AmbariException { if (serviceGroups.containsKey(serviceGroupName)) { throw new AmbariException("Service group already exists" + ", clusterName=" + getClusterName() - + ", clusterId=" + getClusterId() + ", serviceGroupName=" + serviceGroupName); + + ", clusterId=" + getClusterId() + ", serviceGroupName=" + serviceGroupName); } - - ServiceGroup serviceGroup = serviceGroupFactory.createNew(this, serviceGroupName, new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(this, serviceGroupName, stackId, new HashSet()); addServiceGroup(serviceGroup); return serviceGroup; } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java index f4058a1e79d..6fbb59e810a 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java @@ -355,7 +355,7 @@ public void createAmbariServiceAndComponentResources(ClusterTopology topology, S } Set serviceGroupRequests = serviceGroups.stream() - .map(serviceGroupName -> new ServiceGroupRequest(clusterName, serviceGroupName)) + .map(serviceGroupName -> new ServiceGroupRequest(clusterName, serviceGroupName, Iterables.getFirst(topology.getBlueprint().getStackIds(), null).getStackId())) .collect(toSet()); Set serviceRequests = new HashSet<>(); diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql index 8bec98b07da..ab18e49e2b5 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql @@ -123,8 +123,10 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, + stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), - CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); + CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), + CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); CREATE TABLE servicegroupdependencies ( id BIGINT NOT NULL, diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql index e7dd862b96b..5bc29a32d26 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -142,8 +142,10 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, + stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), - CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); + CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), + CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); CREATE TABLE servicegroupdependencies ( id BIGINT NOT NULL, diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql index c123d6cc57f..a03d123f817 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -123,8 +123,10 @@ CREATE TABLE servicegroups ( id NUMBER(19) NOT NULL, service_group_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, + stack_id NUMBER(19) NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), - CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); + CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), + CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); CREATE TABLE servicegroupdependencies ( id NUMBER(19) NOT NULL, diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index bbd02397c76..b635f76398c 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -125,8 +125,10 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, + stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), - CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); + CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), + CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); CREATE TABLE servicegroupdependencies ( id BIGINT NOT NULL, diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql index 2bc81748bd2..831eba0db65 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql @@ -122,8 +122,10 @@ CREATE TABLE servicegroups ( id NUMERIC(19) NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id NUMERIC(19) NOT NULL, + stack_id NUMERIC(19) NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), - CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); + CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), + CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); CREATE TABLE servicegroupdependencies ( id NUMBER(19) NOT NULL, diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index ebeb17bfd4a..696be2d15a2 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -137,8 +137,10 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, + stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), - CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id)); + CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), + CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); CREATE TABLE servicegroupdependencies ( id BIGINT NOT NULL, diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java index 9bea4aeec88..50653eb9888 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java @@ -116,7 +116,7 @@ public static void setup() throws AmbariException { OrmTestHelper helper = injector.getInstance(OrmTestHelper.class); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster1); - ServiceGroup serviceGroup = cluster1.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster1.addServiceGroup("CORE", "HDP-2.6.0"); cluster1.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); SERVICE_SITE_CLUSTER = new HashMap<>(); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java index 6688510a5c8..64ce0759982 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java @@ -109,7 +109,7 @@ public void testDesiredConfigurationsAfterApplyingLatestForStackInOtherThreads() // add a service String serviceName = "ZOOKEEPER"; RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service service = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); String configType = "zoo.cfg"; diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java index bc5a50a3a08..a23fae966a4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java @@ -1311,7 +1311,7 @@ public void testComponentInProgressStatusSafeAfterStatusReport() throws Exceptio */ private Service addService(Cluster cluster, String serviceName) throws AmbariException { RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0"); return cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); } } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java index 42374c4109d..2a7b8b2784b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java @@ -1604,7 +1604,7 @@ private File createTestKeytabData(HeartBeatHandler heartbeatHandler) throws Exce */ private Service addService(Cluster cluster, String serviceName) throws AmbariException { RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0"); return cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java index 69546bfdc46..5c96ece24ef 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java @@ -174,7 +174,7 @@ public void testStateCommandsGeneration() throws AmbariException, InterruptedExc clusters.mapAndPublishHostsToCluster(hostNames, clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); hdfs.addServiceComponent(Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); @@ -277,7 +277,7 @@ public void testStatusCommandForAnyComponents() throws Exception { clusters.mapAndPublishHostsToCluster(hostNames, clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); hdfs.addServiceComponent(Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost @@ -385,7 +385,7 @@ public void testHeartbeatStateCommandsEnqueueing() throws AmbariException, Inter clusters.mapAndPublishHostsToCluster(hostNames, clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); hdfs.addServiceComponent(Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); @@ -467,7 +467,7 @@ public void testHeartbeatLossWithComponent() throws AmbariException, Interrupted clusters.mapAndPublishHostsToCluster(hostNames, clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); hdfs.addServiceComponent(Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); @@ -586,7 +586,7 @@ public void testStateCommandsWithAlertsGeneration() throws AmbariException, Inte clusters.mapAndPublishHostsToCluster(hostNames, clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); hdfs.addServiceComponent(Role.DATANODE.name()); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java index 8b185ca0b31..1b2ffb35200 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java @@ -1741,12 +1741,12 @@ public void testAlertDefinitionMerging() throws Exception { Clusters clusters = injector.getInstance(Clusters.class); Cluster cluster = clusters.getClusterById(clusterId); - cluster.setDesiredStackVersion( - new StackId(STACK_NAME_HDP, stackVersion)); + StackId stackId = new StackId(STACK_NAME_HDP, stackVersion); + cluster.setDesiredStackVersion(stackId); RepositoryVersionEntity repositoryVersion = ormHelper.getOrCreateRepositoryVersion( cluster.getCurrentStackVersion(), repoVersion); - ServiceGroup sg = cluster.addServiceGroup("core"); + ServiceGroup sg = cluster.addServiceGroup("core", stackId.getStackId()); cluster.addService(sg, "HDFS", "HDFS", repositoryVersion); metaInfo.reconcileAlertDefinitions(clusters, false); @@ -1861,7 +1861,7 @@ public void testAlertDefinitionMergingRemoveScenario() throws Exception { RepositoryVersionEntity repositoryVersion = ormHelper.getOrCreateRepositoryVersion( cluster.getCurrentStackVersion(), repoVersion); - ServiceGroup sg = cluster.addServiceGroup("core"); + ServiceGroup sg = cluster.addServiceGroup("core", "HDP-2.0.6"); cluster.addService(sg, "HDFS", "HDFS", repositoryVersion); metaInfo.reconcileAlertDefinitions(clusters, false); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java index 06d773e6782..f0fff2b19d7 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java @@ -148,7 +148,7 @@ public void testServiceComponentInstalled() Cluster cluster = heartbeatTestHelper.getDummyCluster(); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0.0"); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); @@ -183,7 +183,7 @@ public void testServiceComponentUninstalled() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0.0"); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); @@ -220,7 +220,7 @@ public void testClusterEnvConfigChanged() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0.0"); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); @@ -261,7 +261,7 @@ public void testMaintenanceModeChanged() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0.0"); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); @@ -297,7 +297,7 @@ public void testServiceComponentRecoveryChanged() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0.0"); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); @@ -341,7 +341,7 @@ public void testMultiNodeCluster() RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster); // Add HDFS service with DATANODE component to the cluster - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.6.0.0"); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java index b0ac089f334..8fb34c00296 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java @@ -786,7 +786,7 @@ private void createClusterFixture(String clusterName, StackId stackId, Assert.assertNotNull(cluster); String serviceGroupName = "CORE"; - cluster.addServiceGroup(serviceGroupName); + cluster.addServiceGroup(serviceGroupName, stackId.getStackId()); createService(clusterName, serviceGroupName, "HDFS", repositoryVersion); createService(clusterName, serviceGroupName, "YARN", repositoryVersion); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index b09f1528ac9..c33bb9da2a2 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -1043,7 +1043,7 @@ public void testCreateServiceComponentWithInvalidRequest() RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); - ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName, stackId.getStackId()); Service s1 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); Service s2 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); c1.addService(s1); @@ -1364,7 +1364,7 @@ public void testCreateServiceComponentMultiple() throws Exception { RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); String serviceGroupName = "CORE"; - ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName, stackId.getStackId()); Service s1 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); Service s2 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); c1.addService(s1); @@ -1625,11 +1625,11 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception // Expected } - Service s1 = serviceFactory.createNew(foo, foo.addServiceGroup(serviceGroupName), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); + Service s1 = serviceFactory.createNew(foo, foo.addServiceGroup(serviceGroupName, stackId.getStackId()), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); foo.addService(s1); - Service s2 = serviceFactory.createNew(c1, c1.addServiceGroup(serviceGroupName), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); + Service s2 = serviceFactory.createNew(c1, c1.addServiceGroup(serviceGroupName, stackId.getStackId()), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c1.addService(s2); - Service s3 = serviceFactory.createNew(c2, c2.addServiceGroup(serviceGroupName), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); + Service s3 = serviceFactory.createNew(c2, c2.addServiceGroup(serviceGroupName, stackId.getStackId()), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c2.addService(s3); @@ -2215,7 +2215,7 @@ public void testGetServices() throws Exception { clusters.addCluster(cluster1, stackId); Cluster c1 = clusters.getCluster(cluster1); - ServiceGroup serviceGroup = c1.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c1.addServiceGroup("CORE", stackId.getStackId()); Service s1 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c1.addService(s1); @@ -2251,11 +2251,11 @@ public void testGetServicesWithFilters() throws Exception { c1.setDesiredStackVersion(stackId); c2.setDesiredStackVersion(stackId); - ServiceGroup sg1 = c1.addServiceGroup("CORE"); + ServiceGroup sg1 = c1.addServiceGroup("CORE", stackId.getStackId()); Service s1 = serviceFactory.createNew(c1, sg1, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); Service s2 = serviceFactory.createNew(c1, sg1, new ArrayList<>(),"MAPREDUCE", "MAPREDUCE", repositoryVersion); Service s3 = serviceFactory.createNew(c1, sg1, new ArrayList<>(),"HBASE", "HBASE", repositoryVersion); - ServiceGroup sg2 = c2.addServiceGroup("CORE"); + ServiceGroup sg2 = c2.addServiceGroup("CORE", stackId.getStackId()); Service s4 = serviceFactory.createNew(c2, sg2, new ArrayList<>(),"HIVE", "HIVE", repositoryVersion); Service s5 = serviceFactory.createNew(c2, sg2, new ArrayList<>(),"ZOOKEEPER", "ZOOKEEPER", repositoryVersion); @@ -2329,7 +2329,7 @@ public void testGetServiceComponents() throws Exception { Cluster c1 = clusters.getCluster(cluster1); c1.setDesiredStackVersion(stackId); String serviceGroupName = "CORE"; - Service s1 = serviceFactory.createNew(c1, c1.addServiceGroup(serviceGroupName), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); + Service s1 = serviceFactory.createNew(c1, c1.addServiceGroup(serviceGroupName, "HDP-0.2"), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c1.addService(s1); s1.setDesiredState(State.INSTALLED); ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE"); @@ -2369,11 +2369,11 @@ public void testGetServiceComponentsWithFilters() throws Exception { Cluster c1 = clusters.getCluster(cluster1); Cluster c2 = clusters.getCluster(cluster2); - ServiceGroup sg1 = c1.addServiceGroup("CORE"); + ServiceGroup sg1 = c1.addServiceGroup("CORE", stackId.getStackId()); Service s1 = serviceFactory.createNew(c1, sg1, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); Service s2 = serviceFactory.createNew(c1, sg1, new ArrayList<>(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); Service s3 = serviceFactory.createNew(c1, sg1, new ArrayList<>(), "HBASE", "HBASE", repositoryVersion); - ServiceGroup sg2 = c2.addServiceGroup("CORE"); + ServiceGroup sg2 = c2.addServiceGroup("CORE", stackId.getStackId()); Service s4 = serviceFactory.createNew(c2, sg2, new ArrayList<>(), "HIVE", "HIVE", repositoryVersion); Service s5 = serviceFactory.createNew(c2, sg2, new ArrayList<>(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion); @@ -2486,7 +2486,7 @@ public void testGetServiceComponentHosts() throws Exception { Cluster c1 = setupClusterWithHosts(cluster1, "HDP-0.1", Lists.newArrayList(host1), "centos5"); RepositoryVersionEntity repositoryVersion = repositoryVersion01; - ServiceGroup serviceGroup = c1.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c1.addServiceGroup("CORE", "HDP-0.1"); Service s1 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c1.addService(s1); ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE"); @@ -2858,7 +2858,7 @@ public void testGetServiceComponentHostsWithFilters() throws Exception { RepositoryVersionEntity repositoryVersion = repositoryVersion02; String serviceGroupName = "CORE"; - ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName, "HDP-0.2"); Service s1 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); Service s2 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); Service s3 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HBASE", "HBASE", repositoryVersion); @@ -3849,7 +3849,7 @@ public void testCreateCustomActions() throws Exception { RepositoryVersionEntity repositoryVersion = repositoryVersion206; String serviceGroupName = "CORE"; - ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName, "HDP-2.0.6"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion); @@ -4007,7 +4007,7 @@ public void testComponentCategorySentWithRestart() throws Exception { RepositoryVersionEntity repositoryVersion = repositoryVersion207; String serviceGroupName = "CORE"; - ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName, "HDP-2.0.7"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); @@ -4113,7 +4113,7 @@ public void testCreateActionsFailures() throws Exception { cluster.addDesiredConfig("_test", Collections.singleton(config2)); String serviceGroupName = "CORE"; - ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName, "HDP-2.0.7"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service hive = cluster.addService(serviceGroup, "HIVE", "HIVE", repositoryVersion); @@ -4381,7 +4381,7 @@ public void testCreateServiceCheckActions() throws Exception { cluster.addDesiredConfig("_test", Collections.singleton(config1)); cluster.addDesiredConfig("_test", Collections.singleton(config2)); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-0.1"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapReduce = cluster.addService(serviceGroup, "MAPREDUCE", "MAPREDUCE", repositoryVersion); @@ -5916,7 +5916,7 @@ public void testResourceFiltersWithCustomActions() throws Exception { put("key1", "value1"); }}, new HashMap<>()); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.0.6"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion); @@ -6014,7 +6014,7 @@ public void testResourceFiltersWithCustomCommands() throws Exception { put("key1", "value1"); }}, new HashMap<>()); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-2.0.6"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion); @@ -8932,7 +8932,7 @@ public void testReinstallClientSchSkippedInMaintenance() throws Exception { RepositoryVersionEntity repositoryVersion = repositoryVersion120; String serviceGroupName = "CORE"; - ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName); + ServiceGroup serviceGroup = c1.addServiceGroup(serviceGroupName, "HDP-1.2.0"); Service hdfs = c1.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); createServiceComponent(cluster1, serviceGroupName, "HDFS", "NAMENODE", State.INIT); createServiceComponent(cluster1, serviceGroupName, "HDFS", "DATANODE", State.INIT); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java index 391d9bca60a..f4d4d2d0dbb 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java @@ -349,8 +349,8 @@ private Cluster createDefaultCluster(String clusterName) throws Exception { RepositoryVersionEntity repositoryVersion = repositoryVersion206; - ServiceGroup serviceGroupCore = cluster.addServiceGroup(SERVICE_GROUP_NAME_CORE); - ServiceGroup serviceGroupTest = cluster.addServiceGroup(SERVICE_GROUP_NAME_TEST); + ServiceGroup serviceGroupCore = cluster.addServiceGroup(SERVICE_GROUP_NAME_CORE, "HDP-1.0"); + ServiceGroup serviceGroupTest = cluster.addServiceGroup(SERVICE_GROUP_NAME_TEST, "HDP-1.0"); Service hdfs = cluster.addService(serviceGroupCore, SERVICE_NAME_HDFS, SERVICE_NAME_HDFS, repositoryVersion); Service yarn = cluster.addService(serviceGroupCore, SERVICE_NAME_YARN, SERVICE_NAME_YARN, repositoryVersion); 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 index bed36895828..9f1910e9f4f 100644 --- 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 @@ -344,8 +344,8 @@ private Cluster createDefaultCluster(String clusterName) throws Exception { RepositoryVersionEntity repositoryVersion = repositoryVersion206; - ServiceGroup serviceGroupCore = cluster.addServiceGroup(SERVICE_GROUP_NAME_CORE); - ServiceGroup serviceGroupTest = cluster.addServiceGroup(SERVICE_GROUP_NAME_TEST); + ServiceGroup serviceGroupCore = cluster.addServiceGroup(SERVICE_GROUP_NAME_CORE, "HDP-2.0.6"); + ServiceGroup serviceGroupTest = cluster.addServiceGroup(SERVICE_GROUP_NAME_TEST, "HDP-2.0.6"); return cluster; diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProviderTest.java index d0b2dc4ce2c..d590b4c3c19 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProviderTest.java @@ -17,13 +17,45 @@ */ package org.apache.ambari.server.controller.internal; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.createNiceMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.api.resources.ResourceInstance; +import org.apache.ambari.server.api.resources.ResourceInstanceFactory; +import org.apache.ambari.server.api.resources.ResourceInstanceFactoryImpl; +import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.api.services.NamedPropertySet; +import org.apache.ambari.server.api.services.RequestBody; +import org.apache.ambari.server.api.services.parsers.JsonRequestBodyParser; import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.controller.ServiceGroupRequest; +import org.apache.ambari.server.controller.ServiceGroupResponse; +import org.apache.ambari.server.controller.spi.ClusterController; +import org.apache.ambari.server.controller.spi.RequestStatus; +import org.apache.ambari.server.controller.spi.Resource; +import org.apache.ambari.server.controller.spi.Schema; +import org.apache.ambari.server.controller.utilities.PropertyHelper; +import org.apache.ambari.server.security.TestAuthenticationFactory; import org.apache.ambari.server.security.authorization.AuthorizationException; +import org.apache.ambari.server.security.authorization.AuthorizationHelperInitializer; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.ServiceGroup; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; public class ServiceGroupResourceProviderTest { @@ -38,8 +70,76 @@ public static void createServiceGroups(AmbariManagementController controller, Se public static void createServiceGroup(AmbariManagementController controller, String clusterName, String serviceGroupName) throws AmbariException, AuthorizationException { - ServiceGroupRequest request = new ServiceGroupRequest(clusterName, serviceGroupName); + ServiceGroupRequest request = new ServiceGroupRequest(clusterName, serviceGroupName, "dummy-stack-name"); createServiceGroups(controller, Collections.singleton(request)); } + @Before + public void before() { + Authentication authentication = TestAuthenticationFactory.createClusterAdministrator(); + AuthorizationHelperInitializer.viewInstanceDAOReturningNull(); + SecurityContextHolder.getContext().setAuthentication(authentication); + } + + @After + public void clearAuthentication() { + SecurityContextHolder.getContext().setAuthentication(null); + } + + @Test + public void testCreateServiceGroupsWithStackId() throws Exception { + String body = "[{\"ServiceGroupInfo\":{\"service_group_name\": \"CORE\",\"stack_id\": \"HDP-1.2.3\"}}]"; + String clusterName = "c1"; + JsonRequestBodyParser jsonParser = new JsonRequestBodyParser(); + RequestBody requestBody = jsonParser.parse(body).iterator().next(); + //RequestFactory requestFactory = new RequestFactory(); + ResourceInstanceFactory resourceFactory = new ResourceInstanceFactoryImpl(); + Map mapIds = new HashMap<>(); + mapIds.put(Resource.Type.Cluster, clusterName); + mapIds.put(Resource.Type.ServiceGroup, null); + ResourceInstance resource = resourceFactory.createResource(Resource.Type.ServiceGroup, mapIds); + Map mapResourceIds = resource.getKeyValueMap(); + mapResourceIds.put(Resource.Type.Cluster, "c1"); + AmbariManagementController ambariManagementController = createMock(AmbariManagementController.class); + AmbariMetaInfo ambariMetaInfo = createMock(AmbariMetaInfo.class); + Clusters clusters = createMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + Schema serviceGroupSchema = createNiceMock("ServiceGroupSchema", Schema.class); + ClusterController clusterController = createNiceMock(ClusterController.class); + ServiceGroup coreServiceGroup = createNiceMock(ServiceGroup.class); + ServiceGroup edmServiceGroup = createNiceMock(ServiceGroup.class); + ServiceGroupResponse coreServiceGroupResponse = new ServiceGroupResponse(1l, "c1", 1l, "CORE", "HDP-1.2.3"); + expect(ambariManagementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(ambariManagementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster(clusterName)).andReturn(cluster).anyTimes(); + expect(cluster.addServiceGroup("CORE", "HDP-1.2.3")).andReturn(coreServiceGroup).anyTimes(); + expect(coreServiceGroup.convertToResponse()).andReturn(coreServiceGroupResponse).anyTimes(); + expect(clusterController.getSchema(Resource.Type.ServiceGroup)).andReturn(serviceGroupSchema).anyTimes(); + expect(serviceGroupSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("ServiceGroupInfo/cluster_name").anyTimes(); + expect(serviceGroupSchema.getKeyPropertyId(Resource.Type.ServiceGroup)).andReturn("ServiceGroupInfo/service_group_name").anyTimes(); + expect(serviceGroupSchema.getKeyTypes()).andReturn(Collections.singleton(Resource.Type.ServiceGroup)).anyTimes(); + + replay(cluster, clusters, ambariManagementController, ambariMetaInfo, serviceGroupSchema, clusterController, coreServiceGroup, edmServiceGroup); + + ServiceGroupResourceProvider serviceGroupResourceProvider = new ServiceGroupResourceProvider(ambariManagementController); + Set setProperties = requestBody.getNamedPropertySets(); + if (setProperties.isEmpty()) { + requestBody.addPropertySet(new NamedPropertySet("", new HashMap<>())); + } + for (NamedPropertySet propertySet : setProperties) { + for (Map.Entry entry : mapResourceIds.entrySet()) { + Map mapProperties = propertySet.getProperties(); + String property = serviceGroupSchema.getKeyPropertyId(entry.getKey()); + if (!mapProperties.containsKey(property)) { + mapProperties.put(property, entry.getValue()); + } + } + } + + RequestStatus requestStatus = serviceGroupResourceProvider.createResources(PropertyHelper.getCreateRequest(requestBody.getPropertySets(), requestBody.getRequestInfoProperties())); + Assert.assertEquals(requestStatus.getStatus(), RequestStatus.Status.Complete); + + verify(cluster, clusters, ambariManagementController, ambariMetaInfo, serviceGroupSchema, clusterController, coreServiceGroup, edmServiceGroup); + } + } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java index d94810c7ee4..c9464061c9a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java @@ -140,7 +140,7 @@ public void setup() throws Exception { cluster.setDesiredStackVersion(stackId); RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service service = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); service.addServiceComponent("NAMENODE"); service.addServiceComponent("DATANODE"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java index 931b3502871..dcbdc586909 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java @@ -263,7 +263,7 @@ public void before() throws Exception { clusters.mapHostToCluster("h1", "c1"); // add a single ZK server and client on 2.1.1.0 - ServiceGroup serviceGroup = cluster.addServiceGroup(UpgradeResourceProvider.DUMMY_SERVICE_GROUP); + ServiceGroup serviceGroup = cluster.addServiceGroup(UpgradeResourceProvider.DUMMY_SERVICE_GROUP, stack211.getStackId()); Service service = cluster.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repoVersionEntity2110); ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER"); ServiceComponentHost sch = component.addServiceComponentHost("h1"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java index f94cb12985f..473a7dd1762 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java @@ -174,7 +174,7 @@ public void createCluster() throws Exception { clusters.mapHostToCluster("h1", "c1"); // add a single ZOOKEEPER server - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service service = cluster.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repoVersionEntity); ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java index c3052e46ff8..0c9805c6207 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java @@ -698,7 +698,7 @@ private void makeService(String serviceName, RepositoryVersionEntity serviceRepo } catch (AmbariException e) { clusters.addCluster(clusterName, parentEntity.getStackId()); cluster = clusters.getCluster(clusterName); - serviceGroup = cluster.addServiceGroup(serviceGroupName); + serviceGroup = cluster.addServiceGroup(serviceGroupName, "HDP-1.0"); } cluster.addService(serviceGroup, serviceName, serviceName, serviceRepo); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java index 720a1f88850..7a4637640b0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java @@ -87,7 +87,7 @@ public void configure(Binder binder) { clusters.addCluster(clusterName, stack211); cluster = clusters.getCluster(clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stack211.getStackId()); service = cluster.addService(serviceGroup, getServiceName(), getServiceName(), repositoryVersion); createComponentsAndHosts(); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java index bfe0b51629f..a312f8efbde 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java @@ -121,7 +121,7 @@ public void setup() throws Exception { m_cluster = m_clusters.getCluster(m_clusterName); Assert.assertNotNull(m_cluster); - serviceGroup = m_cluster.addServiceGroup("CORE"); + serviceGroup = m_cluster.addServiceGroup("CORE", stackId.getStackId()); m_cluster.setDesiredStackVersion(stackId); m_repositoryVersion = m_helper.getOrCreateRepositoryVersion(stackId, REPO_VERSION); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java index 985facf5274..4f05d9ba752 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java @@ -151,7 +151,7 @@ private RepositoryVersionEntity createClusterAndHosts(String INSTALLED_VERSION, Map> zkTopology = new HashMap<>(); List zkServerHosts = Arrays.asList(0, 1, 2); zkTopology.put("ZOOKEEPER_SERVER", new ArrayList<>(zkServerHosts)); - ServiceGroup serviceGroup = c1.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c1.addServiceGroup("CORE", "HDP-1.0"); addService(c1, serviceGroup, hostList, zkTopology, "ZOOKEEPER", repositoryVersionEntity); // install new version @@ -477,7 +477,7 @@ public void testComponentHostVersionNotRequired() throws Exception { .put("NAMENODE", Lists.newArrayList(0)) .put("DATANODE", Lists.newArrayList(1)) .build(); - ServiceGroup serviceGroup = c1.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c1.addServiceGroup("CORE", "HDP-1.0"); addService(c1, serviceGroup, allHosts, topology, "HDFS", repo); topology = new ImmutableMap.Builder>() diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java index 298846443eb..3be8333122b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java @@ -206,6 +206,7 @@ public void createDefaultData() { ServiceGroupEntity serviceGroupEntity = new ServiceGroupEntity(); serviceGroupEntity.setServiceGroupName(SERVICE_GROUP_NAME); serviceGroupEntity.setClusterEntity(clusterEntity); + serviceGroupEntity.setStack(stackEntity); ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity(); clusterServiceEntity.setServiceType("HDFS"); @@ -415,7 +416,7 @@ public Cluster buildNewCluster(Clusters clusters, clusters.addCluster(clusterName, stackId); Cluster cluster = clusters.getCluster(clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup(SERVICE_GROUP_NAME); + ServiceGroup serviceGroup = cluster.addServiceGroup(SERVICE_GROUP_NAME, stackId.getStackId()); cluster = initializeClusterWithStack(cluster); addHost(clusters, cluster, hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java index 623eeb0a445..c20ce18758a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java @@ -117,7 +117,7 @@ public void setup() throws Exception { EventBusSynchronizer.synchronizeAmbariEventPublisher(m_injector); m_cluster = m_clusters.getClusterById(m_helper.createCluster()); - serviceGroup = m_cluster.addServiceGroup("CORE"); + serviceGroup = m_cluster.addServiceGroup("CORE", "HDP-1.0"); m_helper.initializeClusterWithStack(m_cluster); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java index 60d7a246b59..2d7826bf4a4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java @@ -123,7 +123,7 @@ public void setup() throws Exception { // install YARN so there is at least 1 service installed and no // unexpected alerts since the test YARN service doesn't have any alerts m_cluster = m_clusters.getClusterById(m_helper.createCluster()); - serviceGroup = m_cluster.addServiceGroup("CORE"); + serviceGroup = m_cluster.addServiceGroup("CORE", "HDP-1.0"); m_helper.initializeClusterWithStack(m_cluster); m_helper.addHost(m_clusters, m_cluster, HOSTNAME); m_helper.installYarnService(m_cluster, m_serviceFactory, diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java index 08df6c2dd79..06e9d074afb 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java @@ -340,7 +340,7 @@ public void testMixedComponentVersions() throws Exception { Clusters clusters = m_injector.getInstance(Clusters.class); Cluster cluster = clusters.getCluster("c1"); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", targetStack.getStackId()); RepositoryVersionEntity sourceRepoVersion = m_helper.getOrCreateRepositoryVersion(HDP_21_STACK, HDP_2_1_1_0); RepositoryVersionEntity targetRepoVersion = m_helper.getOrCreateRepositoryVersion(HDP_22_STACK, HDP_2_2_1_0); @@ -441,7 +441,7 @@ public void testMatchingPartialVersions() throws Exception { host.setOsInfo("redhat6"); Cluster cluster = clusters.getCluster("c1"); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", targetStack.getStackId()); clusters.mapHostToCluster("h1", "c1"); RepositoryVersionEntity repositoryVersion2110 = m_helper.getOrCreateRepositoryVersion( diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java index 2c8cd913747..5439a6d96e4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java @@ -1719,7 +1719,7 @@ private void makeUpgradeCluster() throws Exception { // !!! very important, otherwise the loops that walk the list of installed // service properties will not run! - ServiceGroup serviceGroup = c.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c.addServiceGroup("CORE", repoVersion2110.getStackId().getStackId()); Service service = installService(c, serviceGroup, "ZOOKEEPER", repoVersion2110); addServiceComponent(c, service, "ZOOKEEPER_SERVER"); addServiceComponent(c, service, "ZOOKEEPER_CLIENT"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java index dfc14046dba..6f75f37d780 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java @@ -222,7 +222,7 @@ private void makeUpgradeCluster() throws Exception { // !!! very important, otherwise the loops that walk the list of installed // service properties will not run! - ServiceGroup serviceGroup = c.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c.addServiceGroup("CORE", repoVersion2110.getStackId().getStackId()); Service zk = installService(c, serviceGroup, "ZOOKEEPER", repoVersion2110); addServiceComponent(zk, "ZOOKEEPER_SERVER"); addServiceComponent(zk, "ZOOKEEPER_CLIENT"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java index d26e22b85ec..ca4d00aee2b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java @@ -314,7 +314,7 @@ public void testExpressUpgradeUpdateDesiredRepositoryAction() throws Exception { Cluster cluster = clusters.getCluster(clusterName); // Install ZK and HDFS with some components - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", targetStack.getStackId()); Service zk = installService(cluster, serviceGroup, "ZOOKEEPER", repositoryVersion2110); addServiceComponent(zk, "ZOOKEEPER_SERVER"); addServiceComponent(zk, "ZOOKEEPER_CLIENT"); @@ -510,7 +510,7 @@ public void testHostVersionsAfterUpgrade() throws Exception { createHostVersions(repositoryVersion2201, hostName); // Install ZK with some components - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", repositoryVersion2111.getStackName()+"-"+repositoryVersion2111.getStackVersion()); Service zk = installService(cluster, serviceGroup, "ZOOKEEPER", repositoryVersion2110); addServiceComponent(zk, "ZOOKEEPER_SERVER"); addServiceComponent(zk, "ZOOKEEPER_CLIENT"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java index faba98f4cee..dc47bc875fa 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java @@ -159,7 +159,7 @@ public void setup() throws Exception { cr2.setType("flume-conf"); cr2.setVersionTag("version1"); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); cluster.addService(serviceGroup, "FLUME", "FLUME", repositoryVersion); cluster.addService(serviceGroup, "OOZIE", "OOZIE", repositoryVersion); cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java index 752c71c5a98..4a4541d6cf7 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java @@ -100,7 +100,7 @@ public void setup() throws Exception { RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service s = serviceFactory.createNew(cluster, serviceGroup, Collections.emptyList(), serviceName, serviceName, repositoryVersion); cluster.addService(s); service = cluster.getService(serviceName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java index 6c66c5a075a..b0ee246b373 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java @@ -90,7 +90,7 @@ public void teardown() throws AmbariException, SQLException { @Test public void testCanBeRemoved() throws Exception{ - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-1.0"); Service service = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); for (State state : State.values()) { @@ -133,7 +133,7 @@ public void testCanBeRemoved() throws Exception{ @Test public void testGetAndSetServiceInfo() throws AmbariException { String serviceName = "HDFS"; - ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", STACK_ID, new HashSet()); Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList(), serviceName, serviceName, repositoryVersion); cluster.addService(s); @@ -160,7 +160,7 @@ public void testGetAndSetServiceInfo() throws AmbariException { @Test public void testAddGetDeleteServiceComponents() throws AmbariException { String serviceName = "HDFS"; - ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", STACK_ID, new HashSet() ); Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList(), serviceName, serviceName, repositoryVersion); cluster.addService(s); @@ -243,7 +243,7 @@ public void testGetAndSetConfigs() { @Test public void testConvertToResponse() throws AmbariException { String serviceName = "HDFS"; - ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", STACK_ID, new HashSet()); Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList(), serviceName, serviceName, repositoryVersion); cluster.addService(s); Service service = cluster.getService(serviceName); @@ -280,7 +280,7 @@ public void testConvertToResponse() throws AmbariException { @Test public void testServiceMaintenance() throws Exception { String serviceName = "HDFS"; - ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", STACK_ID, new HashSet()); Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList(), serviceName, serviceName, repositoryVersion); cluster.addService(s); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java index 7c02a6564db..6f477634887 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java @@ -1302,7 +1302,7 @@ private Cluster makeCluster(boolean clean, Set additionalServices) throw } // !!! add services - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "HDFS", "HDFS", repositoryVersion)); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "YARN", "YARN", repositoryVersion)); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion)); @@ -1512,7 +1512,7 @@ public void testDowngradeAfterPartialUpgrade() throws Exception { } // !!! add services - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "HDFS", "HDFS", repositoryVersion)); Service s = c.getService("HDFS"); @@ -1584,7 +1584,7 @@ public void testResolverWithFailedUpgrade() throws Exception { } // !!! add services - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion2110)); Service s = c.getService("ZOOKEEPER"); @@ -1653,7 +1653,7 @@ public void testResolverCaseInsensitive() throws Exception { } // Add services - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "HDFS", "HDFS", repositoryVersion211)); Service s = c.getService("HDFS"); @@ -1724,7 +1724,7 @@ public void testResolverBadJmx() throws Exception { } // Add services - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "HDFS", "HDFS", repositoryVersion211)); Service s = c.getService("HDFS"); @@ -1846,7 +1846,7 @@ public void testOrchestrationNoServerSideOnDowngrade() throws Exception { } // !!! add storm - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "STORM", "STORM", repoVersion211)); Service s = c.getService("STORM"); @@ -1953,7 +1953,7 @@ public void testMultipleServerTasks() throws Exception { } // !!! add services - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion)); Service s = c.getService("ZOOKEEPER"); @@ -2138,7 +2138,7 @@ public void testHostGroupingOrchestration() throws Exception { // add ZK Server to both hosts, and then Nimbus to only 1 - this will test // how the HOU breaks out dependencies into stages - ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet()); + ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", STACK_ID_HDP_211, new HashSet()); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "ZOOKEEPER", "ZOOKEEPER", repoVersion211)); c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList(), "HBASE", "HBASE", repoVersion211)); Service zookeeper = c.getService("ZOOKEEPER"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java index 933693ba9d6..74201e0f9d7 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java @@ -298,7 +298,7 @@ private void installHdfsService() throws Exception { cluster.getCurrentStackVersion(), REPO_VERSION); String serviceName = "HDFS"; - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-1.0"); serviceFactory.createNew(cluster, serviceGroup, Collections.emptyList(), serviceName, serviceName, repositoryVersion); Service service = cluster.getService(serviceName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java index b1625ff924b..294f6d8dcac 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java @@ -181,7 +181,7 @@ public void testInitialAlertEvent() throws Exception { private void installHdfsService() throws Exception { String serviceName = "HDFS"; - ServiceGroup serviceGroup = m_cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = m_cluster.addServiceGroup("CORE", "HDP-1.0"); m_serviceFactory.createNew(m_cluster, serviceGroup, Collections.emptyList(), serviceName, serviceName, m_repositoryVersion); Service service = m_cluster.getService(serviceName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java index c7c6b7a06fc..9970b9c90ca 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java @@ -143,7 +143,7 @@ public void setup() throws Exception { clusters.mapHostToCluster(hostName, "c1"); } - serviceGroup = cluster.addServiceGroup("CORE"); + serviceGroup = cluster.addServiceGroup("CORE", "HDP-1.0"); Service service = installService("HDFS", serviceGroup); addServiceComponent(service, "NAMENODE"); addServiceComponent(service, "DATANODE"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java index 2f52065d1d3..7fbaf6f5404 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java @@ -234,7 +234,7 @@ public void testDeleteService() throws Exception { clusters.mapAndPublishHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java index 8ca7dd0cb09..9a7deb6886d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java @@ -229,7 +229,7 @@ private void createDefaultCluster(Set hostNames, StackId stackId) throws clusters.mapAndPublishHostsToCluster(hostNames, clusterName); c1 = clusters.getCluster(clusterName); - serviceGroup = c1.addServiceGroup("CORE"); + serviceGroup = c1.addServiceGroup("CORE", stackId.getStackId()); } public ClusterEntity createDummyData() { @@ -334,7 +334,7 @@ private Cluster createClusterForRU(String clusterName, RepositoryVersionEntity r } // Add Services - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service s1 = serviceFactory.createNew(cluster, serviceGroup, Collections.emptyList(), "HDFS", "HDFS", repositoryVersion); Service s2 = serviceFactory.createNew(cluster, serviceGroup, Collections.emptyList(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion); Service s3 = serviceFactory.createNew(cluster, serviceGroup, Collections.emptyList(), "GANGLIA", "GANGLIA", repositoryVersion); @@ -1872,7 +1872,7 @@ public void testTransitionNonReportableHost() throws Exception { RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(c1); - ServiceGroup serviceGroup = c1.addServiceGroup("CORE"); + ServiceGroup serviceGroup = c1.addServiceGroup("CORE", stackId.getStackId()); Service service = c1.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repositoryVersion); ServiceComponent sc = service.addServiceComponent("ZOOKEEPER_SERVER"); sc.addServiceComponentHost("h-1"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java index f5d7ad0aa00..112166882ab 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java @@ -118,7 +118,7 @@ public void setup() throws Exception { helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); // install HDFS - serviceGroup = cluster.addServiceGroup("CORE"); + serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); installService("HDFS", serviceGroup); writerStoppedSignal = new CountDownLatch(NUMBER_OF_THREADS); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java index 8355d36a5f0..849326b6dc2 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java @@ -427,7 +427,7 @@ public void testDeleteCluster() throws Exception { // host config override host1.addDesiredConfig(cluster.getClusterId(), true, "_test", config2); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-1.0"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); //Assert.assertNotNull(injector.getInstance(ClusterServiceDAO.class).findByClusterAndServiceNames(c1, "HDFS")); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java index a91319ee2ae..e3d76b323fe 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java @@ -122,7 +122,7 @@ public void setup() throws Exception { helper.createStack(stackId); clusters.addCluster("c1", stackId); cluster = clusters.getCluster("c1"); - serviceGroup = serviceGroupFactory.createNew(cluster, "test_service_group", new HashSet()); + serviceGroup = serviceGroupFactory.createNew(cluster, "test_service_group", stackId, new HashSet()); String hostName = "c6401.ambari.apache.org"; clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java index a62dd6e9672..8289a0db5b6 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java @@ -126,7 +126,7 @@ public void setup() throws Exception { helper.createStack(stackId); clusters.addCluster("c1", stackId); cluster = clusters.getCluster("c1"); - serviceGroup = serviceGroupFactory.createNew(cluster, "test_service_group", new HashSet()); + serviceGroup = serviceGroupFactory.createNew(cluster, "test_service_group", stackId, new HashSet()); Config config1 = configFactory.createNew(cluster, "test-type1", null, new HashMap<>(), new HashMap<>()); Config config2 = configFactory.createNew(cluster, "test-type2", null, new HashMap<>(), new HashMap<>()); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java index 7c6c258e576..7a17ccc5025 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java @@ -133,7 +133,7 @@ public void setup() throws Exception { createCluster(stackId, clusterName, repositoryVersion.getVersion()); - serviceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "test_group", new HashSet<>()); + serviceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "test_group", stackId, new HashSet<>()); hostAttributes.put("os_family", "redhat"); hostAttributes.put("os_release_version", "5.9"); Set hostNames = new HashSet<>(); @@ -713,7 +713,7 @@ public void testStaleConfigs() throws Exception { String clusterName = "c2"; createCluster(stackId, clusterName, ""); - ServiceGroup customServiceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "custom_group", new HashSet<>()); + ServiceGroup customServiceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "custom_group", stackId, new HashSet<>()); final String hostName = "h3"; Set hostNames = new HashSet<>(); @@ -906,7 +906,7 @@ public void testStaleConfigsAttributes() throws Exception { String clusterName = "c2"; createCluster(stackId, clusterName, ""); - ServiceGroup customServiceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "custom_group", new HashSet<>()); + ServiceGroup customServiceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "custom_group", stackId, new HashSet<>()); final String hostName = "h3"; Set hostNames = new HashSet<>(); @@ -1035,7 +1035,7 @@ public void testMaintenance() throws Exception { String clusterName = "c2"; createCluster(stackId, clusterName, ""); - ServiceGroup customServiceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "custom_group", new HashSet<>()); + ServiceGroup customServiceGroup = serviceGroupFactory.createNew(clusters.getCluster(clusterName), "custom_group", stackId, new HashSet<>()); final String hostName = "h3"; Set hostNames = new HashSet<>(); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/testing/DBInconsistencyTests.java b/ambari-server/src/test/java/org/apache/ambari/server/testing/DBInconsistencyTests.java index 2ba9c39df62..c78b0ee2e09 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/testing/DBInconsistencyTests.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/testing/DBInconsistencyTests.java @@ -91,7 +91,7 @@ public void testOrphanedSCHDesiredEntityReAdd() throws Exception { Assert.assertNotNull(clusterId); Cluster cluster = clusters.getCluster(OrmTestHelper.CLUSTER_NAME); - ServiceGroup serviceGroup = cluster.addServiceGroup("CORE"); + ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", "HDP-1.0"); Assert.assertNotNull(cluster); helper.addHost(clusters, cluster, "h1"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java index b56835424eb..895562d7756 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java @@ -336,7 +336,7 @@ public void testCreateAmbariResources() throws Exception { assertEquals(String.format("%s-%s", STACK_NAME, STACK_VERSION), clusterRequest.getStackVersion()); Set serviceGroupRequests = serviceGroupRequestCapture.getValue(); - Set expectedServiceGroupRequests = Collections.singleton(new ServiceGroupRequest(cluster.getClusterName(), AmbariContext.DEFAULT_SERVICE_GROUP_NAME)); + Set expectedServiceGroupRequests = Collections.singleton(new ServiceGroupRequest(cluster.getClusterName(), AmbariContext.DEFAULT_SERVICE_GROUP_NAME, clusterRequest.getStackVersion())); assertEquals(expectedServiceGroupRequests, serviceGroupRequests); Collection serviceRequests = serviceRequestCapture.getValue();