use of io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO 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();
}
use of io.hops.hopsworks.api.alert.receiver.PostableReceiverDTO 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());
}
}
Aggregations