Search in sources :

Example 1 with JobAlert

use of io.hops.hopsworks.persistence.entity.jobs.description.JobAlert 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)

Example 2 with JobAlert

use of io.hops.hopsworks.persistence.entity.jobs.description.JobAlert in project hopsworks by logicalclocks.

the class JobAlertsResource method createAlert.

private JobAlertsDTO createAlert(PostableJobAlerts jobAlertsDTO, UriInfo uriInfo, ResourceRequest resourceRequest) throws JobException {
    validate(jobAlertsDTO);
    JobAlert jobAlert = new JobAlert();
    jobAlert.setStatus(jobAlertsDTO.getStatus());
    jobAlert.setSeverity(jobAlertsDTO.getSeverity());
    jobAlert.setCreated(new Date());
    jobAlert.setJobId(job);
    jobAlert.setReceiver(getReceiver(jobAlertsDTO.getReceiver()));
    jobAlert.setAlertType(alertController.getAlertType(jobAlert.getReceiver()));
    createRoute(jobAlert);
    jobalertsFacade.save(jobAlert);
    jobAlert = jobalertsFacade.findByJobAndStatus(job, jobAlertsDTO.getStatus());
    return jobalertsBuilder.buildItems(uriInfo, resourceRequest, jobAlert);
}
Also used : JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) Date(java.util.Date)

Example 3 with JobAlert

use of io.hops.hopsworks.persistence.entity.jobs.description.JobAlert in project hopsworks by logicalclocks.

the class JobAlertsResource method createOrUpdate.

@PUT
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an alert.", response = JobAlertsDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response createOrUpdate(@PathParam("id") Integer id, JobAlertsDTO jobAlertsDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws JobException {
    JobAlert jobAlert = jobalertsFacade.findByJobAndId(job, id);
    if (jobAlert == null) {
        throw new JobException(RESTCodes.JobErrorCode.JOB_ALERT_NOT_FOUND, Level.FINE, "Job alert not found. Id=" + id.toString());
    }
    if (jobAlertsDTO == null) {
        throw new JobException(RESTCodes.JobErrorCode.JOB_ALERT_ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    if (jobAlertsDTO.getStatus() != null) {
        if (!jobAlertsDTO.getStatus().equals(jobAlert.getStatus()) && jobalertsFacade.findByJobAndStatus(job, jobAlertsDTO.getStatus()) != null) {
            throw new JobException(RESTCodes.JobErrorCode.JOB_ALERT_ALREADY_EXISTS, Level.FINE, "Job alert with jobId=" + job.getId() + " status=" + jobAlertsDTO.getStatus() + " already exists.");
        }
        jobAlert.setStatus(jobAlertsDTO.getStatus());
    }
    if (jobAlertsDTO.getSeverity() != null) {
        jobAlert.setSeverity(jobAlertsDTO.getSeverity());
    }
    if (!jobAlert.getReceiver().getName().equals(jobAlertsDTO.getReceiver())) {
        deleteRoute(jobAlert);
        jobAlert.setReceiver(getReceiver(jobAlertsDTO.getReceiver()));
        createRoute(jobAlert);
    }
    jobAlert.setAlertType(alertController.getAlertType(jobAlert.getReceiver()));
    jobAlert = jobalertsFacade.update(jobAlert);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ALERTS);
    JobAlertsDTO dto = jobalertsBuilder.build(uriInfo, resourceRequest, jobAlert);
    return Response.ok().entity(dto).build();
}
Also used : JobException(io.hops.hopsworks.exceptions.JobException) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) 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 4 with JobAlert

use of io.hops.hopsworks.persistence.entity.jobs.description.JobAlert 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)

Example 5 with JobAlert

use of io.hops.hopsworks.persistence.entity.jobs.description.JobAlert in project hopsworks by logicalclocks.

the class JobAlertsResource method deleteById.

@DELETE
@Path("{id}")
@ApiOperation(value = "Delete alert by Id.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response deleteById(@PathParam("id") Integer id, @Context UriInfo uriInfo, @Context SecurityContext sc) throws JobException {
    JobAlert jobAlert = jobalertsFacade.findByJobAndId(job, id);
    if (jobAlert != null) {
        deleteRoute(jobAlert);
        jobalertsFacade.remove(jobAlert);
    }
    return Response.noContent().build();
}
Also used : JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

JobAlert (io.hops.hopsworks.persistence.entity.jobs.description.JobAlert)7 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 ProjectServiceAlert (io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)2 FeatureGroupAlert (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert)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 PostableAlert (io.hops.hopsworks.alerting.api.alert.dto.PostableAlert)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 AlertDTO (io.hops.hopsworks.api.alert.AlertDTO)1 AlertException (io.hops.hopsworks.exceptions.AlertException)1