use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class ModelsResource method get.
@ApiOperation(value = "Get a model", response = ModelDTO.class)
@GET
@Path("{id}")
@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.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@PathParam("id") String id, @BeanParam ModelsBeanParam modelsBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ProvenanceException, ModelRegistryException, DatasetException, GenericException, SchematizedTagException, MetadataException {
Users user = jwtHelper.getUserPrincipal(sc);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.MODELS);
resourceRequest.setExpansions(modelsBeanParam.getExpansions().getResources());
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
if (fileState != null) {
ModelDTO dto = modelsBuilder.build(uriInfo, resourceRequest, user, userProject, modelRegistryProject, fileState, modelUtils.getModelsDatasetPath(userProject, modelRegistryProject));
if (dto == null) {
throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.FINE);
} else {
return Response.ok().entity(dto).build();
}
} else {
throw new ModelRegistryException(RESTCodes.ModelRegistryErrorCode.MODEL_NOT_FOUND, Level.FINE);
}
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class ModelsResource method bulkPutTags.
@ApiOperation(value = "Create or update tags(bulk) for a model", response = TagsDTO.class)
@PUT
@Path("/{id}/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.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response bulkPutTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, TagsDTO tags) throws MetadataException, SchematizedTagException, DatasetException, ProvenanceException, ModelRegistryException {
Users user = jwtHelper.getUserPrincipal(sc);
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
AttachTagResult result;
if (tags.getItems().size() == 0) {
result = tagController.upsert(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), tags.getName(), tags.getValue());
} else {
Map<String, String> newTags = new HashMap<>();
for (TagsDTO tag : tags.getItems()) {
newTags.put(tag.getName(), tag.getValue());
}
result = tagController.upsertAll(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), newTags);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), 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();
}
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class ModelsResource method put.
@ApiOperation(value = "Create or update a model", response = ModelDTO.class)
@PUT
@Path("{id}")
@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.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response put(@PathParam("id") String id, ModelDTO modelDTO, @QueryParam("jobName") String jobName, @QueryParam("kernelId") String kernelId, @Context HttpServletRequest req, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ModelRegistryException, JobException, ServiceException, PythonException, MetadataException, GenericException, ProjectException {
if (modelDTO == null) {
throw new IllegalArgumentException("Model summary not provided");
}
modelUtils.validateModelName(modelDTO);
Users user = jwtHelper.getUserPrincipal(sc);
Project modelProject = modelUtils.getModelsProjectAndCheckAccess(modelDTO, userProject);
Project experimentProject = modelUtils.getExperimentProjectAndCheckAccess(modelDTO, userProject);
ModelsController.Accessor accessor = modelUtils.getModelsAccessor(user, userProject, modelProject, experimentProject);
try {
return modelUtils.createModel(uriInfo, accessor, id, modelDTO, jobName, kernelId);
} finally {
dfs.closeDfsClient(accessor.udfso);
}
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class ModelsResource method deleteTag.
@ApiOperation(value = "Delete tag attached to a model")
@DELETE
@Path("/{id}/tags/{name}")
@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.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response deleteTag(@Context SecurityContext sc, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name) throws DatasetException, MetadataException, ProvenanceException, ModelRegistryException {
Users user = jwtHelper.getUserPrincipal(sc);
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
tagController.delete(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), name);
return Response.noContent().build();
}
use of io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired in project hopsworks by logicalclocks.
the class KafkaResource method getTopicAcls.
@ApiOperation(value = "Get all ACLs for a specified topic.")
@GET
@Path("/topics/{topic}/acls")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopicAcls(@Context UriInfo uriInfo, @PathParam("topic") String topicName, @BeanParam Pagination pagination, @BeanParam AclsBeanParam aclsBeanParam, @Context SecurityContext sc) {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(aclsBeanParam.getSortBySet());
resourceRequest.setFilter(aclsBeanParam.getFilter());
AclDTO dto = aclBuilder.build(uriInfo, project, topicName, resourceRequest);
return Response.ok().entity(dto).build();
}
Aggregations