@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof PolicyType)) return false; PolicyType o = (PolicyType) obj; return Objects.equal(name, o.getName()) && Objects.equal(getConfigKeys(), o.getConfigKeys()); }
public static void dumpInfo(Policy pol, Writer out, String currentIndentation, String tab) throws IOException { out.append(currentIndentation+pol.toString()+"\n"); for (ConfigKey<?> key : sortConfigKeys(pol.getPolicyType().getConfigKeys())) { Object val = ((AbstractPolicy)pol).getConfigMap().getRawConfig(key); if (!isTrivial(val)) { out.append(currentIndentation+tab+tab+key); out.append(" = "); if (isSecret(key.getName())) out.append("xxxxxxxx"); else out.append(""+val); out.append("\n"); } } out.flush(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Response set( String application, String entityToken, String policyToken, String configKeyName, String value ) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); policy.setConfig((ConfigKey)ck, TypeCoercions.coerce(value, ck.getType())); return Response.status(Response.Status.OK).build(); }
public PolicyDescriptor(Policy policy) { this.id = policy.getId(); this.type = policy.getPolicyType().getName(); this.name = policy.getName(); } public String getId() {
@Override public List<PolicyConfigSummary> list( final String application, final String entityToken, final String policyToken ) { EntityLocal entity = brooklyn().getEntity(application, entityToken); Policy policy = brooklyn().getPolicy(entity, policyToken); List<PolicyConfigSummary> result = Lists.newArrayList(); for (ConfigKey<?> key : policy.getPolicyType().getConfigKeys()) { result.add(PolicyTransformer.policyConfigSummary(brooklyn(), entity, policy, key)); } return result; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @POST @Path("/{config}/set") @ApiOperation(value = "Sets the given config on this policy") @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") }) public Response set( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") String entityToken, @ApiParam(value = "Policy ID or name", required = true) @PathParam("policy") String policyToken, @ApiParam(value = "Config key ID", required = true) @PathParam("config") String configKeyName, @ApiParam(name = "value", value = "New value for the configuration", required = true) @QueryParam("value") String value ) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); policy.setConfig((ConfigKey)ck, TypeCoercions.coerce(value, ck.getType())); return Response.status(Response.Status.OK).build(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof PolicyType)) return false; PolicyType o = (PolicyType) obj; return Objects.equal(getName(), o.getName()) && Objects.equal(getConfigKeys(), o.getConfigKeys()); }
@GET @ApiOperation(value = "Fetch the config keys for a specific policy", responseClass = "brooklyn.rest.domain.ConfigSummary", multiValueResponse = true) @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application or entity or policy") }) public List<PolicyConfigSummary> list( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken, @ApiParam(value = "Policy ID or name", required = true) @PathParam("policy") final String policyToken ) { EntityLocal entity = brooklyn().getEntity(application, entityToken); Policy policy = brooklyn().getPolicy(entity, policyToken); List<PolicyConfigSummary> result = Lists.newArrayList(); for (ConfigKey<?> key : policy.getPolicyType().getConfigKeys()) { result.add(new PolicyConfigSummary(entity, policy, key)); } return result; }
@GET @Path("/{config}") @ApiOperation(value = "Fetch config value", responseClass = "Object") @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") }) public String get( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") String entityToken, @ApiParam(value = "Policy ID or name", required = true) @PathParam("policy") String policyToken, @ApiParam(value = "Config key ID", required = true) @PathParam("config") String configKeyName ) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); return getValueForDisplay(policy, policy.getConfig(ck)); }
@Override public String get(String application, String entityToken, String policyToken, String configKeyName) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); return getStringValueForDisplay(brooklyn(), policy, policy.getConfig(ck)); }