brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [14/16] incubator-brooklyn git commit: Extract identical code to utils
Date Thu, 15 Oct 2015 14:02:35 GMT
Extract identical code to utils


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5d0c765c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5d0c765c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5d0c765c

Branch: refs/heads/master
Commit: 5d0c765ca869cfad497da85329f51a8354b11511
Parents: 1db8875
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Thu Oct 15 13:15:02 2015 +0300
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Thu Oct 15 13:33:03 2015 +0300

----------------------------------------------------------------------
 .../spi/creation/CampToSpecTransformer.java     | 11 ++------
 .../camp/brooklyn/spi/creation/CampUtils.java   | 29 ++++++++++++--------
 2 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5d0c765c/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
index 60f00c6..ae995e4 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
@@ -60,15 +60,10 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
     public EntitySpec<? extends Application> createApplicationSpec(String plan) {
         try {
             CampPlatform camp = CampCatalogUtils.getCampPlatform(mgmt);
-            AssemblyTemplate at = camp.pdp().registerDeploymentPlan( new StringReader(plan)
);
-            AssemblyTemplateInstantiator instantiator;
-            try {
-                instantiator = at.getInstantiator().newInstance();
-            } catch (Exception e) {
-                throw Exceptions.propagate(e);
-            }
+            BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
+            AssemblyTemplate at = CampUtils.registerDeploymentPlan(plan, loader, camp);
+            AssemblyTemplateInstantiator instantiator = CampUtils.getInstantiator(at);
             if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
-                BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
                 return ((AssemblyTemplateSpecInstantiator) instantiator).createApplicationSpec(at,
camp, loader);
             } else {
                 // The unknown instantiator can create the app (Assembly), but not a spec.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5d0c765c/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
index 83b85e2..289fb97 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
@@ -57,25 +57,32 @@ public class CampUtils {
     public static List<EntitySpec<?>> createServiceSpecs(String plan, BrooklynClassLoadingContext
loader, Set<String> encounteredTypes) {
         CampPlatform camp = getCampPlatform(loader.getManagementContext());
 
-        AssemblyTemplate at;
-        BrooklynLoaderTracker.setLoader(loader);
-        try {
-            at = camp.pdp().registerDeploymentPlan(new StringReader(plan));
-        } finally {
-            BrooklynLoaderTracker.unsetLoader(loader);
+        AssemblyTemplate at = registerDeploymentPlan(plan, loader, camp);
+        AssemblyTemplateInstantiator instantiator = getInstantiator(at);
+        if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
+            return ((AssemblyTemplateSpecInstantiator)instantiator).createServiceSpecs(at,
camp, loader, encounteredTypes);
+        } else {
+            throw new IllegalStateException("Unable to instantiate YAML; incompatible instantiator
"+instantiator+" for "+at);
         }
+    }
 
+    public static AssemblyTemplateInstantiator getInstantiator(AssemblyTemplate at) {
         try {
-            AssemblyTemplateInstantiator instantiator = at.getInstantiator().newInstance();
-            if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
-                return ((AssemblyTemplateSpecInstantiator)instantiator).createServiceSpecs(at,
camp, loader, encounteredTypes);
-            }
-            throw new IllegalStateException("Unable to instantiate YAML; incompatible instantiator
"+instantiator+" for "+at);
+            return at.getInstantiator().newInstance();
         } catch (Exception e) {
             throw Exceptions.propagate(e);
         }
     }
 
+    public static AssemblyTemplate registerDeploymentPlan(String plan, BrooklynClassLoadingContext
loader, CampPlatform camp) {
+        BrooklynLoaderTracker.setLoader(loader);
+        try {
+            return camp.pdp().registerDeploymentPlan(new StringReader(plan));
+        } finally {
+            BrooklynLoaderTracker.unsetLoader(loader);
+        }
+    }
+
     public static PolicySpec<?> createPolicySpec(String yamlPlan, BrooklynClassLoadingContext
loader, Set<String> encounteredCatalogTypes) {
         DeploymentPlan plan = makePlanFromYaml(loader.getManagementContext(), yamlPlan);
 


Mime
View raw message