Search in sources :

Example 26 with DatasetManagementException

use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.

the class PreviewDatasetFramework method getDataset.

@Nullable
@Override
public <T extends Dataset> T getDataset(final DatasetId datasetInstanceId, final Map<String, String> arguments, @Nullable final ClassLoader classLoader, final DatasetClassLoaderProvider classLoaderProvider, @Nullable final Iterable<? extends EntityId> owners, final AccessType accessType) throws DatasetManagementException, IOException {
    Principal principal = authenticationContext.getPrincipal();
    try {
        AuthorizationEnforcer enforcer;
        final boolean isUserDataset = DatasetsUtil.isUserDataset(datasetInstanceId);
        // only for the datasets from the real space enforce the authorization.
        if (isUserDataset && actualDatasetFramework.hasInstance(datasetInstanceId)) {
            enforcer = authorizationEnforcer;
        } else {
            enforcer = NOOP_ENFORCER;
        }
        return DefaultDatasetRuntimeContext.execute(enforcer, NOOP_DATASET_ACCESS_RECORDER, principal, datasetInstanceId, null, new Callable<T>() {

            @Override
            public T call() throws Exception {
                if (isUserDataset && actualDatasetFramework.hasInstance(datasetInstanceId)) {
                    return actualDatasetFramework.getDataset(datasetInstanceId, arguments, classLoader, classLoaderProvider, owners, accessType);
                }
                return localDatasetFramework.getDataset(datasetInstanceId, arguments, classLoader, classLoaderProvider, owners, accessType);
            }
        });
    } catch (IOException | DatasetManagementException e) {
        throw e;
    } catch (Exception e) {
        throw new DatasetManagementException("Failed to create dataset instance: " + datasetInstanceId, e);
    }
}
Also used : DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) AuthorizationEnforcer(co.cask.cdap.security.spi.authorization.AuthorizationEnforcer) IOException(java.io.IOException) Principal(co.cask.cdap.proto.security.Principal) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 27 with DatasetManagementException

use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.

the class TimePartitionedFileSetTest method validateInputPaths.

/**
   * Validates that the output configuration of the tpfs, when instantiated with (time - start * minutes) as
   * input start time and (time + end * minutes) as input end time, returns the expected list of paths.
   */
private void validateInputPaths(long time, long start, long end, final String... expected) throws IOException, DatasetManagementException, InterruptedException, TransactionFailureException {
    Map<String, String> arguments = Maps.newHashMap();
    TimePartitionedFileSetArguments.setInputStartTime(arguments, time + start * MINUTE);
    TimePartitionedFileSetArguments.setInputEndTime(arguments, time + end * MINUTE);
    final TimePartitionedFileSet tpfs = dsFrameworkUtil.getInstance(TPFS_INSTANCE, arguments);
    TransactionAware txAwareDataset = (TransactionAware) tpfs;
    dsFrameworkUtil.newInMemoryTransactionExecutor(txAwareDataset).execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Map<String, String> inputConfig = tpfs.getInputFormatConfiguration();
            String inputs = inputConfig.get(FileInputFormat.INPUT_DIR);
            Assert.assertNotNull(inputs);
            if (expected.length == 0) {
                Assert.assertTrue(inputs.isEmpty());
                return;
            }
            String[] inputPaths = inputs.split(",");
            Assert.assertEquals(expected.length, inputPaths.length);
            // order is not guaranteed.
            Arrays.sort(expected);
            Arrays.sort(inputPaths);
            for (int i = 0; i < expected.length; i++) {
                // every input path is absolute, whereas expected paths are relative
                Assert.assertTrue("path #" + i + " does not match", inputPaths[i].endsWith(expected[i]));
            }
        }
    });
}
Also used : TransactionAware(org.apache.tephra.TransactionAware) TransactionExecutor(org.apache.tephra.TransactionExecutor) TimePartitionedFileSet(co.cask.cdap.api.dataset.lib.TimePartitionedFileSet) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionFailureException(org.apache.tephra.TransactionFailureException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) DataSetException(co.cask.cdap.api.dataset.DataSetException)

Example 28 with DatasetManagementException

use of co.cask.cdap.api.dataset.DatasetManagementException in project cdap by caskdata.

the class AdminApp method performAdmin.

// this will get called from the worker, also from a custom workflow action
static void performAdmin(RuntimeContext context) {
    Admin admin = context.getAdmin();
    Map<String, String> args = context.getRuntimeArguments();
    try {
        // if invoked with dropAll=true, clean up all datasets (a, b, c, d)
        if ("true".equals(args.get("dropAll"))) {
            for (String name : new String[] { "a", "b", "c", "d" }) {
                if (admin.datasetExists(name)) {
                    admin.dropDataset(name);
                }
            }
        } else {
            // create a, update b with /extra in base path, truncate c, drop d
            admin.createDataset("a", Table.class.getName(), DatasetProperties.EMPTY);
            String type = admin.getDatasetType("b");
            Assert.assertEquals(FileSet.class.getName(), type);
            DatasetProperties bProps = admin.getDatasetProperties("b");
            String base = bProps.getProperties().get("base.path");
            Assert.assertNotNull(base);
            String newBase = args.get("new.base.path");
            DatasetProperties newBProps = ((FileSetProperties.Builder) FileSetProperties.builder().addAll(bProps.getProperties())).setDataExternal(true).setBasePath(newBase).build();
            admin.updateDataset("b", newBProps);
            admin.truncateDataset("c");
            admin.dropDataset("d");
        }
    } catch (DatasetManagementException e) {
        Throwables.propagate(e);
    }
}
Also used : DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) Table(co.cask.cdap.api.dataset.table.Table) FileSet(co.cask.cdap.api.dataset.lib.FileSet) DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) Admin(co.cask.cdap.api.Admin)

Aggregations

DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)28 IOException (java.io.IOException)14 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)8 DatasetId (co.cask.cdap.proto.id.DatasetId)6 DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)5 AbstractDatasetDefinition (co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition)5 Dataset (co.cask.cdap.api.dataset.Dataset)4 InstanceConflictException (co.cask.cdap.api.dataset.InstanceConflictException)4 ServiceUnavailableException (co.cask.cdap.common.ServiceUnavailableException)4 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)3 Table (co.cask.cdap.api.dataset.table.Table)3 Nullable (javax.annotation.Nullable)3 TransactionFailureException (org.apache.tephra.TransactionFailureException)3 Test (org.junit.Test)3 FileSet (co.cask.cdap.api.dataset.lib.FileSet)2 SystemDatasetInstantiator (co.cask.cdap.data.dataset.SystemDatasetInstantiator)2 Principal (co.cask.cdap.proto.security.Principal)2 AuthorizationEnforcer (co.cask.cdap.security.spi.authorization.AuthorizationEnforcer)2 HttpResponse (co.cask.common.http.HttpResponse)2