@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(); }
@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(); }
@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)); }