Search in sources :

Example 6 with DatasetTypeId

use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.

the class DatasetTypeService method listTypes.

/**
   * Lists all {@link DatasetType dataset types} in the specified {@link NamespaceId}.
   */
List<DatasetTypeMeta> listTypes(final NamespaceId namespaceId) throws Exception {
    ensureNamespaceExists(namespaceId);
    // Sorting by name for convenience
    List<DatasetTypeMeta> allTypes = Lists.newArrayList(typeManager.getTypes(namespaceId));
    Collections.sort(allTypes, new Comparator<DatasetTypeMeta>() {

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

        @Override
        public boolean apply(DatasetTypeMeta datasetTypeMeta) {
            DatasetTypeId datasetTypeId = namespaceId.datasetType(datasetTypeMeta.getName());
            return authFilter.apply(datasetTypeId);
        }
    });
    return Lists.newArrayList(authorizedDatasetTypes);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) Principal(co.cask.cdap.proto.security.Principal)

Example 7 with DatasetTypeId

use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.

the class DatasetTypeService method revokeAllPrivilegesOnModule.

private void revokeAllPrivilegesOnModule(DatasetModuleId moduleId, @Nullable DatasetModuleMeta moduleMeta) throws Exception {
    privilegesManager.revoke(moduleId);
    moduleMeta = moduleMeta == null ? typeManager.getModule(moduleId) : moduleMeta;
    if (moduleMeta == null) {
        LOG.debug("Could not find metadata for module {}. Will not revoke privileges for its types.", moduleId);
        return;
    }
    for (String type : moduleMeta.getTypes()) {
        DatasetTypeId datasetTypeId = moduleId.getParent().datasetType(type);
        privilegesManager.revoke(datasetTypeId);
    }
}
Also used : DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId)

Example 8 with DatasetTypeId

use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.

the class DatasetModulesDeployer method deployModules.

/**
   * Deploy the given dataset modules.
   *
   * @param namespaceId namespace to deploy to
   * @param modules the dataset modules to deploy
   * @param jarLocation the location of the jar file containing the modules
   * @throws Exception if there was a problem deploying a module
   */
void deployModules(NamespaceId namespaceId, Map<String, String> modules, Location jarLocation, ClassLoader artifactClassLoader) throws Exception {
    List<String> implicitModules = new ArrayList<>();
    for (Map.Entry<String, String> moduleEntry : modules.entrySet()) {
        String moduleName = moduleEntry.getKey();
        String typeName = moduleEntry.getValue();
        if (systemDatasetFramework.hasSystemType(typeName)) {
            LOG.info("Not adding dataset type '{}' because it is defined by the system.", typeName);
            continue;
        }
        // Filter out the implicit modules: They have to be deployed last.
        if (moduleName.startsWith(".implicit.")) {
            implicitModules.add(typeName);
            continue;
        }
        loadAndDeployModule(artifactClassLoader, typeName, jarLocation, moduleName, namespaceId);
    }
    for (String typeName : implicitModules) {
        DatasetTypeId typeId = namespaceId.datasetType(typeName);
        DatasetTypeMeta typeMeta = datasetFramework.getTypeInfo(typeId);
        if (typeMeta != null) {
            String existingModule = Iterables.getLast(typeMeta.getModules()).getName();
            if (modules.containsKey(existingModule)) {
                // it was deployed already as part of one of the explicit deployModule() calls
                continue;
            }
        }
        loadAndDeployModule(artifactClassLoader, typeName, jarLocation, typeName, namespaceId);
    }
}
Also used : DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) ArrayList(java.util.ArrayList) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) Map(java.util.Map)

Example 9 with DatasetTypeId

use of co.cask.cdap.proto.id.DatasetTypeId 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 10 with DatasetTypeId

use of co.cask.cdap.proto.id.DatasetTypeId in project cdap by caskdata.

the class CLIMainTest method testDataset.

@Test
public void testDataset() throws Exception {
    String datasetName = PREFIX + "sdf123lkj";
    String ownedDatasetName = PREFIX + "owned";
    DatasetTypeClient datasetTypeClient = new DatasetTypeClient(cliConfig.getClientConfig());
    DatasetTypeMeta datasetType = datasetTypeClient.list(NamespaceId.DEFAULT).get(0);
    testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName + " \"a=1\"", "Successfully created dataset");
    testCommandOutputContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
    testCommandOutputContains(cli, "get dataset instance properties " + datasetName, "a,1");
    // test dataset creation with owner
    String commandOutput = getCommandOutput(cli, "create dataset instance " + datasetType.getName() + " " + ownedDatasetName + " \"a=1\"" + " " + "someDescription " + ArgumentName.PRINCIPAL + " alice/somehost.net@somekdc.net");
    Assert.assertTrue(commandOutput.contains("Successfully created dataset"));
    Assert.assertTrue(commandOutput.contains("alice/somehost.net@somekdc.net"));
    // test describing the table returns the given owner information
    testCommandOutputContains(cli, "describe dataset instance " + ownedDatasetName, "alice/somehost.net@somekdc.net");
    NamespaceClient namespaceClient = new NamespaceClient(cliConfig.getClientConfig());
    NamespaceId barspace = new NamespaceId("bar");
    namespaceClient.create(new NamespaceMeta.Builder().setName(barspace).build());
    cliConfig.setNamespace(barspace);
    // list of dataset instances is different in 'foo' namespace
    testCommandOutputNotContains(cli, "list dataset instances", FakeDataset.class.getSimpleName());
    // also can not create dataset instances if the type it depends on exists only in a different namespace.
    DatasetTypeId datasetType1 = barspace.datasetType(datasetType.getName());
    testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName, new DatasetTypeNotFoundException(datasetType1).getMessage());
    testCommandOutputContains(cli, "use namespace default", "Now using namespace 'default'");
    try {
        testCommandOutputContains(cli, "truncate dataset instance " + datasetName, "Successfully truncated");
    } finally {
        testCommandOutputContains(cli, "delete dataset instance " + datasetName, "Successfully deleted");
    }
    String datasetName2 = PREFIX + "asoijm39485";
    String description = "test-description-for-" + datasetName2;
    testCommandOutputContains(cli, "create dataset instance " + datasetType.getName() + " " + datasetName2 + " \"a=1\"" + " " + description, "Successfully created dataset");
    testCommandOutputContains(cli, "list dataset instances", description);
    testCommandOutputContains(cli, "delete dataset instance " + datasetName2, "Successfully deleted");
    testCommandOutputContains(cli, "delete dataset instance " + ownedDatasetName, "Successfully deleted");
}
Also used : DatasetTypeClient(co.cask.cdap.client.DatasetTypeClient) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceClient(co.cask.cdap.client.NamespaceClient) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) FakeDataset(co.cask.cdap.client.app.FakeDataset) Test(org.junit.Test)

Aggregations

DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)15 Test (org.junit.Test)7 DatasetTypeMeta (co.cask.cdap.proto.DatasetTypeMeta)6 DatasetModuleId (co.cask.cdap.proto.id.DatasetModuleId)5 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)3 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)3 DatasetId (co.cask.cdap.proto.id.DatasetId)3 File (java.io.File)3 IOException (java.io.IOException)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)2 Table (co.cask.cdap.api.dataset.table.Table)2 DatasetMeta (co.cask.cdap.proto.DatasetMeta)2 DatasetModuleMeta (co.cask.cdap.proto.DatasetModuleMeta)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 Action (co.cask.cdap.proto.security.Action)2 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)2 Dataset (co.cask.cdap.api.dataset.Dataset)1 InstanceConflictException (co.cask.cdap.api.dataset.InstanceConflictException)1 FileSet (co.cask.cdap.api.dataset.lib.FileSet)1