DynamicTasks.queue("customize", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH); customize(); }});
DynamicTasks.queue("stop (if running)", new Runnable() { public void run() { boolean previouslyRunning = isRunning(); try { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STOPPING); stop(); } catch (Exception e) { if (previouslyRunning) { log.debug(getEntity() + " restart: stop failed, when was previously running", e); } else { log.debug(getEntity() + " restart: stop failed (but was not previously running, so not a surprise)", e); } } }});
/** returns location (tighten type, since we know it is an ssh machine location here) */ public SshMachineLocation getLocation() { return (SshMachineLocation) super.getLocation(); }
DynamicTasks.queue("install", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH); install(); }});
DynamicTasks.queue("launch", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.LAUNCH_LATCH); launch(); }});
@Override public void restart() { DynamicTasks.queue("stop (if running)", new Runnable() { public void run() { boolean previouslyRunning = isRunning(); try { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STOPPING); stop(); } catch (Exception e) { if (previouslyRunning) { log.debug(getEntity() + " restart: stop failed, when was previously running", e); } else { log.debug(getEntity() + " restart: stop failed (but was not previously running, so not a surprise)", e); } } }}); if (doFullStartOnRestart()) { DynamicTasks.waitForLast(); getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); start(); } else { DynamicTasks.queue("launch", new Runnable() { public void run() { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); launch(); }}); DynamicTasks.queue("post-launch", new Runnable() { public void run() { postLaunch(); }}); } }
public String processTemplate(String templateConfigUrl, Map<String,? extends Object> extraSubstitutions) { return processTemplateContents(getResourceAsString(templateConfigUrl), extraSubstitutions); }
public String processTemplateContents(String templateContents, Map<String,? extends Object> extraSubstitutions) { Map<String, Object> config = getEntity().getApplication().getManagementContext().getConfig().asMapWithStringKeys(); Map<String, Object> substitutions = ImmutableMap.<String, Object>builder() .putAll(config) .put("entity", entity) .put("driver", this) .put("location", getLocation()) .putAll(extraSubstitutions) .build(); return TemplateProcessor.processTemplateContents(templateContents, substitutions); /* try { Configuration cfg = new Configuration(); StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("config", templateContents); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("config"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(baos); template.process(substitutions, out); out.flush(); return new String(baos.toByteArray()); } catch (Exception e) { log.warn("Error creating configuration file for "+entity, e); throw Exceptions.propagate(e); } */ }
/** Takes the contents of a template file from the given URL (often a classpath://com/myco/myprod/myfile.conf or .sh) * and replaces "${entity.xxx}" with the result of entity.getXxx() and similar for other driver, location; * as well as replacing config keys on the management context * <p> * uses Freemarker templates under the covers **/ public String processTemplate(String templateConfigUrl) { return processTemplate(templateConfigUrl, ImmutableMap.<String,String>of()); }
DynamicTasks.queue("post-launch", new Runnable() { public void run() { postLaunch(); }}); }
public String processTemplate(File templateConfigFile) { return processTemplate(templateConfigFile.toURI().toASCIIString()); }
DynamicTasks.queue("post-launch", new Runnable() { public void run() { postLaunch(); }}); }
public String processTemplate(File templateConfigFile, Map<String,Object> extraSubstitutions) { return processTemplate(templateConfigFile.toURI().toASCIIString(),extraSubstitutions); }
/** * Creates the driver (if does not already exist or needs replaced for some reason). Returns either the existing driver * or a new driver. Must not return null. */ protected SoftwareProcessDriver doInitDriver(MachineLocation machine) { if (driver!=null) { if ((driver instanceof AbstractSoftwareProcessDriver) && machine.equals(((AbstractSoftwareProcessDriver)driver).getLocation())) { return driver; //just reuse } else { log.warn("driver/location change is untested for {} at {}; changing driver and continuing", this, machine); return newDriver(machine); } } else { return newDriver(machine); } }