Search in sources :

Example 1 with SilenceID

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();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertException(io.hops.hopsworks.exceptions.AlertException) SilenceID(io.hops.hopsworks.alerting.api.alert.dto.SilenceID) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 2 with SilenceID

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);
    }
}
Also used : AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerServerException(io.hops.hopsworks.alerting.exceptions.AlertManagerServerException) SilenceID(io.hops.hopsworks.alerting.api.alert.dto.SilenceID)

Example 3 with SilenceID

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();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertException(io.hops.hopsworks.exceptions.AlertException) SilenceID(io.hops.hopsworks.alerting.api.alert.dto.SilenceID) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 4 with SilenceID

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;
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) SilenceID(io.hops.hopsworks.alerting.api.alert.dto.SilenceID)

Example 5 with 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();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) AlertException(io.hops.hopsworks.exceptions.AlertException) SilenceID(io.hops.hopsworks.alerting.api.alert.dto.SilenceID) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SilenceID (io.hops.hopsworks.alerting.api.alert.dto.SilenceID)6 AlertException (io.hops.hopsworks.exceptions.AlertException)4 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)4 Users (io.hops.hopsworks.persistence.entity.user.Users)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Consumes (javax.ws.rs.Consumes)4 Produces (javax.ws.rs.Produces)4 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 Project (io.hops.hopsworks.persistence.entity.project.Project)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)1 AlertManagerServerException (io.hops.hopsworks.alerting.exceptions.AlertManagerServerException)1 PostableSilenceDTO (io.hops.hopsworks.api.alert.silence.PostableSilenceDTO)1 SilenceDTO (io.hops.hopsworks.api.alert.silence.SilenceDTO)1 WebTarget (javax.ws.rs.client.WebTarget)1