use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class DatasetInstanceService method dropAll.
/**
* Drops all datasets in the given namespace. If authorization is turned on, only datasets that the current
* principal that has {@link Action#ADMIN} privilege will be deleted
*
* @param namespaceId namespace to operate on
* @throws Exception if it fails to delete dataset
* @return the set of {@link DatasetId} that get deleted
*/
Set<DatasetId> dropAll(NamespaceId namespaceId) throws Exception {
ensureNamespaceExists(namespaceId);
Principal principal = authenticationContext.getPrincipal();
Set<DatasetId> datasets = new HashSet<>();
for (DatasetSpecification spec : instanceManager.getAll(namespaceId)) {
try {
DatasetId datasetId = namespaceId.dataset(spec.getName());
authorizationEnforcer.enforce(datasetId, principal, Action.ADMIN);
dropDataset(datasetId, spec);
datasets.add(datasetId);
} catch (UnauthorizedException e) {
// It's ok to be not authorized. Just skip the deletion.
}
}
return datasets;
}
use of co.cask.cdap.proto.id.DatasetId in project cdap by caskdata.
the class DatasetInstanceHandler method executeAdmin.
/**
* Executes an admin operation on a dataset instance.
*
* @param namespaceId namespace of the dataset instance
* @param name name of the dataset instance
* @param method the admin operation to execute (e.g. "exists", "truncate", "upgrade")
* @throws Exception
*/
@POST
@Path("/data/datasets/{name}/admin/{method}")
public void executeAdmin(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name, @PathParam("method") String method) throws Exception {
DatasetId instance = ConversionHelpers.toDatasetInstanceId(namespaceId, name);
try {
DatasetAdminOpResponse response = instanceService.executeAdmin(instance, method);
responder.sendJson(HttpResponseStatus.OK, response);
} catch (HandlerException e) {
responder.sendStatus(e.getFailureStatus());
}
}
use of co.cask.cdap.proto.id.DatasetId 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.proto.id.DatasetId in project cdap by caskdata.
the class DatasetAdminOpHTTPHandler method exists.
@POST
@Path("/data/datasets/{name}/admin/exists")
public void exists(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) {
propagateUserId(request);
NamespaceId namespace = new NamespaceId(namespaceId);
try {
DatasetId instanceId = namespace.dataset(instanceName);
responder.sendJson(HttpResponseStatus.OK, new DatasetAdminOpResponse(datasetAdminService.exists(instanceId), null));
} catch (NotFoundException e) {
LOG.debug("Got handler exception", e);
responder.sendString(HttpResponseStatus.NOT_FOUND, StringUtils.defaultIfEmpty(e.getMessage(), ""));
} catch (Exception e) {
LOG.error(getAdminOpErrorMessage("exists", instanceName), e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, getAdminOpErrorMessage("exists", instanceName));
}
}
use of co.cask.cdap.proto.id.DatasetId 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