use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class ManagementResource method updateGlobal.
@PUT
@Path("global")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateGlobal(Global global, @Context SecurityContext sc) throws AlertException {
Global dto;
try {
alertManagerConfiguration.updateGlobal(global);
dto = alertManagerConfiguration.getGlobal();
} 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 AdminRouteResource 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(PostableRouteDTO routeDTO, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
if (routeDTO == null) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
}
Route route = routeBuilder.toRoute(routeDTO);
try {
alertManagerConfiguration.addRoute(route);
} 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());
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, route, null);
return Response.created(dto.getHref()).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class AdminRouteResource method update.
@PUT
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
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 {
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);
} 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());
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, updatedRoute, null);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class AdminSilenceResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a silence.", response = SilenceDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response create(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);
SilenceID silenceID = postSilence(postableSilenceDTO, user);
return Response.created(uriInfo.getAbsolutePathBuilder().path(silenceID.getSilenceID()).build()).build();
}
use of io.hops.hopsworks.exceptions.AlertException in project hopsworks by logicalclocks.
the class AdminSilenceResource method postSilence.
private SilenceID postSilence(PostableSilenceDTO postableSilenceDTO, Users users) throws AlertException {
PostableSilence postableSilence = silenceBuilder.getPostableSilence(postableSilenceDTO);
postableSilence.setCreatedBy(users.getEmail());
try {
return alertManager.postSilences(postableSilence);
} 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());
}
}
Aggregations