@Override public boolean equals(Object obj) { if (!(obj instanceof Transition)) return false; if (!state.equals(((Transition)obj).getState())) return false; if (timestampUtc != ((Transition)obj).timestampUtc) return false; return true; }
@Override public boolean apply(Lifecycle.Transition transition) { assertNotNull(transition); return Lifecycle.RUNNING.equals(transition.getState()); } });
@Override public Entity apply(Collection<Entity> members) { synchronized (mutex) { Optional<Entity> choice; if (Lifecycle.STOPPING.equals(getAttribute(Attributes.SERVICE_STATE_ACTUAL))) { choice = Optional.of(members.iterator().next()); } else { // Otherwise should only choose between removable + unusable or available choice = getMemberWithStatusExcludingUnremovable(members, MachinePoolMemberStatus.UNUSABLE) .or(getMemberWithStatusExcludingUnremovable(members, MachinePoolMemberStatus.AVAILABLE)); } if (!choice.isPresent()) { LOG.warn("{} has no machines available to remove!", this); return null; } else { LOG.info("{} selected entity to remove from pool: {}", this, choice.get()); choice.get().getAttribute(SERVER_STATUS); setEntityStatus(choice.get(), null); } MachineLocation entityLocation = getEntityMachineMap().remove(choice.get()); if (entityLocation != null) { getMachineEntityMap().remove(entityLocation); } return choice.get(); } } };
protected Maybe<Lifecycle> computeActualStateWhenExpectedRunning(Map<String, Object> problems, Boolean serviceUp) { if (Boolean.TRUE.equals(serviceUp) && (problems==null || problems.isEmpty())) { return Maybe.of(Lifecycle.RUNNING); } else { if (!Lifecycle.ON_FIRE.equals(entity.getAttribute(SERVICE_STATE_ACTUAL))) { BrooklynLogging.log(log, BrooklynLogging.levelDependingIfReadOnly(entity, LoggingLevel.WARN, LoggingLevel.TRACE, LoggingLevel.DEBUG), "Setting "+entity+" "+Lifecycle.ON_FIRE+" due to problems when expected running, up="+serviceUp+", "+ (problems==null || problems.isEmpty() ? "not-up-indicators: "+entity.getAttribute(SERVICE_NOT_UP_INDICATORS) : "problems: "+problems)); } return Maybe.of(Lifecycle.ON_FIRE); } }
@Override public void stop() { Lifecycle state = sensors().get(Attributes.SERVICE_STATE_ACTUAL); if (Lifecycle.STOPPING.equals(state) || Lifecycle.STOPPED.equals(state)) { LOG.debug("Ignoring request to stop {} when it is already {}", this, state); LOG.trace("Duplicate stop came from: \n" + Joiner.on("\n").join(Thread.getAllStackTraces().get(Thread.currentThread()))); return; } LOG.info("Stopping {} when its state is {}", this, sensors().get(Attributes.SERVICE_STATE_ACTUAL)); ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING); deleteLocation(); // Stop and remove the Marathon task String name = sensors().get(APPLICATION_ID); ((MarathonFramework) getFramework()).stopApplication(name); super.stop(); }
protected void refreshGroupMembership() { try { if (log.isDebugEnabled()) log.debug("GeoDns {} refreshing targets", this); if (targetEntityProvider == null) return; if (targetEntityProvider instanceof DynamicGroup) ((DynamicGroup) targetEntityProvider).rescanEntities(); Set<Entity> pool = MutableSet.copyOf(targetEntityProvider instanceof Group ? targetEntityProvider.getMembers(): targetEntityProvider.getChildren()); if (log.isDebugEnabled()) log.debug("GeoDns {} refreshing targets, pool now {}", this, pool); boolean changed = false; boolean filterForRunning = Boolean.TRUE.equals(config().get(FILTER_FOR_RUNNING)); Set<Entity> previousOnes = MutableSet.copyOf(targetHosts.keySet()); for (Entity e: pool) { if (!filterForRunning || Lifecycle.RUNNING.equals(e.sensors().get(Attributes.SERVICE_STATE_ACTUAL))) { previousOnes.remove(e); changed |= addTargetHost(e); } } // anything left in previousOnes is no longer applicable for (Entity e: previousOnes) { changed |= removeTargetHost(e, false); } // do a periodic full update hourly once we are active (the latter is probably not needed) if (changed || (lastUpdate > 0 && Time.hasElapsedSince(lastUpdate, Duration.ONE_HOUR))) { update(); } } catch (Exception e) { log.error("Problem refreshing group membership: "+e, e); } }
Startable test = Startable.class.cast(child); test.start(locations); if (Lifecycle.RUNNING.equals(child.sensors().get(Attributes.SERVICE_STATE_ACTUAL))) { LOG.debug("Task of {} successfully run, targeting {}", this, target); } else {
@Override public void onEvent(SensorEvent<Lifecycle> event) { synchronized (eventLock) { if (!config().get(HAS_STARTED_TIMER) && config().get(STATE).equals(event.getValue())) { DurationSinceSensor sensor = new DurationSinceSensor(ConfigBag.newInstance(ImmutableMap.of( DurationSinceSensor.SENSOR_NAME, getSensorName(), DurationSinceSensor.SENSOR_PERIOD, config().get(POLL_PERIOD), DurationSinceSensor.SENSOR_TYPE, Duration.class.getName()))); sensor.apply(entity); config().set(HAS_STARTED_TIMER, true); } } } }
if (Lifecycle.STOPPING.equals(getAttribute(Attributes.SERVICE_STATE_ACTUAL))) { return super.shrink(delta);
TargetableTestComponent targetableTestComponent = this.addChild(testSpecCopy); targetableTestComponent.start(locations); if (Lifecycle.RUNNING.equals(targetableTestComponent.sensors().get(Attributes.SERVICE_STATE_ACTUAL))) { logger.debug("Task of {} successfully run, targetting {}", this, member); } else {
@Override public void stop() { Lifecycle state = sensors().get(SERVICE_STATE_ACTUAL); if (Lifecycle.STOPPING.equals(state) || Lifecycle.STOPPED.equals(state)) { LOG.debug("Ignoring request to stop {} when it is already {}", this, state); LOG.trace("Duplicate stop came from: \n" + Joiner.on("\n").join(Thread.getAllStackTraces().get(Thread.currentThread())));
if (!active) { Lifecycle state = found.sensors().get(Attributes.SERVICE_STATE_ACTUAL); if (Lifecycle.ON_FIRE.equals(state) || Lifecycle.STARTING.equals(state)) { continue; } else if (Lifecycle.STOPPING.equals(state) || Lifecycle.STOPPED.equals(state)) { group.removeMember(found); group.removeChild(found);
if (!Lifecycle.RUNNING.equals(getAttribute(SERVICE_STATE_ACTUAL))) {
if (!Lifecycle.RUNNING.equals(getAttribute(SERVICE_STATE_ACTUAL))) {