use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
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 caskdata.
the class ObjectStoreDataset method encode.
private byte[] encode(T object) {
// encode T using schema
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BinaryEncoder encoder = new BinaryEncoder(bos);
try {
this.datumWriter.encode(object, encoder);
} catch (IOException e) {
// SHOULD NEVER happen
throw new DataSetException("Failed to encode object to be written: " + e.getMessage(), e);
}
return bos.toByteArray();
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class HBaseMetricsTable method get.
@Override
@Nullable
public byte[] get(byte[] row, byte[] column) {
try {
byte[] distributedKey = createDistributedRowKey(row);
Get get = tableUtil.buildGet(distributedKey).addColumn(columnFamily, column).setMaxVersions(1).build();
Result getResult = table.get(get);
if (!getResult.isEmpty()) {
return getResult.getValue(columnFamily, column);
}
return null;
} catch (IOException e) {
throw new DataSetException("Get failed on table " + tableId, e);
}
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
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);
}
}
use of io.cdap.cdap.api.dataset.DataSetException in project cdap by caskdata.
the class ObjectMappedTableDataset method write.
@WriteOnly
@Override
public void write(byte[] key, T object) {
Put put = new Put(key);
try {
putWriter.write(object, put);
table.put(put);
} catch (IOException e) {
// should never happen
throw new DataSetException("Failed to encode object to be written: " + e.getMessage(), e);
}
}
Aggregations