use of io.hops.hopsworks.alert.exception.AlertManagerAccessControlException 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.alert.exception.AlertManagerAccessControlException in project hopsworks by logicalclocks.
the class AlertBuilder method items.
private AlertGroupDTO items(AlertGroupDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, AlertFilterBy alertFilterBy, Project project) throws AlertException {
uri(dto, uriInfo);
expandAlertGroups(dto, resourceRequest);
if (dto.isExpand()) {
List<AlertGroup> alertGroups;
try {
if (project != null) {
alertGroups = alertManager.getAlertGroups(alertFilterBy.isActive(), alertFilterBy.isSilenced(), alertFilterBy.isInhibited(), alertFilterBy.getFilter(), alertFilterBy.getReceiver(), project);
} else {
alertGroups = alertManager.getAlertGroups(alertFilterBy.isActive(), alertFilterBy.isSilenced(), alertFilterBy.isInhibited(), alertFilterBy.getFilter(), alertFilterBy.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) alertGroups.size());
return items(dto, uriInfo, resourceRequest, alertGroups);
}
return dto;
}
use of io.hops.hopsworks.alert.exception.AlertManagerAccessControlException in project hopsworks by logicalclocks.
the class RouteResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a route.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableRouteDTO routeDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (routeDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Route route = routeBuilder.toRoute(routeDTO);
try {
alertManagerConfiguration.addRoute(route, 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 (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());
} catch (AlertManagerNoSuchElementException e) {
throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, route, getProject());
routeBuilder.uriItem(dto, uriInfo, route);
return Response.created(dto.getHref()).entity(dto).build();
}
use of io.hops.hopsworks.alert.exception.AlertManagerAccessControlException in project hopsworks by logicalclocks.
the class SilenceBuilder method items.
private SilenceDTO items(SilenceDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, SilenceBeanParam silenceBeanParam, Project project) throws AlertException {
uri(dto, uriInfo);
expand(dto, resourceRequest);
if (dto.isExpand()) {
List<Silence> silenceList;
try {
if (project != null) {
silenceList = alertManager.getSilences(silenceBeanParam.getSilenceFilterBy().getFilter(), project);
} else {
silenceList = alertManager.getSilences(silenceBeanParam.getSilenceFilterBy().getFilter());
}
} catch (AlertManagerClientCreateException | AlertManagerUnreachableException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
} catch (AlertManagerResponseException e) {
throw new AlertException(RESTCodes.AlertErrorCode.RESPONSE_ERROR, Level.FINE, e.getMessage());
} catch (AlertManagerAccessControlException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
}
if (!Strings.isNullOrEmpty(silenceBeanParam.getSilenceFilterBy().getStatus())) {
silenceList = silenceList.stream().filter((s) -> s.getStatus().getState().equals(silenceBeanParam.getSilenceFilterBy().getStatus())).collect(Collectors.toList());
}
if (!Strings.isNullOrEmpty(silenceBeanParam.getSilenceFilterBy().getCreatedBy())) {
silenceList = silenceList.stream().filter((s) -> s.getCreatedBy().equals(silenceBeanParam.getSilenceFilterBy().getCreatedBy())).collect(Collectors.toList());
}
dto.setCount((long) silenceList.size());
return items(dto, uriInfo, resourceRequest, silenceList, silenceBeanParam);
}
return dto;
}
use of io.hops.hopsworks.alert.exception.AlertManagerAccessControlException in project hopsworks by logicalclocks.
the class AdminReceiverResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response create(PostableReceiverDTO postableReceiverDTO, @QueryParam("defaultName") @DefaultValue("false") Boolean defaultName, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
if (postableReceiverDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Receiver receiver;
try {
AlertType alertType = null;
if (defaultName || Strings.isNullOrEmpty(postableReceiverDTO.getName()) || AlertType.fromReceiverName(postableReceiverDTO.getName()) != null) {
alertType = getDefaultName(postableReceiverDTO);
postableReceiverDTO.setName(alertType.getReceiverName());
}
receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
alertManagerConfiguration.addReceiver(receiver);
if (alertType != null) {
// to create a single route for global receivers
alertController.createRoute(alertType);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), null);
dto.setHref(uriInfo.getAbsolutePathBuilder().path(receiver.getName()).build());
return Response.created(dto.getHref()).entity(dto).build();
} 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 (AlertManagerAccessControlException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ACCESS_CONTROL_EXCEPTION, Level.FINE, e.getMessage());
} catch (AlertManagerNoSuchElementException e) {
throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_NOT_FOUND, Level.FINE, e.getMessage());
}
}
Aggregations