Search in sources :

Example 1 with SchematizedTagException

use of io.hops.hopsworks.exceptions.SchematizedTagException 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 2 with SchematizedTagException

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

the class ProvUsageBuilder method buildAccessible.

public ProvArtifactUsageParentDTO buildAccessible(UriInfo uriInfo, Users user, DatasetPath targetEndpoint, String artifactId, Set<ProvUsageType> type) throws ProvenanceException, GenericException, DatasetException, MetadataException, SchematizedTagException {
    if (!accessController.hasAccess(targetEndpoint.getAccessProject(), targetEndpoint.getDataset())) {
        throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.FINE);
    }
    ProvArtifactUsageParentDTO usage = new ProvArtifactUsageParentDTO();
    usage.setArtifactId(artifactId);
    DatasetDTO datasetDTO = datasetBuilder.build(uriInfo, new ResourceRequest(ResourceRequest.Name.DATASET), user, targetEndpoint);
    usage.setDataset(datasetDTO);
    usage.setProjectId(targetEndpoint.getDataset().getProject().getId());
    usage.setProjectName(targetEndpoint.getDataset().getProject().getName());
    ProvOpsParamBuilder params = getBasicUsageOpsParams(targetEndpoint.getDataset(), artifactId);
    ProvOpsDTO ops = opsBuilder.build(targetEndpoint.getDataset().getProject(), params, ProvOpsReturnType.AGGREGATIONS);
    Optional<ProvOpsDTO> aggregation = ops.getItems().stream().filter(agg -> agg.getAggregation() != null && agg.getAggregation().equals(ProvOpsAggregations.APP_USAGE.toString())).findFirst();
    if (!aggregation.isPresent()) {
        return usage;
    }
    Optional<ProvOpsDTO> artifact = aggregation.get().getItems().stream().filter(art -> art.getMlId().equals(artifactId)).findFirst();
    if (!artifact.isPresent()) {
        return usage;
    }
    for (ProvUsageType t : type) {
        switch(t) {
            case READ_CURRENT:
                usage.setReadCurrent(usage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA, true));
                break;
            case WRITE_CURRENT:
                usage.setWriteCurrent(usage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA, true));
                break;
            case READ_LAST:
                lastUsage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA).ifPresent(usage::setReadLast);
                break;
            case WRITE_LAST:
                lastUsage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA).ifPresent(usage::setWriteLast);
                break;
            case READ_HISTORY:
                usage.setReadHistory(usage(uriInfo, artifact.get(), Provenance.FileOps.ACCESS_DATA, false));
                break;
            case WRITE_HISTORY:
                usage.setWriteHistory(usage(uriInfo, artifact.get(), Provenance.FileOps.MODIFY_DATA, false));
                break;
        }
    }
    return usage;
}
Also used : DatasetDTO(io.hops.hopsworks.api.dataset.DatasetDTO) UserFacade(io.hops.hopsworks.common.dao.user.UserFacade) ProvOps(io.hops.hopsworks.common.provenance.ops.ProvOps) AccessController(io.hops.hopsworks.common.util.AccessController) ExecutionFacade(io.hops.hopsworks.common.dao.jobhistory.ExecutionFacade) ExecutionsBuilder(io.hops.hopsworks.api.jobs.executions.ExecutionsBuilder) HdfsUsersFacade(io.hops.hopsworks.common.dao.hdfsUser.HdfsUsersFacade) Provenance(io.hops.hopsworks.common.provenance.core.Provenance) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Execution(io.hops.hopsworks.persistence.entity.jobs.history.Execution) Level(java.util.logging.Level) UsersBuilder(io.hops.hopsworks.api.user.UsersBuilder) TransactionAttributeType(javax.ejb.TransactionAttributeType) MetadataException(io.hops.hopsworks.exceptions.MetadataException) TransactionAttribute(javax.ejb.TransactionAttribute) ProvOpsAggregations(io.hops.hopsworks.common.provenance.ops.ProvOpsAggregations) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UserDTO(io.hops.hopsworks.api.user.UserDTO) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) JobsBuilder(io.hops.hopsworks.api.jobs.JobsBuilder) EJB(javax.ejb.EJB) ExecutionDTO(io.hops.hopsworks.api.jobs.executions.ExecutionDTO) Stateless(javax.ejb.Stateless) Longs(com.google.common.primitives.Longs) ProvArtifactUsageParentDTO(io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO) ProvOpsDTO(io.hops.hopsworks.common.provenance.ops.dto.ProvOpsDTO) DatasetDTO(io.hops.hopsworks.api.dataset.DatasetDTO) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Set(java.util.Set) ProvArtifactUsageDTO(io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageDTO) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) ProvOpsParamBuilder(io.hops.hopsworks.common.provenance.ops.ProvOpsParamBuilder) List(java.util.List) ProvUsageType(io.hops.hopsworks.common.provenance.ops.ProvUsageType) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) GenericException(io.hops.hopsworks.exceptions.GenericException) ProvOpsReturnType(io.hops.hopsworks.common.provenance.ops.ProvOpsReturnType) DatasetPath(io.hops.hopsworks.common.dataset.util.DatasetPath) JobDTO(io.hops.hopsworks.api.jobs.JobDTO) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) Users(io.hops.hopsworks.persistence.entity.user.Users) Comparator(java.util.Comparator) DatasetBuilder(io.hops.hopsworks.api.dataset.DatasetBuilder) SchematizedTagException(io.hops.hopsworks.exceptions.SchematizedTagException) ProvArtifactUsageParentDTO(io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO) ProvOpsParamBuilder(io.hops.hopsworks.common.provenance.ops.ProvOpsParamBuilder) ProvOpsDTO(io.hops.hopsworks.common.provenance.ops.dto.ProvOpsDTO) ProvUsageType(io.hops.hopsworks.common.provenance.ops.ProvUsageType) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) GenericException(io.hops.hopsworks.exceptions.GenericException)

Aggregations

ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)2 GenericException (io.hops.hopsworks.exceptions.GenericException)2 MetadataException (io.hops.hopsworks.exceptions.MetadataException)2 SchematizedTagException (io.hops.hopsworks.exceptions.SchematizedTagException)2 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)2 Users (io.hops.hopsworks.persistence.entity.user.Users)2 Collectors (java.util.stream.Collectors)2 Longs (com.google.common.primitives.Longs)1 DatasetBuilder (io.hops.hopsworks.api.dataset.DatasetBuilder)1 DatasetDTO (io.hops.hopsworks.api.dataset.DatasetDTO)1 JobDTO (io.hops.hopsworks.api.jobs.JobDTO)1 JobsBuilder (io.hops.hopsworks.api.jobs.JobsBuilder)1 ExecutionDTO (io.hops.hopsworks.api.jobs.executions.ExecutionDTO)1 ExecutionsBuilder (io.hops.hopsworks.api.jobs.executions.ExecutionsBuilder)1 ModelRegistryDTO (io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO)1 ModelsBuilder (io.hops.hopsworks.api.modelregistry.models.ModelsBuilder)1 ProvArtifactUsageDTO (io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageDTO)1 ProvArtifactUsageParentDTO (io.hops.hopsworks.api.provenance.ops.dto.ProvArtifactUsageParentDTO)1 UserDTO (io.hops.hopsworks.api.user.UserDTO)1 UsersBuilder (io.hops.hopsworks.api.user.UsersBuilder)1