Skip to content

Commit

Permalink
gh-2435 Updating Tables for changeGraphIds
Browse files Browse the repository at this point in the history
  • Loading branch information
GCHQDev404 committed Jun 4, 2021
1 parent 8467703 commit c103f82
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 0 additions & 1 deletion store-implementation/federated-store/pom.xml
Expand Up @@ -44,7 +44,6 @@
<groupId>uk.gov.gchq.gaffer</groupId>
<artifactId>accumulo-store</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>uk.gov.gchq.gaffer</groupId>
Expand Down
Expand Up @@ -17,9 +17,11 @@
package uk.gov.gchq.gaffer.federatedstore;

import com.google.common.collect.Sets;
import org.apache.accumulo.core.client.Connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.gov.gchq.gaffer.accumulostore.AccumuloStore;
import uk.gov.gchq.gaffer.cache.CacheServiceLoader;
import uk.gov.gchq.gaffer.cache.exception.CacheOperationException;
import uk.gov.gchq.gaffer.commonutil.JsonUtil;
Expand All @@ -32,6 +34,7 @@
import uk.gov.gchq.gaffer.graph.GraphSerialisable;
import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.Store;
import uk.gov.gchq.gaffer.store.StoreTrait;
import uk.gov.gchq.gaffer.store.library.GraphLibrary;
import uk.gov.gchq.gaffer.store.operation.GetSchema;
Expand Down Expand Up @@ -618,6 +621,26 @@ private boolean changeGraphId(final String graphId, final String newGraphId, fin
}
}

//Update Tables
String storeClass = graphToMove.getStoreProperties().getStoreClass();
if (nonNull(storeClass) && storeClass.startsWith(AccumuloStore.class.getPackage().getName())) {
Store tmpStore = Store.createStore(graphId, graphToMove.getSchema(), graphToMove.getStoreProperties());
if (tmpStore instanceof AccumuloStore) {
AccumuloStore accumuloStore = ((AccumuloStore) tmpStore);
try {
Connector connection = accumuloStore.getConnection();
if (connection.tableOperations().exists(graphId)) {
connection.tableOperations().offline(graphId);
connection.tableOperations().clone(graphId, newGraphId, true, null, null);
connection.tableOperations().delete(graphId);
}
} catch (final Exception e) {
LOGGER.warn("Error trying to update tables for graphID:{} graphToMove:{}", graphId, graphToMove);
LOGGER.warn("Error trying to update tables.", e);
}
}
}

final GraphConfig configWithNewGraphId = cloneGraphConfigWithNewGraphId(newGraphId, graphToMove);

//add the graph being renamed.
Expand Down
Expand Up @@ -17,10 +17,12 @@

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.accumulo.core.client.Connector;
import org.junit.Before;
import org.junit.Test;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.utils.TableUtils;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.federatedstore.FederatedAccess;
import uk.gov.gchq.gaffer.federatedstore.FederatedStoreCache;
Expand Down Expand Up @@ -441,8 +443,8 @@ public void shouldNotChangeGraphUserFromSomeoneElseToReplacementUserAsNonAdminWh
@Test
public void shouldChangeGraphIdForOwnGraph() throws Exception {
//given
final String graphA = "graphA";
final String graphB = "graphB";
final String graphA = "graphTableA";
final String graphB = "graphTableB";
graph.execute(new AddGraph.Builder()
.graphId(graphA)
.schema(new Schema())
Expand All @@ -451,16 +453,31 @@ public void shouldChangeGraphIdForOwnGraph() throws Exception {
.build(), user);
assertTrue(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user)).contains(graphA));

Connector connector = TableUtils.getConnector(ACCUMULO_PROPERTIES.getInstance(),
ACCUMULO_PROPERTIES.getZookeepers(),
ACCUMULO_PROPERTIES.getUser(),
ACCUMULO_PROPERTIES.getPassword());

//when
boolean tableGraphABefore = connector.tableOperations().exists(graphA);
boolean tableGraphBBefore = connector.tableOperations().exists(graphB);

final Boolean changed = graph.execute(new ChangeGraphId.Builder()
.graphId(graphA)
.newGraphId(graphB)
.build(), user);

boolean tableGraphAfter = connector.tableOperations().exists(graphA);
boolean tableGraphBAfter = connector.tableOperations().exists(graphB);

//then
assertTrue(changed);
assertFalse(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user)).contains(graphA));
assertTrue(Lists.newArrayList(graph.execute(new GetAllGraphIds(), user)).contains(graphB));
assertTrue(tableGraphABefore);
assertFalse(tableGraphBBefore);
assertFalse(tableGraphAfter);
assertTrue(tableGraphBAfter);

}

Expand Down

0 comments on commit c103f82

Please sign in to comment.