AMBARI-22297. Fix possible ClassCastException (adoroszlai)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/47348a11 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/47348a11 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/47348a11 Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2 Commit: 47348a1182aaa1e3adba53d174ac4fcdeae3f1cc Parents: 0f3d7ce Author: Attila Doroszlai <adorosz...@hortonworks.com> Authored: Fri Nov 17 16:32:18 2017 +0100 Committer: Doroszlai, Attila <adorosz...@hortonworks.com> Committed: Fri Dec 8 20:24:24 2017 +0100 ---------------------------------------------------------------------- .../apache/ambari/server/topology/BlueprintImplV2.java | 4 ++-- .../org/apache/ambari/server/topology/BlueprintV2.java | 6 +++--- .../server/topology/ClusterConfigurationRequest.java | 11 ++++------- 3 files changed, 9 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/47348a11/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java index ad98adc..93dba0c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintImplV2.java @@ -291,8 +291,8 @@ public class BlueprintImplV2 implements BlueprintV2 { @Nonnull @Override - public Collection<String> getComponentNames(ServiceId serviceId) { - return getComponents(serviceId).stream().map(ComponentV2::getName).collect(toList()); + public Set<String> getComponentNames(ServiceId serviceId) { + return getComponents(serviceId).stream().map(ComponentV2::getName).collect(toSet()); } @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/47348a11/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java index f6314be..eed0b68 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2.java @@ -21,6 +21,7 @@ package org.apache.ambari.server.topology; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import javax.annotation.Nonnull; @@ -124,11 +125,10 @@ public interface BlueprintV2 { * Get the components that are included in the blueprint for the specified service. * * @param serviceId serviceId - * - * @return collection of component names for the service. Will not return null. + * @return set of component names for the service. Will not return null. */ @Nonnull - Collection<String> getComponentNames(ServiceId serviceId); + Set<String> getComponentNames(ServiceId serviceId); /** * Get the component names s that are included in the blueprint for the specified service. http://git-wip-us.apache.org/repos/asf/ambari/blob/47348a11/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java index 3273a4e..c380a85 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java @@ -179,7 +179,7 @@ public class ClusterConfigurationRequest { // generate principals & keytabs for headless identities AmbariContext.getController().getKerberosHelper() .ensureHeadlessIdentities(cluster, existingConfigurations, - new HashSet(blueprint.getAllServices())); + new HashSet<>(blueprint.getAllServiceNames())); // apply Kerberos specific configurations Map<String, Map<String, String>> updatedConfigs = AmbariContext.getController().getKerberosHelper() @@ -238,13 +238,10 @@ public class ClusterConfigurationRequest { Map<String, Set<String>> serviceComponents = new HashMap<>(); Collection<Service> services = blueprint.getAllServices(); - if(services != null) { + if (services != null) { for (Service service : services) { - Collection<ComponentV2> components = blueprint.getComponents(service); - serviceComponents.put(service.getType(), - (components == null) - ? Collections.emptySet() - : new HashSet(blueprint.getComponents(service))); + ServiceId serviceId = service.getId(); + serviceComponents.put(service.getType(), blueprint.getComponentNames(serviceId)); } }