Search in sources :

Example 61 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by cdapio.

the class FileSetDataset method determineBaseLocation.

/**
 * Generate the base location of the file set.
 * <ul>
 *   <li>If the properties do not contain a base path, generate one from the dataset name;</li>
 *   <li>If the base path is absolute, return a location relative to the root of the file system;</li>
 *   <li>Otherwise return a location relative to the data directory of the namespace.</li>
 * </ul>
 * This is package visible, because FileSetAdmin needs it, too.
 * TODO: Ideally, this should be done in configure(), but currently it cannot because of CDAP-1721
 */
static Location determineBaseLocation(DatasetContext datasetContext, CConfiguration cConf, DatasetSpecification spec, LocationFactory locationFactory, NamespacePathLocator namespacePathLocator) throws IOException {
    // older versions of file set incorrectly interpret absolute paths as relative to the namespace's
    // data directory. These file sets do not have the file set version property.
    boolean hasAbsoluteBasePathBug = spec.getProperties().get(FILESET_VERSION_PROPERTY) == null;
    String basePath = FileSetProperties.getBasePath(spec.getProperties());
    if (basePath == null) {
        basePath = spec.getName().replace('.', '/');
    }
    // for absolute paths, get the location from the file system's root.
    if (basePath.startsWith("/")) {
        // but only if it is not a legacy dataset that interprets absolute paths as relative
        if (hasAbsoluteBasePathBug) {
            LOG.info("Dataset {} was created with a version of FileSet that treats absolute path {} as relative. " + "To disable this message, upgrade the dataset properties with a relative path. ", spec.getName(), basePath);
        } else {
            String topLevelPath = locationFactory.create("/").toURI().getPath();
            topLevelPath = topLevelPath.endsWith("/") ? topLevelPath : topLevelPath + "/";
            Location baseLocation = Locations.getLocationFromAbsolutePath(locationFactory, basePath);
            if (baseLocation.toURI().getPath().startsWith(topLevelPath)) {
                throw new DataSetException("Invalid base path '" + basePath + "' for dataset '" + spec.getName() + "'. " + "It must not be inside the CDAP base path '" + topLevelPath + "'.");
            }
            return baseLocation;
        }
    }
    NamespaceId namespaceId = new NamespaceId(datasetContext.getNamespaceId());
    String dataDir = cConf.get(Constants.Dataset.DATA_DIR, Constants.Dataset.DEFAULT_DATA_DIR);
    return namespacePathLocator.get(namespaceId).append(dataDir).append(basePath);
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location)

Example 62 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by cdapio.

the class DefaultDatasetRuntimeContext method onMethodEntry.

@Override
public void onMethodEntry(boolean constructor, @Nullable Class<? extends Annotation> annotation) {
    CallStack callStack = this.callStack.get();
    AccessInfo accessInfo = UNKNOWN_ACCESS_INFO;
    if (annotation == null && constructor) {
        annotation = constructorDefaultAnnotation;
    }
    if (annotation != null) {
        accessInfo = ANNOTATION_TO_ACCESS_INFO.get(annotation);
        if (accessInfo == null) {
            // shouldn't happen
            throw new DataSetException("Unsupported annotation " + annotation + " on dataset " + datasetId);
        }
    }
    // but we won't allow no privilege at all
    try {
        enforcer.enforce(datasetId, principal, accessInfo.getPermissions());
    } catch (Exception e) {
        throw new DataSetException("The principal " + principal + " is not authorized to access " + datasetId + " for operation types " + accessInfo.getPermissions(), e);
    }
    recordAccess(callStack.enter(accessInfo.getAccessType()), accessInfo.getAccessType());
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) DataSetException(io.cdap.cdap.api.dataset.DataSetException)

Example 63 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by cdapio.

the class HBaseMetricsTable method delete.

@Override
public void delete(byte[] row, byte[][] columns) {
    byte[] distributedKey = createDistributedRowKey(row);
    DeleteBuilder delete = tableUtil.buildDelete(distributedKey);
    for (byte[] column : columns) {
        delete.deleteColumns(columnFamily, column);
    }
    try {
        table.delete(delete.build());
    } catch (IOException e) {
        throw new DataSetException("Delete failed on table " + tableId, e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) DeleteBuilder(io.cdap.cdap.data2.util.hbase.DeleteBuilder)

Example 64 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by cdapio.

the class HBaseMetricsTable method increment.

@Override
public void increment(byte[] row, Map<byte[], Long> increments) {
    byte[] distributedKey = createDistributedRowKey(row);
    Put increment = getIncrementalPut(distributedKey, increments);
    try {
        mutator.mutate(increment);
        mutator.flush();
    } catch (IOException e) {
        // currently there is not other way to extract that from the HBase exception than string match
        if (e.getMessage() != null && e.getMessage().contains("isn't 64 bits wide")) {
            throw new NumberFormatException("Attempted to increment a value that is not convertible to long," + " row: " + Bytes.toStringBinary(distributedKey));
        }
        throw new DataSetException("Increment failed on table " + tableId, e);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put)

Example 65 with DataSetException

use of io.cdap.cdap.api.dataset.DataSetException in project cdap by cdapio.

the class HBaseMetricsTable method put.

@Override
public void put(SortedMap<byte[], ? extends SortedMap<byte[], Long>> updates) {
    List<Put> puts = Lists.newArrayList();
    for (Map.Entry<byte[], ? extends SortedMap<byte[], Long>> row : updates.entrySet()) {
        byte[] distributedKey = createDistributedRowKey(row.getKey());
        PutBuilder put = tableUtil.buildPut(distributedKey);
        for (Map.Entry<byte[], Long> column : row.getValue().entrySet()) {
            put.add(columnFamily, column.getKey(), Bytes.toBytes(column.getValue()));
        }
        puts.add(put.build());
    }
    try {
        mutator.mutate(puts);
        mutator.flush();
    } catch (IOException e) {
        throw new DataSetException("Put failed on table " + tableId, e);
    }
}
Also used : PutBuilder(io.cdap.cdap.data2.util.hbase.PutBuilder) DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Put(org.apache.hadoop.hbase.client.Put)

Aggregations

DataSetException (io.cdap.cdap.api.dataset.DataSetException)74 IOException (java.io.IOException)54 ReadOnly (io.cdap.cdap.api.annotation.ReadOnly)14 Map (java.util.Map)12 TransactionFailureException (org.apache.tephra.TransactionFailureException)12 Location (org.apache.twill.filesystem.Location)12 PartitionKey (io.cdap.cdap.api.dataset.lib.PartitionKey)10 Result (io.cdap.cdap.api.dataset.table.Result)10 NavigableMap (java.util.NavigableMap)10 Test (org.junit.Test)10 PartitionAlreadyExistsException (io.cdap.cdap.api.dataset.lib.PartitionAlreadyExistsException)8 TimePartitionedFileSet (io.cdap.cdap.api.dataset.lib.TimePartitionedFileSet)8 Put (org.apache.hadoop.hbase.client.Put)8 ImmutableMap (com.google.common.collect.ImmutableMap)6 WriteOnly (io.cdap.cdap.api.annotation.WriteOnly)6 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)6 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)6 Put (io.cdap.cdap.api.dataset.table.Put)6 Row (io.cdap.cdap.api.dataset.table.Row)6 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)6