Search in sources :

Example 26 with Route

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);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) HashMap(java.util.HashMap) Route(io.hops.hopsworks.alerting.config.dto.Route) Test(org.junit.Test)

Example 27 with 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);
    });
}
Also used : HashMap(java.util.HashMap) Route(io.hops.hopsworks.alerting.config.dto.Route) Test(org.junit.Test)

Example 28 with 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;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 29 with Route

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);
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) HashMap(java.util.HashMap) Route(io.hops.hopsworks.alerting.config.dto.Route) Test(org.junit.Test)

Example 30 with 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();
}
Also used : AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) Route(io.hops.hopsworks.alerting.config.dto.Route) 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) PUT(javax.ws.rs.PUT)

Aggregations

Route (io.hops.hopsworks.alerting.config.dto.Route)32 ArrayList (java.util.ArrayList)9 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)7 HashMap (java.util.HashMap)7 Produces (javax.ws.rs.Produces)7 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)6 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)6 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)6 AlertException (io.hops.hopsworks.exceptions.AlertException)6 Project (io.hops.hopsworks.persistence.entity.project.Project)6 ApiOperation (io.swagger.annotations.ApiOperation)6 Test (org.junit.Test)6 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)5 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)5 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)5 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)5 AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)5 AlertManagerNoSuchElementException (io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5