public void waitForServiceUp() { Integer timeout = getConfig(BrooklynConfigKeys.START_TIMEOUT); waitForServiceUp(timeout, TimeUnit.SECONDS); } public void waitForServiceUp(Duration duration) {
protected Map<String,Object> obtainProvisioningFlags(MachineProvisioningLocation location) { Map<String,Object> result = Maps.newLinkedHashMap(location.getProvisioningFlags(ImmutableList.of(getClass().getName()))); result.putAll(getConfig(PROVISIONING_PROPERTIES)); if (result.get("inboundPorts") == null) { Collection<Integer> ports = getRequiredOpenPorts(); if (ports != null && ports.size() > 0) result.put("inboundPorts", ports); } result.put(LocationConfigKeys.CALLER_CONTEXT.getName(), this); return result; }
/** returns the ports that this entity wants to use; * default implementation returns 22 plus first value for each PortAttributeSensorAndConfigKey config key PortRange. */ protected Collection<Integer> getRequiredOpenPorts() { Set<Integer> ports = MutableSet.of(22); for (ConfigKey k: getEntityType().getConfigKeys()) { if (PortRange.class.isAssignableFrom(k.getType())) { PortRange p = (PortRange)getConfig(k); if (p != null && !p.isEmpty()) ports.add(p.iterator().next()); } } log.debug("getRequiredOpenPorts detected default {} for {}", ports, this); return ports; }
public void waitForEntityStart() { if (log.isDebugEnabled()) log.debug("waiting to ensure {} doesn't abort prematurely", this); Duration startTimeout = Duration.seconds(getConfig(START_TIMEOUT)); CountdownTimer timer = startTimeout.countdownTimer(); boolean isRunningResult = false; long delay = 100; while (!isRunningResult && !timer.isExpired()) { Time.sleep(delay); try { isRunningResult = driver.isRunning(); } catch (Exception e) { setAttribute(SERVICE_STATE, Lifecycle.ON_FIRE); // provide extra context info, as we're seeing this happen in strange circumstances if (driver==null) throw new IllegalStateException(this+" concurrent start and shutdown detected"); throw new IllegalStateException("Error detecting whether "+this+" is running: "+e, e); } if (log.isDebugEnabled()) log.debug("checked {}, is running returned: {}", this, isRunningResult); // slow exponential delay -- 1.1^N means after 40 tries and 50s elapsed, it reaches the max of 5s intervals delay = Math.min(delay*11/10, 5000); } if (!isRunningResult) { String msg = "Software process entity "+this+" did not pass is-running check within "+ "the required "+startTimeout+" limit ("+timer.getDurationElapsed()+" elapsed)"; log.warn(msg+" (throwing)"); setAttribute(SERVICE_STATE, Lifecycle.ON_FIRE); throw new IllegalStateException(msg); } }