public static void stopSequentially(Iterable<? extends Startable> entities) { List<Exception> exceptions = Lists.newArrayList(); List<Startable> failedEntities = Lists.newArrayList(); for (final Startable entity : entities) { if (!Entities.isManaged((Entity)entity)) { log.debug("Not stopping {} because it is not managed; continuing", entity); continue; } try { TaskAdaptable<Void> task = TaskTags.markInessential(Effectors.invocation((Entity)entity, Startable.STOP, Collections.emptyMap())); DynamicTasks.submit(task, (Entity)entity).getUnchecked(); } catch (Exception e) { log.warn("Error stopping "+entity+"; continuing with shutdown", e); exceptions.add(e); failedEntities.add(entity); } } if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error stopping "+(failedEntities.size() > 1 ? "entities" : "entity")+": "+failedEntities, exceptions); } }
DynamicTasks.submit(Tasks.sequential("Add JMX Sensor " + sensor.getName(), jmxPortTask, jmxFeedTask), entity); } else { throw new IllegalStateException(String.format("Entity %s does not support JMX", entity));
protected void onServerPoolMemberChanged(final Entity member) { LOG.debug("For {}, considering membership of {} which is in locations {}", new Object[]{ this, member, member.getLocations() }); Map<Entity, String> nodes = MutableMap.copyOf(sensors().get(ETCD_CLUSTER_NODES)); Duration timeout = config().get(BrooklynConfigKeys.START_TIMEOUT); Entity firstNode = AbstractGroup.getFirst(this); if (belongsInServerPool(member) && !nodes.containsKey(member)) { EtcdNode node = (EtcdNode) member; String name = Preconditions.checkNotNull(node.getNodeName()); // Ensure etcd has been installed Task<Boolean> installed = DynamicTasks.submit(DependentConfiguration.attributeWhenReady(member, EtcdNode.ETCD_NODE_INSTALLED), this).asTask(); if (installed.blockUntilEnded(timeout) && installed.getUnchecked()) { // Check if we are first node in the cluster. if (node.equals(firstNode)) { addNode(node, name); } else { // Add node asynchronously Callable<Void> joinCluster = new JoinCluster(firstNode, node, name, timeout); DynamicTasks.submit(Tasks.create("Joining etcd cluster", joinCluster), this); } } } }
@Override public Void call() throws Exception { // Wait for first node to be ready Entities.waitForServiceUp(firstNode); Task<Boolean> joined = DynamicTasks.submit(DependentConfiguration.attributeWhenReady(firstNode, EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER), EtcdClusterImpl.this).asTask(); if (joined.blockUntilEnded(timeout) && joined.getUnchecked()) { // Try invoking joinCluster effector synchronized (clusterMutex) { boolean success = Repeater.create("Calling joinCluster effector") .every(Duration.ONE_MINUTE) .limitIterationsTo(3) .limitTimeTo(timeout) .until(new InvokeJoinEffector()) .run(); if (!success) { throw new IllegalStateException(String.format("Node %s failed to join cluster %s", member, EtcdClusterImpl.this)); } } } return null; }
@Override public void undeploy(String targetName) { checkNotNull(targetName, "targetName"); targetName = FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName); // set it up so future nodes get the right wars if (!removeFromWarsByContext(this, targetName)) { DynamicTasks.submit(Tasks.warning("Context "+targetName+" not known at "+this+"; attempting to undeploy regardless", null), this); } log.debug("Undeploying "+targetName+" across cluster "+this+"; WARs now "+getConfig(WARS_BY_CONTEXT)); Iterable<CanDeployAndUndeploy> targets = Iterables.filter(getChildren(), CanDeployAndUndeploy.class); TaskBuilder<Void> tb = Tasks.<Void>builder().parallel(true).displayName("Undeploy "+targetName+" across cluster (size "+Iterables.size(targets)+")"); for (Entity target: targets) { tb.add(whenServiceUp(target, Effectors.invocation(target, UNDEPLOY, MutableMap.of("targetName", targetName)), "Undeploy "+targetName+" at "+target+" when ready")); } DynamicTasks.queueIfPossible(tb.build()).orSubmitAsync(this).asTask().getUnchecked(); // Update attribute Set<String> deployedWars = MutableSet.copyOf(getAttribute(DEPLOYED_WARS)); deployedWars.remove( FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName) ); sensors().set(DEPLOYED_WARS, deployedWars); }
.environmentVariables(serializer.serialize(env)); Task<String> taskI = DynamicTasks.submit(task.newTask(), target); if (highlight) { highlightAction("Run at "+machine.get().getAddress().getHostAddress(), taskI);