Repository: incubator-brooklyn Updated Branches: refs/heads/master d58d5035f -> 4ed9e97a8
TestCase no longer extends BaseTest, but rather extends Entity directly. Added check in TestCaseImpl to ensure that only non-started children are startable. Added InfrastructureDeploymentTestCase Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2b40644d Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2b40644d Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2b40644d Branch: refs/heads/master Commit: 2b40644d83601773d368d4416bd5fb938e673f5a Parents: aeb56fd Author: Graeme-Miller <graeme.mil...@cloudsoftcorp.com> Authored: Fri Dec 4 19:32:28 2015 +0000 Committer: Graeme-Miller <graeme.mil...@cloudsoftcorp.com> Committed: Mon Dec 7 13:41:39 2015 +0000 ---------------------------------------------------------------------- .../InfrastructureDeploymentTestCase.java | 54 +++++++++++++++++++ .../InfrastructureDeploymentTestCaseImpl.java | 57 ++++++++++++++++++++ .../brooklyn/test/framework/TestCase.java | 4 +- .../brooklyn/test/framework/TestCaseImpl.java | 19 +++++-- 4 files changed, 128 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2b40644d/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCase.java ---------------------------------------------------------------------- diff --git a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCase.java b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCase.java new file mode 100644 index 0000000..5f368df --- /dev/null +++ b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCase.java @@ -0,0 +1,54 @@ +/* + * 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.test.framework; + +import com.google.common.reflect.TypeToken; +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.entity.ImplementedBy; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.core.entity.StartableApplication; +import org.apache.brooklyn.entity.software.base.SoftwareProcess; + +/** + * Created by graememiller on 04/12/2015. + */ +@ImplementedBy(value = InfrastructureDeploymentTestCaseImpl.class) +public interface InfrastructureDeploymentTestCase extends TestCase { + + /** + * Entity spec to deploy. This will be deployed second, after the INFRASTRUCTURE_SPEC has been deployed. This will be deployed to the DEPLOYMENT_LOCATION. + * All children will be deployed after this + */ + ConfigKey<EntitySpec<SoftwareProcess>> ENTITY_SPEC_TO_DEPLOY = ConfigKeys.newConfigKey(new TypeToken<EntitySpec<SoftwareProcess>>(){}, "infrastructure.deployment.entity.spec", "Entity spec to deploy to infrastructure"); + + + /** + * Infrastructure to deploy. This will be deployed first, then the ENTITY_SPEC_TO_DEPLOY will be deployed, then any children + */ + ConfigKey<EntitySpec<StartableApplication>> INFRASTRUCTURE_SPEC = ConfigKeys.newConfigKey(new TypeToken<EntitySpec<StartableApplication>>(){}, "infrastructure.deployment.spec", "Infrastructure to deploy"); + + + /** + * The The location to deploy ENTITY_SPEC_TO_DEPLOY. + */ + ConfigKey<String> DEPLOYMENT_LOCATION_SENSOR_NAME = ConfigKeys.newStringConfigKey("infrastructure.deployment.location.sensor", "Name of the sensor of INFRASTRUCTURE_SPEC to retrieve the Location to deploy the entity to"); + + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2b40644d/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCaseImpl.java ---------------------------------------------------------------------- diff --git a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCaseImpl.java b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCaseImpl.java new file mode 100644 index 0000000..900c0a0 --- /dev/null +++ b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/InfrastructureDeploymentTestCaseImpl.java @@ -0,0 +1,57 @@ +/* + * 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.test.framework; + +import com.google.common.collect.ImmutableList; +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.core.annotation.EffectorParam; +import org.apache.brooklyn.core.entity.StartableApplication; +import org.apache.brooklyn.core.sensor.Sensors; +import org.apache.brooklyn.entity.software.base.SoftwareProcess; + +import java.util.Collection; + +/** + * Created by graememiller on 04/12/2015. + */ +public class InfrastructureDeploymentTestCaseImpl extends TestCaseImpl implements InfrastructureDeploymentTestCase { + + @Override + public void start(@EffectorParam(name = "locations") Collection<? extends Location> locations) { + //Create the infrastructure + EntitySpec<StartableApplication> infrastructureSpec = config().get(INFRASTRUCTURE_SPEC); + StartableApplication infrastructure = this.addChild(infrastructureSpec); + infrastructure.start(locations); + + //Get the location + String deploymentLocationSensorName = config().get(DEPLOYMENT_LOCATION_SENSOR_NAME); + Location locationToDeployTo = infrastructure.sensors().get(Sensors.newSensor(Location.class, deploymentLocationSensorName)); + + + //Start the child entity + EntitySpec<SoftwareProcess> entityToDeploySpec = config().get(ENTITY_SPEC_TO_DEPLOY); + SoftwareProcess entityToDeploy = this.addChild(entityToDeploySpec); + entityToDeploy.start(ImmutableList.of(locationToDeployTo)); + + + //Defer to super class to start children + super.start(locations); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2b40644d/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCase.java ---------------------------------------------------------------------- diff --git a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCase.java b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCase.java index 78fd8d6..34a2e34 100644 --- a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCase.java +++ b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCase.java @@ -18,7 +18,9 @@ */ package org.apache.brooklyn.test.framework; +import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.ImplementedBy; +import org.apache.brooklyn.core.entity.trait.Startable; /** * Entity that logically groups other test entities @@ -26,5 +28,5 @@ import org.apache.brooklyn.api.entity.ImplementedBy; * @author m4rkmckenna */ @ImplementedBy(value = TestCaseImpl.class) -public interface TestCase extends BaseTest { +public interface TestCase extends Entity, Startable { } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2b40644d/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCaseImpl.java ---------------------------------------------------------------------- diff --git a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCaseImpl.java b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCaseImpl.java index 71efca3..1508778 100644 --- a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCaseImpl.java +++ b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestCaseImpl.java @@ -21,17 +21,23 @@ package org.apache.brooklyn.test.framework; import com.google.common.collect.Lists; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.util.exceptions.Exceptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Collection; /** * {@inheritDoc} */ -public class TestCaseImpl extends AbstractTest implements TestCase { +public class TestCaseImpl extends AbstractEntity implements TestCase { + + private static final Logger LOG = LoggerFactory.getLogger(TestCaseImpl.class); /** * {@inheritDoc} @@ -40,12 +46,15 @@ public class TestCaseImpl extends AbstractTest implements TestCase { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); try { for (final Entity childEntity : getChildren()) { - if (childEntity instanceof Startable) ((Startable) childEntity).start(locations); + Boolean serviceUp = childEntity.sensors().get(SERVICE_UP); + if (childEntity instanceof Startable && !Boolean.TRUE.equals(serviceUp)){ + ((Startable) childEntity).start(locations); + } } - sensors().set(SERVICE_UP, true); + sensors().set(Attributes.SERVICE_UP, true); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } catch (Throwable t) { - sensors().set(SERVICE_UP, false); + sensors().set(Attributes.SERVICE_UP, false); ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } @@ -56,7 +65,7 @@ public class TestCaseImpl extends AbstractTest implements TestCase { */ public void stop() { ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING); - sensors().set(SERVICE_UP, false); + sensors().set(Attributes.SERVICE_UP, false); try { for (Entity child : getChildren()) { if (child instanceof Startable) ((Startable) child).stop();