Java Code Examples for org.apache.brooklyn.core.entity.lifecycle.Lifecycle#RUNNING
The following examples show how to use
org.apache.brooklyn.core.entity.lifecycle.Lifecycle#RUNNING .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityAdjuncts.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Beta public static Lifecycle inferAdjunctStatus(EntityAdjunct a) { if (a.isRunning()) return Lifecycle.RUNNING; if (a.isDestroyed()) return Lifecycle.DESTROYED; // adjuncts don't currently support an "error" state; though that would be useful! if (a instanceof Policy) { if (((Policy)a).isSuspended()) return Lifecycle.STOPPED; return Lifecycle.CREATED; } if (a instanceof Feed) { if (((Feed)a).isSuspended()) return Lifecycle.STOPPED; if (((Feed)a).isActivated()) return Lifecycle.STARTING; return Lifecycle.CREATED; } // Enricher doesn't support suspend so if not running or destroyed then // it is just created return Lifecycle.CREATED; }
Example 2
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected Lifecycle computeExpectedState(Lifecycle oldExpectedState, Lifecycle newActualState) { if (oldExpectedState != Lifecycle.STARTING) { return oldExpectedState; } // Are any of our children still starting? Map<Entity, Lifecycle> values = getValues(SERVICE_STATE_ACTUAL); boolean childIsStarting = values.containsValue(Lifecycle.STARTING) || values.containsValue(Lifecycle.CREATED) || values.containsValue(null); if (!childIsStarting) { // We only transition to expected=RUNNING if all our children are no longer starting. // When actual=running, this matters if quorum != all; // When actual=on_fire, this matters for recovering. return Lifecycle.RUNNING; } return oldExpectedState; }
Example 3
Source File: ChefLifecycleEffectorTasks.java From brooklyn-library with Apache License 2.0 | 6 votes |
protected boolean tryStopPid() { Integer pid = entity().getAttribute(Attributes.PID); if (pid==null) { if (entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL)==Lifecycle.RUNNING && getPidFile()==null) log.warn("No PID recorded for "+entity()+" when running, with PID file "+getPidFile()+"; skipping kill in "+Tasks.current()); else if (log.isDebugEnabled()) log.debug("No PID recorded for "+entity()+"; skipping ("+entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL)+" / "+getPidFile()+")"); return false; } // allow non-zero exit as process may have already been killed DynamicTasks.queue(SshEffectorTasks.ssh( "kill "+pid, "sleep 5", BashCommands.ok("kill -9 "+pid)).allowingNonZeroExitCode().runAsRoot()).block(); if (DynamicTasks.queue(SshEffectorTasks.isPidRunning(pid).runAsRoot()).get()) { throw new IllegalStateException("Process for "+entity()+" in "+pid+" still running after kill"); } entity().sensors().set(Attributes.PID, null); return true; }
Example 4
Source File: OpenShiftEntityImpl.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
@Override public void rebind() { Lifecycle state = getAttribute(SERVICE_STATE_ACTUAL); if (state == null || state != Lifecycle.RUNNING) { log.warn("On rebind of {}, not calling software process rebind hooks because " + "state is {}", this, state); return; } // e.g. rebinding to a running instance // FIXME For rebind, what to do about things in STARTING or STOPPING state? // FIXME What if location not set? log.info("Rebind {} connecting to pre-running service", this); OpenShiftPaasLocation location = getLocationOrNull(); if (location != null) { initDriver(location); driver.rebind(); if (log.isDebugEnabled()) log.debug("On rebind of {}, re-created driver {}", this, driver); } else { log.info("On rebind of {}, no MachineLocation found (with locations {}) " + "so not generating driver", this, getLocations()); } callRebindHooks(); }
Example 5
Source File: CassandraFabricImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
public boolean isViableSeed(Entity member) { // TODO remove duplication from CassandraClusterImpl.SeedTracker.isViableSeed boolean managed = Entities.isManaged(member); String hostname = member.getAttribute(Attributes.HOSTNAME); boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP)); Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE_ACTUAL); boolean hasFailed = !managed || (serviceState == Lifecycle.ON_FIRE) || (serviceState == Lifecycle.RUNNING && !serviceUp) || (serviceState == Lifecycle.STOPPED); boolean result = (hostname != null && !hasFailed); if (log.isTraceEnabled()) log.trace("Node {} in Fabric {}: viableSeed={}; hostname={}; serviceUp={}; serviceState={}; hasFailed={}", new Object[] {member, CassandraFabricImpl.this, result, hostname, serviceUp, serviceState, hasFailed}); return result; }
Example 6
Source File: CloudFoundryEntityImpl.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
@Override public void rebind() { Lifecycle state = getAttribute(SERVICE_STATE_ACTUAL); if (state == null || state != Lifecycle.RUNNING) { log.warn("On rebind of {}, not calling software process rebind hooks because " + "state is {}", this, state); return; } // e.g. rebinding to a running instance // FIXME For rebind, what to do about things in STARTING or STOPPING state? // FIXME What if location not set? log.info("Rebind {} connecting to pre-running service", this); CloudFoundryPaasLocation location = getLocationOrNull(); if (location != null) { initDriver(location); driver.rebind(); if (log.isDebugEnabled()) log.debug("On rebind of {}, re-created driver {}", this, driver); } else { log.info("On rebind of {}, no MachineLocation found (with locations {}) " + "so not generating driver", this, getLocations()); } callRebindHooks(); }
Example 7
Source File: DynamicClusterImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public Boolean call() throws Exception { if (cluster.getMembers().isEmpty()) return false; if (Lifecycle.RUNNING != cluster.sensors().get(SERVICE_STATE_ACTUAL)) return false; for (Entity member : cluster.getMembers()) if (!Boolean.TRUE.equals(member.sensors().get(SERVICE_UP))) return false; return true; }
Example 8
Source File: EntityLaunchListener.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public void onEvent(SensorEvent<Lifecycle> event) { if (event.getValue() == Lifecycle.RUNNING) { Task<?>launchTask = getLatestLaunchTask(enricher.getEntity()); if (launchTask != null) { launchTaskRef.set(launchTask); if (!launchTask.isDone()) { launchTask.addListener(this, enricher.getEntityExecutionContext()); } if (launchTask.isDone()) { run(); } } } }
Example 9
Source File: SoftwareProcessImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public void rebind() { //SERVICE_STATE_ACTUAL might be ON_FIRE due to a temporary condition (problems map non-empty) //Only if the expected state is ON_FIRE then the entity has permanently failed. Lifecycle expectedState = ServiceStateLogic.getExpectedState(this); if (expectedState == null || expectedState != Lifecycle.RUNNING) { LOG.warn("On rebind of {}, not calling software process rebind hooks because expected state is {}", this, expectedState); return; } Lifecycle actualState = ServiceStateLogic.getActualState(this); if (actualState == null || actualState != Lifecycle.RUNNING) { LOG.warn("Rebinding entity {}, even though actual state is {}. Expected state is {}", new Object[] { this, actualState, expectedState }); } // e.g. rebinding to a running instance // FIXME What if location not set? LOG.info("Rebind {} connecting to pre-running service", this); MachineLocation machine = getMachineOrNull(); if (machine != null) { initDriver(machine); driver.rebind(); LOG.debug("On rebind of {}, re-created driver {}", this, driver); } else { LOG.info("On rebind of {}, no MachineLocation found (with locations {}) so not generating driver", this, getLocations()); } callRebindHooks(); }
Example 10
Source File: ChefLifecycleEffectorTasks.java From brooklyn-library with Apache License 2.0 | 5 votes |
protected boolean tryStopWindowsService() { if (getWindowsServiceName()==null) return false; int result = DynamicTasks.queue(SshEffectorTasks.ssh("sc query \""+getWindowsServiceName()+"\"").runAsCommand()).get(); if (0==result) return true; if (entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL)!=Lifecycle.RUNNING) return true; throw new IllegalStateException("The process for "+entity()+" appears could not be stopped (exit code "+result+" to service stop)"); }
Example 11
Source File: ChefLifecycleEffectorTasks.java From brooklyn-library with Apache License 2.0 | 5 votes |
protected boolean tryStopService() { if (getServiceName()==null) return false; int result = DynamicTasks.queue(SshEffectorTasks.ssh("/etc/init.d/"+getServiceName()+" stop").runAsRoot()).get(); if (0==result) return true; if (entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL)!=Lifecycle.RUNNING) return true; throw new IllegalStateException("The process for "+entity()+" appears could not be stopped (exit code "+result+" to service stop)"); }
Example 12
Source File: JMSBrokerImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
public void checkStartingOrRunning() { Lifecycle state = getAttribute(SERVICE_STATE_ACTUAL); if (getAttribute(SERVICE_STATE_ACTUAL) == Lifecycle.RUNNING) return; if (getAttribute(SERVICE_STATE_ACTUAL) == Lifecycle.STARTING) return; // TODO this check may be redundant or even inappropriate throw new IllegalStateException("Cannot run against "+this+" in state "+state); }
Example 13
Source File: AbstractGeoDnsServiceImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Override public void setServiceState(Lifecycle state) { sensors().set(HOSTNAME, getHostname()); ServiceStateLogic.setExpectedState(this, state); if (state==Lifecycle.RUNNING) ServiceNotUpLogic.clearNotUpIndicator(this, SERVICE_STATE_ACTUAL); else ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_STATE_ACTUAL, "Not in RUNNING state"); }
Example 14
Source File: AbstractControllerImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Override protected void postRebind() { super.postRebind(); Lifecycle state = getAttribute(SERVICE_STATE_ACTUAL); if (state != null && state == Lifecycle.RUNNING) { isActive = true; updateNeeded(); } }
Example 15
Source File: Jetty6ServerImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
protected void restartIfRunning() { // TODO for now we simply restart jetty to achieve "hot deployment"; should use the config mechanisms Lifecycle serviceState = getAttribute(SERVICE_STATE_ACTUAL); if (serviceState == Lifecycle.RUNNING) restart(); // may need a restart also if deploy effector is done in parallel to starting // but note this routine is used by initialDeployWars so just being in starting state is not enough! }
Example 16
Source File: CassandraDatacenterImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
public boolean isRunningSeed(Entity member) { boolean viableSeed = isViableSeed(member); boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP)); Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE_ACTUAL); boolean result = viableSeed && serviceUp && serviceState == Lifecycle.RUNNING; if (log.isTraceEnabled()) log.trace("Node {} in Cluster {}: runningSeed={}; viableSeed={}; serviceUp={}; serviceState={}", new Object[] {member, this, result, viableSeed, serviceUp, serviceState}); return result; }
Example 17
Source File: CassandraDatacenterImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
public boolean isViableSeed(Entity member) { // TODO would be good to reuse the better logic in ServiceFailureDetector // (e.g. if that didn't just emit a notification but set a sensor as well?) boolean managed = Entities.isManaged(member); String hostname = member.getAttribute(Attributes.HOSTNAME); boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP)); Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE_ACTUAL); boolean hasFailed = !managed || (serviceState == Lifecycle.ON_FIRE) || (serviceState == Lifecycle.RUNNING && !serviceUp) || (serviceState == Lifecycle.STOPPED); boolean result = (hostname != null && !hasFailed); if (log.isTraceEnabled()) log.trace("Node {} in Cluster {}: viableSeed={}; hostname={}; serviceUp={}; serviceState={}; hasFailed={}", new Object[] {member, this, result, hostname, serviceUp, serviceState, hasFailed}); return result; }
Example 18
Source File: MachineLifecycleEffectorTasksTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
public static boolean canStop(Application parent, StopMode stopMode, boolean isEntityStopped) { Lifecycle state = isEntityStopped ? Lifecycle.STOPPED : Lifecycle.RUNNING; BasicEntity entity = parent.addChild(EntitySpec.create(BasicEntity.class)); entity.sensors().set(SoftwareProcess.SERVICE_STATE_ACTUAL, state); return MachineLifecycleEffectorTasks.canStop(stopMode, entity); }
Example 19
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected ValueAndReason<Lifecycle> computeServiceState(Lifecycle expectedState) { if (expectedState != null && (expectedState != Lifecycle.STARTING && expectedState != Lifecycle.RUNNING)) { return new ValueAndReason<>(expectedState, "expected state "+expectedState); } Set<Lifecycle> ignoredStates; if (expectedState == Lifecycle.STARTING) { ignoredStates = getConfig(ENTITY_IGNORED_STATES_ON_STARTING); } else { ignoredStates = getConfig(ENTITY_IGNORED_STATES_ON_OTHERS); } Set<Lifecycle> transitionStates; if (expectedState == Lifecycle.STARTING) { transitionStates = getConfig(ENTITY_TRANSITION_STATES_ON_STARTING); } else { transitionStates = ImmutableSet.of(); } Map<Entity, Lifecycle> values = getValues(SERVICE_STATE_ACTUAL); List<Entity> violators = MutableList.of(); int entries = 0; int numRunning = 0; int numTransitioning = 0; for (Map.Entry<Entity,Lifecycle> entry : values.entrySet()) { if (ignoredStates.contains(entry.getValue())) { continue; } entries++; if (entry.getValue() == Lifecycle.RUNNING) { numRunning++; } else if (transitionStates.contains(entry.getValue())) { numTransitioning++; } else { violators.add(entry.getKey()); } } QuorumCheck qc = getConfig(RUNNING_QUORUM_CHECK); if (qc.isQuorate(numRunning, violators.size()+numRunning+numTransitioning)) { // quorate return new ValueAndReason<Lifecycle>(Lifecycle.RUNNING, "quorate"); } boolean canEverBeQuorate = qc.isQuorate(numRunning+numTransitioning, violators.size()+numRunning+numTransitioning); if (expectedState == Lifecycle.STARTING && canEverBeQuorate) { // quorate return new ValueAndReason<Lifecycle>(Lifecycle.STARTING, "not yet quorate"); } String reason; if (values.isEmpty()) { reason = "No entities present"; } else if (entries == 0) { reason = "No entities in interesting states"; } else if (violators.isEmpty()) { reason = "Not enough entities"; } else if (violators.size() == 1) { reason = violators.get(0)+" is not healthy"; } else if (violators.size() == entries) { reason = "None of the entities are healthy"; } else { reason = violators.size()+" entities are not healthy, including "+violators.get(0); } return new ValueAndReason<>(Lifecycle.ON_FIRE, reason); }