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 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);
}
}
use of uk.gov.gchq.gaffer.store.StoreException 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);
}
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class SplitTableTool method run.
@Override
public int run(final String[] arg0) throws OperationException {
LOGGER.info("Running SplitTableTool");
final Configuration conf = getConf();
FileSystem fs;
try {
fs = FileSystem.get(conf);
} catch (final IOException e) {
throw new OperationException("Failed to get Filesystem from configuration: " + e.getMessage(), e);
}
final SortedSet<Text> splits = new TreeSet<>();
try (final BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(new Path(operation.getInputPath())), CommonConstants.UTF_8))) {
String line = br.readLine();
while (line != null) {
splits.add(new Text(line));
line = br.readLine();
}
} catch (final IOException e) {
throw new OperationException(e.getMessage(), e);
}
try {
store.getConnection().tableOperations().addSplits(store.getProperties().getTable(), splits);
LOGGER.info("Added {} splits to table {}", splits.size(), store.getProperties().getTable());
} catch (final TableNotFoundException | AccumuloException | AccumuloSecurityException | StoreException e) {
LOGGER.error("Failed to add {} split points to table {}", splits.size(), store.getProperties().getTable());
throw new OperationException("Failed to add split points to the table specified: " + e.getMessage(), e);
}
return SUCCESS_RESPONSE;
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class InputFormatTest method shouldReturnCorrectDataToMapReduceJob.
private void shouldReturnCorrectDataToMapReduceJob(final Schema schema, final KeyPackage kp, final List<Element> data, final View view, final User user, final String instanceName, final Set<String> expectedResults) throws Exception {
final AccumuloStore store = new MockAccumuloStore();
final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
switch(kp) {
case BYTE_ENTITY_KEY_PACKAGE:
properties.setKeyPackageClass(ByteEntityKeyPackage.class.getName());
properties.setInstance(instanceName + "_BYTE_ENTITY");
break;
case CLASSIC_KEY_PACKAGE:
properties.setKeyPackageClass(ClassicKeyPackage.class.getName());
properties.setInstance(instanceName + "_CLASSIC");
}
try {
store.initialise(schema, properties);
} catch (StoreException e) {
fail("StoreException thrown: " + e);
}
setupGraph(store, data);
// Set up local conf
final JobConf conf = new JobConf();
conf.set("fs.default.name", "file:///");
conf.set("mapred.job.tracker", "local");
final FileSystem fs = FileSystem.getLocal(conf);
// Update configuration with instance, table name, etc.
store.updateConfiguration(conf, view, user);
// Run Driver
final File outputFolder = testFolder.newFolder();
FileUtils.deleteDirectory(outputFolder);
final Driver driver = new Driver(outputFolder.getAbsolutePath());
driver.setConf(conf);
driver.run(new String[] {});
// Read results and check correct
final SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(outputFolder + "/part-m-00000"), conf);
final Text text = new Text();
final Set<String> results = new HashSet<>();
while (reader.next(text)) {
results.add(text.toString());
}
reader.close();
assertEquals(expectedResults, results);
FileUtils.deleteDirectory(outputFolder);
}
use of uk.gov.gchq.gaffer.store.StoreException in project Gaffer by gchq.
the class PublicAccessPredefinedFederatedStore method initialise.
@Override
public void initialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
HashMapGraphLibrary.clear();
CacheServiceLoader.shutdown();
ExecutorService.shutdown();
super.initialise(graphId, schema, properties);
try {
// Accumulo store just contains edges
addGraphs(null, User.UNKNOWN_USER_ID, true, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_EDGES)).schema(new Schema.Builder().merge(schema.clone()).entities(Collections.emptyMap()).build()).properties(PROPERTIES).build());
// Accumulo store just contains entities
addGraphs(null, User.UNKNOWN_USER_ID, true, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_ENTITIES)).schema(new Schema.Builder().merge(schema.clone()).edges(Collections.emptyMap()).build()).properties(PROPERTIES).build());
} catch (final StorageException e) {
throw new StoreException(e.getMessage(), e);
}
}
Aggregations