public static void updateNotUpIndicatorRequiringNonEmptyList(Entity entity, AttributeSensor<? extends Collection<?>> collectionSensor) { Collection<?> nodes = entity.getAttribute(collectionSensor); if (nodes==null || nodes.isEmpty()) ServiceNotUpLogic.updateNotUpIndicator(entity, collectionSensor, "Should have at least one entry"); else ServiceNotUpLogic.clearNotUpIndicator(entity, collectionSensor); } public static void updateNotUpIndicatorRequiringNonEmptyMap(Entity entity, AttributeSensor<? extends Map<?,?>> mapSensor) {
protected void onUpdated() { Boolean isRunning = entity.getAttribute(SERVICE_PROCESS_IS_RUNNING); if (Boolean.FALSE.equals(isRunning)) { ServiceNotUpLogic.updateNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING, "The software process for this entity does not appear to be running"); return; } if (Boolean.TRUE.equals(isRunning)) { ServiceNotUpLogic.clearNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING); return; } // no info on "isRunning" Boolean isUp = entity.getAttribute(Attributes.SERVICE_UP); if (Boolean.TRUE.equals(isUp)) { // if service explicitly set up, then don't apply our rule ServiceNotUpLogic.clearNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING); return; } // service not up, or no info ServiceNotUpLogic.updateNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING, "No information on whether this service is running"); } }
public static void updateNotUpIndicatorRequiringNonEmptyMap(Entity entity, AttributeSensor<? extends Map<?,?>> mapSensor) { Map<?, ?> nodes = entity.getAttribute(mapSensor); if (nodes==null || nodes.isEmpty()) ServiceNotUpLogic.updateNotUpIndicator(entity, mapSensor, "Should have at least one entry"); else ServiceNotUpLogic.clearNotUpIndicator(entity, mapSensor); }
ServiceNotUpLogic.clearNotUpIndicator(app, Attributes.SERVICE_STATE_ACTUAL); assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING); assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
ServiceProblemsLogic.clearProblemsIndicator(this, START); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application starting"); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STARTING); try { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL);
ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(children.get(0), "myKey");
ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
ServiceProblemsLogic.clearProblemsIndicator(this, START); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application starting"); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STARTING); try { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL);
protected void runRebindWhenNotUp(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); Entity app = createStartWaitAndLogApplication(appYaml); // Make entity go on-fire TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulating a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); // Rebind StartableApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(newEntity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector still functions RecordingSensorEventListener<Object> newListener = subscribeToHaSensors(newEntity); ServiceNotUpLogic.clearNotUpIndicator(newEntity, INDICATOR_KEY_1); newListener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED)); newListener.assertEventCount(1); }
protected Entity runTest(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); Entity app = createStartWaitAndLogApplication(appYaml); TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(entity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector triggers event RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulate a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); listener.assertEventCount(1); listener.clearEvents(); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED)); listener.assertEventCount(1); return app; }
@Override public void onCallback(String childId, boolean success) { Optional<Entity> child = Iterables.tryFind(getChildren(), EntityPredicates.idEqualTo(childId)); if (child.isPresent()) { ((AsyncEntity)child.get()).onCallback(success); } else { LOG.warn("Child not found with resourceId '"+childId+"'; not injecting state from callback"); } Optional<Entity> unstartedVm = Iterables.tryFind(getChildren(), EntityPredicates.attributeSatisfies(Attributes.SERVICE_STATE_EXPECTED, new Predicate<Lifecycle.Transition>() { @Override public boolean apply(Transition input) { return input == null || input.getState() == Lifecycle.STARTING; }})); if (!unstartedVm.isPresent()) { // No VMs are still starting; we are finished starting ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } }
DynamicTasks.queue("pre-restart", new Runnable() { @Override public void run() { //set by shutdown - clear it so the entity starts cleanly. Does the indicator bring any value at all? ServiceNotUpLogic.clearNotUpIndicator(BrooklynNodeImpl.this, SHUTDOWN.getName()); }}); }
@Override protected void preStart() { ServiceNotUpLogic.clearNotUpIndicator(this, SHUTDOWN.getName()); }
@Override public void clearNotUpIndicator() { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); }
@Override public void setServiceState(Lifecycle state) { sensors().set(HOSTNAME, getHostname()); ServiceStateLogic.setExpectedState(this, state); if (state==Lifecycle.RUNNING) ServiceNotUpLogic.clearNotUpIndicator(this, SERVICE_STATE_ACTUAL); else ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_STATE_ACTUAL, "Not in RUNNING state"); }
public void testTwoIndicatorsAreBetterThanOne() { // if we set a not up indicator, entity service up should become false ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "We're pretending to block service up"); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_2, "We're also pretending to block service up"); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); // clearing one indicator is not sufficient assertAttributeEquals(entity, Attributes.SERVICE_UP, false); // but it does not become true when both are cleared ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_2); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); }
@Override public void onCallback(boolean success) { if (success) { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); } else { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "callback reported failure"); } Transition expectedState = sensors().get(Attributes.SERVICE_STATE_EXPECTED); if (expectedState != null && expectedState.getState() == Lifecycle.STARTING) { ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } }