Search in sources :

Example 1 with MetadataException

use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.

the class XAttrsResource method get.

@ApiOperation(value = "Get extended attributes attached to a path.", response = XAttrDTO.class)
@GET
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam("pathType") @DefaultValue("DATASET") DatasetType pathType, @QueryParam("name") String xattrName) throws DatasetException, MetadataException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Map<String, String> result = new HashMap<>();
    DistributedFileSystemOps udfso = dfs.getDfsOps(hdfsUsersController.getHdfsUserName(project, user));
    String inodePath = datasetHelper.getDatasetPathIfFileExist(project, path, pathType).getFullPath().toString();
    try {
        if (xattrName != null) {
            String xattr = xattrsController.getXAttr(inodePath, xattrName, udfso);
            if (Strings.isNullOrEmpty(xattr)) {
                throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
            }
            result.put(xattrName, xattr);
        } else {
            result.putAll(xattrsController.getXAttrs(inodePath, udfso));
        }
    } finally {
        dfs.closeDfsClient(udfso);
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.XATTRS);
    XAttrDTO dto = xattrsBuilder.build(uriInfo, resourceRequest, project, inodePath, result);
    return Response.ok().entity(dto).build();
}
Also used : HashMap(java.util.HashMap) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) MetadataException(io.hops.hopsworks.exceptions.MetadataException) 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 2 with MetadataException

use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.

the class ModelRegistryBuilder method build.

// Build collection
public ModelRegistryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project project) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
    ModelRegistryDTO dto = new ModelRegistryDTO();
    uri(dto, uriInfo, project);
    expand(dto, resourceRequest);
    Collection<Dataset> dsInProject = project.getDatasetCollection();
    // Add all datasets shared with the project
    dsInProject.addAll(project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).map(DatasetSharedWith::getDataset).collect(Collectors.toList()));
    Collection<Dataset> modelsDatasets = dsInProject.stream().filter(ds -> ds.getName().equals(Settings.HOPS_MODELS_DATASET)).collect(Collectors.toList());
    dto.setCount((long) modelsDatasets.size());
    for (Dataset ds : modelsDatasets) {
        ModelRegistryDTO modelRegistryDTO = build(uriInfo, resourceRequest, user, project, ds.getProject());
        if (modelRegistryDTO != null) {
            dto.addItem(modelRegistryDTO);
        }
    }
    return dto;
}
Also used : Stateless(javax.ejb.Stateless) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO) ModelsBuilder(io.hops.hopsworks.api.modelregistry.models.ModelsBuilder) Collection(java.util.Collection) ModelRegistryException(io.hops.hopsworks.exceptions.ModelRegistryException) Collectors(java.util.stream.Collectors) Project(io.hops.hopsworks.persistence.entity.project.Project) Settings(io.hops.hopsworks.common.util.Settings) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) TransactionAttributeType(javax.ejb.TransactionAttributeType) GenericException(io.hops.hopsworks.exceptions.GenericException) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) MetadataException(io.hops.hopsworks.exceptions.MetadataException) TransactionAttribute(javax.ejb.TransactionAttribute) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriInfo(javax.ws.rs.core.UriInfo) Users(io.hops.hopsworks.persistence.entity.user.Users) EJB(javax.ejb.EJB) SchematizedTagException(io.hops.hopsworks.exceptions.SchematizedTagException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO)

Example 3 with MetadataException

use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.

the class ExperimentsResource method post.

@ApiOperation(value = "Create or update an experiment", response = ExperimentDTO.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" })
public Response post(@PathParam("id") String id, ExperimentDTO experimentDTO, @QueryParam("type") ExperimentOperationType type, @Context HttpServletRequest req, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ProvenanceException, PythonException, MetadataException, ProjectException, GenericException, ExperimentsException {
    if (experimentDTO == null) {
        throw new IllegalArgumentException("No Experiment configuration was provided");
    }
    Users user = jwtHelper.getUserPrincipal(sc);
    Project experimentProject = project;
    switch(type) {
        case INIT:
            {
                String experimentPath = Utils.getProjectPath(project.getName()) + Settings.HOPS_EXPERIMENTS_DATASET + "/" + id + "/" + Settings.ENVIRONMENT_FILE;
                experimentDTO.setEnvironment(environmentController.exportEnv(experimentProject, user, experimentPath));
                try {
                    String program = experimentsController.versionProgram(experimentProject, user, experimentDTO.getJobName(), experimentDTO.getKernelId(), id);
                    experimentDTO.setProgram(program);
                } catch (Exception e) {
                    LOGGER.log(Level.SEVERE, "Could not version notebook " + e.getMessage());
                }
            }
            break;
        case MODEL_UPDATE:
            {
                Project modelProject = getModelsProjectAndCheckAccess(experimentDTO);
                experimentsController.attachModel(user, experimentProject, id, modelProject, experimentDTO.getModel());
            }
            break;
        case FULL_UPDATE:
            {
            // no need to update the summary in any way
            }
            break;
        default:
            {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "unhandled experiment summary operation type:" + type);
            }
    }
    experimentsController.attachExperiment(user, experimentProject, id, experimentDTO);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder().path(id);
    switch(type) {
        case INIT:
            return Response.created(builder.build()).entity(experimentDTO).build();
        case MODEL_UPDATE:
        case FULL_UPDATE:
            return Response.ok(builder.build()).entity(experimentDTO).build();
        default:
            {
                throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "unhandled experiment summary operation type:" + type);
            }
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) UriBuilder(javax.ws.rs.core.UriBuilder) GenericException(io.hops.hopsworks.exceptions.GenericException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) GenericException(io.hops.hopsworks.exceptions.GenericException) PythonException(io.hops.hopsworks.exceptions.PythonException) MetadataException(io.hops.hopsworks.exceptions.MetadataException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) Path(javax.ws.rs.Path) 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) PUT(javax.ws.rs.PUT)

Example 4 with MetadataException

use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.

the class XAttrsController method addXAttr.

public boolean addXAttr(Project project, Users user, String inodePath, String name, String metaObj) throws DatasetException, MetadataException {
    if (name == null || name.isEmpty()) {
        throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
    }
    JSONObject metaJSON = null;
    Object json = new JSONTokener(metaObj).nextValue();
    if (json instanceof JSONObject) {
        metaJSON = (JSONObject) json;
    } else if (json instanceof JSONArray) {
        metaJSON = new JSONObject();
        metaJSON.put(name, json.toString());
    }
    if (!metaJSON.has(name)) {
        throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
    }
    String metadata = metaJSON.getString(name);
    boolean created = getXAttr(project, user, inodePath, XATTR_USER_NAMESPACE, name) == null;
    addXAttrInt(project, user, inodePath, name, metadata);
    return created;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) MetadataException(io.hops.hopsworks.exceptions.MetadataException)

Example 5 with MetadataException

use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.

the class HopsFSProvenanceController method setProvCoreXAttr.

private void setProvCoreXAttr(String path, ProvCoreDTO provCore, DistributedFileSystemOps udfso) throws ProvenanceException {
    try {
        String provType = converter.marshal(provCore);
        xattrCtrl.upsertProvXAttr(udfso, path, ProvXAttrs.PROV_XATTR_CORE_VAL, provType.getBytes());
    } catch (GenericException | DatasetException | MetadataException e) {
        throw new ProvenanceException(RESTCodes.ProvenanceErrorCode.FS_ERROR, Level.WARNING, "hopsfs - set xattr - prov core - error", "hopsfs - set xattr - prov core - error", e);
    }
}
Also used : ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) GenericException(io.hops.hopsworks.exceptions.GenericException) MetadataException(io.hops.hopsworks.exceptions.MetadataException) DatasetException(io.hops.hopsworks.exceptions.DatasetException)

Aggregations

MetadataException (io.hops.hopsworks.exceptions.MetadataException)8 GenericException (io.hops.hopsworks.exceptions.GenericException)5 DatasetException (io.hops.hopsworks.exceptions.DatasetException)4 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)4 Users (io.hops.hopsworks.persistence.entity.user.Users)4 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)3 HashMap (java.util.HashMap)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 ExperimentsException (io.hops.hopsworks.exceptions.ExperimentsException)2 SchematizedTagException (io.hops.hopsworks.exceptions.SchematizedTagException)2 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)2 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)2 Project (io.hops.hopsworks.persistence.entity.project.Project)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Map (java.util.Map)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Longs (com.google.common.primitives.Longs)1 DatasetBuilder (io.hops.hopsworks.api.dataset.DatasetBuilder)1 DatasetDTO (io.hops.hopsworks.api.dataset.DatasetDTO)1