Search in sources :

Example 6 with DatasetModuleId

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;
    }
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) ModuleConflictException(co.cask.cdap.data2.dataset2.ModuleConflictException) Dataset(co.cask.cdap.api.dataset.Dataset) SingleTypeModule(co.cask.cdap.data2.dataset2.SingleTypeModule) DatasetModule(co.cask.cdap.api.dataset.module.DatasetModule)

Example 7 with DatasetModuleId

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);
}
Also used : DatasetTypeMDS(co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS) DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetInstanceMDS(co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 8 with DatasetModuleId

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);
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) HttpResponse(co.cask.common.http.HttpResponse) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 9 with DatasetModuleId

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));
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 10 with DatasetModuleId

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));
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) Test(org.junit.Test)

Aggregations

DatasetModuleId (co.cask.cdap.proto.id.DatasetModuleId)21 Test (org.junit.Test)10 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)6 DatasetId (co.cask.cdap.proto.id.DatasetId)5 DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)5 IOException (java.io.IOException)5 DatasetModule (co.cask.cdap.api.dataset.module.DatasetModule)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 DatasetTypeMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS)3 DatasetModuleConflictException (co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException)3 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Transaction (org.apache.tephra.Transaction)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)2 DatasetModuleNotFoundException (co.cask.cdap.common.DatasetModuleNotFoundException)2 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)2 DatasetInstanceMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS)2 NotRecordScannableTableDefinition (co.cask.cdap.explore.service.datasets.NotRecordScannableTableDefinition)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 File (java.io.File)2