Search in sources :

Example 1 with DatasetTypeMeta

use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetTypeService method listTypes.

/**
   * Lists all {@link DatasetType dataset types} in the specified {@link NamespaceId}.
   */
List<DatasetTypeMeta> listTypes(final NamespaceId namespaceId) throws Exception {
    ensureNamespaceExists(namespaceId);
    // Sorting by name for convenience
    List<DatasetTypeMeta> allTypes = Lists.newArrayList(typeManager.getTypes(namespaceId));
    Collections.sort(allTypes, new Comparator<DatasetTypeMeta>() {

        @Override
        public int compare(DatasetTypeMeta o1, DatasetTypeMeta o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Principal principal = authenticationContext.getPrincipal();
    final Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
    Iterable<DatasetTypeMeta> authorizedDatasetTypes = Iterables.filter(allTypes, new com.google.common.base.Predicate<DatasetTypeMeta>() {

        @Override
        public boolean apply(DatasetTypeMeta datasetTypeMeta) {
            DatasetTypeId datasetTypeId = namespaceId.datasetType(datasetTypeMeta.getName());
            return authFilter.apply(datasetTypeId);
        }
    });
    return Lists.newArrayList(authorizedDatasetTypes);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) Principal(co.cask.cdap.proto.security.Principal)

Example 2 with DatasetTypeMeta

use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetAdminOpHTTPHandler method create.

@POST
@Path("/data/datasets/{name}/admin/create")
public void create(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) {
    propagateUserId(request);
    InternalDatasetCreationParams params = GSON.fromJson(request.getContent().toString(Charsets.UTF_8), InternalDatasetCreationParams.class);
    Preconditions.checkArgument(params.getProperties() != null, "Missing required 'instanceProps' parameter.");
    Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
    DatasetProperties props = params.getProperties();
    DatasetTypeMeta typeMeta = params.getTypeMeta();
    try {
        DatasetId instanceId = new DatasetId(namespaceId, name);
        DatasetSpecification spec = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, null);
        responder.sendJson(HttpResponseStatus.OK, spec);
    } catch (BadRequestException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (Exception e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) BadRequestException(co.cask.cdap.common.BadRequestException) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with DatasetTypeMeta

use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetAdminOpHTTPHandler method update.

@POST
@Path("/data/datasets/{name}/admin/update")
public void update(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) {
    propagateUserId(request);
    InternalDatasetUpdateParams params = GSON.fromJson(request.getContent().toString(Charsets.UTF_8), InternalDatasetUpdateParams.class);
    Preconditions.checkArgument(params.getProperties() != null, "Missing required 'instanceProps' parameter.");
    Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
    Preconditions.checkArgument(params.getExistingSpec() != null, "Missing required 'existingSpec' parameter.");
    DatasetProperties props = params.getProperties();
    DatasetSpecification existing = params.getExistingSpec();
    DatasetTypeMeta typeMeta = params.getTypeMeta();
    try {
        DatasetId instanceId = new DatasetId(namespaceId, name);
        DatasetSpecification spec = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
        responder.sendJson(HttpResponseStatus.OK, spec);
    } catch (NotFoundException e) {
        LOG.debug("Got handler exception", e);
        responder.sendString(HttpResponseStatus.NOT_FOUND, StringUtils.defaultIfEmpty(e.getMessage(), ""));
    } catch (BadRequestException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (IncompatibleUpdateException e) {
        responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage());
    } catch (Exception e) {
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) DatasetId(co.cask.cdap.proto.id.DatasetId) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with DatasetTypeMeta

use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetTypeService method getType.

/**
   * Returns details of the specified {@link DatasetTypeId dataset type}.
   */
DatasetTypeMeta getType(DatasetTypeId datasetTypeId) throws Exception {
    ensureNamespaceExists(datasetTypeId.getParent());
    DatasetTypeMeta typeMeta = typeManager.getTypeInfo(datasetTypeId);
    if (typeMeta == null) {
        throw new DatasetTypeNotFoundException(datasetTypeId);
    }
    // TODO: Test if this can be removed
    if (NamespaceId.SYSTEM.equals(datasetTypeId.getParent())) {
        return typeMeta;
    }
    // only return the type if the user has some privileges on it
    Principal principal = authenticationContext.getPrincipal();
    Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
    if (!authFilter.apply(datasetTypeId)) {
        throw new UnauthorizedException(principal, datasetTypeId);
    }
    return typeMeta;
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) Principal(co.cask.cdap.proto.security.Principal)

Example 5 with DatasetTypeMeta

use of co.cask.cdap.proto.DatasetTypeMeta in project cdap by caskdata.

the class DatasetModulesDeployer method deployModules.

/**
   * Deploy the given dataset modules.
   *
   * @param namespaceId namespace to deploy to
   * @param modules the dataset modules to deploy
   * @param jarLocation the location of the jar file containing the modules
   * @throws Exception if there was a problem deploying a module
   */
void deployModules(NamespaceId namespaceId, Map<String, String> modules, Location jarLocation, ClassLoader artifactClassLoader) throws Exception {
    List<String> implicitModules = new ArrayList<>();
    for (Map.Entry<String, String> moduleEntry : modules.entrySet()) {
        String moduleName = moduleEntry.getKey();
        String typeName = moduleEntry.getValue();
        if (systemDatasetFramework.hasSystemType(typeName)) {
            LOG.info("Not adding dataset type '{}' because it is defined by the system.", typeName);
            continue;
        }
        // Filter out the implicit modules: They have to be deployed last.
        if (moduleName.startsWith(".implicit.")) {
            implicitModules.add(typeName);
            continue;
        }
        loadAndDeployModule(artifactClassLoader, typeName, jarLocation, moduleName, namespaceId);
    }
    for (String typeName : implicitModules) {
        DatasetTypeId typeId = namespaceId.datasetType(typeName);
        DatasetTypeMeta typeMeta = datasetFramework.getTypeInfo(typeId);
        if (typeMeta != null) {
            String existingModule = Iterables.getLast(typeMeta.getModules()).getName();
            if (modules.containsKey(existingModule)) {
                // it was deployed already as part of one of the explicit deployModule() calls
                continue;
            }
        }
        loadAndDeployModule(artifactClassLoader, typeName, jarLocation, typeName, namespaceId);
    }
}
Also used : DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) ArrayList(java.util.ArrayList) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) Map(java.util.Map)

Aggregations

DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)25 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)9 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)8 DatasetId (co.cask.cdap.proto.id.DatasetId)8 DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)7 BadRequestException (co.cask.cdap.common.BadRequestException)6 NotFoundException (co.cask.cdap.common.NotFoundException)6 POST (javax.ws.rs.POST)6 Path (javax.ws.rs.Path)6 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)5 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)5 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)4 DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)4 Principal (co.cask.cdap.proto.security.Principal)3 RowMaker (co.cask.cdap.cli.util.RowMaker)2 Table (co.cask.cdap.cli.util.table.Table)2 DatasetTypeClient (co.cask.cdap.client.DatasetTypeClient)2 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 DatasetMeta (co.cask.cdap.proto.DatasetMeta)2 EntityId (co.cask.cdap.proto.id.EntityId)2