Search in sources :

Example 1 with GetAllGraphIds

use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project gaffer-doc by gchq.

the class FederatedStoreWalkThrough method run.

public CloseableIterable<? extends Element> run() throws Exception {
    final Schema schema = new Schema.Builder().json(StreamUtil.openStreams(getClass(), schemaPath)).build();
    final HashMapGraphLibrary library = new HashMapGraphLibrary();
    library.addProperties("mapStore", getMapStoreProperties());
    library.addProperties("accumuloStore", getAccumuloStoreProperties());
    library.addSchema("roadTraffic", schema);
    // [creating a federatedstore] create a store that federates to a MapStore and AccumuloStore
    // ---------------------------------------------------------
    final Graph federatedGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId(getClass().getSimpleName()).library(library).build()).storeProperties(getFederatedStoreProperties()).build();
    // ---------------------------------------------------------
    // [federatedstore properties]
    // ---------------------------------------------------------
    final FederatedStoreProperties exampleFederatedProperty = new FederatedStoreProperties();
    exampleFederatedProperty.setCacheProperties(HashMapCacheService.class.getName());
    // ---------------------------------------------------------
    printJson("FED_PROP", getFederatedStoreProperties());
    final User user = new User("user01");
    final AddGraph addMapGraph = new AddGraph.Builder().graphId("mapGraph").schema(new Schema.Builder().json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/entities.json")).json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/types.json")).build()).storeProperties(getMapStoreProperties()).isPublic(true).build();
    federatedGraph.execute(addMapGraph, user);
    final AddGraph addAccumuloGraph = new AddGraph.Builder().graphId("accumuloGraph").schema(new Schema.Builder().json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/edges.json")).json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/types.json")).build()).storeProperties(getAccumuloStoreProperties()).isPublic(true).build();
    federatedGraph.execute(addAccumuloGraph, user);
    // [add another graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph addAnotherGraph = new AddGraph.Builder().graphId("AnotherGraph").schema(schema).storeProperties(getMapStoreProperties()).build();
    federatedGraph.execute(addAnotherGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(addAnotherGraph);
    addAccumuloGraph.setGraphAuths(null);
    printJson("ADD_GRAPH", addAnotherGraph);
    // [remove graph] remove a graph from the federated store.
    // ---------------------------------------------------------
    RemoveGraph removeGraph = new RemoveGraph.Builder().graphId("AnotherGraph").build();
    federatedGraph.execute(removeGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(removeGraph);
    printJson("REMOVE_GRAPH", removeGraph);
    // [get all graph ids] Get a list of all the graphId within the FederatedStore.
    // ---------------------------------------------------------
    final GetAllGraphIds getAllGraphIDs = new GetAllGraphIds();
    Iterable<? extends String> graphIds = federatedGraph.execute(getAllGraphIDs, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(getAllGraphIDs);
    printJson("GET_ALL_GRAPH_IDS", getAllGraphIDs);
    print("GRAPH_IDS", graphIds.toString());
    // [add elements] Create a data generator and add the edges to the federated graphs using an operation chain consisting of:
    // generateElements - generating edges from the data (note these are directed edges)
    // addElements - add the edges to the graph
    // ---------------------------------------------------------
    final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalities/data.txt"))).build()).then(new AddElements()).build();
    federatedGraph.execute(addOpChain, user);
    // ---------------------------------------------------------
    printJsonAndPython("ADD_ELEMENTS", addOpChain);
    // [get elements]
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<? extends Element>> getOpChain = new OperationChain.Builder().first(new GetElements.Builder().input(new EntitySeed("10")).build()).build();
    CloseableIterable<? extends Element> elements = federatedGraph.execute(getOpChain, user);
    for (final Element element : elements) {
        print("ELEMENTS", element.toString());
    }
    printJsonAndPython("GET_ELEMENTS", getOpChain);
    // [get elements from accumulo graph]
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<? extends Element>> getOpChainOnAccumuloGraph = new OperationChain.Builder().first(new GetElements.Builder().input(new EntitySeed("10")).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "accumuloGraph").build()).build();
    CloseableIterable<? extends Element> elementsFromAccumuloGraph = federatedGraph.execute(getOpChainOnAccumuloGraph, user);
    for (final Element element : elementsFromAccumuloGraph) {
        print("ELEMENTS_FROM_ACCUMULO_GRAPH", element.toString());
    }
    // [select graphs for operations]
    // ---------------------------------------------------------
    GetAllElements selectGraphsForOperations = new Builder().option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "graphId1, graphId2").build();
    // ---------------------------------------------------------
    printJsonAndPython("SELECT_GRAPHS_FOR_OPERATIONS", selectGraphsForOperations);
    // [do not skip failed execution]
    // ---------------------------------------------------------
    GetAllElements doNotSkipFailedExecution = new Builder().option(FederatedStoreConstants.KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE, "false").build();
    // ---------------------------------------------------------
    printJsonAndPython("DO_NOT_SKIP_FAILED_EXECUTION", doNotSkipFailedExecution);
    // [add public graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph publicGraph = new AddGraph.Builder().graphId("publicGraph").parentSchemaIds(Lists.newArrayList("roadTraffic")).parentPropertiesId("mapStore").isPublic(// <-- public access
    true).graphAuths(// <-- used but irrelevant as graph has public access
    "Auth1").build();
    federatedGraph.execute(addAnotherGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(publicGraph);
    printJson("ADD_PUBLIC_GRAPH", publicGraph);
    // [add private graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph privateGraph = new AddGraph.Builder().graphId("privateGraph").parentSchemaIds(Lists.newArrayList("roadTraffic")).parentPropertiesId("mapStore").build();
    federatedGraph.execute(addAnotherGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(privateGraph);
    printJson("ADD_PRIVATE_GRAPH", privateGraph);
    // [add secure graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph addSecureGraph = new AddGraph.Builder().graphId("SecureGraph").parentSchemaIds(Lists.newArrayList("roadTraffic")).parentPropertiesId("mapStore").graphAuths("Auth1", "Auth2", "Auth3").build();
    federatedGraph.execute(addSecureGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(addSecureGraph);
    printJson("ADD_SECURE_GRAPH", addSecureGraph);
    // [disallow public access]
    // ---------------------------------------------------------
    FederatedStoreProperties disallowPublicProperties = new FederatedStoreProperties();
    disallowPublicProperties.setGraphsCanHavePublicAccess(false);
    // ---------------------------------------------------------
    printJson("DISALLOW_PUBLIC_ACCESS", disallowPublicProperties.getProperties());
    // [limit custom properties]
    // ---------------------------------------------------------
    FederatedStoreProperties limitCustomProperties = new FederatedStoreProperties();
    limitCustomProperties.setCustomPropertyAuths("Auth1, Auth2, Auth3");
    // ---------------------------------------------------------
    printJson("LIMIT_CUSTOM_PROPERTIES", limitCustomProperties.getProperties());
    return elements;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) FederatedStoreProperties(uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements.Builder) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashMapCacheService(uk.gov.gchq.gaffer.cache.impl.HashMapCacheService) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) RemoveGraph(uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Graph(uk.gov.gchq.gaffer.graph.Graph) RemoveGraph(uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 2 with GetAllGraphIds

use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.

the class FederatedGetAllGraphsIDHandlerTest method shouldGetGraphIds.

@Test
public void shouldGetGraphIds() throws Exception {
    FederatedGetAllGraphIDHandler federatedGetAllGraphIDHandler = new FederatedGetAllGraphIDHandler();
    GetAllGraphIds op = Mockito.mock(GetAllGraphIds.class);
    Context context = Mockito.mock(Context.class);
    BDDMockito.given(context.getUser()).willReturn(testUser);
    FederatedStore store = Mockito.mock(FederatedStore.class);
    Set<String> expected = Sets.newHashSet();
    expected.add("value1");
    BDDMockito.given(store.getAllGraphIds(testUser, false)).willReturn(expected);
    Iterable<? extends String> actual = federatedGetAllGraphIDHandler.doOperation(op, context, store);
    assertEquals(expected, actual);
    Mockito.verify(store).getAllGraphIds(testUser, false);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Example 3 with GetAllGraphIds

use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.

the class FederatedStorePublicAccessTest method getAllGraphsIdsHasNext.

private static void getAllGraphsIdsHasNext(FederatedStore store, Context blankUserContext, final boolean expected) throws uk.gov.gchq.gaffer.operation.OperationException {
    Iterable<? extends String> execute = store.execute(new GetAllGraphIds(), blankUserContext);
    // final Iterable<? extends String> execute = store.execute(new GetAllGraphIds(), blankUserContext);
    assertEquals(expected, execute.iterator().hasNext());
}
Also used : GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds)

Example 4 with GetAllGraphIds

use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.

the class FederatedAdminIT method shouldChangeGraphAccessIdInCache.

@Test
public void shouldChangeGraphAccessIdInCache() throws Exception {
    // given
    FederatedStoreCache federatedStoreCache = new FederatedStoreCache();
    final String graphA = "graphA";
    graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).build(), user);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
    // when
    FederatedAccess before = federatedStoreCache.getAccessFromCache(graphA);
    final Boolean changed = graph.execute(new ChangeGraphAccess.Builder().graphId(graphA).ownerUserId(ADMIN_USER.getUserId()).build(), user);
    FederatedAccess after = federatedStoreCache.getAccessFromCache(graphA);
    // then
    assertThat(changed).isTrue();
    assertThat(after).isNotEqualTo(before);
    assertThat(before.getAddingUserId()).isEqualTo(user.getUserId());
    assertThat(after.getAddingUserId()).isEqualTo(ADMIN_USER.getUserId());
}
Also used : AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) FederatedStoreCache(uk.gov.gchq.gaffer.federatedstore.FederatedStoreCache) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) FederatedAccess(uk.gov.gchq.gaffer.federatedstore.FederatedAccess) Test(org.junit.jupiter.api.Test)

Example 5 with GetAllGraphIds

use of uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds in project Gaffer by gchq.

the class FederatedAdminIT method shouldChangeGraphUserFromSomeoneElseToReplacementUserAsAdminWhenRequestingAdminAccess.

@Test
public void shouldChangeGraphUserFromSomeoneElseToReplacementUserAsAdminWhenRequestingAdminAccess() throws Exception {
    // given
    final String graphA = "graphA";
    final User replacementUser = new User("replacement");
    graph.execute(new AddGraph.Builder().graphId(graphA).schema(new Schema()).storeProperties(ACCUMULO_PROPERTIES).graphAuths("Auths1").build(), user);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).contains(graphA);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), replacementUser))).doesNotContain(graphA);
    // when
    final Boolean changed = graph.execute(new ChangeGraphAccess.Builder().graphId(graphA).ownerUserId(replacementUser.getUserId()).option(FederatedStoreConstants.KEY_FEDERATION_ADMIN, "true").build(), ADMIN_USER);
    // then
    assertThat(changed).isTrue();
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user))).doesNotContain(graphA);
    assertThat(Lists.newArrayList(graph.execute(new GetAllGraphIds(), replacementUser))).contains(graphA);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) ChangeGraphAccess(uk.gov.gchq.gaffer.federatedstore.operation.ChangeGraphAccess) Test(org.junit.jupiter.api.Test)

Aggregations

GetAllGraphIds (uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds)20 Test (org.junit.jupiter.api.Test)15 Schema (uk.gov.gchq.gaffer.store.schema.Schema)15 User (uk.gov.gchq.gaffer.user.User)6 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)5 FederatedAccess (uk.gov.gchq.gaffer.federatedstore.FederatedAccess)3 FederatedStoreCache (uk.gov.gchq.gaffer.federatedstore.FederatedStoreCache)3 RemoveGraph (uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph)3 Graph (uk.gov.gchq.gaffer.graph.Graph)3 ChangeGraphAccess (uk.gov.gchq.gaffer.federatedstore.operation.ChangeGraphAccess)2 ChangeGraphId (uk.gov.gchq.gaffer.federatedstore.operation.ChangeGraphId)2 GetAllGraphInfo (uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphInfo)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)2 Connector (org.apache.accumulo.core.client.Connector)1 Test (org.junit.Test)1 HashMapCacheService (uk.gov.gchq.gaffer.cache.impl.HashMapCacheService)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Error (uk.gov.gchq.gaffer.core.exception.Error)1 Element (uk.gov.gchq.gaffer.data.element.Element)1