Search in sources :

Example 51 with StoreException

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);
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) GafferWrappedErrorRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferWrappedErrorRuntimeException) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StoreException(uk.gov.gchq.gaffer.store.StoreException) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 52 with StoreException

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);
    }
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) TableExistsException(org.apache.accumulo.core.client.TableExistsException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 53 with StoreException

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) SeedMatchingType(uk.gov.gchq.gaffer.operation.SeedMatching.SeedMatchingType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) KorypheFunction(uk.gov.gchq.koryphe.function.KorypheFunction) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) Collections(java.util.Collections) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 54 with StoreException

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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 55 with StoreException

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) List(java.util.List) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Edge(uk.gov.gchq.gaffer.data.element.Edge) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

StoreException (uk.gov.gchq.gaffer.store.StoreException)70 OperationException (uk.gov.gchq.gaffer.operation.OperationException)26 IOException (java.io.IOException)21 Path (org.apache.hadoop.fs.Path)11 Schema (uk.gov.gchq.gaffer.store.schema.Schema)11 HashSet (java.util.HashSet)10 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)10 Element (uk.gov.gchq.gaffer.data.element.Element)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)9 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)9 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)9 ArrayList (java.util.ArrayList)8 AccumuloException (org.apache.accumulo.core.client.AccumuloException)8 Configuration (org.apache.hadoop.conf.Configuration)8 Test (org.junit.jupiter.api.Test)8 User (uk.gov.gchq.gaffer.user.User)8 Set (java.util.Set)6 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)6 FileSystem (org.apache.hadoop.fs.FileSystem)6