You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by bostko <gi...@git.apache.org> on 2016/06/21 15:11:44 UTC

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

GitHub user bostko opened a pull request:

    https://github.com/apache/brooklyn-server/pull/211

    BROOKLYN-264 Stop app while VM still being provisioned: vm is left

    - Initial Live Tests

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/bostko/brooklyn-server brooklyn-264_expunge_early_tests

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/211.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #211
    
----
commit 7bbf6e0c930a534e0128ee786edccfc56068c65f
Author: Valentin Aitken <bo...@gmail.com>
Date:   2016-06-21T15:10:31Z

    BROOKLYN-264 Stop app while VM still being provisioned: vm is left running when app is expunged
    
    - Initial Live Tests

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70590868
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +712,26 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             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 (Boolean.TRUE.equals(entity().sensors().get(Attributes.JCLOUDS_PROVISIONING_STARTED))
    +                && machine.isAbsent()) {
    +            entity().sensors().set(Attributes.JCLOUDS_PROVISIONING_STARTED, null);
    --- End diff --
    
    This name feels misleading. It's sort-of more about whether the provisioning is running, rather than started. I'd be inclined to use an enum to indicate the exact state. The value could be one of PROVISIONING, ABORTING, or null.
    
    See later comment (not added yet!) about telling the jclouds provisioning to not do anything else (e.g. currently it will wait for ssh'able etc, which we can abort earlier).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70589881
  
    --- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java ---
    @@ -735,7 +737,11 @@ protected MachineLocation obtainOnce(ConfigBag setup) throws NoMachinesAvailable
                         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 callerContextEntity = (Entity)setup.get(JcloudsLocationConfig.CALLER_CONTEXT);
    --- End diff --
    
    Minor: don't call `setup.get()` again - just use your `callerContext` variable.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r69956659
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/ExpungingJcloudsLocationLiveTest.java ---
    @@ -0,0 +1,187 @@
    +/*
    + * 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.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.sensor.Sensors;
    +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);
    +        assertEquals(app.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.RUNNING);
    +        assertEquals(app.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.RUNNING);
    +        assertNull(emptySoftwareProcess.getAttribute(Attributes.JCLOUDS_PROVISIONING_STARTED));
    +
    +        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_STARTED));
    +    }
    +
    +    @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_STARTED));
    +                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() {
    --- End diff --
    
    I have to add a test for one more case. Will see how straight it is to handle it.
    When an exception occurs during deployment, in other words the execution goes here https://github.com/apache/brooklyn-server/blob/master/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java#L1062-L1105
    and `destroyOnFailure` is false then the machine will not be expunged.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    I think I have much better assertions now.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68328600
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -708,7 +710,21 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             DynamicTasks.queue("pre-stop", new PreStopCustomTask());
     
    +        // BROOKLYN-263:
    +        // With this change the stop effector will always wait for machinelocation to provision, so it can stop it.
    +        // However in some situations if the stop effector is called in less than 8 seconds after start was called,
    +        // it may be safe to skip this wait and proceed with stop.
    +        // Hesitant about parameterising this.
             Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations());
    +        if (machine.isAbsent()) {
    --- End diff --
    
    This feels dangerous, for if start were to fail and not get a machine - we'd wait a long time, presumably.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68328852
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/EC2ExpungeLiveTest.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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.api.location.Location;
    +import org.apache.brooklyn.core.entity.Entities;
    +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.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +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.regex.Pattern;
    +
    +public class EC2ExpungeLiveTest extends BrooklynAppLiveTestSupport {
    +    private static final Logger LOG = LoggerFactory.getLogger(EC2ExpungeLiveTest.class);
    +
    +    public static final String PROVIDER = "aws-ec2";
    +    public static final String SMALL_HARDWARE_ID = "m1.small";
    +
    +    public static final String REGION_NAME = "us-west-2";
    +    public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
    +
    +    protected BrooklynProperties brooklynProperties;
    +
    +    protected Location jcloudsLocation;
    +
    +    @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();
    +    }
    +
    +    /**
    +     * 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 testExpunge() {
    +        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);
    +
    +        try {
    +            // Number of seconds we wait for an AWS EC2 instance to be created.
    +            // The test succeeds if stop effector is called 200 seconds or more later
    +            Thread.sleep(16 * 1000);
    --- End diff --
    
    This kind of timing feels brittle to include in a test. But I guess we do need to wait some length of time, so it's not terminating it while it was still constructing the template (rather than in the middle of actually provisioning).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    My comments so far are bike-shedding.
    
    Looking at the big picture, I need to think more about:
    
    * How should we trigger the delete, so that it safely handles success and failure of provisioning? Options include:
      * As you've done here, have `stop()` wait for the machine to be set; but abort if start() fails.
      * Mark the entity's internal state as "requiring machine-release", and have the start() code immediately release the machine. But we'd still need `stop()` to wait for that to be done, otherwise we might go on to unmanage the entity and thus cancel the tasks.
    
    * For speed:
      * Can we use the jclouds event bus to be told of the VM's id long before jclouds has returned from the provisioning call? @andreaturli what do you think?
      * Can we tell the `JcloudsLocation` instance that the provisioning has been aborted (this would allow us to avoid waiting-for-sshable, etc). Not quite sure how best to do that.
    
    We can ignore the speed issue for now, unless there is a quick win that greatly speeds things up. The main thing is to get it functionally correct, and with clean code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70590130
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +712,26 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             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 (Boolean.TRUE.equals(entity().sensors().get(Attributes.JCLOUDS_PROVISIONING_STARTED))
    +                && machine.isAbsent()) {
    +            entity().sensors().set(Attributes.JCLOUDS_PROVISIONING_STARTED, 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.THIRTY_SECONDS)
    --- End diff --
    
    Feels like strange times to use. Why only check every thirty seconds? That means we might take 29 seconds longer than we should have. The call to `getLocations()` should be cheap, so doing it every second seems fine.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    - I marked the sensor as "transient"
    - I added a code which removes the sensor immidiately after a machine location is added
    - I added an enum class for the `jclouds.provisioning.started` flag.<br>
      However I think with this code it could stay a boolean



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by andreaturli <gi...@git.apache.org>.
Github user andreaturli commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68225850
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/EC2ExpungeLiveTest.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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.api.location.Location;
    +import org.apache.brooklyn.core.entity.Entities;
    +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.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +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.regex.Pattern;
    +
    +public class EC2ExpungeLiveTest extends BrooklynAppLiveTestSupport {
    +    private static final Logger LOG = LoggerFactory.getLogger(EC2ExpungeLiveTest.class);
    +
    +    public static final String PROVIDER = "aws-ec2";
    +    public static final String SMALL_HARDWARE_ID = "m1.small";
    +
    +    public static final String REGION_NAME = "us-west-2";
    +    public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
    +
    +    protected BrooklynProperties brooklynProperties;
    +
    +    protected Location jcloudsLocation;
    +
    +    @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();
    +    }
    +
    +    /**
    +     * 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 testExpunge() {
    +        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);
    +
    +        try {
    +            // Number of seconds we wait for an AWS EC2 instance to be created.
    +            // The test succeeds if stop effector is called 200 seconds or more later
    +            Thread.sleep(16 * 1000);
    +        } catch (InterruptedException e) {
    +            Thread.currentThread().interrupt();
    +            Exceptions.propagate(e);
    +        }
    +
    +        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>() {
    --- End diff --
    
    I think you can simplify with something like
    ```
    import static com.google.common.base.Predicates.*;
    import static org.jclouds.compute.predicates.NodePredicates.*;
    import static com.google.common.collect.Iterables.*;
    
    ...
    
    Iterable<? extends NodeMetadata> billedNodes = filter(jcloudsLocation.getComputeService().listNodesDetailsMatching(all()), and(withGroup(group), not(TERMINATED))));
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70606525
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +712,26 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             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 (Boolean.TRUE.equals(entity().sensors().get(Attributes.JCLOUDS_PROVISIONING_STARTED))
    +                && machine.isAbsent()) {
    +            entity().sensors().set(Attributes.JCLOUDS_PROVISIONING_STARTED, null);
    --- End diff --
    
    @aledsage do you have an idea how can I tell the stop task that the provisioning started other than the sensor flag. I feel like the code will need serious refactoring in order stop task to know earlier about the jclouds node.
    The entity knows only about the machine location. It doesn't know about the LocationProvisioner.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68328923
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/EC2ExpungeLiveTest.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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.api.location.Location;
    +import org.apache.brooklyn.core.entity.Entities;
    +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.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +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.regex.Pattern;
    +
    +public class EC2ExpungeLiveTest extends BrooklynAppLiveTestSupport {
    +    private static final Logger LOG = LoggerFactory.getLogger(EC2ExpungeLiveTest.class);
    +
    +    public static final String PROVIDER = "aws-ec2";
    +    public static final String SMALL_HARDWARE_ID = "m1.small";
    +
    +    public static final String REGION_NAME = "us-west-2";
    +    public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
    +
    +    protected BrooklynProperties brooklynProperties;
    +
    +    protected Location jcloudsLocation;
    +
    +    @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();
    +    }
    +
    +    /**
    +     * 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 testExpunge() {
    +        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);
    +
    +        try {
    +            // Number of seconds we wait for an AWS EC2 instance to be created.
    +            // The test succeeds if stop effector is called 200 seconds or more later
    +            Thread.sleep(16 * 1000);
    +        } catch (InterruptedException e) {
    +            Thread.currentThread().interrupt();
    --- End diff --
    
    Don't bother catching and rethrowing. Just declare all your test methods as `throws Exception {`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70246473
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/ExpungingJcloudsLocationLiveTest.java ---
    @@ -0,0 +1,187 @@
    +/*
    + * 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.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.sensor.Sensors;
    +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);
    +        assertEquals(app.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.RUNNING);
    +        assertEquals(app.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.RUNNING);
    +        assertNull(emptySoftwareProcess.getAttribute(Attributes.JCLOUDS_PROVISIONING_STARTED));
    +
    +        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_STARTED));
    +    }
    +
    +    @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_STARTED));
    +                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() {
    --- End diff --
    
    Supporting this case will need won't be one line change.
    What  do you think about leaving this for a later PR?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70590295
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +712,26 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             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 (Boolean.TRUE.equals(entity().sensors().get(Attributes.JCLOUDS_PROVISIONING_STARTED))
    +                && machine.isAbsent()) {
    +            entity().sensors().set(Attributes.JCLOUDS_PROVISIONING_STARTED, 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.THIRTY_SECONDS)
    +                    .limitTimeTo(Duration.FIVE_MINUTES)
    --- End diff --
    
    Why wait for a hard-coded 5 minutes? Should be configurable. 5 minutes is not long enough on some clouds.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/211


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    @aledsage do you have an idea how can I tell the stop task that the provisioning started other than the sensor flag. I feel like the code will need serious refactoring in order stop task to know earlier about the jclouds node.
    The entity knows only about the machine location. It doesn't know about the LocationProvisioner.
    
    Do you thing it is reasonable assigning the location provisioner to the sensor instead true or null?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    Unfortunately this change dramatically slow down unit tests :(. 
    Stopping EmptySoftwareProcess is a common task for most of the tests. Adding a five minute timeout on stop makes `mvn clean install` run for hours.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68328999
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/EC2ExpungeLiveTest.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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.api.location.Location;
    +import org.apache.brooklyn.core.entity.Entities;
    +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.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +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.regex.Pattern;
    +
    +public class EC2ExpungeLiveTest extends BrooklynAppLiveTestSupport {
    +    private static final Logger LOG = LoggerFactory.getLogger(EC2ExpungeLiveTest.class);
    +
    +    public static final String PROVIDER = "aws-ec2";
    +    public static final String SMALL_HARDWARE_ID = "m1.small";
    +
    +    public static final String REGION_NAME = "us-west-2";
    +    public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
    +
    +    protected BrooklynProperties brooklynProperties;
    +
    +    protected Location jcloudsLocation;
    +
    +    @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();
    +    }
    +
    +    /**
    +     * 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 testExpunge() {
    +        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);
    +
    +        try {
    +            // Number of seconds we wait for an AWS EC2 instance to be created.
    +            // The test succeeds if stop effector is called 200 seconds or more later
    +            Thread.sleep(16 * 1000);
    +        } catch (InterruptedException e) {
    +            Thread.currentThread().interrupt();
    +            Exceptions.propagate(e);
    +        }
    +
    +        long beginTime = System.currentTimeMillis();
    +        Entities.destroyCatching(app);
    +        LOG.info("Time for expunging: {}", System.currentTimeMillis() - beginTime);
    --- End diff --
    
    Use guava's `Stopwatch`, rather than this. Can also use `Duration.of(...)` to get a much nicer string representation of the duration.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68554342
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +713,24 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             DynamicTasks.queue("pre-stop", new PreStopCustomTask());
     
    +        // BROOKLYN-263:
    +        // With this change the stop effector will always wait for machinelocation to provision, so it can stop it.
    +        // However in some situations if the stop effector is called in less than 8 seconds after start was called,
    +        // it may be safe to skip this wait and proceed with stop.
    +        // Hesitant about parameterising this.
             Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations());
    +        /*Do not retry if non-jclouds location has started.*/
    +        if (Boolean.TRUE.equals(entity().sensors().get(Sensors.newBooleanSensor("jclouds.provisioningStarted")))
    +                && machine.isAbsent()) {
    +            org.jclouds.util.Predicates2.retry(new Predicate<MachineLifecycleEffectorTasks>() {
    --- End diff --
    
    What do you think about using `Predicates2.retry` across Apache Brooklyn. Can you suggest a guava alternative or what do you think about adding such function in `brooklyn-core`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68260925
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/EC2ExpungeLiveTest.java ---
    @@ -0,0 +1,128 @@
    +/*
    + * 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.api.location.Location;
    +import org.apache.brooklyn.core.entity.Entities;
    +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.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +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.regex.Pattern;
    +
    +public class EC2ExpungeLiveTest extends BrooklynAppLiveTestSupport {
    +    private static final Logger LOG = LoggerFactory.getLogger(EC2ExpungeLiveTest.class);
    +
    +    public static final String PROVIDER = "aws-ec2";
    +    public static final String SMALL_HARDWARE_ID = "m1.small";
    +
    +    public static final String REGION_NAME = "us-west-2";
    +    public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
    +
    +    protected BrooklynProperties brooklynProperties;
    +
    +    protected Location jcloudsLocation;
    +
    +    @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();
    +    }
    +
    +    /**
    +     * 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 testExpunge() {
    --- End diff --
    
    BTW the whole test passes for 3:45 seconds.
    If we exclude the `listNodes` call, users will wait approximately 3 and a half minutes for expunge if they immediately click deploy and expunge.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    I've been looking at how we can do this more generally (entirely in `MachineLifecycleEffectorTasks`, so it's not jclouds-specific). That makes the code easier to follow and easier to test. The former because the places we set the sensors is all in the same place; the latter because we can do it all with unit tests, rather than needing to provision VMs in live tests.
    
    I have a commit that can go on top of this commit. I'll merge yours now, and then submit mine as a new PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server issue #211: BROOKLYN-264 Stop app while VM still being provi...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on the issue:

    https://github.com/apache/brooklyn-server/pull/211
  
    I updated the PR however I do not know why tests in `rest-resources` are failing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68937820
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +713,24 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             DynamicTasks.queue("pre-stop", new PreStopCustomTask());
     
    +        // BROOKLYN-263:
    +        // With this change the stop effector will always wait for machinelocation to provision, so it can stop it.
    +        // However in some situations if the stop effector is called in less than 8 seconds after start was called,
    +        // it may be safe to skip this wait and proceed with stop.
    +        // Hesitant about parameterising this.
             Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations());
    +        /*Do not retry if non-jclouds location has started.*/
    +        if (Boolean.TRUE.equals(entity().sensors().get(Sensors.newBooleanSensor("jclouds.provisioningStarted")))
    +                && machine.isAbsent()) {
    +            org.jclouds.util.Predicates2.retry(new Predicate<MachineLifecycleEffectorTasks>() {
    --- End diff --
    
    It feels like you should use our existing `org.apache.brooklyn.util.repeat.Repeater`. My personal opinion is that the builder pattern for the Repeater is easier to read, compared to the `Predicates2.retry` approach. The latter is probably only a good idea when you want to pass it to something that expects a `Predicate`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by bostko <gi...@git.apache.org>.
Github user bostko commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r68938644
  
    --- Diff: software/base/src/test/java/org/apache/brooklyn/entity/EC2ExpungeLiveTest.java ---
    @@ -0,0 +1,144 @@
    +/*
    + * 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.api.location.Location;
    +import org.apache.brooklyn.core.entity.Entities;
    +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.core.test.entity.TestEntity;
    +import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.core.config.ConfigBag;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +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.*;
    +import java.util.regex.Pattern;
    +
    +public class EC2ExpungeLiveTest extends BrooklynAppLiveTestSupport {
    +    private static final Logger LOG = LoggerFactory.getLogger(EC2ExpungeLiveTest.class);
    +
    +    public static final String PROVIDER = "aws-ec2";
    +    public static final String SMALL_HARDWARE_ID = "m1.small";
    +
    +    public static final String REGION_NAME = "us-west-2";
    +    public static final String LOCATION_SPEC = PROVIDER + (REGION_NAME == null ? "" : ":" + REGION_NAME);
    +
    +    protected BrooklynProperties brooklynProperties;
    +
    +    protected Location jcloudsLocation;
    +
    +    @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();
    +    }
    +
    +    /**
    +     Verifies that when {@link org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks#doStop(ConfigBag, Callable<?>)} is called
    +     it will not retry and wait for a MachineLocation to appear.
    +     */
    +    @Test
    +    public void testExpungeNonJcloudsLocation() throws Exception {
    --- End diff --
    
    This test is for simple entities used in unit tests (have to improve naming here).
    I am trying to add a similar Integration test for a BYON location.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] brooklyn-server pull request #211: BROOKLYN-264 Stop app while VM still bein...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/211#discussion_r70590214
  
    --- Diff: software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java ---
    @@ -709,7 +712,26 @@ protected void doStop(ConfigBag parameters, Callable<StopMachineDetails<Integer>
     
             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 (Boolean.TRUE.equals(entity().sensors().get(Attributes.JCLOUDS_PROVISIONING_STARTED))
    +                && machine.isAbsent()) {
    +            entity().sensors().set(Attributes.JCLOUDS_PROVISIONING_STARTED, 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.THIRTY_SECONDS)
    --- End diff --
    
    And to be able to test it fast (in unit tests, rather than live tests), we'd want to set this very low. But let's not worry about that quite yet.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---