Search in sources :

Example 1 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)

Example 2 with DatasetTypeId

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

the class DatasetInstanceService method getFromMds.

/**
   * Read the dataset meta data (instance and type) from MDS.
   */
private DatasetMeta getFromMds(DatasetId instance) throws Exception {
    // TODO: CDAP-3901 add back namespace existence check
    DatasetSpecification spec = instanceManager.get(instance);
    if (spec == null) {
        throw new NotFoundException(instance);
    }
    spec = DatasetsUtil.fixOriginalProperties(spec);
    DatasetTypeId datasetTypeId = instance.getParent().datasetType(spec.getType());
    DatasetTypeMeta typeMeta = getTypeInfo(instance.getParent(), spec.getType());
    if (typeMeta == null) {
        // TODO: This shouldn't happen unless CDAP is in an invalid state - maybe give different error
        throw new NotFoundException(datasetTypeId);
    }
    // for system dataset do not look up owner information in store as we know that it will be null.
    // Also, this is required for CDAP to start, because initially we don't want to look up owner admin
    // (causing its own lookup) as the SystemDatasetInitiator.getDataset is called when CDAP starts
    String ownerPrincipal = null;
    if (!NamespaceId.SYSTEM.equals(instance.getNamespaceId())) {
        ownerPrincipal = ownerAdmin.getOwnerPrincipal(instance);
    }
    return new DatasetMeta(spec, typeMeta, null, ownerPrincipal);
}
Also used : DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(co.cask.cdap.proto.DatasetTypeMeta) NamespaceNotFoundException(co.cask.cdap.common.NamespaceNotFoundException) DatasetNotFoundException(co.cask.cdap.common.DatasetNotFoundException) DatasetTypeNotFoundException(co.cask.cdap.common.DatasetTypeNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) DatasetMeta(co.cask.cdap.proto.DatasetMeta)

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

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