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