This is an automated email from the ASF dual-hosted git repository. jonathanhurley pushed a commit to branch branch-feature-AMBARI-14714 in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by this push: new fadd582 AMBARI-23735 - Expose Mpack Information As Individual Fields for Service Groups fadd582 is described below commit fadd582759114fe5123fdd41f90fb5a28c306736 Author: Jonathan Hurley <jhur...@hortonworks.com> AuthorDate: Tue May 1 10:52:24 2018 -0400 AMBARI-23735 - Expose Mpack Information As Individual Fields for Service Groups --- .../server/controller/ServiceGroupRequest.java | 60 ++++++++++++---- .../server/controller/ServiceGroupResponse.java | 80 +++++++++++++++++----- .../internal/ServiceGroupResourceProvider.java | 75 +++++++++++--------- .../ambari/server/state/ServiceGroupImpl.java | 27 +++----- .../internal/ServiceGroupResourceProviderTest.java | 2 +- 5 files changed, 160 insertions(+), 84 deletions(-) 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 b9f94ce..d996731 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 @@ -19,16 +19,25 @@ package org.apache.ambari.server.controller; import java.util.Objects; +import org.apache.commons.lang.builder.EqualsBuilder; + +import com.google.common.base.MoreObjects; + 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, String version) { + /** + * ServiceGroups should be addressed by their StackID and/or Mpack ID + */ + @Deprecated + private String stack; // Associated stack version info + + public ServiceGroupRequest(String clusterName, String serviceGroupName, String stack) { this.clusterName = clusterName; this.serviceGroupName = serviceGroupName; - this.version = version; + this.stack = stack; } /** @@ -60,42 +69,65 @@ public class ServiceGroupRequest { } /** + * ServiceGroups should be addressed by their StackID and/or Mpack ID + * * @return the servicegroup version */ - public String getVersion() { - return version; + @Deprecated + public String getStack() { + return stack; } /** - * @param version the servicegroup version to set + * ServiceGroups should be addressed by their StackID and/or Mpack ID + * + * @param stack + * the servicegroup stack to set */ - public void setVersion(String version) { - this.version = version; + @Deprecated + public void setStack(String stack) { + this.stack = stack; } + /** + * {@inheritDoc} + */ @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("clusterName=").append(clusterName).append(", serviceGroupName=").append(serviceGroupName).append(", version=").append(version); - return sb.toString(); + return MoreObjects.toStringHelper(this) + .add("clusterName", clusterName) + .add("serviceGroupName",serviceGroupName) + .add("stackId", stack).toString(); } + /** + * {@inheritDoc} + */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } + if (obj == null || getClass() != obj.getClass()) { return false; } - ServiceGroupRequest other = (ServiceGroupRequest) obj; + ServiceGroupRequest that = (ServiceGroupRequest) obj; + EqualsBuilder equalsBuilder = new EqualsBuilder(); - return Objects.equals(clusterName, other.clusterName) && Objects.equals(serviceGroupName, other.serviceGroupName) && Objects.equals(version, other.version); + equalsBuilder.append(clusterName, that.clusterName); + equalsBuilder.append(serviceGroupName, that.serviceGroupName); + equalsBuilder.append(stack, that.stack); + + return equalsBuilder.isEquals(); } + /** + * {@inheritDoc} + */ @Override public int hashCode() { - return Objects.hash(clusterName, serviceGroupName, version); + return Objects.hash(clusterName, serviceGroupName, stack); } } \ 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 afd7f24..be47b30 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,7 +18,10 @@ package org.apache.ambari.server.controller; -import java.util.Objects; +import org.apache.ambari.server.state.StackId; +import org.apache.commons.lang.builder.EqualsBuilder; + +import com.google.common.base.Objects; import io.swagger.annotations.ApiModelProperty; @@ -28,15 +31,17 @@ public class ServiceGroupResponse { private Long serviceGroupId; private String clusterName; private String serviceGroupName; - private String version; + private Long mpackId; + private StackId stackId; - public ServiceGroupResponse(Long clusterId, String clusterName, Long serviceGroupId, String serviceGroupName, String version) { + public ServiceGroupResponse(Long clusterId, String clusterName, Long mpackId, StackId stackId, + Long serviceGroupId, String serviceGroupName) { this.clusterId = clusterId; this.serviceGroupId = serviceGroupId; this.clusterName = clusterName; this.serviceGroupName = serviceGroupName; - this.version = version; - + this.mpackId = mpackId; + this.stackId = stackId; } /** @@ -96,27 +101,68 @@ public class ServiceGroupResponse { } /** - * @return the servicegroup version (stackName-stackVersion) + * @return the servicegroup stackId (stackName-stackVersion) */ - public String getVersion() { - return version; + public StackId getStackId() { + return stackId; } /** - * @param version the servicegroup version (stackName-stackVersion) + * @param version + * the servicegroup stackId (stackName-stackVersion) */ - public void setVersion(String version) { - this.version = version; + public void setStackId(StackId stackId) { + this.stackId = stackId; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + /** + * Gets the MpackID for this service group. + * + * @return the mpackId + */ + public Long getMpackId() { + return mpackId; + } - ServiceGroupResponse other = (ServiceGroupResponse) o; + /** + * Sets the Mpack ID for this service group. + * + * @param mpackId + * the mpackId to set + */ + public void setMpackId(Long mpackId) { + this.mpackId = mpackId; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (object == null || getClass() != object.getClass()) { + return false; + } + + ServiceGroupResponse that = (ServiceGroupResponse) object; + EqualsBuilder equalsBuilder = new EqualsBuilder(); + + equalsBuilder.append(clusterId, that.clusterId); + equalsBuilder.append(clusterName, that.clusterName); + equalsBuilder.append(mpackId, that.mpackId); + equalsBuilder.append(stackId, that.stackId); + equalsBuilder.append(serviceGroupId, that.serviceGroupId); + equalsBuilder.append(serviceGroupName, that.serviceGroupName); + return equalsBuilder.isEquals(); + } - return Objects.equals(clusterId, other.clusterId) && Objects.equals(clusterName, other.clusterName) && Objects.equals(serviceGroupName, other.serviceGroupName) && Objects.equals(version, other.version); + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(clusterId, clusterName, mpackId, stackId, serviceGroupId, + serviceGroupName); } /** 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 ee87b1b..036bf38 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 @@ -31,9 +31,8 @@ import org.apache.ambari.server.DuplicateResourceException; import org.apache.ambari.server.ObjectNotFoundException; import org.apache.ambari.server.ParentObjectNotFoundException; import org.apache.ambari.server.ServiceGroupNotFoundException; -import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.StaticallyInject; import org.apache.ambari.server.controller.AmbariManagementController; -import org.apache.ambari.server.controller.KerberosHelper; import org.apache.ambari.server.controller.RequestStatusResponse; import org.apache.ambari.server.controller.ServiceGroupRequest; import org.apache.ambari.server.controller.ServiceGroupResponse; @@ -55,19 +54,17 @@ 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; -import com.google.gson.Gson; -import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.AssistedInject; /** * Resource provider for service resources. - **/ - + * + */ +@StaticallyInject public class ServiceGroupResourceProvider extends AbstractControllerResourceProvider { @@ -79,16 +76,25 @@ 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"; + public static final String SERVICE_GROUP_MPACK_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_id"; + public static final String SERVICE_GROUP_MPACK_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name"; + public static final String SERVICE_GROUP_MPACK_VERSION = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_version"; + + /** + * The pieces of the Mpack (ID, name, version) should be broken out - there's + * no need for a single field for this anymore, and we certainly should not be + * creating a ServiceGroup based on a string ID + */ + @Deprecated + public static final String SERVICE_GROUP_STACK_PROPERTY_ID = RESPONSE_KEY + + PropertyHelper.EXTERNAL_PATH_SEP + "stack"; private static Set<String> pkPropertyIds = - new HashSet<String>(Arrays.asList(new String[]{ + new HashSet<>(Arrays.asList(new String[]{ SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID, SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID})); - private static Gson gson = StageUtils.getGson(); - /** * The property ids for an service group resource. */ @@ -105,22 +111,17 @@ 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); + PROPERTY_IDS.add(SERVICE_GROUP_STACK_PROPERTY_ID); + PROPERTY_IDS.add(SERVICE_GROUP_MPACK_ID); + PROPERTY_IDS.add(SERVICE_GROUP_MPACK_NAME); + PROPERTY_IDS.add(SERVICE_GROUP_MPACK_VERSION); // 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); + KEY_PROPERTY_IDS.put(Resource.Type.Stack, SERVICE_GROUP_STACK_PROPERTY_ID); } - private Clusters clusters; - - /** - * kerberos helper - */ - @Inject - private KerberosHelper kerberosHelper; - // ----- Constructors ---------------------------------------------------- /** @@ -164,7 +165,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv 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()); + resource.setProperty(SERVICE_GROUP_STACK_PROPERTY_ID, response.getStackId()); associatedResources.add(resource); } @@ -192,9 +193,11 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv }); Set<String> requestedIds = getRequestPropertyIds(request, predicate); - Set<Resource> resources = new HashSet<Resource>(); + Set<Resource> resources = new HashSet<>(); for (ServiceGroupResponse response : responses) { + StackId stackId = response.getStackId(); + Resource resource = new ResourceImpl(Resource.Type.ServiceGroup); setResourceProperty(resource, SERVICE_GROUP_CLUSTER_ID_PROPERTY_ID, response.getClusterId(), requestedIds); @@ -204,8 +207,14 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv 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); + setResourceProperty(resource, SERVICE_GROUP_STACK_PROPERTY_ID, + stackId.toString(), requestedIds); + + // set the specifics of the mpack regardless of what keys were requested + resource.setProperty(SERVICE_GROUP_MPACK_ID, response.getMpackId()); + resource.setProperty(SERVICE_GROUP_MPACK_NAME, stackId.getStackName()); + resource.setProperty(SERVICE_GROUP_MPACK_VERSION, stackId.getStackVersion()); + resources.add(resource); } return resources; @@ -252,7 +261,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv if (propertyIds.isEmpty()) { return propertyIds; } - Set<String> unsupportedProperties = new HashSet<String>(); + Set<String> unsupportedProperties = new HashSet<>(); return unsupportedProperties; } @@ -275,7 +284,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv private ServiceGroupRequest getRequest(Map<String, Object> properties) { String clusterName = (String) properties.get(SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID); String serviceGroupName = (String) properties.get(SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID); - String version = (String) properties.get(SERVICE_GROUP_VERSION_PROPERTY_ID); + String version = (String) properties.get(SERVICE_GROUP_STACK_PROPERTY_ID); ServiceGroupRequest svcRequest = new ServiceGroupRequest(clusterName, serviceGroupName, version); return svcRequest; } @@ -299,7 +308,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv Cluster cluster = clusters.getCluster(request.getClusterName()); // Already checked that service group does not exist - ServiceGroup sg = cluster.addServiceGroup(request.getServiceGroupName(), request.getVersion()); + ServiceGroup sg = cluster.addServiceGroup(request.getServiceGroupName(), request.getStack()); createdSvcGrps.add(sg.convertToResponse()); } return createdSvcGrps; @@ -308,7 +317,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv // Get services from the given set of requests. protected Set<ServiceGroupResponse> getServiceGroups(Set<ServiceGroupRequest> requests) throws AmbariException { - Set<ServiceGroupResponse> response = new HashSet<ServiceGroupResponse>(); + Set<ServiceGroupResponse> response = new HashSet<>(); for (ServiceGroupRequest request : requests) { try { response.addAll(getServiceGroups(request)); @@ -398,20 +407,18 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv private void validateCreateRequests(Set<ServiceGroupRequest> requests, Clusters clusters) throws AuthorizationException, AmbariException, IllegalArgumentException { - - AmbariMetaInfo ambariMetaInfo = getManagementController().getAmbariMetaInfo(); Map<String, Set<String>> serviceGroupNames = new HashMap<>(); Set<String> duplicates = new HashSet<>(); for (ServiceGroupRequest request : requests) { final String clusterName = request.getClusterName(); final String serviceGroupName = request.getServiceGroupName(); - String version = request.getVersion(); + String version = request.getStack(); //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()); + request.setStack(stackId.getStackId()); } catch (ClusterNotFoundException e) { throw new ParentObjectNotFoundException("Cluster " + clusterName + " does not exist: ", e); } @@ -419,7 +426,7 @@ public class ServiceGroupResourceProvider extends AbstractControllerResourceProv 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"); + Validate.notEmpty(request.getStack(), "Stack version should be provided when creating a service group"); if (LOG.isDebugEnabled()) { LOG.debug("Received a createServiceGroup request" + 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 aed1de6..6813024 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 @@ -52,12 +52,11 @@ public class ServiceGroupImpl implements ServiceGroup { private final Cluster cluster; private final ClusterDAO clusterDAO; - private final StackDAO stackDAO; private final ServiceGroupDAO serviceGroupDAO; private final ServiceFactory serviceFactory; private final AmbariEventPublisher eventPublisher; - private final Clusters clusters; + private Long mpackId; private Long serviceGroupId; private String serviceGroupName; private StackId stackId; @@ -76,9 +75,7 @@ public class ServiceGroupImpl implements ServiceGroup { Clusters clusters) throws AmbariException { this.cluster = cluster; - this.clusters = clusters; this.clusterDAO = clusterDAO; - this.stackDAO = stackDAO; this.serviceGroupDAO = serviceGroupDAO; this.serviceFactory = serviceFactory; this.eventPublisher = eventPublisher; @@ -90,7 +87,11 @@ public class ServiceGroupImpl implements ServiceGroup { serviceGroupEntity.setClusterId(cluster.getClusterId()); serviceGroupEntity.setServiceGroupId(serviceGroupId); serviceGroupEntity.setServiceGroupName(serviceGroupName); - serviceGroupEntity.setStack(stackDAO.find(stackId)); + + StackEntity stackEntity = stackDAO.find(stackId); + + mpackId = stackEntity.getMpackId(); + serviceGroupEntity.setStack(stackEntity); if (serviceGroupDependencies == null) { this.serviceGroupDependencies = new HashSet<>(); } else { @@ -110,9 +111,7 @@ public class ServiceGroupImpl implements ServiceGroup { AmbariEventPublisher eventPublisher, Clusters clusters) throws AmbariException { this.cluster = cluster; - this.clusters = clusters; this.clusterDAO = clusterDAO; - this.stackDAO = stackDAO; this.serviceGroupDAO = serviceGroupDAO; this.serviceFactory = serviceFactory; this.eventPublisher = eventPublisher; @@ -120,6 +119,7 @@ public class ServiceGroupImpl implements ServiceGroup { serviceGroupId = serviceGroupEntity.getServiceGroupId(); serviceGroupName = serviceGroupEntity.getServiceGroupName(); StackEntity stack = serviceGroupEntity.getStack(); + mpackId = stack.getMpackId(); stackId = new StackId(stack.getStackName(), stack.getStackVersion()); serviceGroupDependencies = getServiceGroupDependencies(serviceGroupEntity.getServiceGroupDependencies()); @@ -175,7 +175,8 @@ public class ServiceGroupImpl implements ServiceGroup { @Override public ServiceGroupResponse convertToResponse() { ServiceGroupResponse r = new ServiceGroupResponse(cluster.getClusterId(), - cluster.getClusterName(), getServiceGroupId(), getServiceGroupName(), stackId.getStackId()); + cluster.getClusterName(), mpackId, stackId, getServiceGroupId(), getServiceGroupName()); + return r; } @@ -324,16 +325,6 @@ public class ServiceGroupImpl implements ServiceGroup { serviceGroupDAO.createServiceGroupDependency(serviceGroupDependencyEntity); } - - private Long getServiceGroupClusterId(Long serviceGroupId) throws AmbariException { - for (Cluster cl : clusters.getClusters().values()) { - if (cl.getServiceGroupsById().containsKey(serviceGroupId)) { - return cl.getClusterId(); - } - } - throw new AmbariException("Service group with id=" + serviceGroupId + " is not available."); - } - @Override public ServiceGroupEntity deleteServiceGroupDependency(Long dependencyServiceGroupId) throws AmbariException { ServiceGroupEntity serviceGroupEntity = serviceGroupDAO.findByPK(getServiceGroupId()); 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 7db5cc1..a33c2a2 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 @@ -111,7 +111,7 @@ public class ServiceGroupResourceProviderTest { ClusterController clusterController = createNiceMock(ClusterController.class); ServiceGroup coreServiceGroup = createNiceMock(ServiceGroup.class); ServiceGroup edmServiceGroup = createNiceMock(ServiceGroup.class); - ServiceGroupResponse coreServiceGroupResponse = new ServiceGroupResponse(1l, "c1", 1l, "CORE", STACK_ID); + ServiceGroupResponse coreServiceGroupResponse = new ServiceGroupResponse(1l, "c1", 1L, new StackId(STACK_ID), 1l, "CORE"); expect(ambariManagementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); expect(ambariManagementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster(clusterName)).andReturn(cluster).anyTimes(); -- To stop receiving notification emails like this one, please contact jonathanhur...@apache.org.