use of co.cask.cdap.api.dataset.Updatable in project cdap by caskdata.
the class CubeDatasetAdmin method update.
@Override
public void update(DatasetSpecification oldSpec) throws IOException {
// update all existing resolution tables, create all new resolutions
for (Map.Entry<String, DatasetSpecification> entry : spec.getSpecifications().entrySet()) {
DatasetSpecification oldSubSpec = spec.getSpecification(entry.getKey());
DatasetAdmin subAdmin = delegates.get(entry.getKey());
if (oldSubSpec != null && subAdmin instanceof Updatable) {
((Updatable) subAdmin).update(oldSubSpec);
} else if (oldSubSpec == null) {
subAdmin.create();
}
}
// TODO (CDAP-6342) delete all resolutions that were removed as part of the update
}
use of co.cask.cdap.api.dataset.Updatable in project cdap by caskdata.
the class InMemoryDatasetFramework method updateInstance.
@Override
public void updateInstance(DatasetId datasetInstanceId, DatasetProperties props) throws DatasetManagementException, IOException {
writeLock.lock();
try {
DatasetSpecification oldSpec = instances.get(datasetInstanceId.getParent(), datasetInstanceId);
if (oldSpec == null) {
throw new InstanceNotFoundException(datasetInstanceId.getEntityName());
}
DatasetDefinition def = getDefinitionForType(datasetInstanceId.getParent(), oldSpec.getType());
if (def == null) {
throw new DatasetManagementException(String.format("Dataset type '%s' is neither registered in the '%s' namespace nor in the system namespace", oldSpec.getType(), datasetInstanceId.getParent()));
}
DatasetSpecification spec = AbstractDatasetDefinition.reconfigure(def, datasetInstanceId.getEntityName(), props, oldSpec).setOriginalProperties(props);
if (props.getDescription() != null) {
spec = spec.setDescription(props.getDescription());
}
instances.put(datasetInstanceId.getParent(), datasetInstanceId, spec);
DatasetAdmin admin = def.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec, null);
if (admin instanceof Updatable) {
((Updatable) admin).update(oldSpec);
} else {
admin.upgrade();
}
publishAudit(datasetInstanceId, AuditType.UPDATE);
} catch (IncompatibleUpdateException e) {
throw new InstanceConflictException("Update failed for dataset instance " + datasetInstanceId, e);
} finally {
writeLock.unlock();
}
}
use of co.cask.cdap.api.dataset.Updatable in project cdap by caskdata.
the class DatasetAdminService method createOrUpdate.
/**
* Configures and creates a Dataset
*
* @param datasetInstanceId dataset instance to be created
* @param typeMeta type meta for the dataset
* @param props dataset instance properties
* @param existing if dataset already exists (in case of update), the existing properties
* @return dataset specification
*/
public DatasetSpecification createOrUpdate(final DatasetId datasetInstanceId, final DatasetTypeMeta typeMeta, final DatasetProperties props, @Nullable final DatasetSpecification existing) throws Exception {
if (existing == null) {
LOG.info("Creating dataset instance {}, type meta: {}", datasetInstanceId, typeMeta);
} else {
LOG.info("Updating dataset instance {}, type meta: {}, existing: {}", datasetInstanceId, typeMeta, existing);
}
try (DatasetClassLoaderProvider classLoaderProvider = new DirectoryClassLoaderProvider(cConf, locationFactory)) {
final DatasetContext context = DatasetContext.from(datasetInstanceId.getNamespace());
UserGroupInformation ugi = getUgiForDataset(impersonator, datasetInstanceId);
final DatasetType type = ImpersonationUtils.doAs(ugi, new Callable<DatasetType>() {
@Override
public DatasetType call() throws Exception {
DatasetType type = dsFramework.getDatasetType(typeMeta, null, classLoaderProvider);
if (type == null) {
throw new BadRequestException(String.format("Cannot instantiate dataset type using provided type meta: %s", typeMeta));
}
return type;
}
});
DatasetSpecification spec = ImpersonationUtils.doAs(ugi, new Callable<DatasetSpecification>() {
@Override
public DatasetSpecification call() throws Exception {
DatasetSpecification spec = existing == null ? type.configure(datasetInstanceId.getEntityName(), props) : type.reconfigure(datasetInstanceId.getEntityName(), props, existing);
DatasetAdmin admin = type.getAdmin(context, spec);
if (existing != null) {
if (admin instanceof Updatable) {
((Updatable) admin).update(existing);
} else {
admin.upgrade();
}
} else {
admin.create();
}
return spec;
}
});
// Writing system metadata should be done without impersonation since user may not have access to system tables.
writeSystemMetadata(datasetInstanceId, spec, props, typeMeta, type, context, existing != null, ugi);
return spec;
} catch (Exception e) {
if (e instanceof IncompatibleUpdateException) {
// this is expected to happen if user provides bad update properties, so we log this as debug
LOG.debug("Incompatible update for dataset '{}'", datasetInstanceId, e);
} else {
LOG.error("Error {} dataset '{}': {}", existing == null ? "creating" : "updating", datasetInstanceId, e.getMessage(), e);
}
throw e;
}
}
use of co.cask.cdap.api.dataset.Updatable 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());
}
}
Aggregations