Search in sources :

Example 41 with ApiKeyRequired

use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired 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 42 with ApiKeyRequired

use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.

the class ServingService method startOrStop.

@POST
@Path("/{servingId}")
@Consumes(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 = "Start or stop a Serving instance")
public Response startOrStop(@Context SecurityContext sc, @ApiParam(value = "ID of the Serving instance to start/stop", required = true) @PathParam("servingId") Integer servingId, @ApiParam(value = "Action", required = true) @QueryParam("action") ServingCommands servingCommand) throws ServingException {
    Users user = jWTHelper.getUserPrincipal(sc);
    if (servingId == null) {
        throw new IllegalArgumentException("servingId was not provided");
    }
    if (servingCommand == null) {
        throw new IllegalArgumentException(RESTCodes.ServingErrorCode.COMMANDNOTPROVIDED.getMessage());
    }
    servingController.startOrStop(project, user, servingId, servingCommand);
    return Response.ok().build();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) 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 43 with ApiKeyRequired

use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.

the class FeaturestoreStorageConnectorService method createNewStorageConnector.

/**
 * Endpoint for creating a storage connector with a particular type in a feature store
 *
 * @return a JSON representation of the connector
 * @throws FeaturestoreException
 */
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Create a new storage connector for the feature store", response = FeaturestoreStorageConnectorDTO.class)
public Response createNewStorageConnector(@Context SecurityContext sc, FeaturestoreStorageConnectorDTO featurestoreStorageConnectorDTO) throws FeaturestoreException, UserException, ProjectException {
    if (featurestoreStorageConnectorDTO == null) {
        throw new IllegalArgumentException("Input JSON for creating a new Feature Store Storage Connector Cannot be " + "null");
    }
    Users user = jWTHelper.getUserPrincipal(sc);
    FeaturestoreStorageConnectorDTO createdFeaturestoreStorageConnectorDTO = storageConnectorController.createStorageConnector(user, project, featurestore, featurestoreStorageConnectorDTO);
    GenericEntity<FeaturestoreStorageConnectorDTO> featurestoreStorageConnectorDTOGenericEntity = new GenericEntity<FeaturestoreStorageConnectorDTO>(createdFeaturestoreStorageConnectorDTO) {
    };
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(featurestoreStorageConnectorDTOGenericEntity).build();
}
Also used : GenericEntity(javax.ws.rs.core.GenericEntity) FeaturestoreStorageConnectorDTO(io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) 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) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 44 with ApiKeyRequired

use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.

the class TrainingDatasetService method delete.

/**
 * Endpoint for deleting a training dataset, this will delete both the metadata and the data storage
 *
 * @param trainingdatasetid the id of the trainingDataset
 * @return JSON representation of the deleted trainingDataset
 * @throws FeaturestoreException
 * @throws DatasetException
 * @throws ProjectException
 */
@DELETE
@Path("/{trainingdatasetid: [0-9]+}")
@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.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Delete a training datasets with a specific id from a featurestore", response = TrainingDatasetDTO.class)
public Response delete(@Context SecurityContext sc, @ApiParam(value = "Id of the training dataset", required = true) @PathParam("trainingdatasetid") Integer trainingdatasetid) throws FeaturestoreException {
    verifyIdProvided(trainingdatasetid);
    Users user = jWTHelper.getUserPrincipal(sc);
    String trainingDsName = trainingDatasetController.delete(user, project, featurestore, trainingdatasetid);
    activityFacade.persistActivity(ActivityFacade.DELETED_TRAINING_DATASET + trainingDsName, project, user, ActivityFlag.SERVICE);
    return Response.ok().build();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) DELETE(javax.ws.rs.DELETE) 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)

Example 45 with ApiKeyRequired

use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.

the class TrainingDatasetService method bulkPutTags.

@ApiOperation(value = "Create or update tags(bulk) for a training dataset", response = TagsDTO.class)
@PUT
@Path("/{trainingDatasetId}/tags")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response bulkPutTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the training dataset", required = true) @PathParam("trainingDatasetId") Integer trainingDatasetId, TagsDTO tags) throws MetadataException, FeaturestoreException, SchematizedTagException, DatasetException {
    verifyIdProvided(trainingDatasetId);
    Users user = jWTHelper.getUserPrincipal(sc);
    TrainingDataset trainingDataset = trainingDatasetController.getTrainingDatasetById(featurestore, trainingDatasetId);
    AttachTagResult result;
    if (tags.getItems().size() == 0) {
        result = tagController.upsert(project, user, featurestore, trainingDataset, tags.getName(), tags.getValue());
    } else {
        Map<String, String> newTags = new HashMap<>();
        for (TagsDTO tag : tags.getItems()) {
            newTags.put(tag.getName(), tag.getValue());
        }
        result = tagController.upsert(project, user, featurestore, trainingDataset, newTags);
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, project, featurestore.getId(), ResourceRequest.Name.TRAININGDATASETS.name(), trainingDatasetId, result.getItems());
    UriBuilder builder = uriInfo.getAbsolutePathBuilder();
    if (result.isCreated()) {
        return Response.created(builder.build()).entity(dto).build();
    } else {
        return Response.ok(builder.build()).entity(dto).build();
    }
}
Also used : TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) HashMap(java.util.HashMap) TrainingDataset(io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDataset) AttachTagResult(io.hops.hopsworks.common.tags.AttachTagResult) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriBuilder(javax.ws.rs.core.UriBuilder) Path(javax.ws.rs.Path) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) 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)

Aggregations

ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)175 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)171 ApiOperation (io.swagger.annotations.ApiOperation)169 Produces (javax.ws.rs.Produces)165 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)159 Path (javax.ws.rs.Path)124 Users (io.hops.hopsworks.persistence.entity.user.Users)116 GET (javax.ws.rs.GET)96 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)94 Consumes (javax.ws.rs.Consumes)45 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)38 POST (javax.ws.rs.POST)32 DELETE (javax.ws.rs.DELETE)26 GenericEntity (javax.ws.rs.core.GenericEntity)25 PUT (javax.ws.rs.PUT)23 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)15 Featuregroup (io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup)11 UriBuilder (javax.ws.rs.core.UriBuilder)11 Project (io.hops.hopsworks.persistence.entity.project.Project)10 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)9