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.");
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations