use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class RouteResource method update.
@PUT
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a route.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@PathParam("receiver") String receiver, PostableRouteDTO route, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (route == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Route routeToUpdate = new Route(receiver).withMatch(routeBuilder.toMap(match)).withMatchRe(routeBuilder.toMap(matchRe));
Route updatedRoute = routeBuilder.toRoute(route);
try {
alertManagerConfiguration.updateRoute(routeToUpdate, updatedRoute, 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.ROUTE_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.ROUTES);
RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, updatedRoute, getProject());
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class SilenceResource method update.
@PUT
@Path("{silenceId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a silence.", response = SilenceDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@PathParam("silenceId") String silenceId, PostableSilenceDTO postableSilenceDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
if (postableSilenceDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Users user = jWTHelper.getUserPrincipal(sc);
postableSilenceDTO.setId(silenceId);
Project project = getProject();
SilenceID silenceID = postSilence(postableSilenceDTO, project, user);
SilenceDTO dto = silenceBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.SILENCES), silenceID.getSilenceID(), project);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class AdminReceiverResource method getDefaultName.
private AlertType getDefaultName(PostableReceiverDTO postableReceiverDTO) throws AlertException {
AlertType alertType = null;
int configs = 0;
if (postableReceiverDTO.getEmailConfigs() != null && postableReceiverDTO.getEmailConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_EMAIL;
configs++;
}
if (postableReceiverDTO.getSlackConfigs() != null && postableReceiverDTO.getSlackConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_SLACK;
configs++;
}
if (postableReceiverDTO.getPagerdutyConfigs() != null && postableReceiverDTO.getPagerdutyConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_PAGERDUTY;
configs++;
}
if (postableReceiverDTO.getPushoverConfigs() != null && postableReceiverDTO.getPushoverConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_PUSHOVER;
configs++;
}
if (postableReceiverDTO.getOpsgenieConfigs() != null && postableReceiverDTO.getOpsgenieConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_OPSGENIE;
configs++;
}
if (postableReceiverDTO.getWebhookConfigs() != null && postableReceiverDTO.getWebhookConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_WEBHOOK;
configs++;
}
if (postableReceiverDTO.getVictoropsConfigs() != null && postableReceiverDTO.getVictoropsConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_VICTOROPS;
configs++;
}
if (postableReceiverDTO.getWechatConfigs() != null && postableReceiverDTO.getWechatConfigs().size() > 0) {
alertType = AlertType.GLOBAL_ALERT_WEBCHAT;
configs++;
}
if (configs > 1 || alertType == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "Receiver name not set.");
}
return alertType;
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class ManagementResource method updateInhibitRules.
@PUT
@Path("inhibit")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateInhibitRules(PostableInhibitRulesDTOList postableInhibitRulesDTOList, @Context SecurityContext sc) throws AlertException {
List<InhibitRule> inhibitRules = toInhibitRules(postableInhibitRulesDTOList);
InhibitRulesDTO dto = new InhibitRulesDTO();
try {
alertManagerConfiguration.updateInhibitRules(inhibitRules);
List<InhibitRule> i = alertManagerConfiguration.getInhibitRules();
dto.setInhibitRules(i);
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, 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 (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class ManagementResource method updateRoute.
@PUT
@Path("route")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateRoute(PostableRouteDTO routeDTO, @Context SecurityContext sc) throws AlertException {
Route route = routeBuilder.toRoute(routeDTO);
Route dto;
try {
alertManagerConfiguration.updateRoute(route);
dto = alertManagerConfiguration.getGlobalRoute();
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, 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 (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
return Response.ok().entity(dto).build();
}
Aggregations