use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DescribeDatasetModuleCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
DatasetModuleId moduleId = cliConfig.getCurrentNamespace().datasetModule(arguments.get(ArgumentName.DATASET_MODULE.toString()));
DatasetModuleMeta datasetModuleMeta = datasetModuleClient.get(moduleId);
Table table = Table.builder().setHeader("name", "className", "jarLocationPath", "types", "usesModules", "usedByModules").setRows(ImmutableList.of(datasetModuleMeta), new RowMaker<DatasetModuleMeta>() {
@Override
public List<?> makeRow(DatasetModuleMeta object) {
return Lists.newArrayList(object.getName(), object.getClassName(), object.getJarLocationPath(), Joiner.on(", ").join(object.getTypes()), Joiner.on(", ").join(object.getUsesModules()), Joiner.on(", ").join(object.getUsedByModules()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class ExploreDisabledTest method testDeployRecordScannable.
@Test
public void testDeployRecordScannable() throws Exception {
// Try to deploy a dataset that is not record scannable, when explore is enabled.
// This should be processed with no exception being thrown
DatasetModuleId module1 = new DatasetModuleId(namespaceId.getNamespace(), "module1");
DatasetId instance1 = namespaceId.dataset("table1");
datasetFramework.addModule(module1, new KeyStructValueTableDefinition.KeyStructValueTableModule());
// Performing admin operations to create dataset instance
datasetFramework.addInstance("keyStructValueTable", instance1, DatasetProperties.EMPTY);
Transaction tx1 = transactionManager.startShort(100);
// Accessing dataset instance to perform data operations
KeyStructValueTableDefinition.KeyStructValueTable table = datasetFramework.getDataset(instance1, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
table.startTx(tx1);
KeyStructValueTableDefinition.KeyValue.Value value1 = new KeyStructValueTableDefinition.KeyValue.Value("first", Lists.newArrayList(1, 2, 3, 4, 5));
KeyStructValueTableDefinition.KeyValue.Value value2 = new KeyStructValueTableDefinition.KeyValue.Value("two", Lists.newArrayList(10, 11, 12, 13, 14));
table.put("1", value1);
table.put("2", value2);
Assert.assertEquals(value1, table.get("1"));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx1, table.getTxChanges());
transactionManager.commit(tx1);
table.postTxCommit();
Transaction tx2 = transactionManager.startShort(100);
table.startTx(tx2);
Assert.assertEquals(value1, table.get("1"));
datasetFramework.deleteInstance(instance1);
datasetFramework.deleteModule(module1);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetTypeService method deployDefaultModules.
private void deployDefaultModules() throws Exception {
List<DatasetModuleId> toGrant = new ArrayList<>();
// adding default modules to be available in dataset manager service
for (Map.Entry<String, DatasetModule> module : defaultModules.entrySet()) {
try {
// NOTE: we assume default modules are always in classpath, hence passing null for jar location
// NOTE: we add default modules in the system namespace
DatasetModuleId defaultModule = NamespaceId.SYSTEM.datasetModule(module.getKey());
typeManager.addModule(defaultModule, module.getValue().getClass().getName(), null, false);
toGrant.add(defaultModule);
} catch (DatasetModuleConflictException e) {
// perfectly fine: we need to add default modules only the very first time service is started
LOG.debug("Not adding {} module: it already exists", module.getKey());
} catch (Throwable th) {
LOG.error("Failed to add {} module. Aborting.", module.getKey(), th);
throw Throwables.propagate(th);
}
}
long startTime = System.currentTimeMillis();
LOG.trace("Granting all privileges for {} default dataset modules. ", toGrant.size());
for (DatasetModuleId defaultModule : toGrant) {
grantAllPrivilegesOnModule(defaultModule, authenticationContext.getPrincipal());
}
long doneTime = System.currentTimeMillis();
float elapsedSeconds = doneTime == startTime ? 0.0F : ((float) doneTime - startTime) / 1000;
LOG.debug("Granting all privileges for {} default dataset modules took {} seconds.", toGrant.size(), elapsedSeconds);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetTypeService method deleteSystemModules.
private void deleteSystemModules() throws Exception {
final List<DatasetModuleMeta> toRevoke = new ArrayList<>();
Transactions.createTransactional(datasetCache).execute(60, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
DatasetTypeMDS datasetTypeMDS = datasetCache.getDataset(DatasetMetaTableUtil.META_TABLE_NAME);
Collection<DatasetModuleMeta> allDatasets = datasetTypeMDS.getModules(NamespaceId.SYSTEM);
for (DatasetModuleMeta ds : allDatasets) {
if (ds.getJarLocationPath() == null) {
LOG.debug("Deleting system dataset module: {}", ds.toString());
DatasetModuleId moduleId = NamespaceId.SYSTEM.datasetModule(ds.getName());
datasetTypeMDS.deleteModule(moduleId);
toRevoke.add(ds);
}
}
}
});
long startTime = System.currentTimeMillis();
LOG.trace("Revoking all privileges for {} system dataset modules. ", toRevoke.size());
for (DatasetModuleMeta ds : toRevoke) {
revokeAllPrivilegesOnModule(NamespaceId.SYSTEM.datasetModule(ds.getName()), ds);
}
long doneTime = System.currentTimeMillis();
float elapsedSeconds = doneTime == startTime ? 0.0F : ((float) doneTime - startTime) / 1000;
LOG.debug("Revoking all privileges for {} system dataset modules took {} seconds.", toRevoke.size(), elapsedSeconds);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetTypeMDS method writeModule.
public void writeModule(NamespaceId namespaceId, DatasetModuleMeta moduleMeta) {
DatasetModuleId datasetModuleId = namespaceId.datasetModule(moduleMeta.getName());
DatasetModuleMeta existing = getModule(datasetModuleId);
write(getModuleKey(namespaceId.getEntityName(), moduleMeta.getName()), moduleMeta);
for (String type : moduleMeta.getTypes()) {
writeTypeToModuleMapping(namespaceId.datasetType(type), datasetModuleId);
}
if (existing != null) {
Set<String> removed = new HashSet<>(existing.getTypes());
removed.removeAll(moduleMeta.getTypes());
for (String type : removed) {
deleteAll(getTypeKey(datasetModuleId.getNamespace(), type));
}
}
}
Aggregations