Search in sources :

Example 6 with Route

use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.

the class AdminRouteResource method get.

@GET
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all routes.", response = RouteDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response get(@PathParam("receiver") String receiver, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
    Route route = new Route(receiver).withMatch(routeBuilder.toMap(match)).withMatchRe(routeBuilder.toMap(matchRe));
    RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, route, null);
    return Response.ok().entity(dto).build();
}
Also used : PostableRouteDTO(io.hops.hopsworks.api.alert.route.PostableRouteDTO) RouteDTO(io.hops.hopsworks.api.alert.route.RouteDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Route(io.hops.hopsworks.alerting.config.dto.Route) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Example 7 with Route

use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddRouteDuplicate.

@Test
public void testAddRouteDuplicate() throws 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);
    Assert.assertThrows(AlertManagerDuplicateEntryException.class, () -> {
        alertManagerConfigController.addRoute(route);
    });
}
Also used : HashMap(java.util.HashMap) Route(io.hops.hopsworks.alerting.config.dto.Route) Test(org.junit.Test)

Example 8 with Route

use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.

the class TestAlertManagerConfigController method testAddRouteValidate.

@Test
public void testAddRouteValidate() throws AlertManagerResponseException, AlertManagerServerException {
    Mockito.when(client.reload()).thenReturn(Response.ok().build());
    Map<String, String> matches = new HashMap<>();
    Route route = new Route();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        alertManagerConfigController.addRoute(route);
    });
    Route route1 = new Route("team-X-mails").withMatch(matches);
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        alertManagerConfigController.addRoute(route1);
    });
}
Also used : HashMap(java.util.HashMap) Route(io.hops.hopsworks.alerting.config.dto.Route) Test(org.junit.Test)

Example 9 with Route

use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.

the class ConfigUtil method getRoute.

public static Route getRoute(AlertType alertType) {
    Map<String, String> match = new HashMap<>();
    match.put(Constants.ALERT_TYPE_LABEL, alertType.getValue());
    List<String> groupBy = new ArrayList<>();
    groupBy.add(Constants.LABEL_PROJECT);
    groupBy.add(Constants.LABEL_JOB);
    groupBy.add(Constants.LABEL_FEATURE_GROUP);
    groupBy.add(Constants.LABEL_STATUS);
    return new Route(alertType.getReceiverName()).withContinue(true).withMatch(match).withGroupBy(groupBy);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 10 with Route

use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.

the class ConfigUtil method getRoute.

public static Route getRoute(FeatureGroupAlert alert) {
    if (alert.getAlertType().isGlobal()) {
        return getRoute(alert.getAlertType());
    }
    Map<String, String> match = getMatch(alert);
    List<String> groupBy = new ArrayList<>();
    groupBy.add(Constants.LABEL_PROJECT);
    groupBy.add(Constants.LABEL_FEATURE_GROUP);
    groupBy.add(Constants.LABEL_STATUS);
    return new Route(alert.getReceiver().getName()).withContinue(true).withMatch(match).withGroupBy(groupBy);
}
Also used : ArrayList(java.util.ArrayList) Route(io.hops.hopsworks.alerting.config.dto.Route)

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