Search in sources :

Example 1 with DatasetModuleMeta

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

the class DatasetTypeService method getModule.

/**
   * Returns the {@link DatasetModuleMeta metadata} of the specified {@link DatasetModuleId}.
   */
DatasetModuleMeta getModule(DatasetModuleId datasetModuleId) throws Exception {
    ensureNamespaceExists(datasetModuleId.getParent());
    DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId);
    if (moduleMeta == null) {
        throw new DatasetModuleNotFoundException(datasetModuleId);
    }
    Principal principal = authenticationContext.getPrincipal();
    final Predicate<EntityId> filter = authorizationEnforcer.createFilter(principal);
    if (!filter.apply(datasetModuleId)) {
        throw new UnauthorizedException(principal, datasetModuleId);
    }
    return moduleMeta;
}
Also used : DatasetModuleNotFoundException(co.cask.cdap.common.DatasetModuleNotFoundException) EntityId(co.cask.cdap.proto.id.EntityId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) Principal(co.cask.cdap.proto.security.Principal)

Example 2 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 3 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 4 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)

Example 5 with DatasetModuleMeta

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

the class AuthorizationDatasetTypeService method deleteAll.

@Override
public void deleteAll(NamespaceId namespaceId) throws Exception {
    Principal principal = authenticationContext.getPrincipal();
    for (DatasetModuleMeta meta : delegate.listModules(namespaceId)) {
        DatasetModuleId datasetModuleId = namespaceId.datasetModule(meta.getName());
        authorizationEnforcer.enforce(datasetModuleId, principal, Action.ADMIN);
    }
    delegate.deleteAll(namespaceId);
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetModuleMeta(co.cask.cdap.proto.DatasetModuleMeta) Principal(co.cask.cdap.proto.security.Principal)

Aggregations

DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)24 DatasetModuleNotFoundException (co.cask.cdap.common.DatasetModuleNotFoundException)7 DatasetModuleId (co.cask.cdap.proto.id.DatasetModuleId)7 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)5 Principal (co.cask.cdap.proto.security.Principal)5 DatasetTypeMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetTypeMDS)4 DatasetModuleConflictException (co.cask.cdap.data2.datafabric.dataset.type.DatasetModuleConflictException)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 DatasetModuleCannotBeDeletedException (co.cask.cdap.common.DatasetModuleCannotBeDeletedException)3 DatasetInstanceMDS (co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS)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