You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/11/24 12:39:56 UTC

[14/39] ambari git commit: AMBARI-22325. Set stacks in blueprint (adoroszlai)

AMBARI-22325. Set stacks in blueprint (adoroszlai)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8afa31e9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8afa31e9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8afa31e9

Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2
Commit: 8afa31e9600c13903c70cd250b73095e9e24a9dd
Parents: acfb6b4
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Mon Nov 13 11:24:47 2017 +0100
Committer: Doroszlai, Attila <ad...@hortonworks.com>
Committed: Fri Nov 24 13:30:45 2017 +0100

----------------------------------------------------------------------
 .../server/controller/StackV2Factory.java       |  3 +--
 .../server/topology/BlueprintV2Factory.java     | 23 ++++++++++----------
 2 files changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8afa31e9/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
index 0735171..c7113ae 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackV2Factory.java
@@ -52,8 +52,7 @@ public class StackV2Factory {
     return create(stack.getStackName(), stack.getStackVersion());
   }
 
-  public StackV2 create(String stackId) throws AmbariException {
-    StackId id = new StackId(stackId);
+  public StackV2 create(StackId id) throws AmbariException {
     return create(id.getStackName(), id.getStackVersion());
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/8afa31e9/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
index 4f22aea..9870dcb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Factory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import org.apache.ambari.server.AmbariException;
@@ -102,27 +103,29 @@ public class BlueprintV2Factory {
   public BlueprintV2 convertFromJson(String json) throws IOException {
     BlueprintImplV2 blueprintV2 = createObjectMapper().readValue(json, BlueprintImplV2.class);
     blueprintV2.postDeserialization();
-    blueprintV2.setStacks(
-      blueprintV2.getStackIds().stream().collect(Collectors.toMap(
-        StackId::new,
-        stackId -> parseStack(new StackId(stackId))
-      ))
-    );
+    updateStacks(blueprintV2);
     return blueprintV2;
   }
 
+  private void updateStacks(BlueprintImplV2 blueprintV2) {
+    Map<StackId, StackV2> stacks = blueprintV2.getStackIds().stream()
+      .map(StackId::new)
+      .collect(Collectors.toMap(Function.identity(), this::parseStack));
+    blueprintV2.setStacks(stacks);
+  }
 
   public BlueprintV2 convertFromEntity(BlueprintV2Entity blueprintEntity) throws IOException {
     return convertFromJson(blueprintEntity.getContent());
   }
 
+  @SuppressWarnings("unchecked")
   public Map<String, Object> convertToMap(BlueprintV2Entity entity) throws IOException {
     return createObjectMapper().readValue(entity.getContent(), HashMap.class);
   }
 
   private StackV2 parseStack(StackId stackId) {
     try {
-      return stackFactory.create(stackId.getStackName(), stackId.getStackVersion());
+      return stackFactory.create(stackId);
     } catch (AmbariException e) {
       throw new IllegalArgumentException(
         String.format("Unable to parse stack. name=%s, version=%s", stackId.getStackName(), stackId.getStackVersion()),
@@ -156,7 +159,6 @@ public class BlueprintV2Factory {
    * @param securityConfiguration security related properties
    * @return new blueprint entity
    */
-  @SuppressWarnings("unchecked")
   public BlueprintV2 createBlueprint(Map<String, Object> properties, SecurityConfiguration securityConfiguration) throws NoSuchStackException, IOException {
     String name = String.valueOf(properties.get(BLUEPRINT_NAME_PROPERTY_ID));
     // String.valueOf() will return "null" if value is null
@@ -168,10 +170,7 @@ public class BlueprintV2Factory {
     String json = om.writeValueAsString(properties);
     BlueprintImplV2 blueprint = om.readValue(json, BlueprintImplV2.class);
     blueprint.postDeserialization();
-    Map<String, StackV2> stacks = new HashMap<>();
-    for (String stackId: blueprint.getStackIds()) {
-      stacks.put(stackId, stackFactory.create(stackId));
-    }
+    updateStacks(blueprint);
     blueprint.setSecurityConfiguration(securityConfiguration);
     return blueprint;
   }