You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/09/01 18:55:41 UTC

[10/11] git commit: This closes #127

This closes #127

Conflicts:
	core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
	usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java

Fixed trivial merge conflicts and some inconsistencies in field renames.


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

Branch: refs/heads/master
Commit: 918aff328c431d335af68e7715a24a98538eed07
Parents: b055f0f 01a013b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Sep 1 17:54:25 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Sep 1 17:54:25 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/rebind/RebindManager.java   |   4 +-
 .../entity/rebind/RebindContextImpl.java        |  17 ++
 .../entity/rebind/RebindManagerImpl.java        | 116 +++++++----
 .../rebind/persister/FileBasedObjectStore.java  |  18 +-
 .../event/basic/DependentConfiguration.java     | 190 ++++++++++++-------
 .../NonDeploymentManagementContext.java         |   5 +
 .../basic/DependentConfigurationTest.java       |  64 +++++++
 .../util/text/TemplateProcessorTest.java        | 101 ++++++++++
 .../nosql/mongodb/MongoDBClientSshDriver.java   |  35 ++--
 usage/cli/src/main/java/brooklyn/cli/Main.java  |  88 +++++++++
 .../brooklyn/launcher/BrooklynLauncher.java     | 137 +++++++++----
 .../BrooklynLauncherRebindTestFixture.java      |   8 +-
 .../BrooklynLauncherRebindTestToFiles.java      |  39 +++-
 .../java/brooklyn/util/math/MathPredicates.java |  24 +--
 14 files changed, 663 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/918aff32/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
----------------------------------------------------------------------
diff --cc core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
index dd73cc8,23958e4..d814cca
--- a/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
+++ b/core/src/main/java/brooklyn/event/basic/DependentConfiguration.java
@@@ -194,18 -200,10 +200,18 @@@ public class DependentConfiguration 
                              semaphore.release();
                          }
                      }}));
 +                Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
 +                if (abortCondition.predicate.apply(abortValue)) {
-                     abortion.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
++                    abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
 +                }
 +            }
-             if (abortion.size() > 0) {
-                 throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortion);
++            if (abortionExceptions.size() > 0) {
++                throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
              }
 +            
              value = source.getAttribute(sensor);
              while (!ready.apply(value)) {
-                 String prevBlockingDetails = current.setBlockingDetails("Waiting for ready from "+source+" "+sensor+" (subscription)");
+                 String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
                  try {
                      semaphore.acquire();
                  } finally {
@@@ -414,23 -439,9 +447,9 @@@
          public <T2> Builder<T2,T2> attributeWhenReady(Entity source, AttributeSensor<T2> sensor) {
              this.source = checkNotNull(source, "source");
              this.sensor = (AttributeSensor) checkNotNull(sensor, "sensor");
 -            abortIf(source, Attributes.SERVICE_STATE, Predicates.equalTo(Lifecycle.ON_FIRE));
 +            abortIf(source, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.ON_FIRE));
              return (Builder<T2, T2>) this;
          }
-         /** returns a task for parallel execution returning a list of values of the given sensor list on the given entity, 
-          * optionally when the values satisfy a given readiness predicate (defaulting to groovy truth if not supplied) */ 
-         @Beta
-         public <T2> Builder<T2, List<T2>> attributeWhenReadyFromMultiple(Iterable<? extends Entity> sources, AttributeSensor<T2> sensor) {
-             return attributeWhenReadyFromMultiple(sources, sensor, GroovyJavaMethods.truthPredicate());
-         }
-         @Beta
-         public <T2> Builder<T2, List<T2>> attributeWhenReadyFromMultiple(Iterable<? extends Entity> sources, AttributeSensor<T2> sensor, Predicate<? super T2> readiness) {
-             for (Entity s : checkNotNull(sources, "sources")) {
-                 AttributeAndSensorCondition<T2> condition = new AttributeAndSensorCondition<T2>(s, sensor, readiness);
-                 multiSource.add(condition);
-             }
-             return (Builder<T2, List<T2>>) this;
-         }
          public Builder<T,V> readiness(Closure<Boolean> val) {
              this.readiness = GroovyJavaMethods.predicateFromClosure(checkNotNull(val, "val"));
              return this;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/918aff32/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
----------------------------------------------------------------------
diff --cc core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
index 433d677,b8a6f6a..db237ed
--- a/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/DependentConfigurationTest.java
@@@ -195,8 -229,25 +237,26 @@@ public class DependentConfigurationTes
      }
  
      @Test
+     public void testAttributeWhenReadyWithAbortFailsWhenAbortConditionAlreadyHoldsWaitingNow() throws Exception {
+         entity2.setAttribute(TestEntity.SEQUENCE, 1);
+         final Task<String> t = submit(new Callable<String>() {
+             public String call() {
+                 return DependentConfiguration.builder()
+                         .attributeWhenReady(entity, TestEntity.NAME)
+                         .abortIf(entity2, TestEntity.SEQUENCE, Predicates.equalTo(1))
+                         .runNow();
+             }});
+         try {
+             assertDoneEventually(t);
+             fail();
+         } catch (Exception e) {
+             if (!e.toString().contains("Aborted waiting for ready")) throw e;
+         }
+     }
+ 
+     @Test
 -    public void testAttributeWhenReadyAbortsWhenOnfireByDefault() throws Exception {
 +    public void testAttributeWhenReadyAbortsWhenOnFireByDefault() {
 +        log.info("starting test "+JavaClassNames.niceClassAndMethod());
          final Task<String> t = submit(DependentConfiguration.builder()
                  .attributeWhenReady(entity, TestEntity.NAME)
                  .build());

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/918aff32/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java
----------------------------------------------------------------------
diff --cc core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java
index 0000000,35c1a8e..2f0ce82
mode 000000,100644..100644
--- a/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java
+++ b/core/src/test/java/brooklyn/util/text/TemplateProcessorTest.java
@@@ -1,0 -1,99 +1,101 @@@
+ /*
+  * 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 brooklyn.util.text;
+ 
+ import static org.testng.Assert.assertEquals;
+ 
+ import org.testng.annotations.Test;
+ 
+ import brooklyn.entity.BrooklynAppUnitTestSupport;
+ import brooklyn.entity.proxying.EntitySpec;
+ import brooklyn.event.basic.DependentConfiguration;
+ import brooklyn.test.entity.TestApplication;
+ import brooklyn.test.entity.TestEntity;
+ 
+ import com.google.common.collect.ImmutableMap;
+ 
+ public class TemplateProcessorTest extends BrooklynAppUnitTestSupport {
+ 
+     @Test
+     public void testAdditionalArgs() {
+         TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                 .configure(TestEntity.CONF_NAME, "myval"));
+         String templateContents = "${mykey}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, entity, ImmutableMap.of("mykey", "myval"));
+         assertEquals(result, "myval");
+     }
+     
+     @Test
+     public void testGetSysProp() {
+         System.setProperty("testGetSysProp", "myval");
+         
+         String templateContents = "${javaSysProps['testGetSysProp']}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.<String,Object>of());
+         assertEquals(result, "myval");
+     }
+     
+     @Test
+     public void testEntityGetterMethod() {
+         String templateContents = "${entity.id}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.<String,Object>of());
+         assertEquals(result, app.getId());
+     }
+     
+     @Test
+     public void testEntityConfig() {
+         TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                 .configure(TestEntity.CONF_NAME, "myval"));
+         String templateContents = "${config['"+TestEntity.CONF_NAME.getName()+"']}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, entity, ImmutableMap.<String,Object>of());
+         assertEquals(result, "myval");
+     }
+     
+     // TODO Should this be under a sub-map (e.g. globalConfig or some such)?
+     @Test
+     public void testManagementContextConfig() {
+         mgmt.getBrooklynProperties().put("globalmykey", "myval");
+         String templateContents = "${globalmykey}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.<String,Object>of());
+         assertEquals(result, "myval");
+     }
+     
+     // FIXME Fails because tries to get global, and then call getMyKey() 
+     @Test(groups="WIP")
+     public void testManagementContextConfigWithDot() {
+         mgmt.getBrooklynProperties().put("global.mykey", "myval");
+         String templateContents = "${global.mykey}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, app, ImmutableMap.<String,Object>of());
+         assertEquals(result, "myval");
+     }
+     
+     // FIXME Fails because does not respect attributeWhenReady; just returns its toString
++    // to fix this, we need to intercept lookups in the template processor 
++    // should be possible by passing a custom TemplateHashModel in to the template processor instead of our substitution map
+     @Test(groups="WIP")
+     public void testApplyTemplatedConfigWithAttributeWhenReady() {
+         app.setAttribute(TestApplication.MY_ATTRIBUTE, "myval");
+ 
+         TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                 .configure(TestEntity.CONF_NAME, DependentConfiguration.attributeWhenReady(app, TestApplication.MY_ATTRIBUTE)));
+         
+         String templateContents = "${config['"+TestEntity.CONF_NAME.getName()+"']}";
+         String result = TemplateProcessor.processTemplateContents(templateContents, entity, ImmutableMap.<String,Object>of());
+         assertEquals(result, "myval");
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/918aff32/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
----------------------------------------------------------------------
diff --cc usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
index 6a2eab6,9d55d93..024e825
--- a/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
+++ b/usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java
@@@ -440,10 -485,50 +485,50 @@@ public class BrooklynLauncher 
          started = true;
          
          // Create the management context
+         initManagementContext();
+ 
+         // Create the locations
+         locations.addAll(managementContext.getLocationRegistry().resolve(locationSpecs));
+ 
+         // Add a CAMP platform (TODO include a flag for this?)
+         campPlatform = new BrooklynCampPlatformLauncherNoServer()
+                 .useManagementContext(managementContext)
+                 .launch()
+                 .getCampPlatform();
+         // TODO start CAMP rest _server_ in the below (at /camp) ?
+         
+         try {
+             initPersistence();
+             startPersistence();
+         } catch (Exception e) {
+             handleSubsystemStartupError(ignorePersistenceErrors, "persistence", e);
+         }
+         
+         // Start the web-console
+         if (startWebApps) {
+             try {
+                 startWebApps();
+             } catch (Exception e) {
+                 handleSubsystemStartupError(ignoreWebErrors, "web apps", e);
+             }
+         }
+         
+         try {
+             createApps();
+             startApps();
+         } catch (Exception e) {
+             handleSubsystemStartupError(ignoreAppErrors, "managed apps", e);
+         }
+         
+         return this;
+     }
+ 
+     private void initManagementContext() {
+         // Create the management context
          if (managementContext == null) {
              if (brooklynProperties == null) {
-                 Builder builder = new BrooklynProperties.Factory.Builder();
 -                BrooklynProperties.Factory.Builder builder = new BrooklynProperties.Factory.Builder();
 -                if (globalBrooklynPropertiesFile != null) {
++                BrooklynProperties.Factory.Builder builder = BrooklynProperties.Factory.builderDefault();
 +                if (globalBrooklynPropertiesFile != null && fileExists(globalBrooklynPropertiesFile)) {
                      // brooklyn.properties stores passwords (web-console and cloud credentials), 
                      // so ensure it has sensible permissions
                      checkFileReadable(globalBrooklynPropertiesFile);
@@@ -468,40 -553,8 +553,12 @@@
              brooklynProperties = ((ManagementContextInternal)managementContext).getBrooklynProperties();
              brooklynProperties.addFromMap(brooklynAdditionalProperties);
          }
- 
-         // Create the locations
-         locations.addAll(managementContext.getLocationRegistry().resolve(locationSpecs));
- 
-         // Add a CAMP platform (TODO include a flag for this?)
-         campPlatform = new BrooklynCampPlatformLauncherNoServer()
-                 .useManagementContext(managementContext)
-                 .launch()
-                 .getCampPlatform();
-         // TODO start CAMP rest _server_ in the below (at /camp) ?
-         
-         try {
-             initPersistence();
-         } catch (Exception e) { handleSubsystemStartupError(ignorePersistenceErrors, "persistence", e); }
-         
-         // Start the web-console
-         if (startWebApps) {
-             try {
-                 startWebApps();
-             } catch (Exception e) { handleSubsystemStartupError(ignoreWebErrors, "web apps", e); }
-         }
-         
-         try {
-             createApps();
-             startApps();
-         } catch (Exception e) { handleSubsystemStartupError(ignoreAppErrors, "managed apps", e); }
-         
-         return this;
      }
  
 +    private boolean fileExists(String file) {
 +        return new File(Os.tidyPath(file)).exists();
 +    }
 +
      private void checkFileReadable(String file) {
          File f = new File(Os.tidyPath(file));
          if (!f.exists()) {