Search in sources :

Example 66 with StoreException

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

the class TableUtils method validateTable.

private static void validateTable(final AccumuloStore store, final String tableName, final Connector connector) throws StoreException {
    final IteratorSetting requiredAggItrSetting;
    if (store.getSchema().isAggregationEnabled()) {
        try {
            requiredAggItrSetting = store.getKeyPackage().getIteratorFactory().getAggregatorIteratorSetting(store);
            if (null != requiredAggItrSetting) {
                requiredAggItrSetting.removeOption(AccumuloStoreConstants.SCHEMA);
                requiredAggItrSetting.removeOption(COLUMN_FAMILIES_OPTION);
            }
        } catch (final IteratorSettingException e) {
            throw new StoreException("Unable to create aggregator iterator settings", e);
        }
    } else {
        requiredAggItrSetting = null;
    }
    final IteratorSetting requiredValidatorItrSetting;
    if (store.getProperties().getEnableValidatorIterator()) {
        requiredValidatorItrSetting = store.getKeyPackage().getIteratorFactory().getValidatorIteratorSetting(store);
        if (null != requiredValidatorItrSetting) {
            requiredValidatorItrSetting.removeOption(AccumuloStoreConstants.SCHEMA);
            requiredValidatorItrSetting.removeOption(COLUMN_FAMILIES_OPTION);
        }
    } else {
        requiredValidatorItrSetting = null;
    }
    final ValidationResult validationResult = new ValidationResult();
    for (final IteratorScope iteratorScope : EnumSet.allOf(IteratorScope.class)) {
        final IteratorSetting aggItrSetting;
        final IteratorSetting validatorItrSetting;
        final IteratorSetting versioningIterSetting;
        try {
            aggItrSetting = store.getConnection().tableOperations().getIteratorSetting(tableName, AccumuloStoreConstants.AGGREGATOR_ITERATOR_NAME, iteratorScope);
            if (null != aggItrSetting) {
                aggItrSetting.removeOption(AccumuloStoreConstants.SCHEMA);
                aggItrSetting.removeOption(COLUMN_FAMILIES_OPTION);
            }
            validatorItrSetting = store.getConnection().tableOperations().getIteratorSetting(tableName, AccumuloStoreConstants.VALIDATOR_ITERATOR_NAME, iteratorScope);
            if (null != validatorItrSetting) {
                validatorItrSetting.removeOption(AccumuloStoreConstants.SCHEMA);
                validatorItrSetting.removeOption(COLUMN_FAMILIES_OPTION);
            }
            versioningIterSetting = store.getConnection().tableOperations().getIteratorSetting(tableName, "vers", iteratorScope);
        } catch (final AccumuloSecurityException | AccumuloException | TableNotFoundException e) {
            throw new StoreException("Unable to find iterators on the table " + tableName, e);
        }
        if (!Objects.equals(requiredAggItrSetting, aggItrSetting)) {
            validationResult.addError("Aggregator iterator for scope " + iteratorScope.name() + " is not as expected. " + "Expected: " + requiredAggItrSetting + ", but found: " + aggItrSetting);
        }
        if (!Objects.equals(requiredValidatorItrSetting, validatorItrSetting)) {
            validationResult.addError("Validator iterator for scope " + iteratorScope.name() + " is not as expected. " + "Expected: " + requiredValidatorItrSetting + ", but found: " + validatorItrSetting);
        }
        if (null != versioningIterSetting) {
            validationResult.addError("The versioning iterator for scope " + iteratorScope.name() + " should not be set on the table.");
        }
    }
    final Iterable<Map.Entry<String, String>> tableProps;
    try {
        tableProps = connector.tableOperations().getProperties(tableName);
    } catch (final AccumuloException | TableNotFoundException e) {
        throw new StoreException("Unable to get table properties.", e);
    }
    boolean bloomFilterEnabled = false;
    String bloomKeyFunctor = null;
    for (final Map.Entry<String, String> tableProp : tableProps) {
        if (Property.TABLE_BLOOM_ENABLED.getKey().equals(tableProp.getKey())) {
            if (Boolean.parseBoolean(tableProp.getValue())) {
                bloomFilterEnabled = true;
            }
        } else if (Property.TABLE_BLOOM_KEY_FUNCTOR.getKey().equals(tableProp.getKey())) {
            if (null == bloomKeyFunctor || CoreKeyBloomFunctor.class.getName().equals(tableProp.getValue())) {
                bloomKeyFunctor = tableProp.getValue();
            }
        }
    }
    if (!bloomFilterEnabled) {
        validationResult.addError("Bloom filter is not enabled. " + Property.TABLE_BLOOM_ENABLED.getKey() + " = " + bloomFilterEnabled);
    }
    if (!CoreKeyBloomFunctor.class.getName().equals(bloomKeyFunctor)) {
        validationResult.addError("Bloom key functor class is incorrect. " + "Expected: " + CoreKeyBloomFunctor.class.getName() + ", but found: " + bloomKeyFunctor);
    }
    if (!validationResult.isValid()) {
        throw new StoreException("Your table " + tableName + " is configured incorrectly. " + validationResult.getErrorString() + "\nEither delete the table and let Gaffer create it for you or fix it manually using the Accumulo shell or the Gaffer AddUpdateTableIterator utility.");
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) StoreException(uk.gov.gchq.gaffer.store.StoreException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) CoreKeyBloomFunctor(uk.gov.gchq.gaffer.accumulostore.key.core.impl.CoreKeyBloomFunctor) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) HashMap(java.util.HashMap) Map(java.util.Map)

Example 67 with StoreException

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

the class SummariseGroupOverRangesHandler method doOperation.

public CloseableIterable<? extends Element> doOperation(final SummariseGroupOverRanges 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 (final 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 68 with StoreException

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

the class HBaseAddElementsFromHdfsJobFactory method setupOutput.

protected void setupOutput(final Job job, final AddElementsFromHdfs operation, final HBaseStore store) throws IOException {
    FileOutputFormat.setOutputPath(job, new Path(operation.getOutputPath()));
    String stagingDir = operation.getOption(HBaseStoreConstants.OPERATION_HDFS_STAGING_PATH);
    if (StringUtils.isEmpty(stagingDir)) {
        if (StringUtils.isNotEmpty(operation.getWorkingPath())) {
            stagingDir = operation.getWorkingPath() + (operation.getWorkingPath().endsWith("/") ? "" : "/") + "stagingDir";
        }
    }
    if (StringUtils.isNotEmpty(stagingDir)) {
        job.getConfiguration().set(HConstants.TEMPORARY_FS_DIRECTORY_KEY, stagingDir);
    }
    try {
        HFileOutputFormat2.configureIncrementalLoad(job, store.getTable(), store.getConnection().getRegionLocator(store.getTableName()));
    } catch (final StoreException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 69 with StoreException

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

the class HBaseRetriever method createScanner.

private CloseableIterable<Result> createScanner() {
    // End of input ids
    if (null != idsIterator && !idsIterator.hasNext()) {
        return null;
    }
    Table table = null;
    try {
        final Scan scan = new Scan();
        if (null != idsIterator) {
            final List<MultiRowRangeFilter.RowRange> rowRanges = new ArrayList<>();
            final int maxEntriesForBatchScanner = store.getProperties().getMaxEntriesForBatchScanner();
            int count = 0;
            while (idsIterator.hasNext() && count < maxEntriesForBatchScanner) {
                count++;
                rowRanges.addAll(rowRangeFactory.getRowRange(idsIterator.next(), operation));
            }
            if (rowRanges.isEmpty()) {
                return new WrappedCloseableIterable<>(Collections.emptyList());
            }
            scan.setFilter(new MultiRowRangeFilter(rowRanges));
        }
        scan.setAuthorizations(authorisations);
        scan.setAttribute(HBaseStoreConstants.SCHEMA, store.getSchema().toCompactJson());
        scan.setAttribute(HBaseStoreConstants.INCLUDE_MATCHED_VERTEX, Bytes.toBytes(Boolean.toString(includeMatchedVertex)));
        scan.setAttribute(HBaseStoreConstants.VIEW, operation.getView().toCompactJson());
        if (null != operation.getDirectedType()) {
            scan.setAttribute(HBaseStoreConstants.DIRECTED_TYPE, Bytes.toBytes(operation.getDirectedType().name()));
        }
        if (null != extraProcessors) {
            scan.setAttribute(HBaseStoreConstants.EXTRA_PROCESSORS, extraProcessors);
        }
        scan.setMaxVersions();
        table = store.getTable();
        return new WrappedCloseableIterable<>(table.getScanner(scan));
    } catch (final IOException | StoreException e) {
        if (null != table) {
            CloseableUtil.close(table);
        }
        throw new RuntimeException(e);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) MultiRowRangeFilter(org.apache.hadoop.hbase.filter.MultiRowRangeFilter) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) IOException(java.io.IOException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 70 with StoreException

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

the class HBaseStore method getTable.

/**
 * Gets the table.
 *
 * @return the table.
 * @throws StoreException if a reference to the table could not be created.
 */
public Table getTable() throws StoreException {
    final TableName tableName = getTableName();
    final Connection connection = getConnection();
    try {
        return connection.getTable(tableName);
    } catch (final IOException e) {
        CloseableUtil.close(connection);
        throw new StoreException(e);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Connection(org.apache.hadoop.hbase.client.Connection) IOException(java.io.IOException) 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