use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetModulesDeployer method loadAndDeployModule.
private void loadAndDeployModule(ClassLoader artifactClassLoader, String className, Location jarLocation, String moduleName, NamespaceId namespaceId) throws ClassNotFoundException, IllegalAccessException, InstantiationException, DatasetManagementException {
// 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)
DatasetModuleId moduleId = namespaceId.datasetModule(moduleName);
DatasetModule module;
if (DatasetModule.class.isAssignableFrom(clazz)) {
module = (DatasetModule) clazz.newInstance();
} else if (Dataset.class.isAssignableFrom(clazz)) {
if (systemDatasetFramework.hasSystemType(clazz.getName())) {
return;
}
DatasetTypeId typeId = namespaceId.datasetType(clazz.getName());
if (datasetFramework.hasType(typeId) && !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());
datasetFramework.addModule(moduleId, module, jarLocation);
} catch (ModuleConflictException e) {
LOG.info("Conflict while deploying module {}: {}", moduleName, e.getMessage());
throw e;
}
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetMetaTableUtil method setupDatasets.
/**
* Adds datasets and types to the given {@link DatasetFramework} used by dataset service mds.
*
* @param datasetFramework framework to add types and datasets to
*/
public static void setupDatasets(DatasetFramework datasetFramework) throws IOException, DatasetManagementException {
for (Map.Entry<String, ? extends DatasetModule> entry : getModules().entrySet()) {
// meta tables should be in the system namespace
DatasetModuleId moduleId = NamespaceId.SYSTEM.datasetModule(entry.getKey());
datasetFramework.addModule(moduleId, entry.getValue());
}
datasetFramework.addInstance(DatasetTypeMDS.class.getName(), NamespaceId.SYSTEM.dataset(META_TABLE_NAME), DatasetProperties.EMPTY);
datasetFramework.addInstance(DatasetInstanceMDS.class.getName(), NamespaceId.SYSTEM.dataset(INSTANCE_TABLE_NAME), DatasetProperties.EMPTY);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class DatasetTypeHandlerTest method testNotFound.
@Test
public void testNotFound() throws Exception {
NamespaceId nonExistent = new NamespaceId("nonExistent");
HttpResponse response = makeModulesRequest(nonExistent);
assertNamespaceNotFound(response, nonExistent);
response = makeTypesRequest(nonExistent);
assertNamespaceNotFound(response, nonExistent);
DatasetModuleId datasetModule = nonExistent.datasetModule("module");
response = makeModuleInfoRequest(datasetModule);
assertNamespaceNotFound(response, nonExistent);
DatasetTypeId datasetType = nonExistent.datasetType("type");
response = makeTypeInfoRequest(datasetType);
assertNamespaceNotFound(response, nonExistent);
response = deployModule(datasetModule, TestModule1.class);
assertNamespaceNotFound(response, nonExistent);
response = deleteModule(datasetModule);
assertNamespaceNotFound(response, nonExistent);
response = deleteModules(nonExistent);
assertNamespaceNotFound(response, nonExistent);
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class BackwardCompatDatasetModuleIdDeserializerTest method testDeserialize40DatasetModuleId.
@Test
public void testDeserialize40DatasetModuleId() throws Exception {
// 4.0: {“module":"metricsTable-hbase","namespace":"system","entity":"DATASET_MODULE”}
byte[] serialized = Bytes.toBytes("{\"module\":\"metricsTable-hbase\",\"namespace\":\"system\",\"entity\":\"DATASET_MODULE\"}");
DatasetModuleId moduleId = new DatasetModuleId("system", "metricsTable-hbase");
Assert.assertEquals(moduleId, mds.deserializeProxy(serialized, DatasetModuleId.class));
Assert.assertEquals(moduleId, mds.deserializeProxy(Bytes.toBytes(new Gson().toJson(moduleId)), DatasetModuleId.class));
}
use of co.cask.cdap.proto.id.DatasetModuleId in project cdap by caskdata.
the class BackwardCompatDatasetModuleIdDeserializerTest method testDeserialize35IdDatasetModule.
@Test
public void testDeserialize35IdDatasetModule() throws Exception {
// 3.5: {"namespace":{"id":"system"},"moduleId":"metricsTable-hbase"}
byte[] serialized = Bytes.toBytes("{\"namespace\":{\"id\":\"system\"},\"moduleId\":\"metricsTable-hbase\"}");
Assert.assertEquals(new DatasetModuleId("system", "metricsTable-hbase"), mds.deserializeProxy(serialized, DatasetModuleId.class));
}
Aggregations