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