@Override protected void connectServiceUpIsRunning() { ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); }
@Override public void start(Collection<? extends Location> locations) { setExpectedState(this, STARTING); execute(); }
@Override public void onManagementStarted() { super.onManagementStarted(); try { applyConfig(); } catch (Exception e) { // don't prevent management coming up, but do mark it as on fire log.error("Geoscaling did not come up correctly: "+e, e); ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); } }
@Override public void setExpected(Lifecycle state) { ServiceStateLogic.setExpectedState(this, checkNotNull(state, "state")); }
@Override public void run() { // startInLocations will look up the location, and provision a machine if necessary // (if it remembered the provisioning location) ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); startInLocations(null); } }
protected void setUpAndRunState(boolean up, Lifecycle status) { if (up) { sensors().set(SERVICE_UP, up); setExpectedState(this, status); } else { setExpectedState(this, status); sensors().set(SERVICE_UP, up); } } }
/** runs the tasks needed to start, wrapped by setting {@link Attributes#SERVICE_STATE_EXPECTED} appropriately */ public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); try { startInLocations(locations); DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); } catch (Throwable t) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } }
@Override public void stop() { LOG.trace("Stopping {}", this); callHistory.add("stop"); ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING); counter.decrementAndGet(); sensors().set(SERVICE_UP, false); ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED); }
@Override public void run() { try { // There's no preStartCustom call in the restart effector to get the latch value // so nothing to release here - pass the nop value. postStartCustom(); postRestartCustom(); } finally { ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); } } }
@Override public void start(Collection<? extends Location> locs) { ConfigToAttributes.apply(this); LOG.trace("Starting {}", this); callHistory.add("start"); ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); counter.incrementAndGet(); addLocations(locs); sensors().set(SERVICE_UP, true); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); }
@Override public String call() { if (entity().getAttribute(SoftwareProcess.SERVICE_STATE_ACTUAL) == Lifecycle.STOPPED) { log.debug("Skipping stop of entity " + entity() + " when already stopped"); return "Already stopped"; } ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING); entity().sensors().set(SoftwareProcess.SERVICE_UP, false); preStopCustom(); return null; } }
@Override public void onManagementStarting() { super.onManagementStarting(); Lifecycle state = getAttribute(SERVICE_STATE_ACTUAL); if (state == null || state == Lifecycle.CREATED) { // Expect this is a normal start() sequence (i.e. start() will subsequently be called) sensors().set(SERVICE_UP, false); ServiceStateLogic.setExpectedState(this, Lifecycle.CREATED); // force actual to be created because this is expected subsequently sensors().set(SERVICE_STATE_ACTUAL, Lifecycle.CREATED); } }
@Test public void testReportsFailureWhenAlreadyOnFireOnRegisteringPolicy() throws Exception { ServiceStateLogic.setExpectedState(e1, Lifecycle.ON_FIRE); e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_FAILED_ONLY_IF_PREVIOUSLY_UP, false)); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); }
@Test public void testReportsFailureWhenAlreadyDownOnRegisteringPolicy() throws Exception { ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING); e1.sensors().set(TestEntity.SERVICE_UP, false); e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_FAILED_ONLY_IF_PREVIOUSLY_UP, false)); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); }
@Test(groups="Integration") // Has a 1 second wait public void testNotNotifiedOfFailuresForHealthy() throws Exception { // Create members before and after the policy is registered, to test both scenarios e1.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING); e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class)); assertNoEventsContinually(); assertEquals(e1.getAttribute(TestEntity.SERVICE_STATE_ACTUAL), Lifecycle.RUNNING); }
@Test(groups="Integration") // Has a 1 second wait public void testOnlyReportsFailureIfRunning() throws Exception { e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class)); // Make the entity fail ServiceStateLogic.setExpectedState(e1, Lifecycle.STARTING); e1.sensors().set(TestEntity.SERVICE_UP, true); e1.sensors().set(TestEntity.SERVICE_UP, false); assertNoEventsContinually(); }
@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); } }