Search in sources :

Example 11 with Route

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

the class AlertManagerConfiguration method getRoutesToAdd.

private List<Route> getRoutesToAdd(AlertReceiver alertReceiver, List<Route> routes) {
    Collection<JobAlert> jobAlerts = alertReceiver.getJobAlertCollection();
    Collection<FeatureGroupAlert> featureGroupAlerts = alertReceiver.getFeatureGroupAlertCollection();
    Collection<ProjectServiceAlert> projectServiceAlerts = alertReceiver.getProjectServiceAlertCollection();
    List<Route> routesToAdd = new ArrayList<>();
    for (JobAlert jobAlert : jobAlerts) {
        Route route = jobAlert.getAlertType().isGlobal() ? ConfigUtil.getRoute(jobAlert.getAlertType()) : ConfigUtil.getRoute(jobAlert);
        if (!routes.contains(route) && !routesToAdd.contains(route)) {
            routesToAdd.add(route);
        }
    }
    for (FeatureGroupAlert featureGroupAlert : featureGroupAlerts) {
        Route route = featureGroupAlert.getAlertType().isGlobal() ? ConfigUtil.getRoute(featureGroupAlert.getAlertType()) : ConfigUtil.getRoute(featureGroupAlert);
        if (!routes.contains(route) && !routesToAdd.contains(route)) {
            routesToAdd.add(route);
        }
    }
    for (ProjectServiceAlert projectServiceAlert : projectServiceAlerts) {
        Route route = projectServiceAlert.getAlertType().isGlobal() ? ConfigUtil.getRoute(projectServiceAlert.getAlertType()) : ConfigUtil.getRoute(projectServiceAlert);
        if (!routes.contains(route) && !routesToAdd.contains(route)) {
            routesToAdd.add(route);
        }
    }
    return routesToAdd;
}
Also used : FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) ArrayList(java.util.ArrayList) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 12 with Route

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

the class AlertManagerConfiguration method getRoute.

public Route getRoute(String receiver, Map<String, String> match, Map<String, String> matchRe, Project project) throws AlertManagerConfigCtrlCreateException, AlertManagerNoSuchElementException, AlertManagerAccessControlException, AlertManagerConfigReadException {
    doSanityCheck();
    Route route = new Route(receiver).withMatch(match).withMatchRe(matchRe);
    List<Route> routes = getRoutes(project);
    int index = routes.indexOf(route);
    if (index < 0) {
        throw new AlertManagerNoSuchElementException("A route with the given receiver name was not found. Receiver Name=" + route.getReceiver());
    }
    return routes.get(index);
}
Also used : AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 13 with Route

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

the class AlertManagerConfiguration method getRoutes.

public List<Route> getRoutes(Project project) throws AlertManagerConfigCtrlCreateException, AlertManagerConfigReadException {
    List<Route> projectRoutes = new ArrayList<>();
    List<Route> routeList = getRoutes();
    for (Route route : routeList) {
        if (isRouteInProject(route, project)) {
            projectRoutes.add(route);
        } else if (isRouteGlobal(route)) {
            projectRoutes.add(route);
        }
    }
    return projectRoutes;
}
Also used : ArrayList(java.util.ArrayList) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 14 with Route

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

the class AlertManagerConfiguration method fixRoutes.

private boolean fixRoutes(AlertManagerConfig alertManagerConfig, List<AlertReceiver> alertReceivers) {
    List<Route> routes = getRoutes(alertManagerConfig);
    List<Route> routesToAdd = new ArrayList<>();
    for (AlertReceiver alertReceiver : alertReceivers) {
        if (!alertReceiver.getName().equals(AlertType.DEFAULT.getValue())) {
            routesToAdd.addAll(getRoutesToAdd(alertReceiver, routes));
        }
    }
    if (!routesToAdd.isEmpty()) {
        alertManagerConfig.getRoute().getRoutes().addAll(routesToAdd);
        LOGGER.log(Level.INFO, "Alert manager config updated. Added {0} routes.", routesToAdd.size());
        return true;
    }
    return false;
}
Also used : AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) ArrayList(java.util.ArrayList) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 15 with Route

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

the class AlertManagerConfiguration method fixReceivers.

private boolean fixReceivers(AlertManagerConfig alertManagerConfig, ObjectMapper objectMapper, List<AlertReceiver> alertReceivers) throws IOException {
    List<Route> routes = getRoutes(alertManagerConfig);
    List<Receiver> receivers = alertManagerConfig.getReceivers() == null ? new ArrayList<>() : alertManagerConfig.getReceivers();
    List<Receiver> receiversToAdd = new ArrayList<>();
    for (AlertReceiver alertReceiver : alertReceivers) {
        Receiver receiver = receiverToAdd(receivers, alertReceiver, objectMapper);
        if (receiver != null && !receiversToAdd.contains(receiver)) {
            receiversToAdd.add(receiver);
        }
    }
    List<Receiver> receiversToRemove = new ArrayList<>();
    for (Receiver receiver : receivers) {
        Optional<AlertReceiver> alertReceiver = alertReceiverFacade.findByName(receiver.getName());
        if (!alertReceiver.isPresent() && isNotSystemReceiver(alertManagerConfig, receiver)) {
            receiversToRemove.add(receiver);
        }
    }
    if (!receiversToAdd.isEmpty() || !receiversToRemove.isEmpty()) {
        if (!receiversToAdd.isEmpty()) {
            receivers.addAll(receiversToAdd);
            LOGGER.log(Level.INFO, "Alert manager config updated. Added {0} receivers.", receiversToAdd.size());
        }
        if (!receiversToRemove.isEmpty()) {
            List<Route> routesToRemove = new ArrayList<>();
            for (Route route : routes) {
                if (receiversToRemove.contains(new Receiver(route.getReceiver()))) {
                    routesToRemove.add(route);
                }
            }
            if (!routesToRemove.isEmpty()) {
                alertManagerConfig.getRoute().getRoutes().removeAll(routesToRemove);
                LOGGER.log(Level.INFO, "Alert manager config updated. Removed {0} routes.", routesToRemove.size());
            }
            receivers.removeAll(receiversToRemove);
            LOGGER.log(Level.INFO, "Alert manager config updated. Removed {0} receivers.", receiversToRemove.size());
        }
        alertManagerConfig.setReceivers(receivers);
        return true;
    }
    return false;
}
Also used : AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) 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)

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