Search in sources :

Example 1 with ServingWrapper

use of io.hops.hopsworks.common.serving.ServingWrapper in project hopsworks by logicalclocks.

the class ServingService method put.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Create or update a serving instance")
public Response put(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "serving specification", required = true) ServingView serving) throws ServingException, ServiceException, KafkaException, ProjectException, UserException, InterruptedException, ExecutionException, UnsupportedEncodingException {
    Users user = jWTHelper.getUserPrincipal(sc);
    if (serving == null) {
        throw new IllegalArgumentException("serving was not provided");
    }
    ServingWrapper servingWrapper = serving.getServingWrapper();
    servingUtil.validateUserInput(servingWrapper, project);
    servingController.put(project, user, servingWrapper);
    ServingView servingView = new ServingView(servingWrapper);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder().path(String.valueOf(servingView.getId()));
    GenericEntity<ServingView> servingEntity = new GenericEntity<ServingView>(servingView) {
    };
    return Response.created(builder.build()).entity(servingEntity).build();
}
Also used : ServingWrapper(io.hops.hopsworks.common.serving.ServingWrapper) GenericEntity(javax.ws.rs.core.GenericEntity) Users(io.hops.hopsworks.persistence.entity.user.Users) UriBuilder(javax.ws.rs.core.UriBuilder) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 2 with ServingWrapper

use of io.hops.hopsworks.common.serving.ServingWrapper in project hopsworks by logicalclocks.

the class ServingService method get.

@GET
@Path("/{servingId}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Get info about a serving instance for the project", response = ServingView.class)
public Response get(@Context SecurityContext sc, @ApiParam(value = "Id of the Serving instance", required = true) @PathParam("servingId") Integer servingId) throws ServingException, KafkaException, CryptoPasswordNotFoundException {
    if (servingId == null) {
        throw new IllegalArgumentException("servingId was not provided");
    }
    ServingWrapper servingWrapper = servingController.get(project, servingId);
    ServingView servingView = new ServingView(servingWrapper);
    GenericEntity<ServingView> servingEntity = new GenericEntity<ServingView>(servingView) {
    };
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(servingEntity).build();
}
Also used : ServingWrapper(io.hops.hopsworks.common.serving.ServingWrapper) GenericEntity(javax.ws.rs.core.GenericEntity) 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) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 3 with ServingWrapper

use of io.hops.hopsworks.common.serving.ServingWrapper in project hopsworks by logicalclocks.

the class ServingView method getServingWrapper.

@JsonIgnore
public ServingWrapper getServingWrapper() {
    ServingWrapper servingWrapper = new ServingWrapper(new Serving(id, name, description, modelPath, modelName, modelVersion, predictor, requestedInstances, batchingEnabled, modelServer, servingTool));
    servingWrapper.setKafkaTopicDTO(kafkaTopicDTO);
    return servingWrapper;
}
Also used : Serving(io.hops.hopsworks.persistence.entity.serving.Serving) ServingWrapper(io.hops.hopsworks.common.serving.ServingWrapper) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 4 with ServingWrapper

use of io.hops.hopsworks.common.serving.ServingWrapper in project hopsworks by logicalclocks.

the class ServingService method getAll.

@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Get the list of serving instances for the project", response = ServingView.class, responseContainer = "List")
public Response getAll(@QueryParam("model") String modelName, @QueryParam("status") ServingStatusEnum status, @QueryParam("name") String servingName, @Context SecurityContext sc) throws ServingException, KafkaException, CryptoPasswordNotFoundException {
    // if filter by name, return a single serving
    if (!Strings.isNullOrEmpty(servingName)) {
        ServingWrapper servingWrapper = servingController.get(project, servingName);
        ServingView servingView = new ServingView(servingWrapper);
        GenericEntity<ServingView> servingEntity = new GenericEntity<ServingView>(servingView) {
        };
        return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(servingEntity).build();
    }
    List<ServingWrapper> servingDAOList = servingController.getAll(project, modelName, status);
    ArrayList<ServingView> servingViewList = new ArrayList<>();
    for (ServingWrapper servingWrapper : servingDAOList) {
        servingViewList.add(new ServingView(servingWrapper));
    }
    GenericEntity<ArrayList<ServingView>> genericListServingView = new GenericEntity<ArrayList<ServingView>>(servingViewList) {
    };
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(genericListServingView).build();
}
Also used : ServingWrapper(io.hops.hopsworks.common.serving.ServingWrapper) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

ServingWrapper (io.hops.hopsworks.common.serving.ServingWrapper)4 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Produces (javax.ws.rs.Produces)3 GenericEntity (javax.ws.rs.core.GenericEntity)3 GET (javax.ws.rs.GET)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Serving (io.hops.hopsworks.persistence.entity.serving.Serving)1 Users (io.hops.hopsworks.persistence.entity.user.Users)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 UriBuilder (javax.ws.rs.core.UriBuilder)1