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;
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class RouteBuilder method items.
private RouteDTO items(RouteDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, RouteBeanParam routeBeanParam, Project project) throws AlertException {
uri(dto, uriInfo);
expand(dto, resourceRequest);
List<Route> routes;
if (dto.isExpand()) {
try {
if (project != null) {
routes = alertManagerConfiguration.getRoutes(project);
} else {
routes = alertManagerConfiguration.getRoutes();
}
} catch (AlertManagerConfigReadException | AlertManagerConfigCtrlCreateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
}
dto.setCount((long) routes.size());
return items(dto, uriInfo, resourceRequest, routeBeanParam, routes);
}
return dto;
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class RouteResource method get.
@GET
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a route by receiver and match.", response = RouteDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "HOPS_SERVICE_USER" })
public Response get(@PathParam("receiver") String receiver, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws AlertException, ProjectException {
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, getProject());
return Response.ok().entity(dto).build();
}
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", "HOPS_SERVICE_USER" })
public Response update(@PathParam("receiver") String receiver, PostableRouteDTO route, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context HttpServletRequest req, @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();
}
use of io.hops.hopsworks.alerting.config.dto.Route in project hopsworks by logicalclocks.
the class AlertController method createRoute.
public void createRoute(FeatureGroupAlert alert) throws AlertManagerUnreachableException, AlertManagerAccessControlException, AlertManagerNoSuchElementException, AlertManagerConfigUpdateException, AlertManagerConfigCtrlCreateException, AlertManagerConfigReadException, AlertManagerClientCreateException {
Project project = alert.getFeatureGroup().getFeaturestore().getProject();
Route route = ConfigUtil.getRoute(alert);
addRouteIfNotExist(alert.getAlertType(), route, project);
}
Aggregations