This is an automated email from the ASF dual-hosted git repository. jgolieb pushed a commit to branch branch-feature-AMBARI-14714-mpack-advisor in repository https://gitbox.apache.org/repos/asf/ambari.git
commit d7429cbbdc353fa2899ce5d774153e1879b9b176 Author: Doroszlai, Attila <[email protected]> AuthorDate: Tue May 29 19:32:03 2018 +0200 AMBARI-23746. Cannot create same named component in different service groups in same request --- .../internal/ComponentResourceProvider.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java index 2ffce9d..c59e51d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java @@ -68,6 +68,7 @@ import org.apache.commons.lang.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; @@ -393,7 +394,7 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide ServiceComponentFactory serviceComponentFactory = getManagementController().getServiceComponentFactory(); // do all validation checks - Map<String, Map<String, Set<String>>> componentNames = new HashMap<>(); + Map<String, Set<Set<String>>> componentNames = new HashMap<>(); Set<String> duplicates = new HashSet<>(); for (ServiceComponentRequest request : requests) { @@ -413,21 +414,16 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide debug("Received a createComponent request: {}", request); - if (!componentNames.containsKey(request.getClusterName())) { - componentNames.put(request.getClusterName(), new HashMap<>()); - } - - Map<String, Set<String>> serviceComponents = componentNames.get(request.getClusterName()); - if (!serviceComponents.containsKey(request.getServiceName())) { - serviceComponents.put(request.getServiceName(), new HashSet<String>()); - } + Set<String> componentID = ImmutableSet.of(request.getServiceGroupName(), request.getServiceName(), request.getComponentName()); + boolean added = componentNames + .computeIfAbsent(request.getClusterName(), __ -> new HashSet<>()) + .add(componentID); - if (serviceComponents.get(request.getServiceName()).contains(request.getComponentName())) { + if (!added) { // throw error later for dup duplicates.add(request.toString()); continue; } - serviceComponents.get(request.getServiceName()).add(request.getComponentName()); if (StringUtils.isNotEmpty(request.getDesiredState())) { Validate.isTrue(State.INIT == State.valueOf(request.getDesiredState()), @@ -462,9 +458,8 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide // Validate dups if (!duplicates.isEmpty()) { - //Java8 has StringJoiner library but ambari is not on Java8 yet. throw new DuplicateResourceException("Attempted to create one or more components which already exist:" - + StringUtils.join(duplicates, ",")); + + String.join(", ", duplicates)); } // now doing actual work -- To stop receiving notification emails like this one, please contact [email protected].
