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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations