use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class TableUtils method setLocalityGroups.
public static void setLocalityGroups(final AccumuloStore store) throws StoreException {
final String tableName = store.getTableName();
Map<String, Set<Text>> localityGroups = new HashMap<>();
for (final String group : store.getSchema().getGroups()) {
HashSet<Text> localityGroup = new HashSet<>();
localityGroup.add(new Text(group));
localityGroups.put(group, localityGroup);
}
LOGGER.info("Setting locality groups on table {}", tableName);
try {
store.getConnection().tableOperations().setLocalityGroups(tableName, localityGroups);
} catch (final AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
throw new StoreException(e.getMessage(), e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class AddElementsHandler method addElements.
private void addElements(final AddElements operation, final AccumuloStore store) throws OperationException {
try {
final Iterable<? extends Element> validatedElements;
if (operation.isValidate()) {
validatedElements = new ValidatedElements(operation.getInput(), store.getSchema(), operation.isSkipInvalidElements());
} else {
validatedElements = operation.getInput();
}
store.addElements(validatedElements);
} catch (final StoreException e) {
throw new OperationException("Failed to add elements", e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class PredefinedFederatedStore method initialise.
@Override
public void initialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
HashMapGraphLibrary.clear();
CacheServiceLoader.shutdown();
ExecutorService.shutdown();
super.initialise(graphId, schema, properties);
// Accumulo store just contains edges
try {
addGraphs(null, User.UNKNOWN_USER_ID, false, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_EDGES)).schema(new Schema.Builder().merge(schema.clone()).entities(Collections.emptyMap()).build()).properties(PROPERTIES).build());
// Accumulo store just contains entities
addGraphs(null, User.UNKNOWN_USER_ID, false, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_ENTITIES)).schema(new Schema.Builder().merge(schema.clone()).edges(Collections.emptyMap()).build()).properties(PROPERTIES).build());
} catch (final StorageException e) {
throw new StoreException(e.getMessage(), e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class ParquetStore method setLatestSnapshot.
public void setLatestSnapshot(final long snapshot) throws StoreException {
final Path snapshotPath = new Path(getDataDir(), getSnapshotPath(snapshot));
try {
if (!fs.exists(snapshotPath)) {
throw new StoreException(String.format("Failed setting currentSnapshot: '%s' does not exist", snapshotPath.toString()));
}
} catch (final IOException e) {
throw new StoreException("IOException checking Path: ", e);
}
LOGGER.info("Setting currentSnapshot to {} and reloading graph partitioner", snapshot);
this.currentSnapshot = snapshot;
loadGraphPartitioner();
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class ParquetStore method initialise.
private void initialise() throws IOException, StoreException {
// If data directory is empty or does not exist then this is the first time the store has been created.
final Path dataDirPath = new Path(getDataDir());
if (!fs.exists(dataDirPath) || 0 == fs.listStatus(dataDirPath).length) {
LOGGER.info("Data directory {} doesn't exist or is empty so initialising directory structure", dataDirPath);
currentSnapshot = System.currentTimeMillis();
LOGGER.info("Initialising snapshot id to {}", currentSnapshot);
final Path snapshotPath = new Path(dataDirPath, getSnapshotPath(currentSnapshot));
LOGGER.info("Creating snapshot directory {}", snapshotPath);
fs.mkdirs(snapshotPath);
LOGGER.info("Creating group directories under {}", snapshotPath);
for (final String group : getSchema().getGroups()) {
final Path groupDir = getGroupPath(group);
fs.mkdirs(groupDir);
LOGGER.info("Created directory {}", groupDir);
}
LOGGER.info("Creating group directories for reversed edges under {}", snapshotPath);
for (final String group : getSchema().getEdgeGroups()) {
final Path groupDir = getGroupPathForReversedEdges(group);
fs.mkdirs(groupDir);
LOGGER.info("Created directory {}", groupDir);
}
LOGGER.info("Creating GraphPartitioner with 0 split points for each group");
graphPartitioner = new GraphPartitioner();
for (final String group : getSchema().getGroups()) {
graphPartitioner.addGroupPartitioner(group, new GroupPartitioner(group, new ArrayList<>()));
}
for (final String group : getSchema().getEdgeGroups()) {
graphPartitioner.addGroupPartitionerForReversedEdges(group, new GroupPartitioner(group, new ArrayList<>()));
}
LOGGER.info("Writing GraphPartitioner to snapshot directory");
final FSDataOutputStream dataOutputStream = fs.create(getGraphPartitionerPath());
new GraphPartitionerSerialiser().write(graphPartitioner, dataOutputStream);
dataOutputStream.close();
LOGGER.info("Wrote GraphPartitioner to file {}", getGraphPartitionerPath().toString());
} else {
LOGGER.info("Data directory {} exists and is non-empty, validating a snapshot directory exists", dataDirPath);
final FileStatus[] fileStatuses = fs.listStatus(dataDirPath, f -> f.getName().startsWith(SNAPSHOT + "="));
final List<FileStatus> directories = Arrays.stream(fileStatuses).filter(f -> f.isDirectory()).collect(Collectors.toList());
if (0 == directories.size()) {
LOGGER.error("Data directory {} should contain a snapshot directory", dataDirPath);
throw new StoreException("Data directory should contain a snapshot directory");
}
this.currentSnapshot = getLatestSnapshot();
LOGGER.info("Latest snapshot directory in data directory {} is {}", dataDirPath, this.currentSnapshot);
LOGGER.info("Verifying snapshot directory contains the correct directories");
for (final String group : getSchema().getGroups()) {
final Path groupDir = getGroupPath(group);
if (!fs.exists(groupDir)) {
LOGGER.error("Directory {} should exist", groupDir);
throw new StoreException("Group directory " + groupDir + " should exist in snapshot directory " + getSnapshotPath(this.currentSnapshot));
}
}
for (final String group : getSchema().getEdgeGroups()) {
final Path groupDir = getGroupPathForReversedEdges(group);
if (!fs.exists(groupDir)) {
LOGGER.error("Directory {} should exist", groupDir);
throw new StoreException("Group directory " + groupDir + " should exist in snapshot directory " + getSnapshotPath(this.currentSnapshot));
}
}
}
}
Aggregations