Search in sources :

Example 6 with DatasetType

use of co.cask.cdap.data2.datafabric.dataset.DatasetType in project cdap by caskdata.

the class InMemoryDatasetOpExecutor method update.

@Override
public DatasetSpecification update(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props, DatasetSpecification existing) throws Exception {
    DatasetType type = client.getDatasetType(typeMeta, null, new ConstantClassLoaderProvider());
    if (type == null) {
        throw new IllegalArgumentException("Dataset type cannot be instantiated for provided type meta: " + typeMeta);
    }
    try {
        DatasetSpecification spec = type.reconfigure(datasetInstanceId.getEntityName(), props, existing);
        DatasetAdmin admin = type.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec);
        if (admin instanceof Updatable) {
            ((Updatable) admin).update(existing);
        } else {
            admin.create();
        }
        if (spec.getDescription() == null && existing.getDescription() != null) {
            spec.setDescription(existing.getDescription());
        }
        return spec;
    } catch (IncompatibleUpdateException e) {
        throw new ConflictException(e.getMessage());
    }
}
Also used : ConflictException(co.cask.cdap.common.ConflictException) Updatable(co.cask.cdap.api.dataset.Updatable) ConstantClassLoaderProvider(co.cask.cdap.data2.datafabric.dataset.type.ConstantClassLoaderProvider) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) DatasetType(co.cask.cdap.data2.datafabric.dataset.DatasetType) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException)

Aggregations

DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)5 DatasetType (co.cask.cdap.data2.datafabric.dataset.DatasetType)5 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)3 BadRequestException (co.cask.cdap.common.BadRequestException)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 ConstantClassLoaderProvider (co.cask.cdap.data2.datafabric.dataset.type.ConstantClassLoaderProvider)3 IOException (java.io.IOException)3 Updatable (co.cask.cdap.api.dataset.Updatable)2 DatasetClassLoaderProvider (co.cask.cdap.data2.datafabric.dataset.type.DatasetClassLoaderProvider)2 DirectoryClassLoaderProvider (co.cask.cdap.data2.datafabric.dataset.type.DirectoryClassLoaderProvider)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 Dataset (co.cask.cdap.api.dataset.Dataset)1 DatasetContext (co.cask.cdap.api.dataset.DatasetContext)1 ConflictException (co.cask.cdap.common.ConflictException)1 DatasetSystemMetadataWriter (co.cask.cdap.data2.metadata.system.DatasetSystemMetadataWriter)1 SystemMetadataWriter (co.cask.cdap.data2.metadata.system.SystemMetadataWriter)1 Callable (java.util.concurrent.Callable)1