Search in sources :

Example 6 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeService method listModules.

/**
   * Returns all {@link DatasetModuleMeta dataset modules} in the specified {@link NamespaceId namespace}.
   */
List<DatasetModuleMeta> listModules(final NamespaceId namespaceId) throws Exception {
    ensureNamespaceExists(namespaceId);
    // Sorting by name for convenience
    List<DatasetModuleMeta> allModules = Lists.newArrayList(typeManager.getModules(namespaceId));
    Collections.sort(allModules, new Comparator<DatasetModuleMeta>() {

        @Override
        public int compare(DatasetModuleMeta o1, DatasetModuleMeta o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Principal principal = authenticationContext.getPrincipal();
    final Predicate<EntityId> authFilter = authorizationEnforcer.createFilter(principal);
    Iterable<DatasetModuleMeta> authorizedDatasetModules = Iterables.filter(allModules, new com.google.common.base.Predicate<DatasetModuleMeta>() {

        @Override
        public boolean apply(DatasetModuleMeta datasetModuleMeta) {
            return authFilter.apply(namespaceId.datasetModule(datasetModuleMeta.getName()));
        }
    });
    return Lists.newArrayList(authorizedDatasetModules);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) Principal(co.cask.cdap.proto.security.Principal)

Example 7 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class InMemoryDatasetFramework method addModule.

@Override
public void addModule(DatasetModuleId moduleId, DatasetModule module) throws ModuleConflictException {
    // TODO (CDAP-6297): check if existing modules overlap, or if this removes a type other modules depend on
    writeLock.lock();
    try {
        DatasetDefinitionRegistry registry = registries.get(moduleId.getParent());
        if (registry == null) {
            registry = registryFactory.create();
            registries.put(moduleId.getParent(), registry);
        }
        TypesTrackingRegistry trackingRegistry = new TypesTrackingRegistry(registry);
        module.register(trackingRegistry);
        String moduleClassName = DatasetModules.getDatasetModuleClass(module).getName();
        moduleClasses.put(moduleId.getParent(), moduleId, moduleClassName);
        List<String> types = trackingRegistry.getTypes();
        nonDefaultTypes.putAll(moduleId.getParent(), types);
        for (String type : types) {
            this.types.put(moduleId.getParent().datasetType(type), new DatasetTypeMeta(type, Collections.singletonList(new DatasetModuleMeta(moduleId.getEntityName(), moduleClassName, null, types, Collections.<String>emptyList()))));
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) DatasetDefinitionRegistry(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)

Example 8 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class GenerateClientUsageExample method datasetModuleClient.

public void datasetModuleClient() throws Exception {
    // Construct the client used to interact with CDAP
    DatasetModuleClient datasetModuleClient = new DatasetModuleClient(clientConfig);
    // Add a dataset module
    File moduleJarFile = createAppJarFile(SomeDatasetModule.class);
    DatasetModuleId datasetModuleId = NamespaceId.DEFAULT.datasetModule("someDatasetModule");
    datasetModuleClient.add(datasetModuleId, SomeDatasetModule.class.getName(), moduleJarFile);
    // Fetch the dataset module information
    DatasetModuleMeta datasetModuleMeta = datasetModuleClient.get(datasetModuleId);
    // Delete all dataset modules
    datasetModuleClient.deleteAll(NamespaceId.DEFAULT);
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) File(java.io.File) DatasetModuleClient(co.cask.cdap.client.DatasetModuleClient)

Example 9 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class ListDatasetTypesCommand method perform.

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    List<DatasetTypeMeta> datasetTypeMetas = datasetTypeClient.list(cliConfig.getCurrentNamespace());
    Table table = Table.builder().setHeader("name", "modules").setRows(datasetTypeMetas, new RowMaker<DatasetTypeMeta>() {

        @Override
        public List<?> makeRow(DatasetTypeMeta object) {
            List<String> modulesStrings = Lists.newArrayList();
            for (DatasetModuleMeta module : object.getModules()) {
                modulesStrings.add(module.getName());
            }
            return Lists.newArrayList(object.getName(), Joiner.on(", ").join(modulesStrings));
        }
    }).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}
Also used : Table(co.cask.cdap.cli.util.table.Table) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) RowMaker(co.cask.cdap.cli.util.RowMaker) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta)

Example 10 with DatasetModuleMeta

use of co.cask.cdap.proto.DatasetModuleMeta in project cdap by caskdata.

the class DatasetTypeHandlerTest method testBundledJarModule.

// Tests that a module can be deployed from a jar that is embedded in a bundle jar. This verifies class loading.
@Test
public void testBundledJarModule() throws Exception {
    // Get jar of TestModule1
    Location module1Jar = createModuleJar(TestModule1.class);
    // Create bundle jar with TestModule2 and TestModule1 inside it, request for deploy is made for Module1.
    Assert.assertEquals(200, deployModuleBundled("module1", TestModule1.class.getName(), TestModule2.class, module1Jar));
    Assert.assertEquals(HttpStatus.SC_OK, deleteModules().getResponseCode());
    List<DatasetModuleMeta> modules = getModules().getResponseObject();
    Assert.assertEquals(0, modules.size());
}
Also used : DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Aggregations

DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)21 DatasetModuleId (co.cask.cdap.proto.id.DatasetModuleId)6 DatasetModuleNotFoundException (co.cask.cdap.common.DatasetModuleNotFoundException)5 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)5 DatasetTypeMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS)4 Principal (co.cask.cdap.proto.security.Principal)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 RowMaker (co.cask.cdap.cli.util.RowMaker)3 Table (co.cask.cdap.cli.util.table.Table)3 DatasetInstanceMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS)3 DatasetModuleConflictException (co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException)3 TypeConflictException (co.cask.cdap.data2.dataset2.TypeConflictException)3 File (java.io.File)3 Location (org.apache.twill.filesystem.Location)3 Test (org.junit.Test)3 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)2 ConflictException (co.cask.cdap.common.ConflictException)2