public PolicyConfigSummary(ApplicationSummary application, EntityLocal entity, Policy policy, ConfigKey<?> config) { this(entity, policy, config); if (!entity.getApplicationId().equals(application.getInstance().getId())) throw new IllegalStateException("Application "+application+" does not match app "+entity.getApplication()+" of "+entity); }
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); } */ }
public String getRunDir() { if (runDir == null) { String runBasedir = ((EntityInternal)entity).getManagementContext().getConfig().getFirst("brooklyn.dirs.run"); if (runBasedir == null) runBasedir = DEFAULT_RUN_BASEDIR; if (runBasedir.endsWith(File.separator)) runBasedir.substring(0, runBasedir.length()-1); runDir = elvis(entity.getConfig(SoftwareProcess.SUGGESTED_RUN_DIR), runBasedir+"/"+entity.getApplication().getId()+"/"+"entities"+"/"+ getEntityVersionLabel()+"_"+entity.getId()); } return runDir; }
/** finds the entity indicated by the given ID or name * <p> * prefers ID based lookup in which case appId is optional, and if supplied will be enforced. * optionally the name can be supplied, for cases when paths should work across versions, * in which case names will be searched recursively (and the application is required). * * @throws 404 or 412 (unless input is null in which case output is null) */ public EntityLocal getEntity(String application, String entity) { if (entity==null) return null; Application app = application!=null ? getApplication(application) : null; EntityLocal e = (EntityLocal) mgmt.getEntityManager().getEntity(entity); if (e!=null) { if (app==null || app.equals(findTopLevelApplication(e))) return e; throw WebResourceUtils.preconditionFailed("Application '%s' specified does not match application '%s' to which entity '%s' (%s) is associated", application, e.getApplication().getId(), entity, e); } if (application==null) throw WebResourceUtils.notFound("Cannot find entity '%s': no known ID and application not supplied for searching", entity); assert app!=null : "null app should not be returned from getApplication"; e = searchForEntityNamed(app, entity); if (e!=null) return e; throw WebResourceUtils.notFound("Cannot find entity '%s' in application '%s' (%s)", entity, application, app); }
/** finds the entity indicated by the given ID or name * <p> * prefers ID based lookup in which case appId is optional, and if supplied will be enforced. * optionally the name can be supplied, for cases when paths should work across versions, * in which case names will be searched recursively (and the application is required). * * @throws 404 or 412 (unless input is null in which case output is null) */ public EntityLocal getEntity(String application, String entity) { if (entity==null) return null; Application app = application!=null ? getApplication(application) : null; EntityLocal e = (EntityLocal) mgmt.getEntityManager().getEntity(entity); if (e!=null) { if (app==null || app.equals(findTopLevelApplication(e))) return e; throw WebResourceUtils.preconditionFailed("Application '%s' specified does not match application '%s' to which entity '%s' (%s) is associated", application, e.getApplication().getId(), entity, e); } if (application==null) throw WebResourceUtils.notFound("Cannot find entity '%s': no known ID and application not supplied for searching", entity); assert app!=null : "null app should not be returned from getApplication"; e = searchForEntityNamed(app, entity); if (e!=null) return e; throw WebResourceUtils.notFound("Cannot find entity '%s' in application '%s' (%s)", entity, application, app); }