Search in sources :

Example 1 with DatasetSystemMetadataProvider

use of io.cdap.cdap.data2.metadata.system.DatasetSystemMetadataProvider in project cdap by caskdata.

the class DatasetAdminService method computeSystemMetadata.

private SystemMetadata computeSystemMetadata(DatasetId datasetInstanceId, final DatasetSpecification spec, DatasetProperties props, final DatasetTypeMeta typeMeta, final DatasetType type, final DatasetContext context, boolean existing, UserGroupInformation ugi) throws IOException {
    // add system metadata for user datasets only
    if (DatasetsUtil.isUserDataset(datasetInstanceId)) {
        Dataset dataset = null;
        try {
            try {
                dataset = ImpersonationUtils.doAs(ugi, () -> type.getDataset(context, spec, DatasetDefinition.NO_ARGUMENTS));
            } catch (Exception e) {
                LOG.warn("Exception while instantiating Dataset {}", datasetInstanceId, e);
            }
            // Make sure to write whatever system metadata that can be derived
            // even if the above instantiation throws exception
            DatasetSystemMetadataProvider metadataProvider;
            if (existing) {
                metadataProvider = new DatasetSystemMetadataProvider(datasetInstanceId, props, dataset, typeMeta.getName(), spec.getDescription());
            } else {
                long createTime = System.currentTimeMillis();
                metadataProvider = new DatasetSystemMetadataProvider(datasetInstanceId, props, createTime, dataset, typeMeta.getName(), spec.getDescription());
            }
            return new SystemMetadata(metadataProvider.getSystemPropertiesToAdd(), metadataProvider.getSystemTagsToAdd(), metadataProvider.getSchemaToAdd());
        } finally {
            if (dataset != null) {
                dataset.close();
            }
        }
    }
    return SystemMetadata.EMPTY;
}
Also used : Dataset(io.cdap.cdap.api.dataset.Dataset) DatasetSystemMetadataProvider(io.cdap.cdap.data2.metadata.system.DatasetSystemMetadataProvider) SystemMetadata(io.cdap.cdap.data2.metadata.system.SystemMetadata) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) AccessException(io.cdap.cdap.api.security.AccessException) IOException(java.io.IOException) BadRequestException(io.cdap.cdap.common.BadRequestException) NotFoundException(io.cdap.cdap.common.NotFoundException)

Aggregations

Dataset (io.cdap.cdap.api.dataset.Dataset)1 IncompatibleUpdateException (io.cdap.cdap.api.dataset.IncompatibleUpdateException)1 AccessException (io.cdap.cdap.api.security.AccessException)1 BadRequestException (io.cdap.cdap.common.BadRequestException)1 NotFoundException (io.cdap.cdap.common.NotFoundException)1 DatasetSystemMetadataProvider (io.cdap.cdap.data2.metadata.system.DatasetSystemMetadataProvider)1 SystemMetadata (io.cdap.cdap.data2.metadata.system.SystemMetadata)1 IOException (java.io.IOException)1