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();
}
}
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()));
}
}));
}
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();
}
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());
}
}
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());
}
}
Aggregations