You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2021/09/14 21:56:41 UTC
[brooklyn-server] 22/27: tidy up a few more places where we get
warns on unmanaging
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 8477a27eb2d24960b9340eb57a30e03b0c706a00
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Tue Sep 14 17:46:59 2021 +0100
tidy up a few more places where we get warns on unmanaging
add a new marker to tell us if we are unmanaging
---
.../main/java/org/apache/brooklyn/core/entity/Entities.java | 9 +++++++--
.../brooklyn/core/entity/lifecycle/ServiceStateLogic.java | 11 ++++++++---
.../brooklyn/core/mgmt/internal/EntityManagementSupport.java | 10 +++++++++-
.../apache/brooklyn/util/core/task/BasicExecutionManager.java | 7 ++++---
.../apache/brooklyn/policy/failover/ElectPrimaryPolicy.java | 2 +-
.../brooklyn/policy/failover/PrimaryRunningEnricher.java | 5 +++++
6 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
index 43a5104..52d611f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
@@ -799,12 +799,17 @@ public class Entities {
/** If entity is under management and the management node is the primary for this entity, i.e. not read-only. */
public static boolean isManagedActive(Entity e) {
- return ((EntityInternal)e).getManagementSupport().isDeployed() && ((EntityInternal)e).getManagementContext().isRunning() && !isReadOnly(e);
+ return ((EntityInternal)e).getManagementSupport().isActive() && ((EntityInternal)e).getManagementContext().isRunning() && !isReadOnly(e);
+ }
+
+ /** If entity is under management or coming up and the management node is the primary for this entity, i.e. not read-only. */
+ public static boolean isManagedActiveOrComingUp(Entity e) {
+ return (isManagedActive(e) || !((EntityInternal)e).getManagementSupport().wasDeployed()) && !isReadOnly(e);
}
/** If entity is under management either as primary or in read-only (hot-standby) state. */
public static boolean isManagedOrReadOnly(Entity e) {
- return ((EntityInternal)e).getManagementSupport().isDeployed() && ((EntityInternal)e).getManagementContext().isRunning();
+ return ((EntityInternal)e).getManagementSupport().isActive() && ((EntityInternal)e).getManagementContext().isRunning();
}
public static boolean isNoLongerManaged(Entity e) {
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
index 8ab3d27..2fc948f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
@@ -185,7 +185,7 @@ public class ServiceStateLogic {
private static void waitBrieflyForServiceUpIfStateIsRunning(Entity entity, Lifecycle state) {
if (state==Lifecycle.RUNNING) {
Boolean up = entity.getAttribute(Attributes.SERVICE_UP);
- if (!Boolean.TRUE.equals(up) && !Entities.isReadOnly(entity)) {
+ if (!Boolean.TRUE.equals(up) && Entities.isManagedActive(entity)) {
// pause briefly to allow any recent problem-clearing processing to complete
Stopwatch timer = Stopwatch.createStarted();
boolean nowUp = Repeater.create()
@@ -196,8 +196,10 @@ public class ServiceStateLogic {
if (nowUp) {
log.debug("Had to wait "+Duration.of(timer)+" for "+entity+" "+Attributes.SERVICE_UP+" to be true before setting "+state);
} else {
- log.warn("Service is not up when setting "+state+" on "+entity+"; delayed "+Duration.of(timer)+" "
- + "but "+Attributes.SERVICE_UP+" did not recover from "+up+"; not-up-indicators="+entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
+ if (Entities.isManagedActive(entity)) {
+ log.warn("Service is not up when setting " + state + " on " + entity + "; delayed " + Duration.of(timer) + " "
+ + "but " + Attributes.SERVICE_UP + " did not recover from " + up + "; not-up-indicators=" + entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
+ }
}
}
}
@@ -322,6 +324,9 @@ public class ServiceStateLogic {
if (Boolean.TRUE.equals(serviceUp) && (problems==null || problems.isEmpty())) {
return Maybe.of(Lifecycle.RUNNING);
} else {
+ if (!Entities.isManagedActive(entity)) {
+ return Maybe.absent("entity not managed active");
+ }
if (!Lifecycle.ON_FIRE.equals(entity.getAttribute(SERVICE_STATE_ACTUAL))) {
Lifecycle.Transition serviceExpected = entity.getAttribute(SERVICE_STATE_EXPECTED);
// very occasional race here; might want to give a grace period if entity has just transitioned,
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java
index 7bb36fd..7dd074e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java
@@ -91,6 +91,7 @@ public class EntityManagementSupport {
protected transient volatile ExecutionContext executionContext;
protected final AtomicBoolean managementContextUsable = new AtomicBoolean(false);
+ protected final AtomicBoolean currentlyStopping = new AtomicBoolean(false);
protected final AtomicBoolean currentlyDeployed = new AtomicBoolean(false);
protected final AtomicBoolean everDeployed = new AtomicBoolean(false);
protected Boolean readOnly = null;
@@ -107,12 +108,17 @@ public class EntityManagementSupport {
}
/**
- * Use this instead of !Entities.isManaged(entity) to avoid skipping publishing ov values that to be published before the entity starts.
+ * Use this instead of negating {@link Entities#isManaged(Entity)} to avoid skipping publishing of values that to be published before the entity is deployed;
+ * or (better) see {@link Entities#isManagedActiveOrComingUp(Entity)}
*/
public boolean isNoLongerManaged() {
return wasDeployed() && !isDeployed();
}
+ public boolean isActive() { return !isUnmanaging() && isDeployed(); }
+
+ public boolean isUnmanaging() { return currentlyStopping.get(); }
+
/** whether entity has ever been deployed (managed) */
public boolean wasDeployed() {
return everDeployed.get();
@@ -304,6 +310,7 @@ public class EntityManagementSupport {
@SuppressWarnings("deprecation")
public void onManagementStopping(ManagementTransitionInfo info, boolean wasDryRun) {
synchronized (this) {
+ currentlyStopping.set(true);
if (!wasDryRun) {
if (managementContext != info.getManagementContext()) {
throw new IllegalStateException("onManagementStopping encountered different management context for " + entity +
@@ -383,6 +390,7 @@ public class EntityManagementSupport {
entityChangeListener = EntityChangeListener.NOOP;
managementContextUsable.set(false);
currentlyDeployed.set(false);
+ currentlyStopping.set(false);
executionContext = null;
subscriptionContext = null;
}
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
index 88812e0..0498c4f 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionManager.java
@@ -418,13 +418,14 @@ public class BasicExecutionManager implements ExecutionManager {
if (context != null && !Entities.isManaged(context)) {
log.debug("Deleting active task on unmanagement of " + context + ": " + removed);
} else {
- if (removed.isDone()) {
+ boolean debugOnly = removed.isDone();
+
+ if (debugOnly) {
log.debug("Deleting cancelled task before completion: " + removed + "; this task will continue to run in the background outwith " + this);
} else {
log.warn("Deleting submitted task before completion: " + removed + " (tags " + removed.getTags() + "); this task will continue to run in the background outwith " + this + ", but perhaps it should have been cancelled?");
-
+ log.debug("Active task deletion trace", new Throwable("Active task deletion trace"));
}
- log.debug("Active task deletion trace", new Throwable("Active task deletion trace"));
}
}
task.getTags().forEach(t -> {
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java b/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
index ac9531d..35adfbf 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryPolicy.java
@@ -261,7 +261,7 @@ public class ElectPrimaryPolicy extends AbstractPolicy implements ElectPrimaryCo
}
} catch (Throwable e) {
Exceptions.propagateIfFatal(e);
- if (Entities.isNoLongerManaged(entity)) throw Exceptions.propagate(e);
+ if (!Entities.isManagedActive(entity)) throw Exceptions.propagate(e);
Throwable root = Throwables.getRootCause(e);
if (root instanceof UserFacingException) {
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/failover/PrimaryRunningEnricher.java b/policy/src/main/java/org/apache/brooklyn/policy/failover/PrimaryRunningEnricher.java
index 0353aa8..0c8b08c 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/failover/PrimaryRunningEnricher.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/failover/PrimaryRunningEnricher.java
@@ -24,6 +24,7 @@ import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.enricher.AbstractEnricher;
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.entity.lifecycle.ServiceStateLogic;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceNotUpLogic;
@@ -55,6 +56,10 @@ public class PrimaryRunningEnricher extends AbstractEnricher implements SensorEv
@Override
public void onEvent(SensorEvent<Object> event) {
+ if (!Entities.isManagedActive(entity)) {
+ return;
+ }
+
Entity primary = entity.getAttribute( Sensors.newSensor(Entity.class, config().get(PRIMARY_SENSOR_NAME)) );
if (primary==null) {
ServiceNotUpLogic.updateNotUpIndicator(entity, "primary.enricher", "no primary found");