/** see {@link DynamicTasks#waitForLast()} */ protected Task<?> waitForLast() { return DynamicTasks.waitForLast(); }
/** * Submits the task to the ExecutionManager and then waits until the task has completed. * * @param taskAdaptable the TaskAdaptable to submit for execution. */ private void submitTaskAndWait(final TaskAdaptable<?> taskAdaptable) { // Submit the task to the ExecutionManager. DynamicTasks.queue(taskAdaptable); // Block until the task has completed. This will also throw if anything went wrong. DynamicTasks.waitForLast(); }
private Result executeDownloadedScript(SshMachineLocation machineLocation, String url, String scriptPath, Map<String, String> env) { TaskFactory<?> install = SshTasks.installFromUrl(ImmutableMap.<String, Object>of(), machineLocation, url, scriptPath); DynamicTasks.queue(install); DynamicTasks.waitForLast(); List<String> commands = ImmutableList.<String>builder() .add("chmod u+x " + scriptPath) .addAll(maybeCdToRunDirCmd()) .add(scriptPath) .build(); return runCommands(machineLocation, commands, env); }
@Override public String call() { DynamicTasks.markInessential(); stopProcessesAtMachine(); DynamicTasks.waitForLast(); return "Stop processes completed with no errors."; } }
@Override public String call() { DynamicTasks.markInessential(); stop(ConfigBag.newInstance().configure(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.IF_NOT_STOPPED)); DynamicTasks.waitForLast(); return "Stop of machine completed with no errors."; } }
@Override protected String stopProcessesAtMachine() { TaskAdaptable<?> children = StartableMethods.stoppingChildren(entity()); DynamicTasks.queue(children); Exception childException = null; try { DynamicTasks.waitForLast(); } catch (Exception e) { childException = e; } try { children.asTask().get(); } catch (Exception e) { childException = e; LOG.debug("Error stopping children; continuing and will rethrow if no other errors", e); } if (childException != null) throw new IllegalStateException("error stopping child", childException); return "children stopped"; }
@Override public void restart() { String mode = getConfig(RESTART_MODE); if (mode==null) { throw new UnsupportedOperationException("Restart not supported for this cluster: "+RESTART_MODE.getName()+" is not configured."); } if ("off".equalsIgnoreCase(mode)) { throw new UnsupportedOperationException("Restart not supported for this cluster."); } if ("sequential".equalsIgnoreCase(mode)) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); DynamicTasks.queue(Effectors.invocationSequential(Startable.RESTART, null, Iterables.filter(getChildren(), Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.isManaged())))); } else if ("parallel".equalsIgnoreCase(mode)) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); for (Entity member : Iterables.filter(getChildren(), Predicates.and(Predicates.instanceOf(Startable.class), EntityPredicates.isManaged()))) { DynamicTasks.queue(newThrottledEffectorTask(member, Startable.RESTART, Collections.emptyMap())); } } else { throw new IllegalArgumentException("Unknown "+RESTART_MODE.getName()+" '"+mode+"'"); } DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); }
@Override protected String startProcessesAtMachine(Supplier<MachineLocation> machineS) { DynamicTasks.queueIfPossible(StartableMethods.startingChildren(entity(), machineS.get())) .orSubmitAsync(entity()) .getTask() .getUnchecked(); DynamicTasks.waitForLast(); return "children started"; }
@Override public String call() { DynamicTasks.markInessential(); for (Feed feed : entity().feeds().getFeeds()) { if (feed.isActivated()) feed.stop(); } DynamicTasks.waitForLast(); return "Stop feeds completed with no errors."; } }
@Override public void run() { try { if (doFullStartOnRestart()) { DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(getEntity(), Lifecycle.STARTING); start(); } else { DynamicTasks.queue("pre-launch-command", new Runnable() { @Override public void run() { ServiceStateLogic.setExpectedState(getEntity(), Lifecycle.STARTING); runPreLaunchCommand(); }}); DynamicTasks.queue("launch (main)", new Runnable() { @Override public void run() { launch(); }}); DynamicTasks.queue("post-launch-command", new Runnable() { @Override public void run() { runPostLaunchCommand(); }}); DynamicTasks.queue("post-launch", new Runnable() { @Override public void run() { postLaunch(); }}); } DynamicTasks.waitForLast(); } catch (Exception e) { ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE); throw Exceptions.propagate(e); } } });
/** runs the tasks needed to start, wrapped by setting {@link Attributes#SERVICE_STATE_EXPECTED} appropriately */ public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); try { startInLocations(locations); DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); } catch (Throwable t) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } }
log.debug("{} deployed {} to {}:{}", new Object[]{entity, url, getHostname(), dest}); DynamicTasks.waitForLast(); } finally { Tasks.resetBlockingDetails();
@Override public void customizeService() { DynamicTasks.queue( SshEffectorTasks.put("/tmp/" + getServiceScriptFileName()) .contents(TemplateProcessor.processTemplateContents( ResourceUtils.create().getResourceAsString(config().get(CustomService.SERVICE_SCRIPT_TEMPLATE_URL)), this, ImmutableMap.<String,String>of())), SshEffectorTasks.put("/tmp/" + getMetaInfoXmlFileName()) .contents(TemplateProcessor.processTemplateContents( ResourceUtils.create().getResourceAsString(config().get(CustomService.SERVICE_METAINFO_TEMPLATE_URL)), this, ImmutableMap.<String,String>of())), SshEffectorTasks.ssh( sudo(format("mkdir -p %s", getServiceDirectory())), sudo(format("mv /tmp/%s %s", getMetaInfoXmlFileName(), getServiceDirectory())), sudo(format("mkdir -p %s", getServiceScriptDirectory())), sudo(format("mv /tmp/%s %s/",getServiceScriptFileName(), getServiceScriptDirectory())), sudo(format("mkdir -p %s", getServiceConfigDirectory())))); Map<String, ?> serviceConf = getConfig(CustomService.CUSTOM_SERVICE_CONF); for (Entry<String, ?> entry: serviceConf.entrySet()) { DynamicTasks.queue( SshEffectorTasks.put("/tmp/" + getServicePropertyFileName(entry.getKey())) .contents(prepareServiceConfigurationXmlContent(entry.getKey(), (Map) entry.getValue())), SshEffectorTasks.ssh( sudo(format("mv %s %s/", "/tmp/" + getServicePropertyFileName(entry.getKey()), getServiceConfigDirectory())))); } DynamicTasks.waitForLast(); }
DynamicTasks.queue(children); try { DynamicTasks.waitForLast(); } catch (Exception e) { childException = e;
@Override public void run() { DynamicTasks.waitForLast(); entity().sensors().set(SoftwareProcess.INSTALL_DIR, (String)null); entity().config().set(SoftwareProcess.INSTALL_UNIQUE_LABEL, (String)null); entity().config().putAll(parameters.getAllConfig()); entity().sensors().set(BrooklynNode.DOWNLOAD_URL, entity().getConfig(DOWNLOAD_URL)); // Setting SUGGESTED_VERSION will result in an new empty INSTALL_FOLDER, but clear it // just in case the user specified already installed version. ((BrooklynNodeDriver)((DriverDependentEntity<?>)entity()).getDriver()).clearInstallDir(); } }).build());
DynamicTasks.waitForLast(); if (mode.isBackground) { Entities.submit(entity(), children);
try { doStart(); DynamicTasks.waitForLast(); } catch (Exception e) { ServiceProblemsLogic.updateProblemsIndicator(this, START, "start failed with error: "+e);
DynamicTasks.waitForLast(); .summary("move install dir from user to postgres owned space")); DynamicTasks.waitForLast(); setInstallDir(altInstallDir); setRunDir(newRunDir);
DynamicTasks.queue("post-restart", new PostRestartTask()); DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
DynamicTasks.waitForLast(); if(Boolean.TRUE.equals(entity.getConfig(PostgreSqlNode.INITIALIZE_DB))){ initializeNewDatabase();