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;
}
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);
}
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();
}
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();
}
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();
}
Aggregations