You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/07/18 20:11:08 UTC
[1/2] brooklyn-server git commit: BROOKLYN-264: Stop app while VM
still being provisioned
Repository: brooklyn-server
Updated Branches:
refs/heads/master af4963537 -> 8f9d73ef6
BROOKLYN-264: Stop app while VM still being provisioned
- put a wait in MachineLifecycleEffectorTasks.java#doStop for MachineLocations
- Live test for jclouds locations
- integration test for byon locations
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5b3c412a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5b3c412a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5b3c412a
Branch: refs/heads/master
Commit: 5b3c412a229ab3b7f553148471989cf741d12a30
Parents: c4d5055
Author: Valentin Aitken <bo...@gmail.com>
Authored: Tue Jun 21 18:10:31 2016 +0300
Committer: Valentin Aitken <bo...@gmail.com>
Committed: Fri Jul 15 17:23:42 2016 +0300
----------------------------------------------------------------------
.../apache/brooklyn/core/entity/Attributes.java | 14 +-
.../core/server/BrooklynServerConfig.java | 5 +
.../location/jclouds/JcloudsLocation.java | 6 +-
.../MachineLifecycleEffectorTasks.java | 27 ++-
.../ExpungingJcloudsLocationLiveTest.java | 186 +++++++++++++++++++
5 files changed, 235 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5b3c412a/core/src/main/java/org/apache/brooklyn/core/entity/Attributes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Attributes.java b/core/src/main/java/org/apache/brooklyn/core/entity/Attributes.java
index 80ed765..95d1bcd 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/Attributes.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/Attributes.java
@@ -144,7 +144,19 @@ public interface Attributes {
AttributeSensor<URI> MAIN_URI = MainUri.MAIN_URI;
- // this class is added because the MAIN_URI relies on a static initialization which unfortunately can't be added to an interface.
+ AttributeSensor<JcloudsProvisioningState> JCLOUDS_PROVISIONING_RUNNING = new BasicAttributeSensor(TypeToken.of(JcloudsProvisioningState.class), "jclouds.provisioning.running",
+ "Internal sensor. Please do NOT change its value across entities.", AttributeSensor.SensorPersistenceMode.NONE);
+ /**
+ * Used only by {@link org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks#doStop}
+ */
+ @Beta
+ enum JcloudsProvisioningState {
+ STARTED,
+ DONE,
+ NONE
+ }
+
+ // this class is added because the MAIN_URI relies on a static initialization which unfortunately can't be added to an interface.
class MainUri {
private final static AttributeSensor<URI> MAIN_URI = Sensors.newSensor(URI.class, "main.uri", "Main URI for contacting the service/endpoint offered by this entity");
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5b3c412a/core/src/main/java/org/apache/brooklyn/core/server/BrooklynServerConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/server/BrooklynServerConfig.java b/core/src/main/java/org/apache/brooklyn/core/server/BrooklynServerConfig.java
index 84cdfdb..33f1873 100644
--- a/core/src/main/java/org/apache/brooklyn/core/server/BrooklynServerConfig.java
+++ b/core/src/main/java/org/apache/brooklyn/core/server/BrooklynServerConfig.java
@@ -31,6 +31,7 @@ import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -121,6 +122,10 @@ public class BrooklynServerConfig {
public static final ConfigKey<Boolean> OSGI_CACHE_CLEAN = ConfigKeys.newBooleanConfigKey("brooklyn.osgi.cache.clean",
"Whether to delete the OSGi directory before and after use; if unset, it will delete if the node ID forms part of the cache dir path (which by default it does) to avoid file leaks");
+ public static final ConfigKey<Duration> ENTITIES_STOP_WAIT_PROVISIONING_TIMEOUT = ConfigKeys.newDurationConfigKey("entities.stop.wait.provisioning.timeout",
+ "When stop is called on the Entity, it doesn't have a machine location instance so it doesn't have anything to ask to stop. To be able to stop the machine it has to wait for provisioning to complete. " +
+ "This ConfigKey sets the timeout for which the stop task will wait provisioning to complete.", Duration.FIVE_MINUTES);
+
/** @see BrooklynServerPaths#getMgmtBaseDir(ManagementContext) */
public static String getMgmtBaseDir(ManagementContext mgmt) {
return BrooklynServerPaths.getMgmtBaseDir(mgmt);
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5b3c412a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index 572a0bf..14e310e 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -63,6 +63,7 @@ import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
import org.apache.brooklyn.core.BrooklynVersion;
import org.apache.brooklyn.core.config.ConfigUtils;
import org.apache.brooklyn.core.config.Sanitizer;
+import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.location.AbstractLocation;
import org.apache.brooklyn.core.location.BasicMachineMetadata;
import org.apache.brooklyn.core.location.LocationConfigKeys;
@@ -732,7 +733,10 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
if (LOG.isDebugEnabled())
LOG.debug("NOTE: unused flags passed to obtain VM in "+setup.getDescription()+": "
+ Sanitizer.sanitize(setup.getUnusedConfig()));
-
+ Object callerContext = setup.get(JcloudsLocationConfig.CALLER_CONTEXT);
+ if (callerContext != null && callerContext instanceof Entity) {
+ ((Entity)callerContext).sensors().set(Attributes.JCLOUDS_PROVISIONING_RUNNING, Attributes.JcloudsProvisioningState.STARTED);
+ }
nodes = computeService.createNodesInGroup(groupId, 1, template);
provisionTimestamp = Duration.of(provisioningStopwatch);
} finally {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5b3c412a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
index dfee728..964e016 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
@@ -28,6 +28,8 @@ import java.util.concurrent.Callable;
import javax.annotation.Nullable;
+import org.apache.brooklyn.core.server.BrooklynServerConfig;
+import org.apache.brooklyn.util.repeat.Repeater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -77,10 +79,11 @@ import org.apache.brooklyn.entity.software.base.SoftwareProcess.RestartSoftwareP
import org.apache.brooklyn.entity.software.base.SoftwareProcess.StopSoftwareParameters;
import org.apache.brooklyn.entity.software.base.SoftwareProcess.StopSoftwareParameters.StopMode;
import org.apache.brooklyn.entity.stock.EffectorStartableImpl.StartParameters;
+import org.apache.brooklyn.util.collections.MutableSet;
+
import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.task.DynamicTasks;
import org.apache.brooklyn.util.core.task.Tasks;
@@ -441,6 +444,9 @@ public abstract class MachineLifecycleEffectorTasks {
}
}
entity().addLocations(ImmutableList.of((Location) machine));
+ if (entity().getAttribute(Attributes.JCLOUDS_PROVISIONING_RUNNING) != null) {
+ entity().sensors().remove(Attributes.JCLOUDS_PROVISIONING_RUNNING);
+ }
// elsewhere we rely on (public) hostname being set _after_ subnet_hostname
// (to prevent the tiny possibility of races resulting in hostname being returned
@@ -709,7 +715,26 @@ public abstract class MachineLifecycleEffectorTasks {
DynamicTasks.queue("pre-stop", new PreStopCustomTask());
+ // BROOKLYN-263:
+ // With this change the stop effector will wait for Location to provision so it can stop it.
+ // It will not retry if non-jclouds location is used in the entity.
Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations());
+ if (Attributes.JcloudsProvisioningState.STARTED.equals(entity().sensors().get(Attributes.JCLOUDS_PROVISIONING_RUNNING))
+ && machine.isAbsent()) {
+ entity().sensors().set(Attributes.JCLOUDS_PROVISIONING_RUNNING, null);
+ Repeater.create("Wait for a machine to appear")
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ return Machines.findUniqueMachineLocation(entity().getLocations()).isPresent();
+ }
+ })
+ .every(Duration.FIVE_SECONDS)
+ .limitTimeTo(entity().getManagementContext().getConfig().getConfig(BrooklynServerConfig.ENTITIES_STOP_WAIT_PROVISIONING_TIMEOUT))
+ .run();
+ machine = Machines.findUniqueMachineLocation(entity().getLocations());
+ }
+
Task<List<?>> stoppingProcess = null;
if (canStop(stopProcessMode, entity())) {
stoppingProcess = Tasks.parallel("stopping",
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5b3c412a/software/base/src/test/java/org/apache/brooklyn/entity/ExpungingJcloudsLocationLiveTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/ExpungingJcloudsLocationLiveTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/ExpungingJcloudsLocationLiveTest.java
new file mode 100644
index 0000000..4b49be4
--- /dev/null
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/ExpungingJcloudsLocationLiveTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.entity;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.location.LocationConfigKeys;
+import org.apache.brooklyn.core.location.cloud.CloudLocationConfig;
+import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
+import org.apache.brooklyn.core.test.BrooklynAppLiveTestSupport;
+import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
+import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess;
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.jclouds.aws.ec2.compute.AWSEC2ComputeService;
+import org.jclouds.compute.domain.ComputeMetadata;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+
+import static org.apache.brooklyn.test.Asserts.*;
+
+public class ExpungingJcloudsLocationLiveTest extends BrooklynAppLiveTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(ExpungingJcloudsLocationLiveTest.class);
+
+ protected BrooklynProperties brooklynProperties;
+
+ @BeforeMethod(alwaysRun=true)
+ @Override
+ public void setUp() throws Exception {
+ // Don't let any defaults from brooklyn.properties (except credentials) interfere with test
+ brooklynProperties = BrooklynProperties.Factory.newDefault();
+
+ // Also removes scriptHeader (e.g. if doing `. ~/.bashrc` and `. ~/.profile`, then that can cause "stdin: is not a tty")
+ brooklynProperties.remove("brooklyn.ssh.config.scriptHeader");
+
+ mgmt = new LocalManagementContextForTests(brooklynProperties);
+ super.setUp();
+ }
+
+ @Test
+ public void verifyExpungingMockedEntityIsQuick() throws Exception {
+ final EmptySoftwareProcess emptySoftwareProcess = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class));
+ executeInLimitedTime(new Callable<Void>() {
+ public Void call() {
+ app.start(ImmutableList.of(mgmt.getLocationManager().createLocation(TestApplication.LOCALHOST_PROVISIONER_SPEC)));
+ return null;
+ }
+ }, 2, TimeUnit.SECONDS);
+ EntityAsserts.assertEntityHealthy(emptySoftwareProcess);
+ assertNull(emptySoftwareProcess.getAttribute(Attributes.JCLOUDS_PROVISIONING_RUNNING));
+
+ executeInLimitedTime(new Callable<Void>() {
+ public Void call() {
+ Entities.destroy(app);
+ return null;
+ }
+ }, 1, TimeUnit.SECONDS);
+ assertEquals(app.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.STOPPED);
+ assertEquals(app.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STOPPED);
+ assertNull(emptySoftwareProcess.getAttribute(Attributes.JCLOUDS_PROVISIONING_RUNNING));
+ }
+
+ @Test(groups = "Integration")
+ public void verifyExpungingByonLocationIsQuick() throws Exception {
+ final VanillaSoftwareProcess entity = app.addChild(EntitySpec.create(VanillaSoftwareProcess.class)
+ .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "echo install")
+ .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "echo launch")
+ .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "echo running"));
+ app.addLocations(ImmutableList.of(mgmt.getLocationFactory().createLocation(TestApplication.LOCALHOST_PROVISIONER_SPEC)));
+
+ EntityManagementUtils.start(app);
+
+ succeedsEventually(ImmutableMap.of("timeout", "4s"), new Callable<Boolean>() {
+ public Boolean call() {
+ assertTrue(entity.sensors().get(Attributes.SERVICE_UP));
+ assertNull(entity.getAttribute(Attributes.JCLOUDS_PROVISIONING_RUNNING));
+ return entity.sensors().get(Attributes.SERVICE_UP);
+ }
+ });
+
+ executeInLimitedTime(new Callable<Void>() {
+ public Void call() {
+ Entities.destroy(app);
+ return null;
+ }
+ }, 2, TimeUnit.SECONDS);
+ // Make sure that the entity will be stopped fast. Two seconds at most.
+ assertEquals(app.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.STOPPED);
+ assertEquals(app.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STOPPED);
+ }
+
+ public static final String PROVIDER = "aws-ec2";
+ public static final String REGION_NAME = "us-west-2";
+ public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
+
+ /**
+ * Verifies the behavior described in
+ * <a href="https://issues.apache.org/jira/browse/BROOKLYN-264">BROOKLYN-264 Stop app while VM still being provisioned: vm is left running when app is expunged</a>
+ * <ul>
+ * <li>ApplicationResource.launch</li>
+ * <li>wait a few seconds and EntityResponse.expunge</li>
+ * <li>assert the image is on the cloud</li>
+ * </ul>
+ */
+ @Test(groups = {"Live"})
+ public void verifyJclousMachineIsExpungedWhenStoppedImmediatelyAfterStart() {
+ Map<String,String> flags = ImmutableMap.of("imageId", "us-west-2/ami-cd715dfd", LocationConfigKeys.CLOUD_MACHINE_NAMER_CLASS.getName(), "");
+ Map<String,?> allFlags = MutableMap.<String,Object>builder()
+ .put("tags", ImmutableList.of(getClass().getName()))
+ .putAll(flags)
+ .build();
+ JcloudsLocation jcloudsLocation = (JcloudsLocation)mgmt.getLocationRegistry().getLocationManaged(LOCATION_SPEC, allFlags);
+
+ final EmptySoftwareProcess emptySoftwareProcess = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)
+ .configure(EmptySoftwareProcess.PROVISIONING_PROPERTIES.subKey(CloudLocationConfig.INBOUND_PORTS.getName()), ImmutableList.of(22)));
+
+ app.addLocations(ImmutableList.of(jcloudsLocation));
+
+ EntityManagementUtils.start(app);
+
+ succeedsEventually(ImmutableMap.of("timeout", "16s"), new Callable<Attributes.JcloudsProvisioningState>() {
+ public Attributes.JcloudsProvisioningState call() {
+ assertEquals(emptySoftwareProcess.getAttribute(Attributes.JCLOUDS_PROVISIONING_RUNNING), Attributes.JcloudsProvisioningState.STARTED);
+ return emptySoftwareProcess.getAttribute(Attributes.JCLOUDS_PROVISIONING_RUNNING);
+ }
+ });
+
+ long beginTime = System.currentTimeMillis();
+ Entities.destroyCatching(app);
+ LOG.info("Time for expunging: {}", System.currentTimeMillis() - beginTime);
+
+ NodeMetadata nodeMetadata = Iterables.getFirst(((AWSEC2ComputeService) jcloudsLocation.getComputeService()).listNodesDetailsMatching(new Predicate<ComputeMetadata>() {
+ @Override public boolean apply(@Nullable ComputeMetadata computeMetadata) {
+ return ((NodeMetadata)computeMetadata).getGroup() == null ? false
+ : Pattern.matches(
+ "brooklyn-.*" + System.getProperty("user.name") + ".*emptysoftware.*"+emptySoftwareProcess.getId().substring(0, 4),
+ ((NodeMetadata)computeMetadata).getGroup()
+ );
+ }}),
+ null);
+ LOG.info("nodeMetadata found after app was created: {}", nodeMetadata);
+ assertTrue(nodeMetadata.getStatus().equals(NodeMetadata.Status.TERMINATED), "The application should be destroyed after stop effector was called.");
+ }
+
+ private <T> T executeInLimitedTime(Callable<T> callable, long timeout, TimeUnit timeUnit) throws Exception {
+ Future<T> future = Executors.newCachedThreadPool().submit(callable);
+ return future.get(timeout, timeUnit);
+ }
+}
[2/2] brooklyn-server git commit: This closes #211
Posted by al...@apache.org.
This closes #211
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8f9d73ef
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8f9d73ef
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8f9d73ef
Branch: refs/heads/master
Commit: 8f9d73ef63114ae9972ac7ec5a746e6ec31dcfb1
Parents: af49635 5b3c412
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jul 18 21:10:30 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jul 18 21:10:30 2016 +0100
----------------------------------------------------------------------
.../apache/brooklyn/core/entity/Attributes.java | 14 +-
.../core/server/BrooklynServerConfig.java | 5 +
.../location/jclouds/JcloudsLocation.java | 6 +-
.../MachineLifecycleEffectorTasks.java | 27 ++-
.../ExpungingJcloudsLocationLiveTest.java | 186 +++++++++++++++++++
5 files changed, 235 insertions(+), 3 deletions(-)
----------------------------------------------------------------------