use of io.cdap.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DeleteDatasetModuleCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
DatasetModuleId module = cliConfig.getCurrentNamespace().datasetModule(arguments.get(ArgumentName.DATASET_MODULE.toString()));
datasetClient.delete(module);
output.printf("Successfully deleted dataset module '%s'\n", module.getEntityName());
}
use of io.cdap.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class ExploreDisabledTest method testDeployNotRecordScannable.
@Test
public void testDeployNotRecordScannable() throws Exception {
// Try to deploy a dataset that is not record scannable, when explore is enabled.
// This should be processed with no exceptionbeing thrown
DatasetModuleId module2 = namespaceId.datasetModule("module2");
DatasetId instance2 = namespaceId.dataset("table1");
datasetFramework.addModule(module2, new NotRecordScannableTableDefinition.NotRecordScannableTableModule());
// Performing admin operations to create dataset instance
datasetFramework.addInstance("NotRecordScannableTableDef", instance2, DatasetProperties.EMPTY);
Transaction tx1 = transactionManager.startShort(100);
// Accessing dataset instance to perform data operations
NotRecordScannableTableDefinition.KeyValueTable table = datasetFramework.getDataset(instance2, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
table.startTx(tx1);
table.write("key1", "value1");
table.write("key2", "value2");
byte[] value = table.read("key1");
Assert.assertEquals("value1", Bytes.toString(value));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx1.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx1.getTransactionId(), tx1.getWritePointer());
table.postTxCommit();
Transaction tx2 = transactionManager.startShort(100);
table.startTx(tx2);
value = table.read("key1");
Assert.assertNotNull(value);
Assert.assertEquals("value1", Bytes.toString(value));
datasetFramework.deleteInstance(instance2);
datasetFramework.deleteModule(module2);
}
use of io.cdap.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class HiveExploreServiceTestRun method testDeployNotRecordScannable.
@Test
public void testDeployNotRecordScannable() 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 module2 = NAMESPACE_ID.datasetModule("module2");
DatasetId myTableNotRecordScannable = NAMESPACE_ID.dataset("my_table_not_record_scannable");
datasetFramework.addModule(module2, new NotRecordScannableTableDefinition.NotRecordScannableTableModule());
datasetFramework.addInstance("NotRecordScannableTableDef", myTableNotRecordScannable, DatasetProperties.EMPTY);
datasetFramework.deleteInstance(myTableNotRecordScannable);
datasetFramework.deleteModule(module2);
}
use of io.cdap.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class HiveExploreStructuredRecordTestRun method start.
@BeforeClass
public static void start() throws Exception {
initialize(tmpFolder);
DatasetModuleId moduleId = NAMESPACE_ID.datasetModule("email");
datasetFramework.addModule(moduleId, new EmailTableDefinition.EmailTableModule());
datasetFramework.addInstance("email", MY_TABLE, DatasetProperties.EMPTY);
transactional = Transactions.createTransactional(new MultiThreadDatasetCache(new SystemDatasetInstantiator(datasetFramework), transactionSystemClient, NAMESPACE_ID, Collections.<String, String>emptyMap(), null, null));
transactional.execute(new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
// Accessing dataset instance to perform data operations
EmailTableDefinition.EmailTable table = context.getDataset(MY_TABLE.getDataset());
Assert.assertNotNull(table);
table.writeEmail("email1", "this is the subject", "this is the body", "sljackson@boss.com");
}
});
datasetFramework.addModule(NAMESPACE_ID.datasetModule("TableWrapper"), new TableWrapperDefinition.Module());
}
use of io.cdap.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetModulesDeployer method loadAndDeployModule.
private void loadAndDeployModule(ClassLoader artifactClassLoader, String className, final Location jarLocation, String moduleName, NamespaceId namespaceId, String authorizingUser) throws Exception {
// note: using app class loader to load module class
@SuppressWarnings("unchecked") Class<Dataset> clazz = (Class<Dataset>) artifactClassLoader.loadClass(className);
try {
// note: we can deploy module or create module from Dataset class
// note: it seems dangerous to instantiate dataset module here, but this will be fine when we move deploy into
// isolated user's environment (e.g. separate yarn container)
final DatasetModuleId moduleId = namespaceId.datasetModule(moduleName);
final DatasetModule module;
if (DatasetModule.class.isAssignableFrom(clazz)) {
module = (DatasetModule) clazz.newInstance();
} else if (Dataset.class.isAssignableFrom(clazz)) {
if (systemDatasetFramework.hasSystemType(clazz.getName())) {
return;
}
final DatasetTypeId typeId = namespaceId.datasetType(clazz.getName());
boolean hasType = AuthorizationUtil.authorizeAs(authorizingUser, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return datasetFramework.hasType(typeId);
}
});
if (hasType && !allowDatasetUncheckedUpgrade) {
return;
}
module = new SingleTypeModule(clazz);
} else {
throw new IllegalArgumentException(String.format("Cannot use class %s to add dataset module: it must be of type DatasetModule or Dataset", clazz.getName()));
}
LOG.info("Adding module: {}", clazz.getName());
AuthorizationUtil.authorizeAs(authorizingUser, new Callable<Void>() {
@Override
public Void call() throws Exception {
datasetFramework.addModule(moduleId, module, jarLocation);
return null;
}
});
} catch (ModuleConflictException e) {
LOG.info("Conflict while deploying module {}: {}", moduleName, e.getMessage());
throw e;
}
}
Aggregations