Search in sources :

Example 1 with DatasetTypeNotFoundException

use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.

the class DatasetInstanceService method getTypeInfo.

/**
 * Finds the {@link DatasetTypeMeta} for the specified dataset type name.
 * Search order - first in the specified namespace, then in the 'system' namespace from defaultModules
 *
 * @param namespaceId {@link NamespaceId} for the specified namespace
 * @param typeName the name of the dataset type to search
 * @param byPassCheck a flag which determines whether to check privilege for the dataset type
 * @return {@link DatasetTypeMeta} for the type if found in either the specified namespace or in the system namespace,
 * null otherwise.
 * TODO: This may need to move to a util class eventually
 */
@Nullable
private DatasetTypeMeta getTypeInfo(NamespaceId namespaceId, String typeName, boolean byPassCheck) throws Exception {
    DatasetTypeId datasetTypeId = ConversionHelpers.toDatasetTypeId(namespaceId, typeName);
    try {
        LOG.trace("Retrieving metadata from mds for dataset type {} with authorization: {}", typeName, byPassCheck);
        DatasetTypeMeta meta = byPassCheck ? noAuthDatasetTypeService.getType(datasetTypeId) : authorizationDatasetTypeService.getType(datasetTypeId);
        LOG.trace("Retrieved metadata from mds for dataset type {}", typeName);
        return meta;
    } catch (DatasetTypeNotFoundException | UnauthorizedException e) {
        try {
            // Type not found in the instance's namespace. Now try finding it in the system namespace
            LOG.trace("Retrieving metadata from mds for system dataset type {}", typeName);
            DatasetTypeId systemDatasetTypeId = ConversionHelpers.toDatasetTypeId(NamespaceId.SYSTEM, typeName);
            LOG.trace("Retrieved metadata from mds for system dataset type {}", typeName);
            return noAuthDatasetTypeService.getType(systemDatasetTypeId);
        } catch (DatasetTypeNotFoundException exnWithSystemNS) {
            // if it's not found in system namespace, throw the original exception with the correct namespace
            throw e;
        }
    }
}
Also used : DatasetTypeId(io.cdap.cdap.proto.id.DatasetTypeId) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) Nullable(javax.annotation.Nullable)

Example 2 with DatasetTypeNotFoundException

use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.

the class DefaultDatasetTypeService method getType.

/**
 * Returns details of the specified {@link DatasetTypeId dataset type}.
 */
@Override
public DatasetTypeMeta getType(DatasetTypeId datasetTypeId) throws Exception {
    ensureNamespaceExists(datasetTypeId.getParent());
    DatasetTypeMeta typeMeta = typeManager.getTypeInfo(datasetTypeId);
    if (typeMeta == null) {
        throw new DatasetTypeNotFoundException(datasetTypeId);
    }
    return typeMeta;
}
Also used : DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException)

Example 3 with DatasetTypeNotFoundException

use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.

the class DatasetClient method create.

/**
 * Creates a dataset.
 *
 * @param instance ID of the dataset instance
 * @param properties properties of the dataset to create
 * @throws DatasetTypeNotFoundException if the desired dataset type was not found
 * @throws DatasetAlreadyExistsException if a dataset by the same name already exists
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public void create(DatasetId instance, DatasetInstanceConfiguration properties) throws DatasetTypeNotFoundException, DatasetAlreadyExistsException, IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s", instance.getDataset()));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new DatasetTypeNotFoundException(instance.getParent().datasetType(properties.getTypeName()));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
        throw new DatasetAlreadyExistsException(instance);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) DatasetAlreadyExistsException(io.cdap.cdap.common.DatasetAlreadyExistsException) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) URL(java.net.URL)

Example 4 with DatasetTypeNotFoundException

use of io.cdap.cdap.common.DatasetTypeNotFoundException in project cdap by caskdata.

the class DatasetTypeClient method get.

/**
 * Gets information about a dataset type.
 *
 * @param type the dataset type
 * @return {@link DatasetTypeMeta} of the dataset type
 * @throws DatasetTypeNotFoundException if the dataset type 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 DatasetTypeMeta get(DatasetTypeId type) throws DatasetTypeNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(type.getParent(), String.format("data/types/%s", type.getType()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new DatasetTypeNotFoundException(type);
    }
    return ObjectResponse.fromJsonBody(response, DatasetTypeMeta.class).getResponseObject();
}
Also used : DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) HttpResponse(io.cdap.common.http.HttpResponse) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) URL(java.net.URL)

Example 5 with DatasetTypeNotFoundException

use of io.cdap.cdap.common.DatasetTypeNotFoundException 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 StandardPermission#UPDATE} privilege on the #instance
 */
void update(DatasetId instance, Map<String, String> properties) throws Exception {
    ensureNamespaceExists(instance.getParent());
    Principal requestingUser = authenticationContext.getPrincipal();
    if (!DatasetsUtil.isSystemDatasetInUserNamespace(instance)) {
        accessEnforcer.enforce(instance, requestingUser, StandardPermission.UPDATE);
    }
    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);
    DatasetCreationResponse response = opExecutorClient.update(instance, typeMeta, datasetProperties, existing);
    DatasetSpecification spec = response.getSpec();
    instanceManager.add(instance.getParent(), spec);
    metaCache.invalidate(instance);
    updateExplore(instance, datasetProperties, existing, spec);
    publishAudit(instance, AuditType.UPDATE);
    publishMetadata(instance, response.getMetadata());
}
Also used : DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetCreationResponse(io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetCreationResponse) DatasetNotFoundException(io.cdap.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(io.cdap.cdap.common.DatasetTypeNotFoundException) Principal(io.cdap.cdap.proto.security.Principal)

Aggregations

DatasetTypeNotFoundException (io.cdap.cdap.common.DatasetTypeNotFoundException)9 DatasetTypeMeta (io.cdap.cdap.proto.DatasetTypeMeta)7 DatasetAlreadyExistsException (io.cdap.cdap.common.DatasetAlreadyExistsException)3 DatasetTypeId (io.cdap.cdap.proto.id.DatasetTypeId)3 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)2 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)2 DatasetNotFoundException (io.cdap.cdap.common.DatasetNotFoundException)2 HandlerException (io.cdap.cdap.common.HandlerException)2 DatasetCreationResponse (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetCreationResponse)2 DatasetInstanceConfiguration (io.cdap.cdap.proto.DatasetInstanceConfiguration)2 DatasetId (io.cdap.cdap.proto.id.DatasetId)2 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)2 Principal (io.cdap.cdap.proto.security.Principal)2 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)2 HttpResponse (io.cdap.common.http.HttpResponse)2 URL (java.net.URL)2 Test (org.junit.Test)2 DatasetTypeClient (io.cdap.cdap.client.DatasetTypeClient)1 NamespaceClient (io.cdap.cdap.client.NamespaceClient)1 FakeDataset (io.cdap.cdap.client.app.FakeDataset)1