You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2017/10/19 12:35:38 UTC

[3/4] ambari git commit: Create first unit test for Blueprint v2 data model (benyoka)

Create first unit test for Blueprint v2 data model (benyoka)


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

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 37b1e6e5132823d71b3cfe91ca4c270bd11a2013
Parents: f82497d
Author: Balazs Bence Sari <be...@apache.org>
Authored: Wed Oct 18 18:29:56 2017 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Thu Oct 19 14:30:23 2017 +0200

----------------------------------------------------------------------
 .../ambari/server/topology/BlueprintImplV2.java |  29 ----
 .../validators/BlueprintImplV2Test.java         |  45 +++++-
 .../test/resources/blueprintv2/blueprintv2.json | 152 +++++++++++++++++++
 3 files changed, 196 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/37b1e6e5/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 827fa39..b2119e6 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
@@ -19,7 +19,6 @@
 
 package org.apache.ambari.server.topology;
 
-import java.io.File;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -38,11 +37,6 @@ import org.apache.commons.lang.StringUtils;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.Version;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver;
-import com.fasterxml.jackson.databind.module.SimpleModule;
 
 /**
  * Blueprint implementation.
@@ -336,27 +330,4 @@ public class BlueprintImplV2 implements BlueprintV2 {
     public Blueprints() { }
   }
 
-  public static void main(String[] args) throws Exception {
-    ObjectMapper mapper = new ObjectMapper();
-    SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
-    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
-    resolver.addMapping(HostGroupV2.class, HostGroupV2Impl.class);
-    module.setAbstractTypes(resolver);
-    mapper.registerModule(module);
-    mapper.enable(SerializationFeature.INDENT_OUTPUT);
-    BlueprintImplV2 bp = mapper.readValue(new File("/Users/bsari/develop/blueprints/blueprintv2.json"), BlueprintImplV2.class);
-    String bpJson = mapper.writeValueAsString(bp);
-    System.out.println(bpJson);
-    System.out.println("\n\n====================================================================================\n\n");
-    Map<String, Object> map = mapper.readValue(new File("/Users/bsari/develop/blueprints/blueprintv2.json"), HashMap.class);
-    System.out.println(map);
-    System.out.println("\n\n====================================================================================\n\n");
-    String bpJson2 = mapper.writeValueAsString(map);
-    System.out.println(bpJson2);
-    System.out.println("\n\n====================================================================================\n\n");
-    BlueprintImplV2 bp2 = mapper.readValue(bpJson2, BlueprintImplV2.class);
-    System.out.println(bp2);
-  }
-
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37b1e6e5/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
index dbe269a..5a676bc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/BlueprintImplV2Test.java
@@ -1,9 +1,52 @@
 package org.apache.ambari.server.topology.validators;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.topology.BlueprintImplV2;
+import org.apache.ambari.server.topology.HostGroupV2;
+import org.apache.ambari.server.topology.HostGroupV2Impl;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+
 public class BlueprintImplV2Test {
 
-  private static final String BLUEPRINT_LOCATION = "";
+  static String BLUEPRINT_V2_JSON;
 
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    BLUEPRINT_V2_JSON = Resources.toString(Resources.getResource("blueprintv2/blueprintv2.json"), Charsets.UTF_8);
+  }
 
+  @Test
+  public void testSerialization() throws Exception {
+    ObjectMapper mapper = new ObjectMapper();
+    SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
+    SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
+    resolver.addMapping(HostGroupV2.class, HostGroupV2Impl.class);
+    module.setAbstractTypes(resolver);
+    mapper.registerModule(module);
+    mapper.enable(SerializationFeature.INDENT_OUTPUT);
+    BlueprintImplV2 bp = mapper.readValue(BLUEPRINT_V2_JSON, BlueprintImplV2.class);
+    String bpJson = mapper.writeValueAsString(bp);
+    System.out.println(bpJson);
+    System.out.println("\n\n====================================================================================\n\n");
+    Map<String, Object> map = mapper.readValue(BLUEPRINT_V2_JSON, HashMap.class);
+    System.out.println(map);
+    System.out.println("\n\n====================================================================================\n\n");
+    String bpJson2 = mapper.writeValueAsString(map);
+    System.out.println(bpJson2);
+    System.out.println("\n\n====================================================================================\n\n");
+    BlueprintImplV2 bp2 = mapper.readValue(bpJson2, BlueprintImplV2.class);
+    System.out.println(bp2);
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37b1e6e5/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/blueprintv2/blueprintv2.json b/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
new file mode 100644
index 0000000..7884abf
--- /dev/null
+++ b/ambari-server/src/test/resources/blueprintv2/blueprintv2.json
@@ -0,0 +1,152 @@
+{
+  "Blueprints": {
+    "blueprint_name": "blueprint-def",
+    "security": {
+      "type": "NONE"
+    }
+  },
+  "cluster-settings": {
+    "deployment_settings": [
+      {"skip_failure":"true"}
+    ],
+    "recovery_settings":[
+      {"recovery_enabled":"true"}
+    ]
+  },
+  "repository_versions": [
+    {
+      "stack_id": "HDPCORE-3.0.0",
+      "repository_version": "3.0.0.0-1"
+    },
+    {
+      "stack_id": "ANALYTICS-1.0.0",
+      "repository_version": "1.0.0.0-12"
+    }
+  ],
+  "service_groups": [
+    {
+      "name": "Core SG",
+      "dependencies": [],
+      "services": [
+        {
+          "type": "ZOOKEEPER",
+          "name": "ZK1",
+          "stack_id": "HDPCORE-3.0.0",
+          "configurations": [
+            {
+              "zoo.cfg" : {
+                "properties" : {
+                  "dataDir" : "/zookeeper1"
+                }
+              }
+            }
+          ]
+        },
+        {
+          "type": "ZOOKEEPER",
+          "name": "ZK2",
+          "stack_id": "HDPCORE-3.0.0",
+          "configurations": [
+            {
+              "zoo.cfg" : {
+                "properties" : {
+                  "dataDir" : "/zookeeper2"
+                }
+              }
+            }
+          ]
+        },
+        {
+          "type": "HDFS",
+          "stack_id": "HDPCORE-3.0.0"
+        },
+        {
+          "type": "YARN",
+          "stack_id": "HDPCORE-3.0.0"
+        },
+        {
+          "type": "HBASE",
+          "stack_id": "HDPCORE-3.0.0"
+        }
+      ]
+    },
+    {
+      "name": "StreamSG",
+      "services": [
+        {
+          "type": "KAFKA",
+          "stack_id": "HDPCORE-3.0.0",
+          "dependencies": [
+            {
+              "service_group" : "CoreSG",
+              "service_name" : "ZK2"
+            }
+          ]
+        },
+        {
+          "type": "NIFI",
+          "stack_id": "HDPCORE-3.0.0"
+        }
+      ],
+      "dependencies": ["Core SG"]
+    }
+  ],
+  "host_groups": [
+    {
+      "cardinality": "1",
+      "name": "host_group_1",
+      "configurations": [],
+      "components": [
+        {
+          "type": "NAMENODE",
+          "service_name": "HDFS",
+          "service_group": "Core SG",
+          "configurations": [],
+          "provision_action": "INSTALL_AND_START"
+        },
+        {
+          "type": "ZOOKEEPER_SERVER",
+          "service_name": "ZK1",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "ZOOKEEPER_SERVER",
+          "service_name": "ZK2",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "RESOURCEMANAGER",
+          "service_name": "YARN",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "HBASE_MASTER",
+          "service_name": "HBASE",
+          "service_group": "Core SG",
+          "configurations": []
+        },
+        {
+          "type": "ZOOKEEPER_SERVER",
+          "service_name": "ZOOKEEPER",
+          "service_group": "Stream SG",
+          "configurations": []
+        },
+        {
+          "type": "KAFKA_MASTER",
+          "service_name": "KAFKA",
+          "service_group": "Stream SG",
+          "configurations": []
+        },
+        {
+          "type": "NIFI_MASTER",
+          "service_name": "NIFI",
+          "service_group": "Stream SG",
+          "configurations": []
+        }
+      ]
+    }
+  ]
+}