brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/6] brooklyn-server git commit: no need for camp to record everything (or anything) that brooklyn creates
Date Mon, 26 Sep 2016 10:37:55 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 0b96ca3eb -> dfcd8857a


no need for camp to record everything (or anything) that brooklyn creates

fixes slow camp ResourceLookup items leak


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

Branch: refs/heads/master
Commit: efb07421af3ef842bfc8ab1b141f00daa8fb03c4
Parents: 84aded4
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Sep 16 11:48:26 2016 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Sep 16 16:53:19 2016 +0100

----------------------------------------------------------------------
 .../brooklyn/camp/spi/PlatformTransaction.java  |  5 +++
 .../spi/pdp/AssemblyTemplateConstructor.java    | 13 +++++--
 .../brooklyn/camp/spi/resolve/PdpProcessor.java | 26 ++++++++++---
 .../camp/brooklyn/BrooklynCampPlatform.java     |  9 ++++-
 .../brooklyn/spi/creation/CampCatalogUtils.java | 40 --------------------
 .../spi/creation/CampInternalUtils.java         | 20 +++++-----
 .../brooklyn/spi/creation/CampResolver.java     |  2 +-
 .../spi/creation/CampToSpecTransformer.java     |  2 +-
 .../camp/brooklyn/EntitiesYamlTest.java         | 35 ++++++++++++++++-
 9 files changed, 91 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/PlatformTransaction.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/PlatformTransaction.java
b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/PlatformTransaction.java
index ae54beb..4d0dd23 100644
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/PlatformTransaction.java
+++ b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/PlatformTransaction.java
@@ -43,4 +43,9 @@ public abstract class PlatformTransaction {
         return this;
     }
 
+    public PlatformTransaction clear() {
+        additions.clear();
+        return this;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
index a5814fc..a236148 100644
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
+++ b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/pdp/AssemblyTemplateConstructor.java
@@ -40,15 +40,22 @@ public class AssemblyTemplateConstructor {
         this.transaction = this.campPlatform.transaction();
     }
     
-    /** records all the templates to the underlying platform */
+    /** records all the templates to the underlying platform 
+     * @deprecated since 0.10.0 use {@link #construct(boolean)} */
     public AssemblyTemplate commit() {
+        return construct(false);
+    }
+    
+    /** builds the template, optionally recording everything to the underlying platform */
+    public AssemblyTemplate construct(boolean save) {
         checkState();
         AssemblyTemplate at = builder.build();
-        transaction.add(at).commit();
+        if (!save) transaction.clear();
+        transaction.commit();
         transaction = null;
         return at;
     }
-
+    
     public void name(String name) {
         checkState();
         builder.name(name);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/resolve/PdpProcessor.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/resolve/PdpProcessor.java
b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/resolve/PdpProcessor.java
index e1e69cf..f10c013 100644
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/resolve/PdpProcessor.java
+++ b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/spi/resolve/PdpProcessor.java
@@ -76,16 +76,32 @@ public class PdpProcessor {
         return DeploymentPlan.of(dpRootInterpreted, yaml);
     }
     
-    /** create and return an AssemblyTemplate based on the given DP (yaml) */
+    /** create and return an AssemblyTemplate based on the given DP (yaml),
+     * applying matchers to the given deployment plan to create an assembly template,
+     * and registering with the platform for re-use */
     public AssemblyTemplate registerDeploymentPlan(Reader yaml) {
         DeploymentPlan plan = parseDeploymentPlan(yaml);
         return registerDeploymentPlan(plan);
     }
 
-    /** applies matchers to the given deployment plan to create an assembly template */
+    /** as {@link #registerDeploymentPlan(Reader)} but taking a parsed plan */
     public AssemblyTemplate registerDeploymentPlan(DeploymentPlan plan) {
+        return resolveDeploymentPlanInternal(plan).construct(true);
+    }
+
+    /** as {@link #registerDeploymentPlan(Reader)} but not registering it */
+    public AssemblyTemplate resolveDeploymentPlan(Reader yaml) {
+        DeploymentPlan plan = parseDeploymentPlan(yaml);
+        return resolveDeploymentPlan(plan);
+    }
+
+    /** as {@link #registerDeploymentPlan(DeploymentPlan)} but not registering it */
+    public AssemblyTemplate resolveDeploymentPlan(DeploymentPlan plan) {
+        return resolveDeploymentPlanInternal(plan).construct(false);
+    }
+
+    protected AssemblyTemplateConstructor resolveDeploymentPlanInternal(DeploymentPlan plan)
{
         AssemblyTemplateConstructor atc = new AssemblyTemplateConstructor(campPlatform);
-        
         if (plan.getName()!=null) atc.name(plan.getName());
         if (plan.getDescription()!=null) atc.description(plan.getDescription());
         if (plan.getSourceCode()!=null) atc.sourceCode(plan.getSourceCode());
@@ -120,8 +136,8 @@ public class PdpProcessor {
             // set a default instantiator which just invokes the component's instantiators
             // (or throws unsupported exceptions, currently!)
             atc.instantiator(BasicAssemblyTemplateInstantiator.class);
-
-        return atc.commit();
+        
+        return atc;
     }
     
     public AssemblyTemplate registerPdpFromArchive(InputStream archiveInput) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/BrooklynCampPlatform.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/BrooklynCampPlatform.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/BrooklynCampPlatform.java
index 7290c24..a6d65b4 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/BrooklynCampPlatform.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/BrooklynCampPlatform.java
@@ -22,6 +22,8 @@ import static com.google.common.base.Preconditions.checkState;
 
 import java.util.Map;
 
+import javax.annotation.Nullable;
+
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.ManagementContext.PropertiesReloadListener;
 import org.apache.brooklyn.camp.AggregatingCampPlatform;
@@ -31,8 +33,8 @@ import org.apache.brooklyn.camp.brooklyn.spi.dsl.BrooklynDslInterpreter;
 import org.apache.brooklyn.camp.brooklyn.spi.platform.BrooklynImmutableCampPlatform;
 import org.apache.brooklyn.camp.spi.PlatformRootSummary;
 import org.apache.brooklyn.core.mgmt.HasBrooklynManagementContext;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.internal.CampYamlParser;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
@@ -61,6 +63,11 @@ public class BrooklynCampPlatform extends AggregatingCampPlatform implements
Has
         });
     }
 
+    /** finds and returns the {@link CampPlatform} registered for the management context,
or null if none */
+    @Nullable public static CampPlatform findPlatform(ManagementContext mgmt) {
+        return mgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM);
+    }
+    
     // --- brooklyn setup
     
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampCatalogUtils.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampCatalogUtils.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampCatalogUtils.java
deleted file mode 100644
index 706d6f2..0000000
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampCatalogUtils.java
+++ /dev/null
@@ -1,40 +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 java.util.Set;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.camp.CampPlatform;
-import org.apache.brooklyn.core.typereg.RegisteredTypes;
-
-@Deprecated /** @deprecated since 0.9.0 use RegisteredType and CampResolver */
-public class CampCatalogUtils {
-
-    public static AbstractBrooklynObjectSpec<?, ?> createSpec(ManagementContext mgmt,
CatalogItem<?, ?> item, Set<String> parentEncounteredTypes) {
-        return CampResolver.createSpecFromFull(mgmt, RegisteredTypes.of(item), item.getCatalogItemJavaType(),
parentEncounteredTypes, null);
-    }
-    
-    public static CampPlatform getCampPlatform(ManagementContext mgmt) {
-        return CampInternalUtils.getCampPlatform(mgmt);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
index e2519e3..07b94f5 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampInternalUtils.java
@@ -26,10 +26,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
+import javax.annotation.Nonnull;
 
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.EntitySpec;
@@ -44,7 +41,7 @@ import org.apache.brooklyn.api.policy.PolicySpec;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
 import org.apache.brooklyn.camp.CampPlatform;
-import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
+import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatform;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampReservedKeys;
 import org.apache.brooklyn.camp.spi.AssemblyTemplate;
 import org.apache.brooklyn.camp.spi.AssemblyTemplate.Builder;
@@ -61,6 +58,11 @@ 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;
+
 /** package-private; as {@link RegisteredType} becomes standard hopefully we can remove this
*/
 class CampInternalUtils {
 
@@ -101,10 +103,10 @@ class CampInternalUtils {
         }
     }
 
-    static AssemblyTemplate registerDeploymentPlan(String plan, BrooklynClassLoadingContext
loader, CampPlatform camp) {
+    static AssemblyTemplate resolveDeploymentPlan(String plan, BrooklynClassLoadingContext
loader, CampPlatform camp) {
         BrooklynLoaderTracker.setLoader(loader);
         try {
-            return camp.pdp().registerDeploymentPlan(new StringReader(plan));
+            return camp.pdp().resolveDeploymentPlan(new StringReader(plan));
         } finally {
             BrooklynLoaderTracker.unsetLoader(loader);
         }
@@ -191,8 +193,8 @@ class CampInternalUtils {
         return camp.pdp().parseDeploymentPlan(Streams.newReaderWithContents(yaml));
     }
 
-    public static CampPlatform getCampPlatform(ManagementContext mgmt) {
-        CampPlatform result = mgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM);
+    @Nonnull public static CampPlatform getCampPlatform(ManagementContext mgmt) {
+        CampPlatform result = BrooklynCampPlatform.findPlatform(mgmt);
         if (result!=null) {
             return result;
         } else {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
index d73f6e2..006617f 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampResolver.java
@@ -139,7 +139,7 @@ class CampResolver {
     private static EntitySpec<?> createEntitySpecFromServicesBlock(String plan, BrooklynClassLoadingContext
loader, Set<String> encounteredTypes, boolean isApplication) {
         CampPlatform camp = CampInternalUtils.getCampPlatform(loader.getManagementContext());
 
-        AssemblyTemplate at = CampInternalUtils.registerDeploymentPlan(plan, loader, camp);
+        AssemblyTemplate at = CampInternalUtils.resolveDeploymentPlan(plan, loader, camp);
         AssemblyTemplateInstantiator instantiator = CampInternalUtils.getInstantiator(at);
         if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
             EntitySpec<? extends Application> appSpec = ((AssemblyTemplateSpecInstantiator)instantiator).createApplicationSpec(at,
camp, loader, encounteredTypes);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
index 01b721a..4c94b16 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampToSpecTransformer.java
@@ -64,7 +64,7 @@ public class CampToSpecTransformer implements PlanToSpecTransformer {
         try {
             CampPlatform camp = CampInternalUtils.getCampPlatform(mgmt);
             BrooklynClassLoadingContext loader = JavaBrooklynClassLoadingContext.create(mgmt);
-            AssemblyTemplate at = CampInternalUtils.registerDeploymentPlan(plan, loader,
camp);
+            AssemblyTemplate at = CampInternalUtils.resolveDeploymentPlan(plan, loader, camp);
             AssemblyTemplateInstantiator instantiator = CampInternalUtils.getInstantiator(at);
             if (instantiator instanceof AssemblyTemplateSpecInstantiator) {
                 return ((AssemblyTemplateSpecInstantiator) instantiator).createApplicationSpec(at,
camp, loader, MutableSet.<String>of());

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/efb07421/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
index 55136d6..92d9adc 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EntitiesYamlTest.java
@@ -36,6 +36,7 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.camp.CampPlatform;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.BrooklynDslCommon;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslComponent;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslComponent.Scope;
@@ -47,6 +48,7 @@ import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityFunctions;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.EntityPredicates;
+import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.mgmt.internal.EntityManagerInternal;
 import org.apache.brooklyn.core.sensor.Sensors;
@@ -55,8 +57,8 @@ import org.apache.brooklyn.core.test.entity.TestEntityImpl;
 import org.apache.brooklyn.entity.group.DynamicCluster;
 import org.apache.brooklyn.entity.group.DynamicFabric;
 import org.apache.brooklyn.entity.software.base.SameServerEntity;
-import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess;
 import org.apache.brooklyn.entity.software.base.SoftwareProcessShellEnvironmentTest.EnvRecordingLocation;
+import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.task.Tasks;
@@ -1067,4 +1069,35 @@ public class EntitiesYamlTest extends AbstractYamlTest {
     protected Logger getLogger() {
         return log;
     }
+    
+    @Test
+    public void testLeakSimple() throws Exception {
+        String yaml =
+            "services:\n"+
+                "- type: "+TestEntity.class.getName()+"\n"+
+                "- type: "+TestEntity.class.getName()+"\n"+
+                "";
+        doTestLeak(yaml);
+    }
+
+    @Test
+    public void testLeakWithPct() throws Exception {
+        String yaml = loadYaml("same-server-entity-test.yaml");
+        doTestLeak(yaml);
+    }
+    
+    protected void doTestLeak(String yaml) throws Exception {
+        CampPlatform camp = BrooklynCampPlatform.findPlatform(mgmt());
+
+        Application app = (Application) createStartWaitAndLogApplication(yaml);
+        ((StartableApplication)app).stop();
+
+        Assert.assertEquals(camp.assemblyTemplates().links().size(), 0);
+        Assert.assertEquals(camp.assemblies().links().size(), 0);
+        Assert.assertEquals(camp.applicationComponentTemplates().links().size(), 0);
+        Assert.assertEquals(camp.applicationComponents().links().size(), 0);
+        Assert.assertEquals(camp.platformComponentTemplates().links().size(), 0);
+        Assert.assertEquals(camp.platformComponents().links().size(), 0);
+    }
+
 }


Mime
View raw message