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);
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations