use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testRemoveReceiver.
@Test
public void testRemoveReceiver() throws AlertManagerConfigReadException, AlertManagerConfigUpdateException, AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
Receiver receiver = new Receiver("team-Y-mails");
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
assert alertManagerConfig.getReceivers().contains(receiver);
AlertManagerConfig config = alertManagerConfigController.removeReceiver("team-Y-mails", true);
alertManagerConfigController.writeAndReload(config);
alertManagerConfig = this.alertManagerConfigController.read();
assert !alertManagerConfig.getReceivers().contains(receiver);
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class AlertManagerConfigController method addEmailToReceiver.
/**
* @param name
* @param emailConfig
* @return updated AlertManagerConfig
* @throws IOException
* @throws AlertManagerNoSuchElementException
* @throws AlertManagerDuplicateEntryException
* @throws AlertManagerConfigUpdateException
* @throws IllegalArgumentException if emailConfig is missing to
*/
public AlertManagerConfig addEmailToReceiver(String name, EmailConfig emailConfig) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
validate(emailConfig);
AlertManagerConfig alertManagerConfig = read();
int index = getIndexOfReceiver(alertManagerConfig, name);
Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
if (receiverToUpdate.getEmailConfigs() == null) {
receiverToUpdate.setEmailConfigs(new ArrayList<>());
}
if (receiverToUpdate.getEmailConfigs().contains(emailConfig)) {
throw new AlertManagerDuplicateEntryException("A receiver with the same email already exists.");
}
receiverToUpdate.getEmailConfigs().add(emailConfig);
return alertManagerConfig;
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class AlertManagerConfigController method addSlackToReceiver.
/**
* @param name
* @param slackConfig
* @return updated AlertManagerConfig
* @throws IOException
* @throws AlertManagerNoSuchElementException
* @throws AlertManagerDuplicateEntryException
* @throws AlertManagerConfigUpdateException
* @throws IllegalArgumentException if slackConfig is missing apiUrl or channel
*/
public AlertManagerConfig addSlackToReceiver(String name, SlackConfig slackConfig) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
validate(slackConfig);
AlertManagerConfig alertManagerConfig = read();
int index = getIndexOfReceiver(alertManagerConfig, name);
Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
if (receiverToUpdate.getSlackConfigs() == null) {
receiverToUpdate.setSlackConfigs(new ArrayList<>());
}
if (receiverToUpdate.getSlackConfigs().contains(slackConfig)) {
throw new AlertManagerDuplicateEntryException("A receiver with the same api url and channel already exists.");
}
receiverToUpdate.getSlackConfigs().add(slackConfig);
return alertManagerConfig;
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class AlertManagerConfigController method removeSlackFromReceiver.
/**
* @param name
* @param slackConfig
* @return updated AlertManagerConfig or null if it was not updated
* @throws AlertManagerNoSuchElementException
* @throws AlertManagerServerException
* @throws AlertManagerConfigReadException
*/
public AlertManagerConfig removeSlackFromReceiver(String name, SlackConfig slackConfig) throws AlertManagerNoSuchElementException, AlertManagerConfigReadException {
AlertManagerConfig alertManagerConfig = read();
int index = getIndexOfReceiver(alertManagerConfig, name);
Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
index = receiverToUpdate.getSlackConfigs() == null ? -1 : receiverToUpdate.getSlackConfigs().indexOf(slackConfig);
if (index > -1) {
receiverToUpdate.getSlackConfigs().remove(index);
return alertManagerConfig;
}
return null;
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class ReceiverResource method update.
@PUT
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a receiver.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response update(@PathParam("name") String name, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, PostableReceiverDTO postableReceiverDTO, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws AlertException, ProjectException {
if (postableReceiverDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Receiver receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
validateReceiverOneConfig(receiver);
try {
alertManagerConfiguration.updateReceiver(name, receiver, getProject());
} 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());
} catch (AlertManagerAccessControlException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
} catch (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), getProject());
return Response.ok().entity(dto).build();
}
Aggregations