use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.
the class ReceiverResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableReceiverDTO postableReceiverDTO, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, @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.addReceiver(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 (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());
dto.setHref(uriInfo.getAbsolutePathBuilder().path(receiver.getName()).build());
return Response.created(dto.getHref()).entity(dto).build();
}
use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException 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.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.
the class AlertManagerConfigController method addPagerdutyToReceiver.
/**
* @param name
* @param pagerdutyConfig
* @return updated AlertManagerConfig
* @throws IOException
* @throws AlertManagerNoSuchElementException
* @throws AlertManagerDuplicateEntryException
* @throws AlertManagerConfigUpdateException
* @throws IllegalArgumentException if pagerdutyConfig is missing both RoutingKey and ServiceKey
*/
public AlertManagerConfig addPagerdutyToReceiver(String name, PagerdutyConfig pagerdutyConfig) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
validate(pagerdutyConfig);
AlertManagerConfig alertManagerConfig = read();
int index = getIndexOfReceiver(alertManagerConfig, name);
Receiver receiverToUpdate = alertManagerConfig.getReceivers().get(index);
if (receiverToUpdate.getPagerdutyConfigs() == null) {
receiverToUpdate.setPagerdutyConfigs(new ArrayList<>());
}
if (receiverToUpdate.getPagerdutyConfigs().contains(pagerdutyConfig)) {
throw new AlertManagerDuplicateEntryException("A receiver with the same api url and channel already exists.");
}
receiverToUpdate.getPagerdutyConfigs().add(pagerdutyConfig);
return alertManagerConfig;
}
use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.
the class AlertManagerConfigController method addReceiver.
/**
* @param receiver
* @return updated AlertManagerConfig
* @throws IOException
* @throws AlertManagerDuplicateEntryException
* @throws AlertManagerConfigUpdateException
* @throws IllegalArgumentException if receiver is missing configuration
*/
public AlertManagerConfig addReceiver(Receiver receiver) throws AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
validate(receiver);
AlertManagerConfig alertManagerConfig = read();
if (alertManagerConfig.getReceivers() == null) {
alertManagerConfig.setReceivers(new ArrayList<>());
}
if (alertManagerConfig.getReceivers().contains(receiver)) {
throw new AlertManagerDuplicateEntryException("A receiver with the same name already exists.");
}
alertManagerConfig.getReceivers().add(receiver);
return alertManagerConfig;
}
use of io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException in project hopsworks by logicalclocks.
the class AlertManagerConfigController method updateReceiver.
/**
* @param name
* @param receiver
* @return updated AlertManagerConfig
* @throws IOException
* @throws AlertManagerNoSuchElementException
* @throws AlertManagerDuplicateEntryException
* @throws AlertManagerConfigUpdateException
* @throws IllegalArgumentException if receiver is missing configuration
*/
public AlertManagerConfig updateReceiver(String name, Receiver receiver) throws AlertManagerNoSuchElementException, AlertManagerDuplicateEntryException, AlertManagerConfigReadException {
validate(receiver);
AlertManagerConfig alertManagerConfig = read();
int index = getIndexOfReceiver(alertManagerConfig, name);
if (!name.equals(receiver.getName()) && alertManagerConfig.getReceivers().contains(receiver)) {
throw new AlertManagerDuplicateEntryException("A receiver with the same name already exists.");
}
alertManagerConfig.getReceivers().remove(index);
alertManagerConfig.getReceivers().add(receiver);
return alertManagerConfig;
}
Aggregations