use of io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO in project hopsworks by logicalclocks.
the class ModelsResource method getTags.
@ApiOperation(value = "Get all tags attached to a model", response = TagsDTO.class)
@GET
@Path("/{id}/tags")
@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 getTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException, ProvenanceException, ModelRegistryException {
Users user = jwtHelper.getUserPrincipal(sc);
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
Map<String, String> result = tagController.getAll(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()));
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), result);
return Response.status(Response.Status.OK).entity(dto).build();
}
use of io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO in project hopsworks by logicalclocks.
the class ModelsBuilder method build.
// Build collection
public ModelDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project userProject, Project modelRegistryProject) throws ModelRegistryException, GenericException, SchematizedTagException, MetadataException {
ModelDTO dto = new ModelDTO();
uri(dto, uriInfo, userProject, modelRegistryProject);
expand(dto, resourceRequest);
dto.setCount(0l);
if (dto.isExpand()) {
validatePagination(resourceRequest);
ProvStateDTO fileState;
try {
Pair<ProvStateParamBuilder, ModelRegistryDTO> provFilesParamBuilder = buildModelProvenanceParams(userProject, modelRegistryProject, resourceRequest);
if (provFilesParamBuilder.getValue1() == null) {
// no endpoint - no results
return dto;
}
fileState = provenanceController.provFileStateList(provFilesParamBuilder.getValue1().getParentProject(), provFilesParamBuilder.getValue0());
List<ProvStateDTO> models = new LinkedList<>(fileState.getItems());
dto.setCount(fileState.getCount());
String modelsDatasetPath = modelUtils.getModelsDatasetPath(userProject, modelRegistryProject);
for (ProvStateDTO fileProvStateHit : models) {
ModelDTO modelDTO = build(uriInfo, resourceRequest, user, userProject, modelRegistryProject, fileProvStateHit, modelsDatasetPath);
if (modelDTO != null) {
dto.addItem(modelDTO);
}
}
} catch (ProvenanceException e) {
if (ProvHelper.missingMappingForField(e)) {
LOGGER.log(Level.WARNING, "Could not find elastic mapping for experiments query", e);
return dto;
} else {
throw new ModelRegistryException(RESTCodes.ModelRegistryErrorCode.MODEL_LIST_FAILED, Level.FINE, "Unable to list models for project " + modelRegistryProject.getName(), e.getMessage(), e);
}
} catch (DatasetException e) {
throw new ModelRegistryException(RESTCodes.ModelRegistryErrorCode.MODEL_LIST_FAILED, Level.FINE, "Unable to list models for project " + modelRegistryProject.getName(), e.getMessage(), e);
}
}
return dto;
}
use of io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO in project hopsworks by logicalclocks.
the class ModelsResource method getTag.
@ApiOperation(value = "Get tag attached to a model", response = TagsDTO.class)
@GET
@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 getTag(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException, ProvenanceException, ModelRegistryException {
Users user = jwtHelper.getUserPrincipal(sc);
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
Map<String, String> result = new HashMap<>();
result.put(name, tagController.get(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), name));
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), result);
return Response.status(Response.Status.OK).entity(dto).build();
}
use of io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO in project hopsworks by logicalclocks.
the class ModelsResource method putTag.
@ApiOperation(value = "Create or update one tag for a model", response = TagsDTO.class)
@PUT
@Path("/{id}/tags/{name}")
@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 putTag(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @ApiParam(value = "Name of the tag", required = true) @PathParam("name") String name, @ApiParam(value = "Value to set for the tag") String value) throws MetadataException, SchematizedTagException, DatasetException, ProvenanceException, ModelRegistryException {
Users user = jwtHelper.getUserPrincipal(sc);
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
AttachTagResult result = tagController.upsert(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()), name, value);
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.modelregistry.models.dto.ModelDTO in project hopsworks by logicalclocks.
the class ModelsResource method deleteTags.
@ApiOperation(value = "Delete all tags attached to a model")
@DELETE
@Path("/{id}/tags")
@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 deleteTags(@Context SecurityContext sc, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id) throws DatasetException, MetadataException, ProvenanceException, ModelRegistryException {
Users user = jwtHelper.getUserPrincipal(sc);
ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
tagController.deleteAll(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()));
return Response.noContent().build();
}
Aggregations