ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adorosz...@apache.org
Subject [28/50] [abbrv] ambari git commit: AMBARI-22325. Set stacks in blueprint (adoroszlai)
Date Wed, 06 Dec 2017 10:10:26 GMT
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/3cfb74b9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3cfb74b9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3cfb74b9

Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2
Commit: 3cfb74b9a8a0175082e30bcca13fe9a6e4f4632b
Parents: 52806dd
Author: Attila Doroszlai <adoroszlai@hortonworks.com>
Authored: Mon Nov 13 11:24:47 2017 +0100
Committer: Doroszlai, Attila <adoroszlai@hortonworks.com>
Committed: Tue Dec 5 23:55:56 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/3cfb74b9/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/3cfb74b9/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;
   }


Mime
View raw message