BrooklynCluster: add memberSpec + test - Before memberSpec was added, it would fail if you asked for a BrooklynCluster without supplying a memberSpec yourself.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/e9ab67b3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/e9ab67b3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/e9ab67b3 Branch: refs/heads/master Commit: e9ab67b3e248ea4968b059e852d317b97df8c718 Parents: 32b47a9 Author: Aled Sage <[email protected]> Authored: Tue Mar 10 13:48:01 2015 +0000 Committer: Aled Sage <[email protected]> Committed: Thu Mar 26 10:09:40 2015 +0000 ---------------------------------------------------------------------- .../entity/brooklynnode/BrooklynCluster.java | 19 ++-- .../BrooklynClusterIntegrationTest.java | 96 ++++++++++++++++++++ 2 files changed, 108 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9ab67b3/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java index 7b5c095..65a7202 100644 --- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java +++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynCluster.java @@ -26,16 +26,21 @@ import brooklyn.entity.basic.ConfigKeys; import brooklyn.entity.brooklynnode.effector.BrooklynNodeUpgradeEffectorBody; import brooklyn.entity.effector.Effectors; import brooklyn.entity.group.DynamicCluster; +import brooklyn.entity.proxying.EntitySpec; import brooklyn.entity.proxying.ImplementedBy; import brooklyn.event.AttributeSensor; import brooklyn.event.basic.Sensors; @ImplementedBy(BrooklynClusterImpl.class) public interface BrooklynCluster extends DynamicCluster { - public static final AttributeSensor<BrooklynNode> MASTER_NODE = Sensors.newSensor( + + ConfigKey<EntitySpec<?>> MEMBER_SPEC = ConfigKeys.newConfigKeyWithDefault(DynamicCluster.MEMBER_SPEC, + EntitySpec.create(BrooklynNode.class)); + + AttributeSensor<BrooklynNode> MASTER_NODE = Sensors.newSensor( BrooklynNode.class, "brooklyncluster.master", "Pointer to the child node with MASTER state in the cluster"); - public interface SelectMasterEffector { + interface SelectMasterEffector { ConfigKey<String> NEW_MASTER_ID = ConfigKeys.newStringConfigKey( "brooklyncluster.new_master_id", "The ID of the node to become master", null); Effector<Void> SELECT_MASTER = Effectors.effector(Void.class, "selectMaster") @@ -44,11 +49,11 @@ public interface BrooklynCluster extends DynamicCluster { .buildAbstract(); } - public static final Effector<Void> SELECT_MASTER = SelectMasterEffector.SELECT_MASTER; + Effector<Void> SELECT_MASTER = SelectMasterEffector.SELECT_MASTER; - public interface UpgradeClusterEffector { - public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey(); - public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = BrooklynNodeUpgradeEffectorBody.EXTRA_CONFIG; + interface UpgradeClusterEffector { + ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey(); + ConfigKey<Map<String,Object>> EXTRA_CONFIG = BrooklynNodeUpgradeEffectorBody.EXTRA_CONFIG; Effector<Void> UPGRADE_CLUSTER = Effectors.effector(Void.class, "upgradeCluster") .description("Upgrade the cluster with new distribution version, " @@ -60,6 +65,6 @@ public interface BrooklynCluster extends DynamicCluster { .buildAbstract(); } - public static final Effector<Void> UPGRADE_CLUSTER = UpgradeClusterEffector.UPGRADE_CLUSTER; + Effector<Void> UPGRADE_CLUSTER = UpgradeClusterEffector.UPGRADE_CLUSTER; } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e9ab67b3/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynClusterIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynClusterIntegrationTest.java b/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynClusterIntegrationTest.java new file mode 100644 index 0000000..d623a38 --- /dev/null +++ b/software/base/src/test/java/brooklyn/entity/brooklynnode/BrooklynClusterIntegrationTest.java @@ -0,0 +1,96 @@ +/* + * 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.entity.brooklynnode; + +import java.io.File; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import brooklyn.entity.BrooklynAppUnitTestSupport; +import brooklyn.entity.Entity; +import brooklyn.entity.brooklynnode.BrooklynNode.ExistingFileBehaviour; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.location.basic.LocalhostMachineProvisioningLocation; +import brooklyn.test.EntityTestUtils; +import brooklyn.util.javalang.JavaClassNames; +import brooklyn.util.net.Networking; +import brooklyn.util.os.Os; + +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + +public class BrooklynClusterIntegrationTest extends BrooklynAppUnitTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(BrooklynNodeIntegrationTest.class); + + private File pseudoBrooklynPropertiesFile; + private File pseudoBrooklynCatalogFile; + private File persistenceDir; + private LocalhostMachineProvisioningLocation loc; + private List<LocalhostMachineProvisioningLocation> locs; + + @BeforeMethod(alwaysRun=true) + @Override + public void setUp() throws Exception { + super.setUp(); + pseudoBrooklynPropertiesFile = Os.newTempFile("brooklynnode-test", ".properties"); + pseudoBrooklynPropertiesFile.delete(); + + pseudoBrooklynCatalogFile = Os.newTempFile("brooklynnode-test", ".catalog"); + pseudoBrooklynCatalogFile.delete(); + + loc = app.newLocalhostProvisioningLocation(); + locs = ImmutableList.of(loc); + } + + @AfterMethod(alwaysRun=true) + @Override + public void tearDown() throws Exception { + try { + super.tearDown(); + } finally { + if (pseudoBrooklynPropertiesFile != null) pseudoBrooklynPropertiesFile.delete(); + if (pseudoBrooklynCatalogFile != null) pseudoBrooklynCatalogFile.delete(); + if (persistenceDir != null) Os.deleteRecursively(persistenceDir); + } + } + + @Test(groups="Integration") + public void testCanStartAndStop() throws Exception { + BrooklynCluster cluster = app.createAndManageChild(EntitySpec.create(BrooklynCluster.class) + .configure(BrooklynCluster.INITIAL_SIZE, 1) + .configure(BrooklynNode.WEB_CONSOLE_BIND_ADDRESS, Networking.ANY_NIC) + .configure(BrooklynNode.ON_EXISTING_PROPERTIES_FILE, ExistingFileBehaviour.DO_NOT_USE)); + app.start(locs); + Entity brooklynNode = Iterables.find(cluster.getMembers(), Predicates.instanceOf(BrooklynNode.class)); + LOG.info("started "+app+" containing "+cluster+" for "+JavaClassNames.niceClassAndMethod()); + + EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynNode.SERVICE_UP, true); + EntityTestUtils.assertAttributeEqualsEventually(brooklynNode, BrooklynNode.SERVICE_UP, true); + + cluster.stop(); + EntityTestUtils.assertAttributeEquals(cluster, BrooklynNode.SERVICE_UP, false); + } +}
