Search in sources :

Example 1 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class InMemoryDatasetFramework method getInstances.

@Override
public Collection<DatasetSpecificationSummary> getInstances(NamespaceId namespaceId) {
    readLock.lock();
    try {
        // don't expect this to be called a lot.
        // might be better to maintain this collection separately and just return it, but seems like its not worth it.
        Collection<DatasetSpecification> specs = instances.row(namespaceId).values();
        ImmutableList.Builder<DatasetSpecificationSummary> specSummaries = ImmutableList.builder();
        for (DatasetSpecification spec : specs) {
            specSummaries.add(new DatasetSpecificationSummary(spec.getName(), spec.getType(), spec.getProperties()));
        }
        return specSummaries.build();
    } finally {
        readLock.unlock();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetSpecificationSummary(co.cask.cdap.proto.DatasetSpecificationSummary)

Example 2 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class DatasetInstanceService method list.

/**
   * Lists all dataset instances in a namespace. If perimeter security and authorization are enabled, only returns the
   * dataset instances that the current user has access to.
   *
   * @param namespace the namespace to list datasets for
   * @return the dataset instances in the provided namespace
   * @throws NotFoundException if the namespace was not found
   * @throws IOException if there is a problem in making an HTTP request to check if the namespace exists
   */
Collection<DatasetSpecification> list(final NamespaceId namespace) throws Exception {
    Principal principal = authenticationContext.getPrincipal();
    ensureNamespaceExists(namespace);
    Collection<DatasetSpecification> datasets = instanceManager.getAll(namespace);
    final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
    return Lists.newArrayList(Iterables.filter(datasets, new com.google.common.base.Predicate<DatasetSpecification>() {

        @Override
        public boolean apply(DatasetSpecification spec) {
            return filter.apply(namespace.dataset(spec.getName()));
        }
    }));
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) Principal(co.cask.cdap.proto.security.Principal) Predicate(co.cask.cdap.api.Predicate)

Example 3 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification in project cdap by caskdata.

the class DatasetInstanceService method getOriginalProperties.

/**
   * Return the original properties of a dataset instance, that is, the properties with which the dataset was
   * created or last reconfigured.
   * @param instance the id of the dataset
   * @return The original properties as stored in the dataset's spec, or if they are not available, a best effort
   *   to derive the original properties from the top-level properties of the spec
   * @throws UnauthorizedException if perimeter security and authorization are enabled, and the current user does not
   *   have any privileges on the #instance
   */
Map<String, String> getOriginalProperties(DatasetId instance) throws Exception {
    DatasetSpecification spec = instanceManager.get(instance);
    if (spec == null) {
        throw new NotFoundException(instance);
    }
    // Only return the properties if authorization succeeds
    ensureAccess(instance);
    return DatasetsUtil.fixOriginalProperties(spec).getOriginalProperties();
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 4 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification 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 5 with DatasetSpecification

use of co.cask.cdap.api.dataset.DatasetSpecification 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)

Aggregations

DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)72 DatasetId (co.cask.cdap.proto.id.DatasetId)21 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)17 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)15 Test (org.junit.Test)14 DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)11 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)10 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)9 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 AbstractDatasetDefinition (co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition)7 BadRequestException (co.cask.cdap.common.BadRequestException)7 IOException (java.io.IOException)7 DatasetSpecificationSummary (co.cask.cdap.proto.DatasetSpecificationSummary)6 Map (java.util.Map)6 DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)5 Reconfigurable (co.cask.cdap.api.dataset.Reconfigurable)4 Updatable (co.cask.cdap.api.dataset.Updatable)4