use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class VisibilityIT method shouldAccessMultipleVisibilityGroups_or.
@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMultipleVisibilityGroups_or() throws OperationException {
final Set<Element> elements = new HashSet<>();
final Entity entity1 = new Entity(TestGroups.ENTITY, "B");
entity1.putProperty(TestTypes.VISIBILITY, "vis1|vis2");
elements.add(entity1);
final AddElements addElements = new AddElements.Builder().input(elements).build();
graph.execute(addElements, new User());
final GetElements get = new GetElements.Builder().input(new EntitySeed("B")).build();
final CloseableIterable<? extends Element> iterable = graph.execute(get, new User(User.UNKNOWN_USER_ID, Sets.newHashSet("vis1")));
final List<Element> results = Lists.newArrayList(iterable);
assertThat(results).withFailMessage("Results do not contain all expected entities.").hasSize(1);
for (final Element e : results) {
assertThat(e.getProperties()).containsKey(TestTypes.VISIBILITY);
}
iterable.close();
}
use of uk.gov.gchq.gaffer.user.User 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);
}
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class JsonSerialisationConfigIT method shouldSerialiseHyperLogLogPlussesWhenSerialiserModulesConfigured.
@Test
public void shouldSerialiseHyperLogLogPlussesWhenSerialiserModulesConfigured() throws OperationException {
// Given
graphFactory.getGraph().execute(new AddElements.Builder().input(new Entity.Builder().vertex("vertex1").group("Cardinality").property("hllp", new HyperLogLogPlus(5, 5)).build()).build(), new User());
// When
ResponseEntity<List> elements = post("/graph/operations/execute", new GetAllElements(), List.class);
Map<String, Object> result = ((List<Map<String, Object>>) elements.getBody()).get(0);
Map<String, Object> hllp = ((Map<String, Map<String, Map<String, Map<String, Object>>>>) result.get("properties")).get("hllp").get(HyperLogLogPlus.class.getName()).get("hyperLogLogPlus");
assertNotNull(hllp);
assertTrue(hllp.containsKey("cardinality"));
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class OperationControllerTest method shouldCorrectlyChunkIterables.
@Test
public void shouldCorrectlyChunkIterables() throws IOException, OperationException {
// Given
when(userFactory.createContext()).thenReturn(new Context(new User()));
when(store.execute(any(Output.class), any(Context.class))).thenReturn(Arrays.asList(1, 2, 3));
// When
ResponseEntity<StreamingResponseBody> response = operationController.executeChunked(new GetAllElements());
OutputStream output = new ByteArrayOutputStream();
response.getBody().writeTo(output);
// Then
assertEquals("1\r\n2\r\n3\r\n", output.toString());
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class FederatedAggregateHandlerTest method shouldAggregateDuplicatesFromDiffStores.
@Test
public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
FederatedStoreProperties federatedStoreProperties = FederatedStoreProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "predefinedFederatedStore.properties"));
final Graph fed = new Graph.Builder().config(new GraphConfig("fed")).addSchema(new Schema()).storeProperties(federatedStoreProperties).build();
final String graphNameA = "a";
final String graphNameB = "b";
final Context context = new Context(new User());
fed.execute(new OperationChain.Builder().first(new AddGraph.Builder().graphId(graphNameA).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).then(new AddGraph.Builder().graphId(graphNameB).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).build(), context);
fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameA).build(), context);
fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameB).build(), context);
final CloseableIterable<? extends Element> getAll = fed.execute(new GetAllElements(), context);
List<Element> list = new ArrayList<>();
getAll.forEach(list::add);
assertThat(list).hasSize(2);
final Iterable<? extends Element> getAggregate = fed.execute(new OperationChain.Builder().first(new GetAllElements()).then(new Aggregate()).build(), context);
list.clear();
getAggregate.forEach(list::add);
assertThat(list).hasSize(1);
}
Aggregations