brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [06/14] incubator-brooklyn git commit: Working CampTypePlanTransformer
Date Tue, 17 Nov 2015 22:51:21 GMT
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/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 35feb65..39959e0 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
@@ -34,10 +34,13 @@ import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.mgmt.classloading.JavaBrooklynClassLoadingContext;
 import org.apache.brooklyn.core.plan.PlanNotRecognizedException;
 import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Deprecated /** @deprecated since 0.9.0 use CampTypePlanTransformer */
 public class CampToSpecTransformer implements PlanToSpecTransformer {
 
     public static final String YAML_CAMP_PLAN_TYPE = "org.apache.brooklyn.camp/yaml";
@@ -59,12 +62,12 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
     @Override
     public EntitySpec<? extends Application> createApplicationSpec(String plan) {
         try {
-            CampPlatform camp = CampUtils.getCampPlatform(mgmt);
+            CampPlatform camp = CampInternalUtils.getCampPlatform(mgmt);
             BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
-            AssemblyTemplate at = CampUtils.registerDeploymentPlan(plan, loader, camp);
-            AssemblyTemplateInstantiator instantiator = CampUtils.getInstantiator(at);
+            AssemblyTemplate at = CampInternalUtils.registerDeploymentPlan(plan, loader,
camp);
+            AssemblyTemplateInstantiator instantiator = CampInternalUtils.getInstantiator(at);
             if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
-                return ((AssemblyTemplateSpecInstantiator) instantiator).createApplicationSpec(at,
camp, loader);
+                return ((AssemblyTemplateSpecInstantiator) instantiator).createApplicationSpec(at,
camp, loader, MutableSet.<String>of());
             } else {
                 // The unknown instantiator can create the app (Assembly), but not a spec.
                 // Currently, all brooklyn plans should produce the above.
@@ -84,7 +87,7 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
         }
     }
 
-    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @SuppressWarnings({ "unchecked" })
     @Override
     public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>>
SpecT createCatalogSpec(CatalogItem<T, SpecT> item, Set<String> encounteredTypes)
{
         // Ignore old-style java type catalog items - there is a different (deprecated) transformer
for that
@@ -96,7 +99,7 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
         }
 
         // Not really clear what should happen to the top-level attributes, ignored until
a good use case appears.
-        return (SpecT) CampCatalogUtils.createSpec(mgmt, (CatalogItem)item, encounteredTypes);
+        return (SpecT) CampResolver.createSpecFromFull(mgmt, RegisteredTypes.of(item), encounteredTypes,
null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
new file mode 100644
index 0000000..dd8a0d5
--- /dev/null
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.camp.brooklyn.spi.creation;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.api.typereg.RegisteredType.TypeImplementationPlan;
+import org.apache.brooklyn.api.typereg.RegisteredTypeConstraint;
+import org.apache.brooklyn.core.typereg.AbstractCustomImplementationPlan;
+import org.apache.brooklyn.core.typereg.AbstractTypePlanTransformer;
+import org.apache.brooklyn.core.typereg.BasicTypeImplementationPlan;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.util.guava.Maybe;
+
+import com.google.common.collect.ImmutableList;
+
+public class CampTypePlanTransformer extends AbstractTypePlanTransformer {
+
+    private static final List<String> FORMATS = ImmutableList.of("brooklyn-camp", "camp",
"brooklyn");
+    
+    public CampTypePlanTransformer() {
+        super(FORMATS.get(0), "OASIS CAMP / Brooklyn", "The Apache Brooklyn implementation
of the OASIS CAMP blueprint plan format and extensions");
+    }
+
+    @Override
+    protected double scoreForNullFormat(Object planData, RegisteredType type, RegisteredTypeConstraint
context) {
+        Maybe<Map<Object, Object>> plan = RegisteredTypes.getAsYamlMap(planData);
+        if (plan.isAbsent()) return 0;
+        if (plan.get().containsKey("services")) return 0.8;
+        return 0;
+    }
+
+    @Override
+    protected double scoreForNonmatchingNonnullFormat(String planFormat, Object planData,
RegisteredType type, RegisteredTypeConstraint context) {
+        if (FORMATS.contains(planFormat.toLowerCase())) return 0.9;
+        return 0;
+    }
+
+    @Override
+    protected AbstractBrooklynObjectSpec<?, ?> createSpec(RegisteredType type, RegisteredTypeConstraint
context) throws Exception {
+        // TODO cache
+        return new CampResolver(mgmt, type, context).createSpec();
+    }
+
+    @Override
+    protected Object createBean(RegisteredType type, RegisteredTypeConstraint context) throws
Exception {
+        // beans not supported by this?
+        return null;
+    }
+
+    @Override
+    public double scoreForTypeDefinition(String formatCode, Object catalogData) {
+        // TODO catalog parsing
+        return 0;
+    }
+
+    @Override
+    public List<RegisteredType> createFromTypeDefinition(String formatCode, Object
catalogData) {
+        // TODO catalog parsing
+        return null;
+    }
+
+    public static class CampTypeImplementationPlan extends AbstractCustomImplementationPlan<String>
{
+        public CampTypeImplementationPlan(TypeImplementationPlan otherPlan) {
+            super(FORMATS.get(0), String.class, otherPlan);
+        }
+        public CampTypeImplementationPlan(String planData) {
+            this(new BasicTypeImplementationPlan(FORMATS.get(0), planData));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/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
deleted file mode 100644
index 637a8eb..0000000
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.camp.brooklyn.spi.creation;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.io.StringReader;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.objs.SpecParameter;
-import org.apache.brooklyn.api.policy.Policy;
-import org.apache.brooklyn.api.policy.PolicySpec;
-import org.apache.brooklyn.api.typereg.RegisteredType;
-import org.apache.brooklyn.camp.CampPlatform;
-import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
-import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
-import org.apache.brooklyn.camp.brooklyn.api.AssemblyTemplateSpecInstantiator;
-import org.apache.brooklyn.camp.spi.AssemblyTemplate;
-import org.apache.brooklyn.camp.spi.AssemblyTemplate.Builder;
-import org.apache.brooklyn.camp.spi.instantiate.AssemblyTemplateInstantiator;
-import org.apache.brooklyn.camp.spi.pdp.DeploymentPlan;
-import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
-import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog.BrooklynLoaderTracker;
-import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
-import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
-import org.apache.brooklyn.core.objs.BasicSpecParameter;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal.ConfigurationSupportInternal;
-import org.apache.brooklyn.entity.stock.BasicApplicationImpl;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.stream.Streams;
-import org.apache.brooklyn.util.yaml.Yamls;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-//TODO-type-registry
-public class CampUtils {
-
-    public static EntitySpec<?> createRootServiceSpec(String plan, BrooklynClassLoadingContext
loader, Set<String> encounteredTypes) {
-        CampPlatform camp = getCampPlatform(loader.getManagementContext());
-
-        AssemblyTemplate at = registerDeploymentPlan(plan, loader, camp);
-        AssemblyTemplateInstantiator instantiator = getInstantiator(at);
-        if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
-            List<EntitySpec<?>> serviceSpecs = ((AssemblyTemplateSpecInstantiator)instantiator).createServiceSpecs(at,
camp, loader, encounteredTypes);
-            if (serviceSpecs.size() > 1) {
-                throw new UnsupportedOperationException("Single service expected, but got
"+serviceSpecs);
-            }
-            EntitySpec<?> rootSpec = serviceSpecs.get(0);
-            EntitySpec<? extends Application> wrapperApp = createWrapperApp(at, loader);
-            EntityManagementUtils.mergeWrapperParentSpecToChildEntity(wrapperApp, rootSpec);
-            return rootSpec;
-        } else {
-            throw new IllegalStateException("Unable to instantiate YAML; incompatible instantiator
"+instantiator+" for "+at);
-        }
-    }
-
-    public static EntitySpec<? extends Application> createWrapperApp(AssemblyTemplate
template, BrooklynClassLoadingContext loader) {
-        BrooklynComponentTemplateResolver resolver = BrooklynComponentTemplateResolver.Factory.newInstance(
-            loader, buildWrapperAppTemplate(template));
-        EntitySpec<Application> wrapperSpec = resolver.resolveSpec(ImmutableSet.<String>of());
-        // Clear out default parameters (coming from the wrapper app's class) so they don't
overwrite the entity's params on unwrap.
-        if (!hasExplicitParams(template)) {
-            wrapperSpec.parameters(ImmutableList.<SpecParameter<?>>of());
-        }
-        return wrapperSpec;
-    }
-
-    private static boolean hasExplicitParams(AssemblyTemplate at) {
-        return at.getCustomAttributes().containsKey(BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
-    }
-
-    private static AssemblyTemplate buildWrapperAppTemplate(AssemblyTemplate template) {
-        Builder<? extends AssemblyTemplate> builder = AssemblyTemplate.builder();
-        builder.type("brooklyn:" + BasicApplicationImpl.class.getName());
-        builder.id(template.getId());
-        builder.name(template.getName());
-        builder.sourceCode(template.getSourceCode());
-        for (Entry<String, Object> entry : template.getCustomAttributes().entrySet())
{
-            builder.customAttribute(entry.getKey(), entry.getValue());
-        }
-        builder.instantiator(template.getInstantiator());
-        AssemblyTemplate wrapTemplate = builder.build();
-        return wrapTemplate;
-    }
-
-    public static AssemblyTemplateInstantiator getInstantiator(AssemblyTemplate at) {
-        try {
-            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);
-
-        //Would ideally re-use the PolicySpecResolver
-        //but it is CAMP specific and there is no easy way to get hold of it.
-        Object policies = checkNotNull(plan.getCustomAttributes().get(BasicBrooklynCatalog.POLICIES_KEY),
"policy config");
-        if (!(policies instanceof Iterable<?>)) {
-            throw new IllegalStateException("The value of " + BasicBrooklynCatalog.POLICIES_KEY
+ " must be an Iterable.");
-        }
-
-        Object policy = Iterables.getOnlyElement((Iterable<?>)policies);
-
-        return createPolicySpec(loader, policy, encounteredCatalogTypes);
-    }
-
-    @SuppressWarnings("unchecked")
-    public static PolicySpec<?> createPolicySpec(BrooklynClassLoadingContext loader,
Object policy, Set<String> encounteredCatalogTypes) {
-        Map<String, Object> itemMap;
-        if (policy instanceof String) {
-            itemMap = ImmutableMap.<String, Object>of("type", policy);
-        } else if (policy instanceof Map) {
-            itemMap = (Map<String, Object>) policy;
-        } else {
-            throw new IllegalStateException("Policy expected to be string or map. Unsupported
object type " + policy.getClass().getName() + " (" + policy.toString() + ")");
-        }
-
-        String versionedId = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "policy_type",
"policyType", "type"), "policy type");
-        PolicySpec<? extends Policy> spec = resolvePolicySpec(versionedId, loader,
encounteredCatalogTypes);
-        Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
-        if (brooklynConfig != null) {
-            spec.configure(brooklynConfig);
-        }
-        List<?> parameters = (List<?>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
-        initParameters(parameters, spec, loader);
-        return spec;
-    }
-
-    public static LocationSpec<?> createLocationSpec(String yamlPlan, BrooklynClassLoadingContext
loader, Set<String> encounteredTypes) {
-        DeploymentPlan plan = makePlanFromYaml(loader.getManagementContext(), yamlPlan);
-        Object locations = checkNotNull(plan.getCustomAttributes().get(BasicBrooklynCatalog.LOCATIONS_KEY),
"location config");
-        if (!(locations instanceof Iterable<?>)) {
-            throw new IllegalStateException("The value of " + BasicBrooklynCatalog.LOCATIONS_KEY
+ " must be an Iterable.");
-        }
-
-        Object location = Iterables.getOnlyElement((Iterable<?>)locations);
-        return createLocationSpec(loader, location);
-    }
-
-    @SuppressWarnings("unchecked")
-    private static LocationSpec<?> createLocationSpec(BrooklynClassLoadingContext loader,
Object location) {
-        Map<String, Object> itemMap;
-        if (location instanceof String) {
-            itemMap = ImmutableMap.<String, Object>of("type", location);
-        } else if (location instanceof Map) {
-            itemMap = (Map<String, Object>) location;
-        } else {
-            throw new IllegalStateException("Location expected to be string or map. Unsupported
object type " + location.getClass().getName() + " (" + location.toString() + ")");
-        }
-
-        String type = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "location_type",
"locationType", "type"), "location type");
-        Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get("brooklyn.config");
-        LocationSpec<?> locationSpec = resolveLocationSpec(type, brooklynConfig, loader);
-        List<?> explicitParams = (List<?>) itemMap.get(BrooklynCampReservedKeys.BROOKLYN_PARAMETERS);
-        initParameters(explicitParams, locationSpec, loader);
-        return locationSpec;
-    }
-
-    private static void initParameters(List<?> explicitParams, AbstractBrooklynObjectSpec<?,
?> spec, BrooklynClassLoadingContext loader) {
-        if (explicitParams != null) {
-            spec.parameters(BasicSpecParameter.fromConfigList(explicitParams, loader));
-        } else {
-            spec.parameters(BasicSpecParameter.fromSpec(loader.getManagementContext(), spec));
-        }
-    }
-
-    public static DeploymentPlan makePlanFromYaml(ManagementContext mgmt, String yaml) {
-        CampPlatform camp = getCampPlatform(mgmt);
-        return camp.pdp().parseDeploymentPlan(Streams.newReaderWithContents(yaml));
-    }
-
-    public static CampPlatform getCampPlatform(ManagementContext mgmt) {
-        CampPlatform result = mgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM);
-        if (result!=null) {
-            return result;
-        } else {
-            throw new IllegalStateException("No CAMP Platform is registered with this Brooklyn
management context.");
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private static PolicySpec<? extends Policy> resolvePolicySpec(
-            String versionedId,
-            BrooklynClassLoadingContext loader,
-            Set<String> encounteredCatalogTypes) {
-        
-        PolicySpec<? extends Policy> spec;
-        RegisteredType item = loader.getManagementContext().getTypeRegistry().get(versionedId);
-        if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName()))
{
-            return loader.getManagementContext().getTypeRegistry().createSpec(item, null,
PolicySpec.class);
-        } else {
-            // TODO-type-registry pass the loader in to the above, and allow it to load with
the loader
-            spec = PolicySpec.create(loader.loadClass(versionedId, Policy.class));
-        }
-        return spec;
-    }
-
-    private static LocationSpec<?> resolveLocationSpec(
-            String type,
-            Map<String, Object> brooklynConfig,
-            BrooklynClassLoadingContext loader) {
-        Maybe<Class<? extends Location>> javaClass = loader.tryLoadClass(type,
Location.class);
-        if (javaClass.isPresent()) {
-            LocationSpec<?> spec = LocationSpec.create(javaClass.get());
-            if (brooklynConfig != null) {
-                spec.configure(brooklynConfig);
-            }
-            return spec;
-        } else {
-            Maybe<Location> loc = loader.getManagementContext().getLocationRegistry().resolve(type,
false, brooklynConfig);
-            if (loc.isPresent()) {
-                // TODO extensions?
-                Map<String, Object> locConfig = ((ConfigurationSupportInternal)loc.get().config()).getBag().getAllConfig();
-                Class<? extends Location> locType = loc.get().getClass();
-                Set<Object> locTags = loc.get().tags().getTags();
-                String locDisplayName = loc.get().getDisplayName();
-                return LocationSpec.create(locType)
-                        .configure(locConfig)
-                        .displayName(locDisplayName)
-                        .tags(locTags);
-            } else {
-                throw new IllegalStateException("No class or resolver found for location
type "+type);
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/UrlServiceSpecResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/UrlServiceSpecResolver.java
b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/UrlServiceSpecResolver.java
index 387212c..1e54f76 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/UrlServiceSpecResolver.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/UrlServiceSpecResolver.java
@@ -20,12 +20,16 @@ package org.apache.brooklyn.camp.brooklyn.spi.creation.service;
 
 import java.util.Set;
 
+import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
-import org.apache.brooklyn.camp.brooklyn.spi.creation.CampUtils;
+import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.resolve.entity.EntitySpecResolver;
+import org.apache.brooklyn.core.typereg.RegisteredTypeConstraints;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.net.Urls;
 import org.slf4j.Logger;
@@ -56,8 +60,19 @@ public class UrlServiceSpecResolver implements EntitySpecResolver {
             log.warn("AssemblyTemplate type " + type + " looks like a URL that can't be fetched.",
e);
             return null;
         }
+        if (encounteredTypes.contains(type)) {
+            throw new IllegalStateException("URL " + type + " is self referential.");
+        }
+        encounteredTypes = MutableSet.<String>builder().addAll(encounteredTypes).add(type).build().asUnmodifiable();
+        
         // Referenced specs are expected to be CAMP format as well.
-        return CampUtils.createRootServiceSpec(yaml, loader, encounteredTypes);
+        // XXX somehow specify to allow full syntax for services
+        EntitySpec<?> item = loader.getManagementContext().getTypeRegistry().createSpec(
+            RegisteredTypes.spec(null, null, 
+                new CampTypePlanTransformer.CampTypeImplementationPlan(yaml), Entity.class),

+            RegisteredTypeConstraints.alreadyVisited(encounteredTypes, loader), 
+            EntitySpec.class);
+        return item;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/main/resources/META-INF/services/org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/resources/META-INF/services/org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer
b/usage/camp/src/main/resources/META-INF/services/org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer
new file mode 100644
index 0000000..0c6fab3
--- /dev/null
+++ b/usage/camp/src/main/resources/META-INF/services/org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
index a45d272..c13e004 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
@@ -23,29 +23,31 @@ import java.io.StringReader;
 import java.util.Set;
 
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
+import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.camp.spi.Assembly;
-import org.apache.brooklyn.camp.spi.AssemblyTemplate;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer.CampTypeImplementationPlan;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.core.typereg.RegisteredTypeConstraints;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.ResourceUtils;
-import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.stream.Streams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 
 import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
 
 public abstract class AbstractYamlTest {
 
@@ -115,25 +117,12 @@ public abstract class AbstractYamlTest {
     }
 
     protected Entity createAndStartApplication(Reader input) throws Exception {
-        AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input);
-        Assembly assembly;
-        try {
-            assembly = at.getInstantiator().newInstance().instantiate(at, platform);
-        } catch (Exception e) {
-            getLogger().warn("Unable to instantiate " + at + " (rethrowing): " + e);
-            throw e;
-        }
-        getLogger().info("Test - created " + assembly);
-        final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId());
-        getLogger().info("App - " + app);
-        
-        // wait for app to have started
-        Set<Task<?>> tasks = brooklynMgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(
-                BrooklynTaskTags.EFFECTOR_TAG, 
-                BrooklynTaskTags.tagForContextEntity(app), 
-                BrooklynTaskTags.tagForEffectorCall(app, "start", ConfigBag.newInstance(ImmutableMap.of("locations",
ImmutableMap.of())))));
-        Iterables.getOnlyElement(tasks).get();
-        
+        RegisteredType type = RegisteredTypes.spec(null, null, new CampTypeImplementationPlan(Streams.readFully(input)),
Application.class);
+        EntitySpec<?> spec = 
+            mgmt().getTypeRegistry().createSpec(type, RegisteredTypeConstraints.spec(Application.class),
EntitySpec.class);
+        final Entity app = brooklynMgmt.getEntityManager().createEntity(spec);
+        // start the app (happens automatically if we use camp to instantiate, but not if
we use crate spec approach)
+        app.invoke(Startable.START, MutableMap.<String,String>of()).get();
         return app;
     }
 
@@ -141,8 +130,7 @@ public abstract class AbstractYamlTest {
         Entity app = createAndStartApplication(input);
         waitForApplicationTasks(app);
 
-        getLogger().info("App started:");
-        Entities.dumpInfo(app);
+        getLogger().info("App started: "+app);
         
         return app;
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
index a997904..8131208 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
@@ -81,6 +81,8 @@ public class EntitiesYamlTest extends AbstractYamlTest {
         Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml",
extras));
         waitForApplicationTasks(app);
 
+        Entities.dumpInfo(app);
+        
         Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template");
 
         log.info("App started:");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
index 68aef52..bb0ea90 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java
@@ -49,6 +49,7 @@ public class ReferencedYamlTest extends AbstractYamlTest {
             "services:",
             "- type: classpath://yaml-ref-entity.yaml");
         
+        // the name declared at the root trumps the name on the item itself
         checkChildEntitySpec(app, "Basic entity");
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
index c426897..215fd1a 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
@@ -33,6 +33,7 @@ import org.apache.brooklyn.camp.brooklyn.spi.creation.BrooklynEntityMatcher;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiVersionMoreEntityTest;
 import org.apache.brooklyn.core.objs.BrooklynTypes;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.text.Strings;
@@ -239,17 +240,24 @@ public class CatalogOsgiVersionMoreEntityTest extends AbstractYamlTest
{
         Iterable<RegisteredType> items = types.getAll();
         for (RegisteredType item: items) {
             Object spec = types.createSpec(item, null, null);
-            if (Entity.class.isAssignableFrom(item.getJavaType())) {
+            int match = 0;
+            if (RegisteredTypes.isSubTypeOf(item, Entity.class)) {
                 assertTrue(spec instanceof EntitySpec, "Not an EntitySpec: " + spec);
                 BrooklynTypes.getDefinedEntityType(((EntitySpec<?>)spec).getType());
-            } else if (Policy.class.isAssignableFrom(item.getJavaType())) { 
+                match++;
+            }
+            if (RegisteredTypes.isSubTypeOf(item, Policy.class)) {
                 assertTrue(spec instanceof PolicySpec, "Not a PolicySpec: " + spec);
                 BrooklynTypes.getDefinedBrooklynType(((PolicySpec<?>)spec).getType());
-            } else if (Location.class.isAssignableFrom(item.getJavaType())) {
+                match++;
+            }
+            if (RegisteredTypes.isSubTypeOf(item, Location.class)) {
                 assertTrue(spec instanceof LocationSpec, "Not a LocationSpec: " + spec);
                 BrooklynTypes.getDefinedBrooklynType(((LocationSpec<?>)spec).getType());
-            } else {
-                Assert.fail("Unexpected type: "+item.getJavaType()+" / "+item);
+                match++;
+            }
+            if (match==0) {
+                Assert.fail("Unexpected type: "+item+" ("+item.getSuperTypes()+")");
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
index e13792d..52d48e4 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
@@ -34,6 +34,7 @@ import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.core.config.BasicConfigKey;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.text.StringFunctions;
@@ -110,7 +111,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     private void assertAdded(String symbolicName, String expectedJavaType) {
         RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
         assertEquals(item.getSymbolicName(), symbolicName);
-        Assert.assertTrue(Location.class.isAssignableFrom(item.getJavaType()), "Expected
Location, not "+item.getJavaType());
+        Assert.assertTrue(RegisteredTypes.isSubTypeOf(item, Location.class), "Expected Location,
not "+item.getSuperTypes());
         assertEquals(countCatalogLocations(), 1);
 
         // Item added to catalog should automatically be available in location registry

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
index 6c0a09a..f820597 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssemblyInstantiator.java
@@ -38,6 +38,7 @@ import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 
 import com.google.common.collect.ImmutableList;
@@ -55,13 +56,18 @@ public class TestAppAssemblyInstantiator extends BasicAssemblyTemplateInstantiat
         }
         ManagementContext mgmt = ((HasBrooklynManagementContext)platform).getBrooklynManagementContext();
         
-        TestApplication app = (TestApplication) mgmt.getEntityManager().createEntity( createApplicationSpec(template,
platform, null) );
+        TestApplication app = (TestApplication) mgmt.getEntityManager().createEntity( createApplicationSpec(template,
platform, null, MutableSet.<String>of()) );
 
         return new TestAppAssembly(app);
     }
 
     @Override
     public EntitySpec<? extends Application> createApplicationSpec(AssemblyTemplate
template, CampPlatform platform, BrooklynClassLoadingContext loader) {
+        return createApplicationSpec(template, platform, loader, MutableSet.<String>of());
+    }
+    @Override
+    public EntitySpec<? extends Application> createApplicationSpec(AssemblyTemplate
template, CampPlatform platform,
+        BrooklynClassLoadingContext loader, Set<String> encounteredCatalogTypes) {
         EntitySpec<TestApplication> app = EntitySpec.create(TestApplication.class)
             .configure(TestEntity.CONF_NAME, template.getName())
             .configure(TestEntity.CONF_MAP_THING, MutableMap.of("type", template.getType(),
"desc", template.getDescription()));
@@ -87,7 +93,7 @@ public class TestAppAssemblyInstantiator extends BasicAssemblyTemplateInstantiat
 
     @Override
     public List<EntitySpec<?>> createServiceSpecs(AssemblyTemplate template,
CampPlatform platform, BrooklynClassLoadingContext itemLoader, Set<String> encounteredCatalogTypes)
{
-        EntitySpec<?> createApplicationSpec = createApplicationSpec(template, platform,
itemLoader);
+        EntitySpec<?> createApplicationSpec = createApplicationSpec(template, platform,
itemLoader, encounteredCatalogTypes);
         return ImmutableList.<EntitySpec<?>>of(createApplicationSpec);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
index e92c5f1..1b9aa77 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
@@ -281,7 +281,7 @@ public class BrooklynRestResourceUtils {
                     //different from the javaType.
                     resultI = mgmt.getTypeRegistry().get(typeName, BrooklynCatalog.DEFAULT_VERSION);
                     if (resultI != null) {
-                        if (resultI.getJavaType() == null) {
+                        if (resultI.getSuperTypes().isEmpty()) {
                             //Catalog items scanned from the classpath (using reflection
and annotations) now
                             //get yaml spec rather than a java type. Can't use those when
creating apps from
                             //the legacy app spec format.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/904c45e9/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/PropagatedRuntimeException.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/PropagatedRuntimeException.java
b/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/PropagatedRuntimeException.java
index 1b1aa5a..0859ce8 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/PropagatedRuntimeException.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/exceptions/PropagatedRuntimeException.java
@@ -36,6 +36,12 @@ public class PropagatedRuntimeException extends RuntimeException {
         causeEmbeddedInMessage = message.endsWith(Exceptions.collapseText(getCause()));
     }
 
+    public PropagatedRuntimeException(String messagePart1, String messagePart2PossiblyIncludingPart1,
Throwable cause) {
+        super(messagePart2PossiblyIncludingPart1!=null && messagePart2PossiblyIncludingPart1.startsWith(messagePart1)
? messagePart2PossiblyIncludingPart1 : messagePart1+messagePart2PossiblyIncludingPart1, cause);
+        warnIfWrapping(cause);
+        causeEmbeddedInMessage = getMessage().endsWith(Exceptions.collapseText(getCause()));
+    }
+
     public PropagatedRuntimeException(String message, Throwable cause, boolean causeEmbeddedInMessage)
{
         super(message, cause);
         warnIfWrapping(cause);



Mime
View raw message