Search in sources :

Example 1 with ReceiverDTO

use of io.hops.hopsworks.api.alert.receiver.ReceiverDTO in project hopsworks by logicalclocks.

the class AdminReceiverResource method update.

@PUT
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a receiver.", response = ReceiverDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response update(@PathParam("name") String name, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, PostableReceiverDTO postableReceiverDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    if (postableReceiverDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Receiver receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
    try {
        alertManagerConfiguration.updateReceiver(name, receiver);
    } catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
    } catch (AlertManagerDuplicateEntryException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_EXIST, Level.FINE, e.getMessage());
    } catch (AlertManagerConfigUpdateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
    } catch (AlertManagerClientCreateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
    } catch (AlertManagerNoSuchElementException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
    ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), null);
    return Response.ok().entity(dto).build();
}
Also used : AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) ReceiverDTO(io.hops.hopsworks.api.alert.receiver.ReceiverDTO) PostableReceiverDTO(io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) 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) PUT(javax.ws.rs.PUT)

Example 2 with ReceiverDTO

use of io.hops.hopsworks.api.alert.receiver.ReceiverDTO in project hopsworks by logicalclocks.

the class AdminReceiverResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response create(PostableReceiverDTO postableReceiverDTO, @QueryParam("defaultName") @DefaultValue("false") Boolean defaultName, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    if (postableReceiverDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Receiver receiver;
    try {
        AlertType alertType = null;
        if (defaultName || Strings.isNullOrEmpty(postableReceiverDTO.getName()) || AlertType.fromReceiverName(postableReceiverDTO.getName()) != null) {
            alertType = getDefaultName(postableReceiverDTO);
            postableReceiverDTO.setName(alertType.getReceiverName());
        }
        receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
        alertManagerConfiguration.addReceiver(receiver);
        if (alertType != null) {
            // to create a single route for global receivers
            alertController.createRoute(alertType);
        }
        ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
        ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), null);
        dto.setHref(uriInfo.getAbsolutePathBuilder().path(receiver.getName()).build());
        return Response.created(dto.getHref()).entity(dto).build();
    } catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
    } catch (AlertManagerDuplicateEntryException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_EXIST, Level.FINE, e.getMessage());
    } catch (AlertManagerConfigUpdateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
    } catch (AlertManagerClientCreateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
    } catch (AlertManagerAccessControlException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
    } catch (AlertManagerNoSuchElementException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
    }
}
Also used : ReceiverDTO(io.hops.hopsworks.api.alert.receiver.ReceiverDTO) PostableReceiverDTO(io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) AlertType(io.hops.hopsworks.persistence.entity.alertmanager.AlertType) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) 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)

Example 3 with ReceiverDTO

use of io.hops.hopsworks.api.alert.receiver.ReceiverDTO in project hopsworks by logicalclocks.

the class AdminReceiverResource method getByName.

@GET
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get receiver by name.", response = ReceiverDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response getByName(@PathParam("name") String name, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
    ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, name, null);
    return Response.ok().entity(dto).build();
}
Also used : ReceiverDTO(io.hops.hopsworks.api.alert.receiver.ReceiverDTO) PostableReceiverDTO(io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with ReceiverDTO

use of io.hops.hopsworks.api.alert.receiver.ReceiverDTO in project hopsworks by logicalclocks.

the class AdminReceiverResource method get.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all receivers.", response = ReceiverDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response get(@BeanParam Pagination pagination, @BeanParam ReceiverBeanParam receiverBeanParam, @QueryParam("expand") @DefaultValue("false") Boolean expand, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    ReceiverDTO dto = receiverBuilder.buildItems(uriInfo, resourceRequest, receiverBeanParam, expand);
    return Response.ok().entity(dto).build();
}
Also used : ReceiverDTO(io.hops.hopsworks.api.alert.receiver.ReceiverDTO) PostableReceiverDTO(io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

PostableReceiverDTO (io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO)4 ReceiverDTO (io.hops.hopsworks.api.alert.receiver.ReceiverDTO)4 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)4 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Produces (javax.ws.rs.Produces)4 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)2 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)2 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)2 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)2 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)2 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)2 AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)2 AlertManagerNoSuchElementException (io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException)2 AlertException (io.hops.hopsworks.exceptions.AlertException)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 AlertManagerAccessControlException (io.hops.hopsworks.alert.exception.AlertManagerAccessControlException)1 AlertType (io.hops.hopsworks.persistence.entity.alertmanager.AlertType)1