Search in sources :

Example 1 with ProjectServiceAlert

use of io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert in project hopsworks by logicalclocks.

the class AlertController method getPostableAlerts.

private List<PostableAlert> getPostableAlerts(Featuregroup featuregroup, List<ExpectationResult> results, FeatureGroupValidation.Status status) {
    List<PostableAlert> postableAlerts = new ArrayList<>();
    if (FeatureGroupValidation.Status.NONE.equals(status)) {
        return postableAlerts;
    }
    if (featuregroup.getFeatureGroupAlerts() != null && !featuregroup.getFeatureGroupAlerts().isEmpty()) {
        for (FeatureGroupAlert alert : featuregroup.getFeatureGroupAlerts()) {
            if (alert.getStatus().equals(ValidationRuleAlertStatus.getStatus(status))) {
                String name = featurestoreFacade.getHiveDbName(featuregroup.getFeaturestore().getHiveDbId());
                PostableAlert postableAlert = getPostableAlert(featuregroup.getFeaturestore().getProject().getName(), alert.getAlertType(), alert.getSeverity(), alert.getStatus().getName(), getExpectationResult(status, results), featuregroup.getId(), name, featuregroup.getName(), featuregroup.getVersion());
                postableAlerts.add(postableAlert);
            }
        }
    } else if (featuregroup.getFeaturestore().getProject().getProjectServiceAlerts() != null && !featuregroup.getFeaturestore().getProject().getProjectServiceAlerts().isEmpty()) {
        for (ProjectServiceAlert alert : featuregroup.getFeaturestore().getProject().getProjectServiceAlerts()) {
            if (ProjectServiceEnum.FEATURESTORE.equals(alert.getService()) && alert.getStatus().equals(ProjectServiceAlertStatus.getStatus(status))) {
                String name = featurestoreFacade.getHiveDbName(featuregroup.getFeaturestore().getHiveDbId());
                PostableAlert postableAlert = getPostableAlert(featuregroup.getFeaturestore().getProject().getName(), alert.getAlertType(), alert.getSeverity(), alert.getStatus().getName(), getExpectationResult(status, results), featuregroup.getId(), name, featuregroup.getName(), featuregroup.getVersion());
                postableAlerts.add(postableAlert);
            }
        }
    }
    return postableAlerts;
}
Also used : FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) ArrayList(java.util.ArrayList) PostableAlert(io.hops.hopsworks.alerting.api.alert.dto.PostableAlert) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert)

Example 2 with ProjectServiceAlert

use of io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert 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 ProjectServiceAlert

use of io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert in project hopsworks by logicalclocks.

the class ProjectAlertsResource method createAlert.

private ProjectAlertsDTO createAlert(PostableProjectAlerts projectAlertsDTO, UriInfo uriInfo, Project project, ResourceRequest resourceRequest) throws ProjectException {
    validate(projectAlertsDTO);
    ProjectServiceAlert projectServiceAlert = new ProjectServiceAlert();
    projectServiceAlert.setStatus(projectAlertsDTO.getStatus());
    projectServiceAlert.setSeverity(projectAlertsDTO.getSeverity());
    projectServiceAlert.setService(projectAlertsDTO.getService());
    projectServiceAlert.setCreated(new Date());
    projectServiceAlert.setProject(project);
    projectServiceAlert.setReceiver(getReceiver(projectAlertsDTO.getReceiver()));
    projectServiceAlert.setAlertType(alertController.getAlertType(projectServiceAlert.getReceiver()));
    createRoute(projectServiceAlert);
    projectServiceAlertsFacade.save(projectServiceAlert);
    projectServiceAlert = projectServiceAlertsFacade.findByProjectAndStatus(project, projectAlertsDTO.getStatus());
    return projectAlertsBuilder.buildItems(uriInfo, resourceRequest, projectServiceAlert);
}
Also used : ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Date(java.util.Date)

Example 4 with ProjectServiceAlert

use of io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert in project hopsworks by logicalclocks.

the class ProjectAlertsResource method createOrUpdate.

@PUT
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an alert.", response = ProjectAlertsDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response createOrUpdate(@PathParam("id") Integer id, ProjectAlertsDTO projectAlertsDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProjectException {
    ProjectServiceAlert projectServiceAlert = projectServiceAlertsFacade.findByProjectAndId(getProject(), id);
    if (projectServiceAlert == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.ALERT_NOT_FOUND, Level.FINE, "Alert not found. Id=" + id.toString());
    }
    if (projectAlertsDTO == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.ALERT_ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Project project = getProject();
    if (projectAlertsDTO.getStatus() != null) {
        if (!projectAlertsDTO.getStatus().equals(projectServiceAlert.getStatus()) && projectServiceAlertsFacade.findByProjectAndStatus(project, projectAlertsDTO.getStatus()) != null) {
            throw new ProjectException(RESTCodes.ProjectErrorCode.ALERT_ALREADY_EXISTS, Level.FINE, "Alert with projectId=" + project.getId() + " status=" + projectAlertsDTO.getStatus() + " already exists.");
        }
        projectServiceAlert.setStatus(projectAlertsDTO.getStatus());
    }
    if (projectAlertsDTO.getSeverity() != null) {
        projectServiceAlert.setSeverity(projectAlertsDTO.getSeverity());
    }
    if (!projectServiceAlert.getReceiver().getName().equals(projectAlertsDTO.getReceiver())) {
        deleteRoute(projectServiceAlert);
        projectServiceAlert.setReceiver(getReceiver(projectAlertsDTO.getReceiver()));
        projectServiceAlert.setAlertType(alertController.getAlertType(projectServiceAlert.getReceiver()));
        createRoute(projectServiceAlert);
    }
    projectServiceAlert = projectServiceAlertsFacade.update(projectServiceAlert);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ALERTS);
    ProjectAlertsDTO dto = projectAlertsBuilder.build(uriInfo, resourceRequest, projectServiceAlert);
    return Response.ok().entity(dto).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 5 with ProjectServiceAlert

use of io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert 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;
}
Also used : FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) ArrayList(java.util.ArrayList) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) Route(io.hops.hopsworks.alerting.config.dto.Route)

Aggregations

ProjectServiceAlert (io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert)9 Project (io.hops.hopsworks.persistence.entity.project.Project)4 ArrayList (java.util.ArrayList)4 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 FeatureGroupAlert (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert)3 JobAlert (io.hops.hopsworks.persistence.entity.jobs.description.JobAlert)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Path (javax.ws.rs.Path)3 PostableAlert (io.hops.hopsworks.alerting.api.alert.dto.PostableAlert)2 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)2 ProjectException (io.hops.hopsworks.exceptions.ProjectException)2 Date (java.util.Date)2 Produces (javax.ws.rs.Produces)2 AlertManagerAccessControlException (io.hops.hopsworks.alert.exception.AlertManagerAccessControlException)1 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)1 Alert (io.hops.hopsworks.alerting.api.alert.dto.Alert)1 Route (io.hops.hopsworks.alerting.config.dto.Route)1 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)1 AlertManagerResponseException (io.hops.hopsworks.alerting.exceptions.AlertManagerResponseException)1