Move INTERNAL_PROVISIONING_TASK_STATE to AttributesInternal So that it can subsequently be used to fix BROOKLYN-325.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/fbfe2fef Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/fbfe2fef Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/fbfe2fef Branch: refs/heads/master Commit: fbfe2fefa4af329bacf18dc9553938a01230228d Parents: 5b65fad Author: Aled Sage <aled.s...@gmail.com> Authored: Mon Nov 14 17:41:06 2016 +0000 Committer: Aled Sage <aled.s...@gmail.com> Committed: Wed Nov 16 12:47:50 2016 +0000 ---------------------------------------------------------------------- .../entity/internal/AttributesInternal.java | 46 ++++++++++++++++++++ .../deserializingClassRenames.properties | 2 + .../MachineLifecycleEffectorTasks.java | 31 +++---------- ...eProcessStopsDuringStartJcloudsLiveTest.java | 7 +-- .../SoftwareProcessStopsDuringStartTest.java | 13 +++--- 5 files changed, 66 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fbfe2fef/core/src/main/java/org/apache/brooklyn/core/entity/internal/AttributesInternal.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/internal/AttributesInternal.java b/core/src/main/java/org/apache/brooklyn/core/entity/internal/AttributesInternal.java new file mode 100644 index 0000000..6051e05 --- /dev/null +++ b/core/src/main/java/org/apache/brooklyn/core/entity/internal/AttributesInternal.java @@ -0,0 +1,46 @@ +/* + * 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.core.entity.internal; + +import org.apache.brooklyn.api.sensor.AttributeSensor; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.sensor.BasicAttributeSensor; + +import com.google.common.annotations.Beta; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.reflect.TypeToken; + +public interface AttributesInternal extends Attributes { + @Beta + public static final AttributeSensor<ProvisioningTaskState> INTERNAL_PROVISIONING_TASK_STATE = new BasicAttributeSensor<ProvisioningTaskState>( + TypeToken.of(ProvisioningTaskState.class), + "internal.provisioning.task.state", + "Internal transient sensor (do not use) for tracking the provisioning of a machine (to better handle aborting/rebind)", + AttributeSensor.SensorPersistenceMode.NONE); + + /** + * Used only internally by {@link org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks} + * to track provisioning, so machine can be terminated if stopped while opaque provision call is being made. + */ + @Beta + @VisibleForTesting + public enum ProvisioningTaskState { + RUNNING, + DONE; + } +} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fbfe2fef/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties ---------------------------------------------------------------------- diff --git a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties index 64981fb..300bba2 100644 --- a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties +++ b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties @@ -1434,3 +1434,5 @@ brooklyn.test.entity.BlockingEntityImpl org.apache.brooklyn.config.ConfigInheritance$None : org.apache.brooklyn.config.ConfigInheritance$Legacy$None org.apache.brooklyn.config.ConfigInheritance$Always : org.apache.brooklyn.config.ConfigInheritance$Legacy$Always org.apache.brooklyn.config.ConfigInheritance$Merged : org.apache.brooklyn.config.ConfigInheritance$Legacy$Merged + +org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks$ProvisioningTaskState : org.apache.brooklyn.core.entity.internal.AttributesInternal$ProvisioningTaskState http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fbfe2fef/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 fc738b1..439770a 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 @@ -49,6 +49,8 @@ import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.entity.BrooklynConfigKeys; import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.internal.AttributesInternal; +import org.apache.brooklyn.core.entity.internal.AttributesInternal.ProvisioningTaskState; import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; import org.apache.brooklyn.core.entity.lifecycle.Lifecycle.Transition; import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; @@ -90,7 +92,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.annotations.Beta; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; @@ -143,30 +144,12 @@ public abstract class MachineLifecycleEffectorTasks { Duration.minutes(10)); @Beta - public static final AttributeSensor<ProvisioningTaskState> INTERNAL_PROVISIONING_TASK_STATE = new BasicAttributeSensor<ProvisioningTaskState>( - TypeToken.of(ProvisioningTaskState.class), - "internal.provisioning.task.state", - "Internal transient sensor (do not use) for tracking the provisioning of a machine (to better handle aborting)", - AttributeSensor.SensorPersistenceMode.NONE); - - @Beta public static final AttributeSensor<MachineLocation> INTERNAL_PROVISIONED_MACHINE = new BasicAttributeSensor<MachineLocation>( TypeToken.of(MachineLocation.class), "internal.provisioning.task.machine", "Internal transient sensor (do not use) for tracking the machine being provisioned (to better handle aborting)", AttributeSensor.SensorPersistenceMode.NONE); - /** - * Used only internally by {@link org.apache.brooklyn.entity.software.base.lifecycle.MachineLifecycleEffectorTasks} - * to track provisioning, so machine can be terminated if stopped while opaque provision call is being made. - */ - @Beta - @VisibleForTesting - public enum ProvisioningTaskState { - RUNNING, - DONE; - } - protected final MachineInitTasks machineInitTasks = new MachineInitTasks(); /** Attaches lifecycle effectors (start, restart, stop) to the given entity post-creation. */ @@ -424,14 +407,14 @@ public abstract class MachineLifecycleEffectorTasks { if (expectedState != null && (expectedState.getState() == Lifecycle.STOPPING || expectedState.getState() == Lifecycle.STOPPED)) { throw new IllegalStateException("Provisioning aborted before even begun for "+entity()+" in "+location+" (presumably by a concurrent call to stop"); } - entity().sensors().set(INTERNAL_PROVISIONING_TASK_STATE, ProvisioningTaskState.RUNNING); + entity().sensors().set(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, ProvisioningTaskState.RUNNING); MachineLocation machine; try { machine = Tasks.withBlockingDetails("Provisioning machine in " + location, new ObtainLocationTask(location, flags)); entity().sensors().set(INTERNAL_PROVISIONED_MACHINE, machine); } finally { - entity().sensors().set(INTERNAL_PROVISIONING_TASK_STATE, ProvisioningTaskState.DONE); + entity().sensors().set(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, ProvisioningTaskState.DONE); } if (machine == null) { @@ -781,7 +764,7 @@ public abstract class MachineLifecycleEffectorTasks { // There is some attempt to handle it by ProvisionMachineTask checking if the expectedState // is stopping/stopped. Maybe<MachineLocation> machine = Machines.findUniqueMachineLocation(entity().getLocations()); - ProvisioningTaskState provisioningState = entity().sensors().get(INTERNAL_PROVISIONING_TASK_STATE); + ProvisioningTaskState provisioningState = entity().sensors().get(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); if (machine.isAbsent() && provisioningState == ProvisioningTaskState.RUNNING) { Duration maxWait = entity().config().get(STOP_WAIT_PROVISIONING_TIMEOUT); @@ -790,7 +773,7 @@ public abstract class MachineLifecycleEffectorTasks { .until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { - ProvisioningTaskState state = entity().sensors().get(INTERNAL_PROVISIONING_TASK_STATE); + ProvisioningTaskState state = entity().sensors().get(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); return (state == ProvisioningTaskState.DONE); }}) .backoffTo(Duration.FIVE_SECONDS) @@ -801,7 +784,7 @@ public abstract class MachineLifecycleEffectorTasks { } machine = Maybe.ofDisallowingNull(entity().sensors().get(INTERNAL_PROVISIONED_MACHINE)); } - entity().sensors().remove(INTERNAL_PROVISIONING_TASK_STATE); + entity().sensors().remove(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); entity().sensors().remove(INTERNAL_PROVISIONED_MACHINE); Task<List<?>> stoppingProcess = null; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fbfe2fef/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartJcloudsLiveTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartJcloudsLiveTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartJcloudsLiveTest.java index a375406..f5dcf5d 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartJcloudsLiveTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartJcloudsLiveTest.java @@ -42,6 +42,7 @@ import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.core.entity.BrooklynConfigKeys; import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.core.entity.EntityAsserts; +import org.apache.brooklyn.core.entity.internal.AttributesInternal; import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.core.internal.BrooklynProperties; @@ -141,7 +142,7 @@ public class SoftwareProcessStopsDuringStartJcloudsLiveTest extends BrooklynAppL } }, Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS); EntityAsserts.assertEntityHealthy(entity); - assertEquals(entity.getAttribute(MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE), MachineLifecycleEffectorTasks.ProvisioningTaskState.DONE); + assertEquals(entity.getAttribute(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE), AttributesInternal.ProvisioningTaskState.DONE); assertEquals(entity.getAttribute(MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE), Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get()); executeInLimitedTime(new Callable<Void>() { @@ -152,7 +153,7 @@ public class SoftwareProcessStopsDuringStartJcloudsLiveTest extends BrooklynAppL }, Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS); assertEquals(app.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.STOPPED); assertEquals(app.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STOPPED); - assertEquals(entity.getAttribute(MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE), null); + assertEquals(entity.getAttribute(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE), null); assertEquals(entity.getAttribute(MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE), null); } @@ -188,7 +189,7 @@ public class SoftwareProcessStopsDuringStartJcloudsLiveTest extends BrooklynAppL // Invoke async @SuppressWarnings("unused") Task<Void> startTask = Entities.invokeEffector(app, app, Startable.START, ImmutableMap.of("locations", MutableList.of())); - EntityAsserts.assertAttributeEqualsEventually(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, MachineLifecycleEffectorTasks.ProvisioningTaskState.RUNNING); + EntityAsserts.assertAttributeEqualsEventually(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, AttributesInternal.ProvisioningTaskState.RUNNING); Stopwatch stopwatch = Stopwatch.createStarted(); Entities.destroyCatching(app); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fbfe2fef/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartTest.java index eabea4b..99d9678 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessStopsDuringStartTest.java @@ -42,6 +42,7 @@ import org.apache.brooklyn.api.location.LocationSpec; import org.apache.brooklyn.api.location.MachineProvisioningLocation; import org.apache.brooklyn.api.location.NoMachinesAvailableException; import org.apache.brooklyn.core.entity.EntityAsserts; +import org.apache.brooklyn.core.entity.internal.AttributesInternal; import org.apache.brooklyn.core.location.AbstractLocation; import org.apache.brooklyn.core.location.Machines; import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport; @@ -98,14 +99,14 @@ public class SoftwareProcessStopsDuringStartTest extends BrooklynAppUnitTestSupp entity.start(ImmutableList.<Location>of(loc)); SshMachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get(); - EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, MachineLifecycleEffectorTasks.ProvisioningTaskState.DONE); + EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, AttributesInternal.ProvisioningTaskState.DONE); EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, machine); Stopwatch stopwatch = Stopwatch.createStarted(); entity.stop(); Duration stopDuration = Duration.of(stopwatch); assertTrue(Asserts.DEFAULT_LONG_TIMEOUT.isLongerThan(stopDuration), "stop took "+stopDuration); - EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, null); + EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, null); EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, null); assertEquals(loc.getCalls(), ImmutableList.of("obtain", "release")); @@ -119,20 +120,20 @@ public class SoftwareProcessStopsDuringStartTest extends BrooklynAppUnitTestSupp entity.start(ImmutableList.<Location>of(loc)); SshMachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get(); - EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, MachineLifecycleEffectorTasks.ProvisioningTaskState.DONE); + EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, AttributesInternal.ProvisioningTaskState.DONE); EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, machine); entity.stop(); - EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, null); + EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, null); EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, null); entity.start(ImmutableList.<Location>of(loc)); SshMachineLocation machine2 = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get(); - EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, MachineLifecycleEffectorTasks.ProvisioningTaskState.DONE); + EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, AttributesInternal.ProvisioningTaskState.DONE); EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, machine2); entity.stop(); - EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONING_TASK_STATE, null); + EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, null); EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, null); assertEquals(loc.getCalls(), ImmutableList.of("obtain", "release", "obtain", "release"));