Search in sources :

Example 16 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class AccumuloStore method preInitialise.

/**
 * Performs general initialisation without creating the table.
 *
 * @param graphId    The graph ID.
 * @param schema     The Gaffer Schema.
 * @param properties The Accumulo store properties.
 * @throws StoreException If the store could not be initialised.
 */
public void preInitialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
    setProperties(properties);
    final String deprecatedTableName = getProperties().getTable();
    if (null == graphId && null != deprecatedTableName) {
        // Deprecated
        super.initialise(deprecatedTableName, schema, getProperties());
    } else if (null != deprecatedTableName && !deprecatedTableName.equals(graphId)) {
        throw new IllegalArgumentException("The table in store.properties should no longer be used. " + "Please use a graphId instead or for now just set the graphId to be the same value as the store.properties table.");
    } else {
        super.initialise(graphId, schema, getProperties());
    }
    final String keyPackageClass = getProperties().getKeyPackageClass();
    try {
        this.keyPackage = Class.forName(keyPackageClass).asSubclass(AccumuloKeyPackage.class).newInstance();
    } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new StoreException("Unable to construct an instance of key package: " + keyPackageClass, e);
    }
    this.keyPackage.setSchema(getSchema());
}
Also used : StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 17 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException 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 StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class ElementInputFormat method createRecordReader.

@Override
public RecordReader<Element, NullWritable> createRecordReader(final InputSplit split, final TaskAttemptContext context) throws IOException, InterruptedException {
    log.setLevel(getLogLevel(context));
    final Configuration conf = context.getConfiguration();
    final String keyPackageClass = conf.get(KEY_PACKAGE);
    final Schema schema = Schema.fromJson(conf.get(SCHEMA).getBytes(CommonConstants.UTF_8));
    final View view = View.fromJson(conf.get(VIEW).getBytes(CommonConstants.UTF_8));
    try {
        return new ElementWithPropertiesRecordReader(keyPackageClass, schema, view);
    } catch (final StoreException | SchemaException | SerialisationException e) {
        throw new IOException("Exception creating RecordReader", e);
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Configuration(org.apache.hadoop.conf.Configuration) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) IOException(java.io.IOException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 19 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class AddElementsHandler method addElements.

private void addElements(final AddElements addElementsOperation, final HBaseStore store) throws OperationException {
    if (null == addElementsOperation.getInput()) {
        return;
    }
    try {
        final Table table = store.getTable();
        final Iterator<? extends Element> elements = addElementsOperation.getInput().iterator();
        final ElementSerialisation serialisation = new ElementSerialisation(store.getSchema());
        final int batchSize = store.getProperties().getWriteBufferSize();
        List<Put> puts = new ArrayList<>(batchSize);
        while (elements.hasNext()) {
            for (int i = 0; i < batchSize && elements.hasNext(); i++) {
                final Element element = elements.next();
                if (null == element) {
                    i--;
                    continue;
                }
                try {
                    final Pair<Put, Put> putPair = serialisation.getPuts(element);
                    puts.add(putPair.getFirst());
                    if (null != putPair.getSecond()) {
                        i++;
                        if (i >= batchSize) {
                            executePuts(table, puts);
                            puts = new ArrayList<>(batchSize);
                            i = 0;
                        }
                        puts.add(putPair.getSecond());
                    }
                } catch (final Exception e) {
                    if (addElementsOperation.isValidate() && !addElementsOperation.isSkipInvalidElements()) {
                        throw e;
                    }
                // otherwise just ignore the error
                }
            }
            executePuts(table, puts);
            puts = new ArrayList<>(batchSize);
        }
    } catch (final IOException | StoreException e) {
        throw new OperationException("Failed to add elements", e);
    }
}
Also used : HTable(org.apache.hadoop.hbase.client.HTable) Table(org.apache.hadoop.hbase.client.Table) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) StoreException(uk.gov.gchq.gaffer.store.StoreException) IOException(java.io.IOException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException) ElementSerialisation(uk.gov.gchq.gaffer.hbasestore.serialisation.ElementSerialisation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 20 with StoreException

use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.

the class GetAdjacentIdsHandler method doOperation.

private CloseableIterable<? extends EntityId> doOperation(final GetAdjacentIds op, final User user, final HBaseStore store) throws OperationException {
    if (null == op.getInput()) {
        // If null seeds no results are returned
        return new WrappedCloseableIterable<>();
    }
    final HBaseRetriever<?> edgeRetriever;
    final GetElements getEdges = new GetElements.Builder().options(op.getOptions()).view(new View.Builder().merge(op.getView()).entities(Collections.emptyMap()).build()).inputIds(op.getInput()).directedType(op.getDirectedType()).inOutType(op.getIncludeIncomingOutGoing()).build();
    try {
        edgeRetriever = store.createRetriever(getEdges, user, getEdges.getInput(), true);
    } catch (final StoreException e) {
        throw new OperationException(e.getMessage(), e);
    }
    return new ExtractDestinationEntityId(edgeRetriever);
}
Also used : WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

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