@Override public void onEvent(SensorEvent<Object> event) { if (firstUpTime==null) { if (event!=null && Attributes.SERVICE_UP.equals(event.getSensor()) && Boolean.TRUE.equals(event.getValue())) { firstUpTime = event.getTimestamp(); } else if (event == null && Boolean.TRUE.equals(entity.getAttribute(Attributes.SERVICE_UP))) { // If this enricher is registered after the entity is up, then we'll get a "synthetic" onEvent(null) firstUpTime = System.currentTimeMillis(); } } super.onEvent(event); }
@Override protected <T> void doReconfigureConfig(ConfigKey<T> key, T val) { if (key.equals(LAST_PUBLISHED)) { // find to modify this on-the-fly; no additional work required } else { super.doReconfigureConfig(key, val); } }
new Object[] {this, state}); setEntityOnFireTime = null; super.setActualState(state); } else { recomputeIn = Math.min(recomputeIn, delayBeforeCheck); super.setActualState(state);
@Test(groups={"WIP", "Broken"}) public void testServiceStateNotCalledExplicitly() throws Exception { ComputeServiceState oldEnricher = (ComputeServiceState) Iterables.find(app.enrichers(), Predicates.instanceOf(ComputeServiceState.class)); String oldUniqueTag = oldEnricher.getUniqueTag(); CountingComputeServiceState enricher = app.enrichers().add(EnricherSpec.create(CountingComputeServiceState.class) .uniqueTag(oldUniqueTag)); // Confirm that we only have one enricher now (i.e. we've replaced the original) Iterable<Enricher> newEnrichers = Iterables.filter(app.enrichers(), Predicates.instanceOf(ComputeServiceState.class)); assertEquals(Iterables.size(newEnrichers), 1, "newEnrichers="+newEnrichers); assertEquals(Iterables.getOnlyElement(newEnrichers), enricher, "newEnrichers="+newEnrichers); // When setting the expected state, previously that caused a onEvent(null) to be triggered synchronously ServiceStateLogic.setExpectedState(app, Lifecycle.RUNNING); assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertTrue(enricher.cntCalled.get() > 0); assertEquals(enricher.cntCalledWithNull.get(), 0); }
@SuppressWarnings("unchecked") @Override public void setEntity(EntityLocal entity) { super.setEntity(entity); if (suppressDuplicates==null) { // only publish on changes, unless it is configured otherwise suppressDuplicates = true; } Map<String, ?> notifyOfInitialValue = ImmutableMap.of("notifyOfInitialValue", Boolean.TRUE); subscriptions().subscribe(notifyOfInitialValue, entity, SERVICE_PROBLEMS, this); subscriptions().subscribe(notifyOfInitialValue, entity, SERVICE_UP, this); subscriptions().subscribe(notifyOfInitialValue, entity, SERVICE_STATE_EXPECTED, this); highlightTriggers(MutableList.of(SERVICE_PROBLEMS, SERVICE_UP, SERVICE_STATE_EXPECTED), null); }
protected void setActualState(Maybe<Lifecycle> state) { if (log.isTraceEnabled()) log.trace("{} setting actual state {}", this, state); if (((EntityInternal)entity).getManagementSupport().isNoLongerManaged()) { // won't catch everything, but catches some BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity), entity+" is no longer managed when told to set actual state to "+state+"; suppressing"); return; } Object newVal = (state.isAbsent() ? Entities.UNCHANGED : (state.get() == null ? Entities.REMOVE : state.get())); emit(SERVICE_STATE_ACTUAL, newVal); }
@Override public void onEvent(SensorEvent<Object> event) { cntCalled.incrementAndGet(); if (event == null) { cntCalledWithNull.incrementAndGet(); } super.onEvent(event); } }
private static void setExpectedState(Entity entity, Lifecycle state, boolean waitBrieflyForServiceUpIfRunning) { if (waitBrieflyForServiceUpIfRunning) { waitBrieflyForServiceUpIfStateIsRunning(entity, state); } ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state, new Date())); Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.enrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG); if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState) { ((ComputeServiceState)enricher.get()).onEvent(null); } }
@Override public void onEvent(@Nullable SensorEvent<Object> event) { Preconditions.checkNotNull(entity, "Cannot handle subscriptions or compute state until associated with an entity"); Map<String, Object> serviceProblems = entity.getAttribute(SERVICE_PROBLEMS); Boolean serviceUp = entity.getAttribute(SERVICE_UP); Lifecycle.Transition serviceExpected = entity.getAttribute(SERVICE_STATE_EXPECTED); if (serviceExpected!=null && serviceExpected.getState()==Lifecycle.RUNNING) { setActualState( computeActualStateWhenExpectedRunning(serviceProblems, serviceUp) ); } else { setActualState( computeActualStateWhenNotExpectedRunning(serviceProblems, serviceUp, serviceExpected) ); } }