Search in sources :

Example 11 with AlertManagerDuplicateEntryException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.

the class AlertManagerConfigController method updateRoute.

/**
 * @param routeToUpdate
 * @param route
 * @return updated AlertManagerConfig
 * @throws IOException
 * @throws AlertManagerNoSuchElementException
 * @throws AlertManagerDuplicateEntryException
 * @throws AlertManagerConfigUpdateException
 * @throws IllegalArgumentException if route is missing a receiver or match
 */
public AlertManagerConfig updateRoute(Route routeToUpdate, Route route) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
    validate(route);
    AlertManagerConfig alertManagerConfig = read();
    // check if receiver exists
    getIndexOfReceiver(alertManagerConfig, route.getReceiver());
    int index = getIndexOfRoute(alertManagerConfig, routeToUpdate);
    if (!routeToUpdate.equals(route.getReceiver()) && alertManagerConfig.getRoute().getRoutes().contains(route)) {
        throw new AlertManagerDuplicateEntryException("A route with the same mather and receiver name already exists.");
    }
    alertManagerConfig.getRoute().getRoutes().remove(index);
    alertManagerConfig.getRoute().getRoutes().add(route);
    return alertManagerConfig;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)

Example 12 with AlertManagerDuplicateEntryException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException 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;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) Route(io.hops.hopsworks.alerting.config.dto.Route)

Example 13 with AlertManagerDuplicateEntryException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.

the class AlertManagerConfigController method addSlackToReceiver.

/**
 * @param name
 * @param slackConfig
 * @return updated AlertManagerConfig
 * @throws IOException
 * @throws AlertManagerNoSuchElementException
 * @throws AlertManagerDuplicateEntryException
 * @throws AlertManagerConfigUpdateException
 * @throws IllegalArgumentException if slackConfig is missing apiUrl or channel
 */
public AlertManagerConfig addSlackToReceiver(String name, SlackConfig slackConfig) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
    validate(slackConfig);
    AlertManagerConfig alertManagerConfig = read();
    int index = getIndexOfReceiver(alertManagerConfig, name);
    Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
    if (receiverToUpdate.getSlackConfigs() == null) {
        receiverToUpdate.setSlackConfigs(new ArrayList<>());
    }
    if (receiverToUpdate.getSlackConfigs().contains(slackConfig)) {
        throw new AlertManagerDuplicateEntryException("A receiver with the same api url and channel already exists.");
    }
    receiverToUpdate.getSlackConfigs().add(slackConfig);
    return alertManagerConfig;
}
Also used : AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver)

Example 14 with AlertManagerDuplicateEntryException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.

the class AdminRouteResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response create(PostableRouteDTO routeDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    if (routeDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Route route = routeBuilder.toRoute(routeDTO);
    try {
        alertManagerConfiguration.addRoute(route);
    } 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.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
    RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, route, null);
    return Response.created(dto.getHref()).build();
}
Also used : AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) PostableRouteDTO(io.hops.hopsworks.api.alert.route.PostableRouteDTO) RouteDTO(io.hops.hopsworks.api.alert.route.RouteDTO) 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) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with AlertManagerDuplicateEntryException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.

the class AdminRouteResource method update.

@PUT
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
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 {
    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);
    } 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());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
    RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, updatedRoute, null);
    return Response.ok().entity(dto).build();
}
Also used : AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) PostableRouteDTO(io.hops.hopsworks.api.alert.route.PostableRouteDTO) RouteDTO(io.hops.hopsworks.api.alert.route.RouteDTO) 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) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) 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) PUT(javax.ws.rs.PUT)

Aggregations

AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)15 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)8 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)8 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)8 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)8 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)8 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)8 AlertException (io.hops.hopsworks.exceptions.AlertException)8 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)8 ApiOperation (io.swagger.annotations.ApiOperation)8 Consumes (javax.ws.rs.Consumes)8 Produces (javax.ws.rs.Produces)8 AlertManagerConfig (io.hops.hopsworks.alerting.config.dto.AlertManagerConfig)7 Receiver (io.hops.hopsworks.alerting.config.dto.Receiver)7 AlertManagerNoSuchElementException (io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException)7 Route (io.hops.hopsworks.alerting.config.dto.Route)5 AlertManagerAccessControlException (io.hops.hopsworks.alert.exception.AlertManagerAccessControlException)4 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)4 POST (javax.ws.rs.POST)4 PUT (javax.ws.rs.PUT)4