Search in sources :

Example 16 with IteratorSettingException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEntitiesOnly.

private void testEntityIdQueryEntitiesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    // Should find only the entities i
    assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 17 with IteratorSettingException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException 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 18 with IteratorSettingException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException 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 view The {@link View} 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 View view, final User user) throws StoreException {
    try {
        // Table name
        InputConfigurator.setInputTableName(AccumuloInputFormat.class, conf, getProperties().getTable());
        // 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);
        // Zookeeper
        addZookeeperToConfiguration(conf);
        // Add keypackage, schema and view to conf
        conf.set(ElementInputFormat.KEY_PACKAGE, getProperties().getKeyPackageClass());
        conf.set(ElementInputFormat.SCHEMA, new String(getSchema().toCompactJson(), CommonConstants.UTF_8));
        conf.set(ElementInputFormat.VIEW, new String(view.toCompactJson(), CommonConstants.UTF_8));
        // Add iterators that depend on the view
        if (view.hasGroups()) {
            IteratorSetting elementPreFilter = getKeyPackage().getIteratorFactory().getElementPreAggregationFilterIteratorSetting(view, this);
            IteratorSetting elementPostFilter = getKeyPackage().getIteratorFactory().getElementPostAggregationFilterIteratorSetting(view, this);
            InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPostFilter);
            InputConfigurator.addIterator(AccumuloInputFormat.class, conf, elementPreFilter);
        }
    } catch (final AccumuloSecurityException | IteratorSettingException | UnsupportedEncodingException e) {
        throw new StoreException(e);
    }
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 19 with IteratorSettingException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException in project Gaffer by gchq.

the class SummariseGroupOverRangesHandler method doOperation.

public CloseableIterable<Element> doOperation(final SummariseGroupOverRanges<Pair<ElementSeed>, Element> operation, final User user, final AccumuloStore store) throws OperationException {
    final int numEdgeGroups = operation.getView().getEdgeGroups().size();
    final int numEntityGroups = operation.getView().getEntityGroups().size();
    if ((numEdgeGroups + numEntityGroups) != 1) {
        throw new OperationException("You may only set one Group in your view for this operation.");
    }
    final String columnFamily;
    if (numEdgeGroups == 1) {
        columnFamily = (String) operation.getView().getEdgeGroups().toArray()[0];
    } else {
        columnFamily = (String) operation.getView().getEntityGroups().toArray()[0];
    }
    final IteratorSettingFactory itrFactory = store.getKeyPackage().getIteratorFactory();
    try {
        return new AccumuloRangeIDRetriever(store, operation, user, itrFactory.getElementPreAggregationFilterIteratorSetting(operation.getView(), store), itrFactory.getElementPostAggregationFilterIteratorSetting(operation.getView(), store), itrFactory.getEdgeEntityDirectionFilterIteratorSetting(operation), itrFactory.getElementPropertyRangeQueryFilter(operation), itrFactory.getRowIDAggregatorIteratorSetting(store, columnFamily));
    } catch (IteratorSettingException | StoreException e) {
        throw new OperationException("Failed to get elements", e);
    }
}
Also used : IteratorSettingFactory(uk.gov.gchq.gaffer.accumulostore.key.IteratorSettingFactory) AccumuloRangeIDRetriever(uk.gov.gchq.gaffer.accumulostore.retriever.impl.AccumuloRangeIDRetriever) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 20 with IteratorSettingException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntitySeedQueryEntitiesOnly.

private void testEntitySeedQueryEntitiesOnly(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEntities(true);
    operation.setIncludeEdges(IncludeEdgeType.NONE);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    //Should find only the entities i
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet)

Aggregations

IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)26 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)16 User (uk.gov.gchq.gaffer.user.User)16 HashSet (java.util.HashSet)15 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)15 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)12 Element (uk.gov.gchq.gaffer.data.element.Element)10 StoreException (uk.gov.gchq.gaffer.store.StoreException)9 Edge (uk.gov.gchq.gaffer.data.element.Edge)7 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)7 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)7 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)6 OperationException (uk.gov.gchq.gaffer.operation.OperationException)6 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Entry (java.util.Map.Entry)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2