Search in sources :

Example 36 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class AccumuloStore method updateConfiguration.

/**
 * Updates a Hadoop {@link Configuration} with information needed to connect to the Accumulo store. It adds
 * iterators to apply the provided {@link View}. This method will be used by operations that run MapReduce
 * or Spark jobs against the Accumulo store.
 *
 * @param conf         A {@link Configuration} to be updated.
 * @param graphFilters The operation {@link GraphFilters} to be applied.
 * @param user         The {@link User} to be used.
 * @throws StoreException If there is a failure to connect to Accumulo or a problem setting the iterators.
 */
public void updateConfiguration(final Configuration conf, final GraphFilters graphFilters, final User user) throws StoreException {
    try {
        final View view = graphFilters.getView();
        // Table name
        LOGGER.info("Updating configuration with table name of {}", getTableName());
        InputConfigurator.setInputTableName(AccumuloInputFormat.class, conf, getTableName());
        // User
        addUserToConfiguration(conf);
        // Authorizations
        Authorizations authorisations;
        if (null != user && null != user.getDataAuths()) {
            authorisations = new Authorizations(user.getDataAuths().toArray(new String[user.getDataAuths().size()]));
        } else {
            authorisations = new Authorizations();
        }
        InputConfigurator.setScanAuthorizations(AccumuloInputFormat.class, conf, authorisations);
        LOGGER.info("Updating configuration with authorizations of {}", authorisations);
        // Zookeeper
        addZookeeperToConfiguration(conf);
        // Add keypackage, schema and view to conf
        conf.set(ElementInputFormat.KEY_PACKAGE, getProperties().getKeyPackageClass());
        LOGGER.info("Updating configuration with key package of {}", getProperties().getKeyPackageClass());
        conf.set(ElementInputFormat.SCHEMA, new String(getSchema().toCompactJson(), CommonConstants.UTF_8));
        LOGGER.debug("Updating configuration with Schema of {}", getSchema());
        conf.set(ElementInputFormat.VIEW, new String(view.toCompactJson(), CommonConstants.UTF_8));
        LOGGER.debug("Updating configuration with View of {}", view);
        if (view.hasGroups()) {
            // Add the columns to fetch
            final Collection<org.apache.accumulo.core.util.Pair<Text, Text>> columnFamilyColumnQualifierPairs = Stream.concat(view.getEntityGroups().stream(), view.getEdgeGroups().stream()).map(g -> new org.apache.accumulo.core.util.Pair<>(new Text(g), (Text) null)).collect(Collectors.toSet());
            InputConfigurator.fetchColumns(AccumuloInputFormat.class, conf, columnFamilyColumnQualifierPairs);
            LOGGER.info("Updated configuration with column family/qualifiers of {}", StringUtils.join(columnFamilyColumnQualifierPairs, ','));
            // Add iterators that depend on the view
            final IteratorSetting elementPreFilter = getKeyPackage().getIteratorFactory().getElementPreAggregationFilterIteratorSetting(view, this);
            if (null != elementPreFilter) {
                InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPreFilter);
                LOGGER.info("Added pre-aggregation filter iterator of {}", elementPreFilter);
            }
            final IteratorSetting elementPostFilter = getKeyPackage().getIteratorFactory().getElementPostAggregationFilterIteratorSetting(view, this);
            if (null != elementPostFilter) {
                InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPostFilter);
                LOGGER.info("Added post-aggregation filter iterator of {}", elementPostFilter);
            }
            final IteratorSetting edgeEntityDirFilter = getKeyPackage().getIteratorFactory().getEdgeEntityDirectionFilterIteratorSetting(graphFilters);
            if (null != edgeEntityDirFilter) {
                InputConfigurator.addIterator(AccumuloInputFormat.class, conf, edgeEntityDirFilter);
                LOGGER.info("Added edge direction filter iterator of {}", edgeEntityDirFilter);
            }
        }
    } catch (final AccumuloSecurityException | IteratorSettingException | UnsupportedEncodingException e) {
        throw new StoreException(e);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) VISIBILITY(uk.gov.gchq.gaffer.store.StoreTrait.VISIBILITY) TableUtils(uk.gov.gchq.gaffer.accumulostore.utils.TableUtils) Text(org.apache.hadoop.io.Text) GenerateSplitPointsFromSampleHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GenerateSplitPointsFromSampleHandler) Element(uk.gov.gchq.gaffer.data.element.Element) SchemaOptimiser(uk.gov.gchq.gaffer.store.schema.SchemaOptimiser) AddElementsFromHdfsHandler(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.handler.AddElementsFromHdfsHandler) STORE_VALIDATION(uk.gov.gchq.gaffer.store.StoreTrait.STORE_VALIDATION) Configuration(org.apache.hadoop.conf.Configuration) GetElementsBetweenSetsHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GetElementsBetweenSetsHandler) InputConfigurator(org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator) SampleElementsForSplitPoints(uk.gov.gchq.gaffer.operation.impl.SampleElementsForSplitPoints) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) AccumuloInputFormat(org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Set(java.util.Set) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) GetElementsBetweenSets(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsBetweenSets) Stream(java.util.stream.Stream) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) AddElementsHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.AddElementsHandler) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) SplitStore(uk.gov.gchq.gaffer.operation.impl.SplitStore) ImportAccumuloKeyValueFiles(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.operation.ImportAccumuloKeyValueFiles) GetElementsWithinSet(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsWithinSet) Key(org.apache.accumulo.core.data.Key) GetElementsHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GetElementsHandler) Status(uk.gov.gchq.gaffer.core.exception.Status) SampleDataForSplitPoints(uk.gov.gchq.gaffer.hdfs.operation.SampleDataForSplitPoints) HdfsSplitStoreFromFileHandler(uk.gov.gchq.gaffer.hdfs.operation.handler.HdfsSplitStoreFromFileHandler) ElementInputFormat(uk.gov.gchq.gaffer.accumulostore.inputformat.ElementInputFormat) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Operation(uk.gov.gchq.gaffer.operation.Operation) SplitStoreFromIterable(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromIterable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) CommonConstants(uk.gov.gchq.gaffer.commonutil.CommonConstants) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) GetElementsWithinSetHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GetElementsWithinSetHandler) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) GetAdjacentIdsHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GetAdjacentIdsHandler) SummariseGroupOverRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.SummariseGroupOverRanges) LoggerFactory(org.slf4j.LoggerFactory) Mutation(org.apache.accumulo.core.data.Mutation) TRANSFORMATION(uk.gov.gchq.gaffer.store.StoreTrait.TRANSFORMATION) SampleElementsForSplitPointsHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.SampleElementsForSplitPointsHandler) GetAllElementsHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GetAllElementsHandler) QUERY_AGGREGATION(uk.gov.gchq.gaffer.store.StoreTrait.QUERY_AGGREGATION) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) POST_TRANSFORMATION_FILTERING(uk.gov.gchq.gaffer.store.StoreTrait.POST_TRANSFORMATION_FILTERING) Value(org.apache.accumulo.core.data.Value) GetElementsInRangesHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.GetElementsInRangesHandler) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) Collection(java.util.Collection) SplitStoreHandler(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.handler.SplitStoreHandler) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Store(uk.gov.gchq.gaffer.store.Store) PRE_AGGREGATION_FILTERING(uk.gov.gchq.gaffer.store.StoreTrait.PRE_AGGREGATION_FILTERING) SplitStoreFromIterableHandler(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.handler.SplitStoreFromIterableHandler) List(java.util.List) INGEST_AGGREGATION(uk.gov.gchq.gaffer.store.StoreTrait.INGEST_AGGREGATION) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Entry(java.util.Map.Entry) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) GraphFilters(uk.gov.gchq.gaffer.operation.graph.GraphFilters) StoreException(uk.gov.gchq.gaffer.store.StoreException) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) ORDERED(uk.gov.gchq.gaffer.store.StoreTrait.ORDERED) SummariseGroupOverRangesHandler(uk.gov.gchq.gaffer.accumulostore.operation.handler.SummariseGroupOverRangesHandler) User(uk.gov.gchq.gaffer.user.User) Connector(org.apache.accumulo.core.client.Connector) AccumuloKeyPackage(uk.gov.gchq.gaffer.accumulostore.key.AccumuloKeyPackage) GetElementsInRanges(uk.gov.gchq.gaffer.accumulostore.operation.impl.GetElementsInRanges) POST_AGGREGATION_FILTERING(uk.gov.gchq.gaffer.store.StoreTrait.POST_AGGREGATION_FILTERING) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Logger(org.slf4j.Logger) AccumuloStoreConstants(uk.gov.gchq.gaffer.accumulostore.utils.AccumuloStoreConstants) GenerateSplitPointsFromSample(uk.gov.gchq.gaffer.operation.impl.GenerateSplitPointsFromSample) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException) SampleDataForSplitPointsHandler(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.handler.SampleDataForSplitPointsHandler) Authorizations(org.apache.accumulo.core.security.Authorizations) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) MATCHED_VERTEX(uk.gov.gchq.gaffer.store.StoreTrait.MATCHED_VERTEX) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ImportAccumuloKeyValueFilesHandler(uk.gov.gchq.gaffer.accumulostore.operation.hdfs.handler.ImportAccumuloKeyValueFilesHandler) AddElementsFromHdfs(uk.gov.gchq.gaffer.hdfs.operation.AddElementsFromHdfs) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Collections(java.util.Collections) Authorizations(org.apache.accumulo.core.security.Authorizations) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Text(org.apache.hadoop.io.Text) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) StoreException(uk.gov.gchq.gaffer.store.StoreException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair)

Example 37 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class GetProxyPropertiesTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    GetProxyProperties testObject = getTestObject();
    Operation operation = testObject.shallowClone();
    assertEquals(testObject, operation);
    assertFalse(testObject == operation);
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 38 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class GraphTest method shouldManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.

@Test
public void shouldManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
    // Given
    operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE_5).edge(TestGroups.EDGE).build()).build();
    final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE)).build();
    given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(opChain.shallowClone()).willReturn(clonedOpChain);
    given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
    given(clonedOpChain.flatten()).willReturn(Arrays.asList(operation));
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(new Schema());
    given(store.getProperties()).willReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(updateViewHook).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
    given(store.execute(captor.capture(), contextCaptor1.capture())).willReturn(new ArrayList<>());
    // When / Then
    graph.execute(opChain, user);
    final List<Operation> ops = captor.getValue().getOperations();
    JsonAssert.assertEquals(new View.Builder().edge(TestGroups.EDGE_5).build().toCompactJson(), ((GetElements) ops.get(0)).getView().toCompactJson());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 39 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddAllOperationsGivenJson.

@Test
public void shouldAddAllOperationsGivenJson() throws IOException {
    // Given
    final byte[] bytes;
    try (final InputStream inputStream = StreamUtil.openStream(getClass(), ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH)) {
        bytes = IOUtils.toByteArray(inputStream);
    }
    final AddOperationsToChain hook = fromJson(bytes);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation validate = new Validate();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation count = new Count<>();
    Operation countGroups = new CountGroups();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).then(count).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) InputStream(java.io.InputStream) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 40 with Operation

use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddAllOperationsWithNoAuthsGivenPath.

@Test
public void shouldAddAllOperationsWithNoAuthsGivenPath() throws IOException {
    // Given
    AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation validate = new Validate();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation count = new Count<>();
    Operation countGroups = new CountGroups();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).then(count).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Aggregations

Operation (uk.gov.gchq.gaffer.operation.Operation)136 Test (org.junit.jupiter.api.Test)88 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)49 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)44 Schema (uk.gov.gchq.gaffer.store.schema.Schema)41 Context (uk.gov.gchq.gaffer.store.Context)35 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)34 Store (uk.gov.gchq.gaffer.store.Store)28 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)26 LinkedHashMap (java.util.LinkedHashMap)21 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)21 User (uk.gov.gchq.gaffer.user.User)21 ArrayList (java.util.ArrayList)18 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)18 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)17 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)13 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)13 OperationException (uk.gov.gchq.gaffer.operation.OperationException)13