Search in sources :

Example 31 with Route

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

the class AlertManagerConfiguration method isNotSystemReceiver.

private boolean isNotSystemReceiver(AlertManagerConfig alertManagerConfig, Receiver receiver) {
    if (alertManagerConfig.getRoute() == null) {
        return true;
    }
    if (alertManagerConfig.getRoute().getReceiver().equals(receiver.getName())) {
        return false;
    }
    List<Route> routes = alertManagerConfig.getRoute().getRoutes();
    for (Route route : routes) {
        Map<String, String> match = route.getMatch() != null ? route.getMatch() : route.getMatchRe();
        String alertType = match != null && match.get(Constants.ALERT_TYPE_LABEL) != null ? match.get(Constants.ALERT_TYPE_LABEL) : null;
        if (alertType != null && alertType.equals(AlertType.SYSTEM_ALERT.getValue()) && route.getReceiver().equals(receiver.getName())) {
            return false;
        }
    }
    return true;
}
Also used : Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 32 with Route

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

the class AlertManagerConfiguration method cleanProject.

public void cleanProject(Project project) throws AlertManagerConfigCtrlCreateException, AlertManagerConfigReadException, AlertManagerConfigUpdateException, AlertManagerUnreachableException, AlertManagerClientCreateException {
    AlertManagerConfig alertManagerConfig = read();
    List<Route> routes = alertManagerConfig.getRoute() == null || alertManagerConfig.getRoute().getRoutes() == null ? Collections.emptyList() : alertManagerConfig.getRoute().getRoutes();
    List<Receiver> receivers = alertManagerConfig.getReceivers() == null ? Collections.emptyList() : alertManagerConfig.getReceivers();
    List<Receiver> receiversToRemove = new ArrayList<>();
    for (Receiver receiver : receivers) {
        if (receiver.getName().startsWith(Constants.RECEIVER_NAME_PREFIX.replace(Constants.PROJECT_PLACE_HOLDER, project.getName()))) {
            receiversToRemove.add(receiver);
        }
    }
    List<Route> routesToRemove = new ArrayList<>();
    for (Route route : routes) {
        if (isRouteInProject(route, project) || receiversToRemove.contains(new Receiver(route.getReceiver()))) {
            routesToRemove.add(route);
        }
    }
    if (!routesToRemove.isEmpty() || !receiversToRemove.isEmpty()) {
        if (!routesToRemove.isEmpty()) {
            alertManagerConfig.getRoute().getRoutes().removeAll(routesToRemove);
        }
        if (!receiversToRemove.isEmpty()) {
            alertManagerConfig.getReceivers().removeAll(receiversToRemove);
            for (Receiver receiver : receiversToRemove) {
                removeReceiverFromDatabase(receiver.getName());
            }
        }
        writeAndReload(alertManagerConfig);
    }
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) ArrayList(java.util.ArrayList) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 33 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(JobAlert 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_JOB);
    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)

Example 34 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(ProjectServiceAlert 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_JOB);
    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)

Example 35 with Route

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

the class RouteResource method update.

@PUT
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a route.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@PathParam("receiver") String receiver, PostableRouteDTO route, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
    if (route == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Route routeToUpdate = new Route(receiver).withMatch(routeBuilder.toMap(match)).withMatchRe(routeBuilder.toMap(matchRe));
    Route updatedRoute = routeBuilder.toRoute(route);
    try {
        alertManagerConfiguration.updateRoute(routeToUpdate, updatedRoute, 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.ROUTE_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.ROUTES);
    RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, updatedRoute, getProject());
    return Response.ok().entity(dto).build();
}
Also used : AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) Route(io.hops.hopsworks.alerting.config.dto.Route) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Aggregations

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