/** * By default, adds enrichers to populate {@link Attributes#SERVICE_UP} and {@link Attributes#SERVICE_STATE_ACTUAL} * based on {@link Attributes#SERVICE_NOT_UP_INDICATORS}, * {@link Attributes#SERVICE_STATE_EXPECTED} and {@link Attributes#SERVICE_PROBLEMS} * (doing nothing if these sensors are not used). * <p> * Subclasses may go further and populate the {@link Attributes#SERVICE_NOT_UP_INDICATORS} * and {@link Attributes#SERVICE_PROBLEMS} from children and members or other sources. */ // these enrichers do nothing unless Attributes.SERVICE_NOT_UP_INDICATORS are used // and/or SERVICE_STATE_EXPECTED protected void initEnrichers() { enrichers().add(ServiceNotUpLogic.newEnricherForServiceUpIfNotUpIndicatorsEmpty()); enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp()); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>(); eventListener = new SensorEventListener<FailureDescriptor>() { @Override public void onEvent(SensorEvent<FailureDescriptor> event) { events.add(event); } }; e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); e1.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp()); app.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_FAILED, eventListener); app.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_RECOVERED, eventListener); }
@Test public void testCreatesDriverAfterRebind() throws Exception { MyService origE = origApp.createAndManageChild(EntitySpec.create(MyService.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); //the entity skips enricher initialization, do it explicitly origE.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp()); MyProvisioningLocation origLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class) .displayName("mylocname")); origApp.start(ImmutableList.of(origLoc)); assertEquals(origE.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.RUNNING); EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); ServiceProblemsLogic.updateProblemsIndicator(origE, "test", "fire"); EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); newApp = rebind(); MyService newE = (MyService) Iterables.getOnlyElement(newApp.getChildren()); assertTrue(newE.getDriver() != null, "driver should be initialized"); }
@Test public void testDoesNotCreateDriverAfterRebind() throws Exception { MyService origE = origApp.createAndManageChild(EntitySpec.create(MyService.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); //the entity skips enricher initialization, do it explicitly origE.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp()); MyProvisioningLocation origLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class) .displayName("mylocname")); origApp.start(ImmutableList.of(origLoc)); assertEquals(origE.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.RUNNING); EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); ServiceStateLogic.setExpectedState(origE, Lifecycle.ON_FIRE); EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); newApp = rebind(); MyService newE = (MyService) Iterables.getOnlyElement(newApp.getChildren()); assertNull(newE.getDriver(), "driver should not be initialized because entity is in a permanent failure"); }