Search in sources :

Example 71 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class RouteResource method get.

@GET
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get a route by receiver and match.", response = RouteDTO.class)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@PathParam("receiver") String receiver, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
    Route route = new Route(receiver).withMatch(routeBuilder.toMap(match)).withMatchRe(routeBuilder.toMap(matchRe));
    RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, route, getProject());
    return Response.ok().entity(dto).build();
}
Also used : ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Route(io.hops.hopsworks.alerting.config.dto.Route) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 72 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired 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();
}
Also used : AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) AlertManagerAccessControlException(io.hops.hopsworks.alert.exception.AlertManagerAccessControlException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerNoSuchElementException(io.hops.hopsworks.alerting.exceptions.AlertManagerNoSuchElementException) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) Route(io.hops.hopsworks.alerting.config.dto.Route) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 73 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class AdminRouteResource method get.

@GET
@Path("{receiver}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all routes.", response = RouteDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response get(@PathParam("receiver") String receiver, @QueryParam("match") List<String> match, @QueryParam("matchRe") List<String> matchRe, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
    Route route = new Route(receiver).withMatch(routeBuilder.toMap(match)).withMatchRe(routeBuilder.toMap(matchRe));
    RouteDTO dto = routeBuilder.build(uriInfo, resourceRequest, route, null);
    return Response.ok().entity(dto).build();
}
Also used : PostableRouteDTO(io.hops.hopsworks.api.alert.route.PostableRouteDTO) RouteDTO(io.hops.hopsworks.api.alert.route.RouteDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Route(io.hops.hopsworks.alerting.config.dto.Route) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Example 74 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class AdminSilenceResource method get.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all silences.", response = SilenceDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response get(@BeanParam Pagination pagination, @BeanParam SilenceBeanParam silenceBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.SILENCES);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    SilenceDTO dto = silenceBuilder.buildItems(uriInfo, resourceRequest, silenceBeanParam, null);
    return Response.ok().entity(dto).build();
}
Also used : SilenceDTO(io.hops.hopsworks.api.alert.silence.SilenceDTO) PostableSilenceDTO(io.hops.hopsworks.api.alert.silence.PostableSilenceDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Example 75 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class AdminSilenceResource method getById.

@GET
@Path("{silenceId}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find silence by Id.", response = SilenceDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response getById(@PathParam("silenceId") String silenceId, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.SILENCES);
    SilenceDTO dto = silenceBuilder.build(uriInfo, resourceRequest, silenceId, null);
    return Response.ok().entity(dto).build();
}
Also used : SilenceDTO(io.hops.hopsworks.api.alert.silence.SilenceDTO) PostableSilenceDTO(io.hops.hopsworks.api.alert.silence.PostableSilenceDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)292 Produces (javax.ws.rs.Produces)265 ApiOperation (io.swagger.annotations.ApiOperation)244 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)238 Path (javax.ws.rs.Path)203 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)171 Users (io.hops.hopsworks.persistence.entity.user.Users)169 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)151 GET (javax.ws.rs.GET)150 Consumes (javax.ws.rs.Consumes)73 POST (javax.ws.rs.POST)62 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)44 PUT (javax.ws.rs.PUT)42 DELETE (javax.ws.rs.DELETE)37 GenericEntity (javax.ws.rs.core.GenericEntity)30 Project (io.hops.hopsworks.persistence.entity.project.Project)24 AlertException (io.hops.hopsworks.exceptions.AlertException)20 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)16 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)16 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)16