use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class ProxyStore method doPost.
protected <O> O doPost(final URL url, final String jsonBody, final ResponseDeserialiser<O> responseDeserialiser, final Context context) throws StoreException {
final Invocation.Builder request = createRequest(jsonBody, url, context);
final Response response;
try {
response = request.post(Entity.json(jsonBody));
} catch (final Exception e) {
throw new StoreException("Failed to execute post via " + "the Gaffer URL " + url.toExternalForm(), e);
}
return handleResponse(response, responseDeserialiser);
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class GetElementsWithinSetHandlerTest method setupGraph.
private static void setupGraph(final AccumuloStore store) {
try {
// Create table
// (this method creates the table, removes the versioning iterator, and adds the SetOfStatisticsCombiner iterator,
// and sets the age off iterator to age data off after it is more than ageOffTimeInMilliseconds milliseconds old).
TableUtils.createTable(store);
final List<Element> data = new ArrayList<>();
// Create edges A0 -> A1, A0 -> A2, ..., A0 -> A99. Also create an Entity for each.
final Entity entity = new Entity(TestGroups.ENTITY);
entity.setVertex("A0");
entity.putProperty(AccumuloPropertyNames.COUNT, 10000);
data.add(entity);
for (int i = 1; i < 100; i++) {
data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, i).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 2).property(AccumuloPropertyNames.COUNT, i).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
data.add(new Edge.Builder().group(TestGroups.EDGE).source("A0").dest("A" + i).directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 3).property(AccumuloPropertyNames.COUNT, i).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build());
data.add(new Entity.Builder().group(TestGroups.ENTITY).vertex("A" + i).property(AccumuloPropertyNames.COUNT, i).build());
}
final User user = new User();
addElements(data, user, store);
} catch (final TableExistsException | StoreException e) {
fail("Failed to set up graph in Accumulo with exception: " + e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class GetElementsHandlerTest method testAddAndGetAllElementsNoAggregationAndDuplicateElements.
@Test
public void testAddAndGetAllElementsNoAggregationAndDuplicateElements() throws StoreException, OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraphNoAggregation();
final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getDuplicateElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EntitySeed("A")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Map<Element, Integer> resultingElementsToCount = GetAllElementsHandlerTest.streamToCount(Streams.toStream(results));
final Stream<Element> expectedResultsStream = GetAllElementsHandlerTest.getDuplicateElements().stream().filter(element -> element.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(element -> {
if (element instanceof Entity) {
return ((Entity) element).getVertex().equals("A");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A");
}
});
final Map<Element, Integer> expectedCounts = GetAllElementsHandlerTest.streamToCount(expectedResultsStream);
assertEquals(expectedCounts, resultingElementsToCount);
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class AddElementsFromRDD method createNewSnapshotDirectory.
/**
* Creates a new snapshot directory within the data directory in the store and moves the new data there.
*
* This is done by first creating the new snapshot directory with "-tmp" at the end, then all files are moved
* into that directory, and then the directory is renamed so that the "-tmp" is removed. This allows us to make
* the replacement of the old data with the new data an atomic operation and ensures that a get operation
* against the store will not read the directory when only some of the data has been moved there.
*
* @throws OperationException if an {@link IOException} or {@link StoreException} is thrown
*/
private void createNewSnapshotDirectory() throws OperationException {
final long snapshot = System.currentTimeMillis();
final String newDataDir = store.getDataDir() + "/" + ParquetStore.getSnapshotPath(snapshot) + "-tmp/";
LOGGER.info("Moving aggregated and sorted data to new snapshot-tmp directory {}", newDataDir);
try {
fs.mkdirs(new Path(newDataDir));
final FileStatus[] fss = fs.listStatus(new Path(getSortedAggregatedDirectory(true, true)));
for (int i = 0; i < fss.length; i++) {
final Path destination = new Path(newDataDir, fss[i].getPath().getName());
LOGGER.debug("Renaming {} to {}", fss[i].getPath(), destination);
fs.rename(fss[i].getPath(), destination);
}
// Move snapshot-tmp directory to snapshot
final String directoryWithoutTmp = newDataDir.substring(0, newDataDir.lastIndexOf("-tmp"));
LOGGER.info("Renaming {} to {}", newDataDir, directoryWithoutTmp);
fs.rename(new Path(newDataDir), new Path(directoryWithoutTmp));
} catch (final IOException e) {
throw new OperationException("IOException moving files to new snapshot directory", e);
}
// Set snapshot on store to new value
LOGGER.info("Updating latest snapshot on store to {}", snapshot);
try {
store.setLatestSnapshot(snapshot);
} catch (final StoreException e) {
throw new OperationException("StoreException setting the latest snapshot on the store to " + snapshot, e);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class OperationChainTest method testOperationChain.
@Test
public void testOperationChain() throws StoreException, OperationException {
// Given
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graph1").build()).addSchemas(StreamUtil.openStreams(getClass(), "example-schema")).storeProperties(new MapStoreProperties()).build();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final CloseableIterable<? extends Element> results = graph.execute(new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("vertex1")).build()).then(new GetElements.Builder().view(new View.Builder().edge("edge").build()).build()).build(), new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e instanceof Edge).filter(e -> {
final Edge edge = (Edge) e;
return edge.getSource().equals("vertex1") || edge.getDestination().equals("vertex2");
}).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
Aggregations