Search in sources :

Example 1 with DatasetNotFoundException

use of co.cask.cdap.common.DatasetNotFoundException in project cdap by caskdata.

the class DatasetInstanceService method dropDataset.

/**
 * Drops a dataset.
 *
 * @param spec specification of dataset to be dropped.
 * @throws Exception on error.
 */
private void dropDataset(DatasetId instance, DatasetSpecification spec) throws Exception {
    LOG.info("Deleting dataset {}.{}", instance.getNamespace(), instance.getEntityName());
    disableExplore(instance, spec);
    if (!instanceManager.delete(instance)) {
        throw new DatasetNotFoundException(instance);
    }
    metaCache.invalidate(instance);
    // by pass the auth check for dataset type when the operation is not creation
    DatasetTypeMeta typeMeta = getTypeInfo(instance.getParent(), spec.getType(), true);
    if (typeMeta == null) {
        throw new DatasetNotFoundException(instance);
    }
    opExecutorClient.drop(instance, typeMeta, spec);
    publishAudit(instance, AuditType.DELETE);
    // deletes the owner principal for the entity if one was stored during creation
    ownerAdmin.delete(instance);
}
Also used : DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException)

Example 2 with DatasetNotFoundException

use of co.cask.cdap.common.DatasetNotFoundException 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":
            // ensure the user has some privilege on the dataset instance if it is not system dataset
            if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
                AuthorizationUtil.ensureAccess(instance, authorizationEnforcer, principal);
            }
            result = opExecutorClient.exists(instance);
            break;
        case "truncate":
            if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
                authorizationEnforcer.enforce(instance, principal, Action.ADMIN);
            }
            if (instanceManager.get(instance) == null) {
                throw new DatasetNotFoundException(instance);
            }
            opExecutorClient.truncate(instance);
            publishAudit(instance, AuditType.TRUNCATE);
            break;
        case "upgrade":
            if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
                authorizationEnforcer.enforce(instance, principal, Action.ADMIN);
            }
            if (instanceManager.get(instance) == null) {
                throw new DatasetNotFoundException(instance);
            }
            opExecutorClient.upgrade(instance);
            publishAudit(instance, AuditType.UPDATE);
            break;
        default:
            throw new HandlerException(HttpResponseStatus.NOT_FOUND, "Invalid admin operation: " + method);
    }
    return new DatasetAdminOpResponse(result, null);
}
Also used : HandlerException(co.cask.cdap.common.HandlerException) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetAdminOpResponse(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpResponse) Principal(co.cask.cdap.proto.security.Principal)

Example 3 with DatasetNotFoundException

use of co.cask.cdap.common.DatasetNotFoundException in project cdap by caskdata.

the class DatasetClient method delete.

/**
 * Deletes a dataset.
 *
 * @param instance the dataset to delete
 * @throws DatasetNotFoundException if the dataset with the specified name could not be found
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public void delete(DatasetId instance) throws DatasetNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s", instance.getDataset()));
    HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new DatasetNotFoundException(instance);
    }
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) URL(java.net.URL)

Example 4 with DatasetNotFoundException

use of co.cask.cdap.common.DatasetNotFoundException in project cdap by caskdata.

the class DatasetInstanceService method drop.

/**
 * Drops the specified dataset instance.
 *
 * @param instance the {@link DatasetId} to drop
 * @throws NamespaceNotFoundException if the namespace was not found
 * @throws DatasetNotFoundException if the dataset instance 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 {@link Action#ADMIN} privileges on the #instance
 */
void drop(DatasetId instance) throws Exception {
    if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
        authorizationEnforcer.enforce(instance, authenticationContext.getPrincipal(), Action.ADMIN);
    }
    ensureNamespaceExists(instance.getParent());
    DatasetSpecification spec = instanceManager.get(instance);
    if (spec == null) {
        throw new DatasetNotFoundException(instance);
    }
    dropDataset(instance, spec);
}
Also used : DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException)

Example 5 with DatasetNotFoundException

use of co.cask.cdap.common.DatasetNotFoundException in project cdap by caskdata.

the class DatasetInstanceService method update.

/**
 * Updates an existing Dataset specification properties.
 * {@link DatasetInstanceConfiguration} is constructed based on request and the Dataset instance is updated.
 *
 * @param instance the dataset instance
 * @param properties the dataset properties to be used
 * @throws NamespaceNotFoundException if the specified namespace was not found
 * @throws DatasetNotFoundException if the dataset was not found
 * @throws DatasetTypeNotFoundException if the type of the existing dataset was not found
 * @throws UnauthorizedException if perimeter security and authorization are enabled, and the current user does not
 *  have {@link Action#ADMIN} privilege on the #instance
 */
void update(DatasetId instance, Map<String, String> properties) throws Exception {
    ensureNamespaceExists(instance.getParent());
    if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
        authorizationEnforcer.enforce(instance, authenticationContext.getPrincipal(), Action.ADMIN);
    }
    DatasetSpecification existing = instanceManager.get(instance);
    if (existing == null) {
        throw new DatasetNotFoundException(instance);
    }
    LOG.info("Update dataset {}, properties: {}", instance.getEntityName(), ConversionHelpers.toJson(properties));
    // by pass the auth check for dataset type when the operation is not creation
    DatasetTypeMeta typeMeta = getTypeInfo(instance.getParent(), existing.getType(), true);
    if (typeMeta == null) {
        // Type not found in the instance's namespace and the system namespace. Bail out.
        throw new DatasetTypeNotFoundException(ConversionHelpers.toDatasetTypeId(instance.getParent(), existing.getType()));
    }
    // Note how we execute configure() via opExecutorClient (outside of ds service) to isolate running user code
    DatasetProperties datasetProperties = DatasetProperties.of(properties);
    DatasetSpecification spec = opExecutorClient.update(instance, typeMeta, datasetProperties, existing);
    instanceManager.add(instance.getParent(), spec);
    metaCache.invalidate(instance);
    updateExplore(instance, datasetProperties, existing, spec);
    publishAudit(instance, AuditType.UPDATE);
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException)

Aggregations

DatasetNotFoundException (co.cask.cdap.common.DatasetNotFoundException)5 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)2 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)2 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)1 HandlerException (co.cask.cdap.common.HandlerException)1 DatasetAdminOpResponse (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpResponse)1 Principal (co.cask.cdap.proto.security.Principal)1 HttpResponse (co.cask.common.http.HttpResponse)1 URL (java.net.URL)1