use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testRemoveRoute.
@Test
public void testRemoveRoute() throws AlertManagerConfigReadException, AlertManagerConfigUpdateException, AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
Map<String, String> matches = new HashMap<>();
matches.put("project", "project1");
Route route = new Route("slack_general").withMatch(matches);
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
assert alertManagerConfig.getRoute().getRoutes().contains(route);
AlertManagerConfig config = alertManagerConfigController.removeRoute(route);
alertManagerConfigController.writeAndReload(config);
alertManagerConfig = this.alertManagerConfigController.read();
assert !alertManagerConfig.getRoute().getRoutes().contains(route);
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testUpdateRouteDuplicate.
@Test
public void testUpdateRouteDuplicate() throws AlertManagerResponseException, AlertManagerServerException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
Map<String, String> matches = new HashMap<>();
matches.put("severity", "critical");
Route routeToUpdate = new Route("team-Y-mails").withMatch(matches);
matches = new HashMap<>();
matches.put("project", "project1");
Route route = new Route("slack_general").withMatch(matches);
Assert.assertThrows(AlertManagerDuplicateEntryException.class, () -> {
alertManagerConfigController.updateRoute(routeToUpdate, route);
});
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class AlertManagerConfigController method addRoute.
/**
* @param route
* @return updated AlertManagerConfig
* @throws IOException
* @throws AlertManagerDuplicateEntryException
* @throws AlertManagerConfigUpdateException
* @throws IllegalArgumentException if route is missing a receiver or match
*/
public AlertManagerConfig addRoute(Route route) throws AlertManagerDuplicateEntryException, AlertManagerConfigReadException, AlertManagerNoSuchElementException {
validate(route);
AlertManagerConfig alertManagerConfig = read();
// check if receiver exists
getIndexOfReceiver(alertManagerConfig, route.getReceiver());
if (alertManagerConfig.getRoute() == null) {
alertManagerConfig.setRoute(new Route());
}
if (alertManagerConfig.getRoute().getRoutes() == null) {
alertManagerConfig.getRoute().setRoutes(new ArrayList<>());
}
if (alertManagerConfig.getRoute().getRoutes().contains(route)) {
throw new AlertManagerDuplicateEntryException("A route with the same match and receiver name already exists.");
}
alertManagerConfig.getRoute().getRoutes().add(route);
return alertManagerConfig;
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class TestAlertManagerConfigController method testAddRoute.
@Test
public void testAddRoute() throws AlertManagerConfigUpdateException, AlertManagerDuplicateEntryException, AlertManagerResponseException, AlertManagerServerException, AlertManagerConfigReadException, AlertManagerNoSuchElementException {
Mockito.when(client.reload()).thenReturn(Response.ok().build());
Map<String, String> matches = new HashMap<>();
matches.put("project", "project3");
Route route = new Route("team-X-mails").withMatch(matches);
AlertManagerConfig config = alertManagerConfigController.addRoute(route);
alertManagerConfigController.writeAndReload(config);
AlertManagerConfig alertManagerConfig = this.alertManagerConfigController.read();
assert alertManagerConfig.getRoute().getRoutes().contains(route);
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class ManagementResource method updateRoute.
@PUT
@Path("route")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateRoute(PostableRouteDTO routeDTO, @Context SecurityContext sc) throws AlertException {
Route route = routeBuilder.toRoute(routeDTO);
Route dto;
try {
alertManagerConfiguration.updateRoute(route);
dto = alertManagerConfiguration.getGlobalRoute();
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, 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());
}
return Response.ok().entity(dto).build();
}
Aggregations