@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; }
/** * The text representation of the {@link #name()}. * * This is formatted as lower case characters, with hyphens instead of spaces. */ public String value() { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()); }
/** @see #value() */ @Override public String toString() { return value(); }
@Override public void run() { //Wait all apps to become managed String appsContent = HttpTestUtils.getContent(webConsoleUri.toString()+"/v1/applications"); List<String> appIds = parseJsonList(appsContent, ImmutableList.of("id"), String.class); assertEquals(appIds.size(), num); // and then to start List<String> statuses = parseJsonList(appsContent, ImmutableList.of("status"), String.class); for (String status : statuses) { assertEquals(status, Lifecycle.RUNNING.toString().toUpperCase()); } }}); }
/** * Creates a {@link Lifecycle} from a text representation. * * This accepts the text representations output by the {@link #value()} method for each entry. * * @see #value() */ public static Lifecycle fromValue(String v) { try { return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, v)); } catch (IllegalArgumentException iae) { return ON_FIRE; } }
@Override public void run() { Object status = api.getSensorApi().get(app, entity, "service.state", false); assertTrue(state.toString().equalsIgnoreCase(status.toString()), "status="+status); }}); }
@Override public Transition apply(final String input) { if (input != null) { Matcher m = TRANSITION_PATTERN.matcher(input); if (m.matches()) { Lifecycle state = Lifecycle.valueOf(m.group(1).toUpperCase().replace('-', '_')); long time = Long.parseLong(m.group(2)); return new Transition(state, new Date(time)); } else { throw new IllegalStateException("Serialized Lifecycle.Transition can't be parsed: " + input); } } else { return null; } } }
@Override public boolean apply(Lifecycle.Transition transition) { assertNotNull(transition); return Lifecycle.RUNNING.equals(transition.getState()); } });
private String getSensorName() { return "duration.since.first-" + config().get(STATE).name().toLowerCase(); }
@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())));