Search in sources :

Example 16 with DatasetModuleId

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);
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) Table(co.cask.cdap.cli.util.table.Table) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) RowMaker(co.cask.cdap.cli.util.RowMaker)

Example 17 with DatasetModuleId

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);
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) Transaction(org.apache.tephra.Transaction) KeyStructValueTableDefinition(co.cask.cdap.explore.service.datasets.KeyStructValueTableDefinition) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 18 with DatasetModuleId

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);
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleConflictException(co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) DatasetModule(co.cask.cdap.api.dataset.module.DatasetModule)

Example 19 with DatasetModuleId

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);
}
Also used : DatasetTypeMDS(co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS) DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) TxRunnable(co.cask.cdap.api.TxRunnable) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DatasetContext(co.cask.cdap.api.data.DatasetContext) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) ConflictException(co.cask.cdap.common.ConflictException) DatasetModuleConflictException(co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) DatasetModuleNotFoundException(co.cask.cdap.common.DatasetModuleNotFoundException) IOException(java.io.IOException) DatasetModuleCannotBeDeletedException(co.cask.cdap.common.DatasetModuleCannotBeDeletedException) NotFoundException(co.cask.cdap.common.NotFoundException)

Example 20 with DatasetModuleId

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));
        }
    }
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) HashSet(java.util.HashSet)

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