Search in sources :

Example 1 with AlertManagerResponseException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException 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 2 with AlertManagerResponseException

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

the class AlertManagerClient method sendRequest.

private Response sendRequest(Invocation.Builder invocationBuilder, RequestMethod method, Entity<String> entity) throws AlertManagerServerException, AlertManagerResponseException {
    Response response = null;
    try {
        switch(method) {
            case GET:
                response = invocationBuilder.get();
                break;
            case POST:
                response = invocationBuilder.post(entity);
                break;
            case DELETE:
                response = invocationBuilder.delete();
                break;
        }
    } catch (Exception e) {
        throw new AlertManagerServerException(e.getMessage());
    }
    checkResponse(response);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) AlertManagerServerException(io.hops.hopsworks.alerting.exceptions.AlertManagerServerException) AlertManagerResponseException(io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException) AlertManagerServerException(io.hops.hopsworks.alerting.exceptions.AlertManagerServerException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)

Example 3 with AlertManagerResponseException

use of io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException 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 AlertManagerResponseException

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

the class SilenceBuilder method items.

private SilenceDTO items(SilenceDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, SilenceBeanParam silenceBeanParam, Project project) throws AlertException {
    uri(dto, uriInfo);
    expand(dto, resourceRequest);
    if (dto.isExpand()) {
        List<Silence> silenceList;
        try {
            if (project != null) {
                silenceList = alertManager.getSilences(silenceBeanParam.getSilenceFilterBy().getFilter(), project);
            } else {
                silenceList = alertManager.getSilences(silenceBeanParam.getSilenceFilterBy().getFilter());
            }
        } catch (AlertManagerClientCreateException | AlertManagerUnreachableException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
        } catch (AlertManagerResponseException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.RESPONSE_ERROR, Level.FINE, e.getMessage());
        } catch (AlertManagerAccessControlException e) {
            throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
        }
        if (!Strings.isNullOrEmpty(silenceBeanParam.getSilenceFilterBy().getStatus())) {
            silenceList = silenceList.stream().filter((s) -> s.getStatus().getState().equals(silenceBeanParam.getSilenceFilterBy().getStatus())).collect(Collectors.toList());
        }
        if (!Strings.isNullOrEmpty(silenceBeanParam.getSilenceFilterBy().getCreatedBy())) {
            silenceList = silenceList.stream().filter((s) -> s.getCreatedBy().equals(silenceBeanParam.getSilenceFilterBy().getCreatedBy())).collect(Collectors.toList());
        }
        dto.setCount((long) silenceList.size());
        return items(dto, uriInfo, resourceRequest, silenceList, silenceBeanParam);
    }
    return dto;
}
Also used : PostableSilence(io.hops.hopsworks.alerting.api.alert.dto.PostableSilence) Silence(io.hops.hopsworks.alerting.api.alert.dto.Silence) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerResponseException(io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)

Example 5 with AlertManagerResponseException

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

the class JobAlertsResource 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 AlertException {
    JobAlert jobAlert = jobalertsFacade.findByJobAndId(job, id);
    List<Alert> alerts;
    try {
        alerts = alertController.testAlert(job.getProject(), jobAlert);
    } 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, job.getProject());
    return Response.ok().entity(alertDTO).build();
}
Also used : AlertDTO(io.hops.hopsworks.api.alert.AlertDTO) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) Alert(io.hops.hopsworks.alerting.api.alert.dto.Alert) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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)

Aggregations

AlertManagerResponseException (io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException)9 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)7 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)7 AlertException (io.hops.hopsworks.exceptions.AlertException)7 AlertManagerAccessControlException (io.hops.hopsworks.alert.exception.AlertManagerAccessControlException)6 Alert (io.hops.hopsworks.alerting.api.alert.dto.Alert)4 AlertDTO (io.hops.hopsworks.api.alert.AlertDTO)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 ApiOperation (io.swagger.annotations.ApiOperation)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 PostableSilence (io.hops.hopsworks.alerting.api.alert.dto.PostableSilence)2 AlertManagerServerException (io.hops.hopsworks.alerting.exceptions.AlertManagerServerException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)1 AlertGroup (io.hops.hopsworks.alerting.api.alert.dto.AlertGroup)1 PostableAlert (io.hops.hopsworks.alerting.api.alert.dto.PostableAlert)1