Search in sources :

Example 1 with AlertException

use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.

the class SilenceResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a silence.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableSilenceDTO postableSilenceDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
    if (postableSilenceDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Users user = jWTHelper.getUserPrincipal(sc);
    Project project = getProject();
    postableSilenceDTO.setId(null);
    SilenceID silenceID = postSilence(postableSilenceDTO, project, user);
    SilenceDTO dto = silenceBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.SILENCES), silenceID.getSilenceID(), project);
    dto.setHref(uriInfo.getAbsolutePathBuilder().path(silenceID.getSilenceID()).build());
    return Response.created(dto.getHref()).entity(dto).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertException(io.hops.hopsworks.exceptions.AlertException) SilenceID(io.hops.hopsworks.alerting.api.alert.dto.SilenceID) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 2 with AlertException

use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.

the class ProjectAlertsResource method getTestById.

@POST
@Path("{id}/test")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Test alert by Id.", response = ProjectAlertsDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTestById(@PathParam("id") Integer id, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException, AlertException {
    Project project = getProject();
    ProjectServiceAlert projectServiceAlert = projectServiceAlertsFacade.findByProjectAndId(project, id);
    List<Alert> alerts;
    try {
        alerts = alertController.testAlert(project, projectServiceAlert);
    } catch (AlertManagerUnreachableException | AlertManagerClientCreateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
    } catch (AlertManagerAccessControlException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
    } catch (AlertManagerResponseException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RESPONSE_ERROR, Level.FINE, e.getMessage());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ALERTS);
    AlertDTO alertDTO = alertBuilder.getAlertDTOs(uriInfo, resourceRequest, alerts, project);
    return Response.ok().entity(alertDTO).build();
}
Also used : AlertDTO(io.hops.hopsworks.api.alert.AlertDTO) FeatureGroupAlertDTO(io.hops.hopsworks.api.featurestore.datavalidation.alert.FeatureGroupAlertDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Alert(io.hops.hopsworks.alerting.api.alert.dto.Alert) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerResponseException(io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 3 with AlertException

use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.

the class AlertBuilder method items.

private AlertGroupDTO items(AlertGroupDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, AlertFilterBy alertFilterBy, Project project) throws AlertException {
    uri(dto, uriInfo);
    expandAlertGroups(dto, resourceRequest);
    if (dto.isExpand()) {
        List<AlertGroup> alertGroups;
        try {
            if (project != null) {
                alertGroups = alertManager.getAlertGroups(alertFilterBy.isActive(), alertFilterBy.isSilenced(), alertFilterBy.isInhibited(), alertFilterBy.getFilter(), alertFilterBy.getReceiver(), project);
            } else {
                alertGroups = alertManager.getAlertGroups(alertFilterBy.isActive(), alertFilterBy.isSilenced(), alertFilterBy.isInhibited(), alertFilterBy.getFilter(), alertFilterBy.getReceiver());
            }
        } catch (AlertManagerResponseException a) {
            throw new AlertException(RESTCodes.AlertErrorCode.RESPONSE_ERROR, Level.FINE, a.getMessage());
        } catch (AlertManagerClientCreateException | AlertManagerUnreachableException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
        } catch (AlertManagerAccessControlException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
        }
        dto.setCount((long) alertGroups.size());
        return items(dto, uriInfo, resourceRequest, alertGroups);
    }
    return dto;
}
Also used : AlertGroup(io.hops.hopsworks.alerting.api.alert.dto.AlertGroup) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) AlertManagerResponseException(io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)

Example 4 with AlertException

use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.

the class ReceiverResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableReceiverDTO postableReceiverDTO, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
    if (postableReceiverDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Receiver receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
    validateReceiverOneConfig(receiver);
    try {
        alertManagerConfiguration.addReceiver(receiver, 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 (IllegalArgumentException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
    ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), getProject());
    dto.setHref(uriInfo.getAbsolutePathBuilder().path(receiver.getName()).build());
    return Response.created(dto.getHref()).entity(dto).build();
}
Also used : AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 5 with AlertException

use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.

the class RouteResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a route.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableRouteDTO routeDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
    if (routeDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Route route = routeBuilder.toRoute(routeDTO);
    try {
        alertManagerConfiguration.addRoute(route, 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 (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());
    } 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, getProject());
    routeBuilder.uriItem(dto, uriInfo, route);
    return Response.created(dto.getHref()).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) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

AlertException (io.hops.hopsworks.exceptions.AlertException)26 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)20 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)20 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)20 Produces (javax.ws.rs.Produces)20 Consumes (javax.ws.rs.Consumes)17 ApiOperation (io.swagger.annotations.ApiOperation)15 AlertManagerConfigCtrlCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException)14 AlertManagerConfigReadException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException)14 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)14 Path (javax.ws.rs.Path)14 AlertManagerConfigUpdateException (io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException)13 AlertManagerAccessControlException (io.hops.hopsworks.alert.exception.AlertManagerAccessControlException)10 POST (javax.ws.rs.POST)10 PUT (javax.ws.rs.PUT)10 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)9 AlertManagerDuplicateEntryException (io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException)8 AlertManagerNoSuchElementException (io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException)7 AlertManagerResponseException (io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException)7 Route (io.hops.hopsworks.alerting.config.dto.Route)6