use of io.hops.hopsworks.exceptions.AlertException 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.exceptions.AlertException in project hopsworks by logicalclocks.
the class FeatureGroupAlertResource 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 {
FeatureGroupAlert featureGroupAlert = featureGroupAlertFacade.findByFeatureGroupAndId(featuregroup, id);
List<Alert> alerts;
try {
alerts = alertController.testAlert(featuregroup.getFeaturestore().getProject(), featureGroupAlert);
} 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, featuregroup.getFeaturestore().getProject());
return Response.ok().entity(alertDTO).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class AlertBuilder method items.
private AlertDTO items(AlertDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, AlertBeanParam alertBeanParam, Project project) throws AlertException {
uri(dto, uriInfo);
expand(dto, resourceRequest);
if (dto.isExpand()) {
List<Alert> alerts;
try {
if (project != null) {
alerts = alertManager.getAlerts(alertBeanParam.getAlertFilterBy().isActive(), alertBeanParam.getAlertFilterBy().isSilenced(), alertBeanParam.getAlertFilterBy().isInhibited(), alertBeanParam.isUnprocessed(), alertBeanParam.getAlertFilterBy().getFilter(), alertBeanParam.getAlertFilterBy().getReceiver(), project);
} else {
alerts = alertManager.getAlerts(alertBeanParam.getAlertFilterBy().isActive(), alertBeanParam.getAlertFilterBy().isSilenced(), alertBeanParam.getAlertFilterBy().isInhibited(), alertBeanParam.isUnprocessed(), alertBeanParam.getAlertFilterBy().getFilter(), alertBeanParam.getAlertFilterBy().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) alerts.size());
return items(dto, uriInfo, resourceRequest, alertBeanParam, alerts);
}
return dto;
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class ReceiverResource method update.
@PUT
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a receiver.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@PathParam("name") String name, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, PostableReceiverDTO postableReceiverDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (postableReceiverDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Receiver receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
validateReceiverOneConfig(receiver);
try {
alertManagerConfiguration.updateReceiver(name, receiver, getProject());
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
} catch (AlertManagerDuplicateEntryException e) {
throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_EXIST, Level.FINE, e.getMessage());
} catch (AlertManagerConfigUpdateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
} catch (AlertManagerClientCreateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
} catch (AlertManagerNoSuchElementException e) {
throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
} catch (AlertManagerAccessControlException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
} catch (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), getProject());
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class RouteBuilder method items.
private RouteDTO items(RouteDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, RouteBeanParam routeBeanParam, Project project) throws AlertException {
uri(dto, uriInfo);
expand(dto, resourceRequest);
List<Route> routes;
if (dto.isExpand()) {
try {
if (project != null) {
routes = alertManagerConfiguration.getRoutes(project);
} else {
routes = alertManagerConfiguration.getRoutes();
}
} catch (AlertManagerConfigReadException | AlertManagerConfigCtrlCreateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
}
dto.setCount((long) routes.size());
return items(dto, uriInfo, resourceRequest, routeBeanParam, routes);
}
return dto;
}
Aggregations