/** returns location (tighten type, since we know it is an ssh machine location here) */ public SshMachineLocation getLocation() { return (SshMachineLocation) super.getLocation(); }
/** * 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); } }
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); } */ }