use of io.hops.hopsworks.alerting.api.alert.dto.SilenceID in project hopsworks by logicalclocks.
the class SilenceResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a silence.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableSilenceDTO postableSilenceDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (postableSilenceDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Users user = jWTHelper.getUserPrincipal(sc);
Project project = getProject();
postableSilenceDTO.setId(null);
SilenceID silenceID = postSilence(postableSilenceDTO, project, user);
SilenceDTO dto = silenceBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.SILENCES), silenceID.getSilenceID(), project);
dto.setHref(uriInfo.getAbsolutePathBuilder().path(silenceID.getSilenceID()).build());
return Response.created(dto.getHref()).entity(dto).build();
}
use of io.hops.hopsworks.alerting.api.alert.dto.SilenceID in project hopsworks by logicalclocks.
the class AlertManager method postSilences.
/**
* Post a new silence or update an existing one
* @param postableSilence
* @return
* @throws AlertManagerResponseException
* @throws AlertManagerClientCreateException
* @throws AlertManagerUnreachableException
*/
public SilenceID postSilences(PostableSilence postableSilence) throws AlertManagerResponseException, AlertManagerClientCreateException, AlertManagerUnreachableException {
doClientSanityCheck();
try {
SilenceID response = client.postSilences(postableSilence);
registerSuccess();
return response;
} catch (AlertManagerServerException e) {
registerServerError();
throw new AlertManagerUnreachableException("Alertmanager not reachable." + e.getMessage(), e);
}
}
use of io.hops.hopsworks.alerting.api.alert.dto.SilenceID in project hopsworks by logicalclocks.
the class SilenceResource method update.
@PUT
@Path("{silenceId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a silence.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@PathParam("silenceId") String silenceId, PostableSilenceDTO postableSilenceDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (postableSilenceDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Users user = jWTHelper.getUserPrincipal(sc);
postableSilenceDTO.setId(silenceId);
Project project = getProject();
SilenceID silenceID = postSilence(postableSilenceDTO, project, user);
SilenceDTO dto = silenceBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.SILENCES), silenceID.getSilenceID(), project);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.alerting.api.alert.dto.SilenceID in project hopsworks by logicalclocks.
the class AlertManagerClient method postSilences.
public SilenceID postSilences(PostableSilence postableSilence) throws AlertManagerResponseException, AlertManagerServerException {
WebTarget wt = webTarget.path(Settings.ALERTS_API_SILENCES);
LOGGER.log(Level.FINE, "Sending request postSilences to: {0}", wt.toString());
SilenceID silenceID = getResponse(sendRequest(wt.request(MediaType.APPLICATION_JSON), RequestMethod.POST, toEntity(postableSilence)), SilenceID.class);
return silenceID;
}
use of io.hops.hopsworks.alerting.api.alert.dto.SilenceID in project hopsworks by logicalclocks.
the class AdminSilenceResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a silence.", response = SilenceDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response create(PostableSilenceDTO postableSilenceDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (postableSilenceDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Users user = jWTHelper.getUserPrincipal(sc);
SilenceID silenceID = postSilence(postableSilenceDTO, user);
return Response.created(uriInfo.getAbsolutePathBuilder().path(silenceID.getSilenceID()).build()).build();
}
Aggregations