use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class ReceiverResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableReceiverDTO postableReceiverDTO, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, @Context UriInfo uriInfo, @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.addReceiver(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 (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());
dto.setHref(uriInfo.getAbsolutePathBuilder().path(receiver.getName()).build());
return Response.created(dto.getHref()).entity(dto).build();
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddDuplicateReceiver.
@Test
public void testAddDuplicateReceiver() throws AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
List<EmailConfig> emailConfigList = new ArrayList<>();
emailConfigList.add(new EmailConfig("ermias@kth.se"));
Receiver receiver = new Receiver("team-X-mails").withEmailConfigs(emailConfigList);
Assert.assertThrows(AlertManagerDuplicateEntryException.class, () -> {
alertManagerConfigController.addReceiver(receiver);
});
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testRemoveSlackFromReceiver.
@Test
public void testRemoveSlackFromReceiver() throws AlertManagerConfigUpdateException, AlertManagerNoSuchElementException, AlertManagerConfigReadException, AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
SlackConfig slackConfig = new SlackConfig("https://hooks.slack.com/services/12345678901/0987654321", "#offtopic");
Receiver receiver = new Receiver("slack_general");
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
int index = alertManagerConfig.getReceivers().indexOf(receiver);
Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
assert updatedReceiver.getSlackConfigs().contains(slackConfig);
AlertManagerConfig config = alertManagerConfigController.removeSlackFromReceiver("slack_general", slackConfig);
alertManagerConfigController.writeAndReload(config);
alertManagerConfig = this.alertManagerConfigController.read();
index = alertManagerConfig.getReceivers().indexOf(receiver);
updatedReceiver = alertManagerConfig.getReceivers().get(index);
assert !updatedReceiver.getSlackConfigs().contains(slackConfig);
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddPagerdutyToReceiver.
@Test
public void testAddPagerdutyToReceiver() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerNoSuchElementException, AlertManagerConfigReadException, AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
PagerdutyConfig pagerdutyConfig = new PagerdutyConfig().withServiceKey("serviceKey");
Receiver receiver = new Receiver("team-DB-pager");
AlertManagerConfig config = alertManagerConfigController.addPagerdutyToReceiver("team-DB-pager", pagerdutyConfig);
alertManagerConfigController.writeAndReload(config);
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
int index = alertManagerConfig.getReceivers().indexOf(receiver);
Receiver updatedReceiver = alertManagerConfig.getReceivers().get(index);
assert updatedReceiver.getPagerdutyConfigs().contains(pagerdutyConfig);
}
use of io.hops.hopsworks.alerting.config.dto.Receiver in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testUpdateReceiverRollbackServerException.
@Test
public void testUpdateReceiverRollbackServerException() throws AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException {
Mockito.when(client.reload()).thenThrow(AlertManagerServerException.class);
List<EmailConfig> emailConfigList = new ArrayList<>();
emailConfigList.add(new EmailConfig("team-Z+alerts@example.org"));
Receiver receiver = new Receiver("team-Z-email").withEmailConfigs(emailConfigList);
Assert.assertThrows(AlertManagerServerException.class, () -> {
AlertManagerConfig config = alertManagerConfigController.addReceiver(receiver);
alertManagerConfigController.writeAndReload(config);
});
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
assert !alertManagerConfig.getReceivers().contains(receiver);
}
Aggregations