This is an automated email from the ASF dual-hosted git repository. mradhakrishnan pushed a commit to branch AMBARI-24711 in repository https://gitbox.apache.org/repos/asf/ambari.git
commit 9360b63c8f12a969f1131268c225d5890bee36cf Author: Madhuvanthi Radhakrishnan <[email protected]> AuthorDate: Thu Mar 15 14:40:47 2018 -0700 [AMBARI-23254] Mpack should have both displayName and description --- .../ambari/server/controller/MpackResponse.java | 10 +++ .../controller/internal/MpackResourceProvider.java | 23 ++++++ .../java/org/apache/ambari/server/state/Mpack.java | 96 +++++++++++++++++----- 3 files changed, 108 insertions(+), 21 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java index bc1e47d..70ddabe 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java @@ -36,6 +36,7 @@ public class MpackResponse { private Long registryId; private String stackId; private String description; + private String displayName; public MpackResponse(Mpack mpack) { this.id = mpack.getResourceId(); @@ -45,6 +46,7 @@ public class MpackResponse { this.mpackUri = mpack.getMpackUri(); this.registryId = mpack.getRegistryId(); this.description = mpack.getDescription(); + this.displayName = mpack.getDisplayName(); } public Long getId() { @@ -111,6 +113,14 @@ public class MpackResponse { this.stackId = stackId; } + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + @Override public int hashCode() { int result = 1; diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java index 57e987d..110e0a2 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java @@ -74,6 +74,7 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider { public static final String MPACK_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name"; public static final String MPACK_VERSION = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_version"; public static final String MPACK_DESCRIPTION = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_description"; + public static final String MPACK_DISPLAY_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_display_name"; public static final String MPACK_URI = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_uri"; public static final String MODULES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "modules"; public static final String STACK_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "stack_name"; @@ -114,6 +115,7 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider { PROPERTY_IDS.add(MODULES); PROPERTY_IDS.add(STACK_NAME_PROPERTY_ID); PROPERTY_IDS.add(STACK_VERSION_PROPERTY_ID); + PROPERTY_IDS.add(MPACK_DISPLAY_NAME); // keys KEY_PROPERTY_IDS.put(Resource.Type.Mpack, MPACK_RESOURCE_ID); @@ -153,6 +155,7 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider { resource.setProperty(MPACK_URI, response.getMpackUri()); resource.setProperty(MPACK_DESCRIPTION, response.getDescription()); resource.setProperty(REGISTRY_ID, response.getRegistryId()); + resource.setProperty(MPACK_DISPLAY_NAME, response.getDisplayName()); associatedResources.add(resource); return getRequestStatus(null, associatedResources); } @@ -241,6 +244,8 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider { resource.setProperty(MPACK_URI, response.getMpackUri()); resource.setProperty(MPACK_DESCRIPTION, response.getDescription()); resource.setProperty(REGISTRY_ID, response.getRegistryId()); + resource.setProperty(MPACK_DISPLAY_NAME, response.getDisplayName()); + results.add(resource); } } else { @@ -293,6 +298,24 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider { "Either the management pack ID or the stack name and version are required when searching"); } + MpackResponse response = getManagementController().getMpack(mpackId); + Resource resource = new ResourceImpl(Resource.Type.Mpack); + if (null != response) { + resource.setProperty(MPACK_RESOURCE_ID, response.getId()); + resource.setProperty(MPACK_ID, response.getMpackId()); + resource.setProperty(MPACK_NAME, response.getMpackName()); + resource.setProperty(MPACK_VERSION, response.getMpackVersion()); + resource.setProperty(MPACK_URI, response.getMpackUri()); + resource.setProperty(MPACK_DESCRIPTION, response.getDescription()); + resource.setProperty(REGISTRY_ID, response.getRegistryId()); + resource.setProperty(MPACK_DISPLAY_NAME, response.getDisplayName()); + + StackId stackId = new StackId(response.getStackId()); + resource.setProperty(STACK_NAME_PROPERTY_ID, stackId.getStackName()); + resource.setProperty(STACK_VERSION_PROPERTY_ID, stackId.getStackVersion()); + results.add(resource); + } + if (results.isEmpty()) { throw new NoSuchResourceException( "The requested resource doesn't exist: " + predicate); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java index 233cd95..3e76338 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java @@ -18,9 +18,12 @@ package org.apache.ambari.server.state; import com.google.gson.annotations.SerializedName; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.builder.EqualsBuilder; import java.util.HashMap; import java.util.List; +import java.util.Objects; /** * Represents the state of an mpack. @@ -59,6 +62,9 @@ public class Mpack { @SerializedName("description") private String description; + @SerializedName("displayName") + private String displayName; + private String mpackUri; public Long getResourceId() { @@ -141,6 +147,54 @@ public class Mpack { this.definition = definition; } + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + * Gets the module with the given name. Module names are service names. + * + * @param moduleName + * the name of the module. + * @return the module or {@code null}. + */ + public Module getModule(String moduleName) { + for (Module module : modules) { + if (StringUtils.equals(moduleName, module.getName())) { + return module; + } + } + + return null; + } + + /** + * Gets a component from a given module. + * + * @param moduleName + * the module (service) name. + * @param moduleComponentName + * the name of the component. + * @return the component or {@code null}. + */ + public ModuleComponent getModuleComponent(String moduleName, String moduleComponentName) { + for (Module module : modules) { + ModuleComponent moduleComponent = module.getModuleComponent(moduleComponentName); + if (null != moduleComponent) { + return moduleComponent; + } + } + + return null; + } + + /** + * {@inheritDoc} + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -148,31 +202,27 @@ public class Mpack { Mpack mpack = (Mpack) o; - if (!resourceId.equals(mpack.resourceId)) return false; - if (registryId != null ? !registryId.equals(mpack.registryId) : mpack.registryId != null) return false; - if (!mpackId.equals(mpack.mpackId)) return false; - if (!name.equals(mpack.name)) return false; - if (!version.equals(mpack.version)) return false; - if (!prerequisites.equals(mpack.prerequisites)) return false; - if (!modules.equals(mpack.modules)) return false; - if (!definition.equals(mpack.definition)) return false; - if (!description.equals(mpack.description)) return false; - return mpackUri.equals(mpack.mpackUri); + Mpack that = (Mpack) o; + EqualsBuilder equalsBuilder = new EqualsBuilder(); + equalsBuilder.append(resourceId, that.resourceId); + equalsBuilder.append(registryId, that.registryId); + equalsBuilder.append(mpackId, that.mpackId); + equalsBuilder.append(name, that.name); + equalsBuilder.append(version, that.version); + equalsBuilder.append(prerequisites, that.prerequisites); + equalsBuilder.append(modules, that.modules); + equalsBuilder.append(definition, that.definition); + equalsBuilder.append(description, that.description); + equalsBuilder.append(mpackUri, that.mpackUri); + equalsBuilder.append(displayName, that.displayName); + + return equalsBuilder.isEquals(); } @Override public int hashCode() { - int result = resourceId.hashCode(); - result = 31 * result + (registryId != null ? registryId.hashCode() : 0); - result = 31 * result + mpackId.hashCode(); - result = 31 * result + name.hashCode(); - result = 31 * result + version.hashCode(); - result = 31 * result + prerequisites.hashCode(); - result = 31 * result + modules.hashCode(); - result = 31 * result + definition.hashCode(); - result = 31 * result + description.hashCode(); - result = 31 * result + mpackUri.hashCode(); - return result; + return Objects.hash(resourceId, registryId, mpackId, name, version, prerequisites, modules, + definition, description, mpackUri, displayName); } @Override @@ -188,6 +238,7 @@ public class Mpack { ", definition='" + definition + '\'' + ", description='" + description + '\'' + ", mpackUri='" + mpackUri + '\'' + + ", displayName='" + mpackUri + '\'' + '}'; } @@ -216,5 +267,8 @@ public class Mpack { if (this.definition == null) { this.definition = mpack.getDefinition(); } + if (displayName == null) { + displayName = mpack.getDisplayName(); + } } }
