use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class HBaseTableTest method testTableWithPermissions.
@Test
public void testTableWithPermissions() throws IOException {
DatasetAdmin admin = getTableAdmin(CONTEXT1, "validPerms", TableProperties.builder().setTablePermissions(ImmutableMap.of("joe", "rwa")).build());
admin.create();
Assert.assertTrue(admin.exists());
admin.drop();
admin = getTableAdmin(CONTEXT1, "invalidPerms", TableProperties.builder().setTablePermissions(ImmutableMap.of("joe", "iwx")).build());
try {
admin.create();
Assert.fail("create() should have failed due to bad permissions");
} catch (IOException e) {
Assert.assertTrue(e.getMessage().contains("Unknown Action"));
}
Assert.assertFalse(admin.exists());
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
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", tableDef);
registry.add(kvTableDef);
registry.add(new KeyValueTableDefinition(KeyValueTable.class.getName(), tableDef));
DatasetDefinition<ObjectStore, DatasetAdmin> objectStoreDef = new ObjectStoreDefinition("objectStore", kvTableDef);
registry.add(new ObjectStoreDefinition("objectStore", kvTableDef));
registry.add(new ObjectStoreDefinition(ObjectStore.class.getName(), kvTableDef));
registry.add(new IndexedObjectStoreDefinition("indexedObjectStore", tableDef, objectStoreDef));
registry.add(new IndexedObjectStoreDefinition(IndexedObjectStore.class.getName(), tableDef, objectStoreDef));
registry.add(new IndexedTableDefinition("indexedTable", tableDef));
registry.add(new IndexedTableDefinition(IndexedTable.class.getName(), tableDef));
registry.add(new TimeseriesTableDefinition("timeseriesTable", tableDef));
registry.add(new TimeseriesTableDefinition(TimeseriesTable.class.getName(), tableDef));
registry.add(new CounterTimeseriesTableDefinition("counterTimeseriesTable", tableDef));
registry.add(new CounterTimeseriesTableDefinition(CounterTimeseriesTable.class.getName(), tableDef));
// in-memory table
registry.add(new InMemoryTableDefinition("memoryTable"));
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class InMemoryDatasetOpExecutor method create.
@Override
public DatasetSpecification create(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props) 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);
}
DatasetSpecification spec = type.configure(datasetInstanceId.getEntityName(), props);
DatasetAdmin admin = type.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec);
admin.create();
return spec;
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class DatasetAdminService method upgrade.
public void upgrade(DatasetId datasetInstanceId) throws Exception {
DatasetAdmin datasetAdmin = getDatasetAdmin(datasetInstanceId);
datasetAdmin.upgrade();
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class HBaseQueueAdmin method upgradeQueues.
private Map<TableId, Future<?>> upgradeQueues(final NamespaceMeta namespaceMeta, ExecutorService executor) throws Exception {
try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
String hbaseNamespace = tableUtil.getHBaseNamespace(namespaceMeta);
List<TableId> tableIds = tableUtil.listTablesInNamespace(admin, hbaseNamespace);
List<TableId> stateStoreTableIds = Lists.newArrayList();
Map<TableId, Future<?>> futures = new HashMap<>();
for (final TableId tableId : tableIds) {
// It's important to skip config table enabled.
if (isDataTable(tableId)) {
Runnable runnable = new Runnable() {
public void run() {
try {
LOG.info("Upgrading queue table: {}", tableId);
Properties properties = new Properties();
HTableDescriptor desc = tableUtil.getHTableDescriptor(admin, tableId);
if (desc.getValue(HBaseQueueAdmin.PROPERTY_PREFIX_BYTES) == null) {
// It's the old queue table. Set the property prefix bytes to SALT_BYTES
properties.setProperty(HBaseQueueAdmin.PROPERTY_PREFIX_BYTES, Integer.toString(SaltedHBaseQueueStrategy.SALT_BYTES));
}
upgrade(tableId, properties);
LOG.info("Upgraded queue table: {}", tableId);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
Future<?> future = executor.submit(runnable);
futures.put(tableId, future);
} else if (isStateStoreTable(tableId)) {
stateStoreTableIds.add(tableId);
}
}
// Upgrade of state store table
for (final TableId tableId : stateStoreTableIds) {
Runnable runnable = new Runnable() {
public void run() {
try {
LOG.info("Upgrading queue state store: {}", tableId);
DatasetId stateStoreId = createStateStoreDataset(namespaceMeta.getName());
DatasetAdmin datasetAdmin = datasetFramework.getAdmin(stateStoreId, null);
if (datasetAdmin == null) {
LOG.error("No dataset admin available for {}", stateStoreId);
return;
}
datasetAdmin.upgrade();
LOG.info("Upgraded queue state store: {}", tableId);
} catch (Exception e) {
new RuntimeException(e);
}
}
};
Future<?> future = executor.submit(runnable);
futures.put(tableId, future);
}
return futures;
}
}
Aggregations