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
The following commit(s) were added to refs/heads/master by this push:
new c0861aa91f set sensors to null before removing
c0861aa91f is described below
commit c0861aa91f98024b3066f8848ca549813ca94a77
Author: Alex Heneveld <[email protected]>
AuthorDate: Fri Jun 30 13:34:05 2023 +0100
set sensors to null before removing
so that subscribers get notified and e.g. can fix service up/state
---
.../brooklyn/core/enricher/AbstractEnricher.java | 15 ++++++++-------
.../core/entity/lifecycle/ServiceStateLogicTest.java | 19 +++++++++++++++++++
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git
a/core/src/main/java/org/apache/brooklyn/core/enricher/AbstractEnricher.java
b/core/src/main/java/org/apache/brooklyn/core/enricher/AbstractEnricher.java
index f97c11cbfc..bf028749c6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/enricher/AbstractEnricher.java
+++ b/core/src/main/java/org/apache/brooklyn/core/enricher/AbstractEnricher.java
@@ -18,10 +18,9 @@
*/
package org.apache.brooklyn.core.enricher;
-import static com.google.common.base.Preconditions.checkState;
-
-import java.util.Map;
-
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.Maps;
import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
import org.apache.brooklyn.api.mgmt.rebind.mementos.EnricherMemento;
import org.apache.brooklyn.api.sensor.AttributeSensor;
@@ -38,9 +37,9 @@ import org.apache.brooklyn.core.objs.AbstractEntityAdjunct;
import org.apache.brooklyn.util.core.flags.TypeCoercions;
import org.apache.brooklyn.util.guava.Maybe;
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.collect.Maps;
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkState;
/**
* Base {@link Enricher} implementation; all enrichers should extend this or
its children
@@ -129,6 +128,8 @@ public abstract class AbstractEnricher extends
AbstractEntityAdjunct implements
return;
}
if (val == Entities.REMOVE) {
+ // set null prior to removal so that listeners can receive it
+ ((EntityInternal)entity).sensors().set((AttributeSensor<T>)
sensor, null);
((EntityInternal)entity).sensors().remove((AttributeSensor<T>)
sensor);
return;
}
diff --git
a/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
index 93f967046c..2f694c7b45 100644
---
a/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
+++
b/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
@@ -49,6 +49,7 @@ import org.apache.brooklyn.test.support.FlakyRetryAnalyser;
import org.apache.brooklyn.util.collections.QuorumCheck.QuorumChecks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
@@ -273,6 +274,24 @@ public class ServiceStateLogicTest extends
BrooklynAppUnitTestSupport {
assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
}
+ public void testEntityWithoutServiceStateOrUp() throws Exception {
+ app.start(null);
+
+ entity.sensors().remove(Attributes.SERVICE_STATE_EXPECTED);
+ entity.sensors().remove(Attributes.SERVICE_STATE_ACTUAL);
+ entity.sensors().remove(Attributes.SERVICE_UP);
+
+ ServiceStateLogic.updateMapSensorEntry(entity,
Attributes.SERVICE_PROBLEMS, "foo", "bar");
+ EntityAsserts.assertAttributeEqualsEventually(entity,
Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+ EntityAsserts.assertAttributeEqualsEventually(app,
Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+
+ ServiceStateLogic.clearMapSensorEntry(entity,
Attributes.SERVICE_PROBLEMS, "foo");
+ Time.sleep(Duration.ONE_SECOND);
+ Dumper.dumpInfo(app);
+ EntityAsserts.assertAttributeEqualsEventually(entity,
Attributes.SERVICE_STATE_ACTUAL, null);
+ EntityAsserts.assertAttributeEqualsEventually(app,
Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+ }
+
@Test
public void testQuorumWithStringStates() {
final DynamicCluster cluster =
app.createAndManageChild(EntitySpec.create(DynamicCluster.class)