use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by cdapio.
the class CoreDatasetsModule method register.
@Override
public void register(DatasetDefinitionRegistry registry) {
DatasetDefinition<Table, DatasetAdmin> tableDef = registry.get("table");
DatasetDefinition<KeyValueTable, DatasetAdmin> kvTableDef = new KeyValueTableDefinition(KeyValueTable.TYPE, tableDef);
registry.add(kvTableDef);
registry.add(new KeyValueTableDefinition(KeyValueTable.class.getName(), tableDef));
DatasetDefinition<ObjectStore, DatasetAdmin> objectStoreDef = new ObjectStoreDefinition(ObjectStore.TYPE, kvTableDef);
registry.add(new ObjectStoreDefinition(ObjectStore.TYPE, kvTableDef));
registry.add(new ObjectStoreDefinition(ObjectStore.class.getName(), kvTableDef));
registry.add(new IndexedObjectStoreDefinition(IndexedObjectStore.TYPE, tableDef, objectStoreDef));
registry.add(new IndexedObjectStoreDefinition(IndexedObjectStore.class.getName(), tableDef, objectStoreDef));
registry.add(new IndexedTableDefinition(IndexedTable.TYPE, tableDef));
registry.add(new IndexedTableDefinition(IndexedTable.class.getName(), tableDef));
registry.add(new TimeseriesTableDefinition(TimeseriesTable.TYPE, tableDef));
registry.add(new TimeseriesTableDefinition(TimeseriesTable.class.getName(), tableDef));
registry.add(new CounterTimeseriesTableDefinition(CounterTimeseriesTable.TYPE, tableDef));
registry.add(new CounterTimeseriesTableDefinition(CounterTimeseriesTable.class.getName(), tableDef));
// in-memory table
registry.add(new InMemoryTableDefinition(InMemoryTable.TYPE));
}
use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by cdapio.
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 io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by cdapio.
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 io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by cdapio.
the class PrefixedTable method register.
@Override
public void register(DatasetDefinitionRegistry registry) {
DatasetDefinition<KeyValueTable, DatasetAdmin> kvTableDef = registry.get("keyValueTable");
DatasetDefinition definition = new PrefixedTableDefinition("prefixedTable", kvTableDef);
registry.add(definition);
}
use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by cdapio.
the class DatasetUpgrader method upgradeSystemDatasets.
private void upgradeSystemDatasets(ExecutorService executor) throws Exception {
Map<String, Future<?>> futures = new HashMap<>();
for (final DatasetSpecificationSummary spec : dsFramework.getInstances(NamespaceId.SYSTEM)) {
final DatasetId datasetId = NamespaceId.SYSTEM.dataset(spec.getName());
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
LOG.info("Upgrading dataset in system namespace: {}, spec: {}", spec.getName(), spec.toString());
DatasetAdmin admin = dsFramework.getAdmin(datasetId, null);
// we know admin is not null, since we are looping over existing datasets
// noinspection ConstantConditions
admin.upgrade();
LOG.info("Upgraded dataset: {}", spec.getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
Future<?> future = executor.submit(runnable);
futures.put(datasetId.toString(), future);
}
// Wait for the system dataset upgrades to complete
Map<String, Throwable> failed = waitForUpgrade(futures);
if (!failed.isEmpty()) {
for (Map.Entry<String, Throwable> entry : failed.entrySet()) {
LOG.error("Failed to upgrade system dataset {}", entry.getKey(), entry.getValue());
}
throw new Exception(String.format("Error upgrading system datasets. %s of %s failed", failed.size(), futures.size()));
}
}
Aggregations