use of co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpResponse 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.data2.datafabric.dataset.service.executor.DatasetAdminOpResponse in project cdap by caskdata.
the class DatasetInstanceService method executeAdmin.
/**
* Executes an admin operation on a dataset instance.
*
* @param instance the instance to execute the admin operation on
* @param method the type of admin operation to execute
* @return the {@link DatasetAdminOpResponse} from the HTTP handler
* @throws NamespaceNotFoundException if the requested namespace was not found
* @throws IOException if there was a problem in checking if the namespace exists over HTTP
* @throws UnauthorizedException if perimeter security and authorization are enabled, and the current user does not
* have -
* <ol>
* <li>{@link Action#ADMIN} privileges on the #instance (for "drop" or "truncate") </li>
* <li>any privileges on the #instance (for "exists")</li>
* <ol>
*/
DatasetAdminOpResponse executeAdmin(DatasetId instance, String method) throws Exception {
ensureNamespaceExists(instance.getParent());
Object result = null;
// NOTE: one cannot directly call create and drop, instead this should be called thru
// POST/DELETE @ /data/datasets/{instance-id}. Because we must create/drop metadata for these at same time
Principal principal = authenticationContext.getPrincipal();
switch(method) {
case "exists":
ensureAccess(instance);
result = opExecutorClient.exists(instance);
break;
case "truncate":
if (instanceManager.get(instance) == null) {
throw new DatasetNotFoundException(instance);
}
authorizationEnforcer.enforce(instance, principal, Action.ADMIN);
opExecutorClient.truncate(instance);
publishAudit(instance, AuditType.TRUNCATE);
break;
case "upgrade":
if (instanceManager.get(instance) == null) {
throw new DatasetNotFoundException(instance);
}
authorizationEnforcer.enforce(instance, principal, Action.ADMIN);
opExecutorClient.upgrade(instance);
publishAudit(instance, AuditType.UPDATE);
break;
default:
throw new HandlerException(HttpResponseStatus.NOT_FOUND, "Invalid admin operation: " + method);
}
return new DatasetAdminOpResponse(result, null);
}
Aggregations