Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tb06904 committed Jan 17, 2025
1 parent 89d808f commit d039e97
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2024 Crown Copyright
* Copyright 2017-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -253,11 +253,11 @@ public enum DefaultIdManager {

private final Graph graph;
private final Configuration configuration;
private final GafferPopGraphVariables variables;
private final GafferPopGraphFeatures features;
private final Map<String, String> opOptions;
private final User defaultUser;
private final ServiceRegistry serviceRegistry;
private final GafferPopGraphVariables variables = new GafferPopGraphVariables();
private final GafferPopGraphFeatures features = new GafferPopGraphFeatures();
private final Map<String, String> opOptions = new HashMap<>();
private final ServiceRegistry serviceRegistry = new ServiceRegistry();

private static final Logger LOGGER = LoggerFactory.getLogger(GafferPopGraph.class);
private static final String GET_DEBUG_MSG = "Requested a GetElements, results will be truncated to: {}.";
Expand All @@ -270,8 +270,6 @@ public GafferPopGraph(final Configuration configuration) {
public GafferPopGraph(final Configuration configuration, final Graph graph) {
this.configuration = configuration;
this.graph = graph;
features = new GafferPopGraphFeatures();
opOptions = new HashMap<>();
if (configuration().containsKey(OP_OPTIONS)) {
for (final String option : configuration().getStringArray(OP_OPTIONS)) {
final String[] parts = option.split(":");
Expand All @@ -285,10 +283,8 @@ public GafferPopGraph(final Configuration configuration, final Graph graph) {
.build();

// Set the graph variables to current config
variables = new GafferPopGraphVariables();
setDefaultVariables();

serviceRegistry = new ServiceRegistry();
serviceRegistry.registerService(new GafferPopNamedOperationServiceFactory(this));

// Add and register custom traversals
Expand Down Expand Up @@ -364,21 +360,6 @@ public Vertex addVertex(final Object... keyValues) {
idValue = ElementHelper.getIdValue(keyValues).orElseThrow(() -> new IllegalArgumentException("ID is required"));
}

/*
* TODO: Check the ID type is relevant for the group (a.k.a label) in the schema and auto convert
* as the some Standard tinkerpop tests add data for the same group but with a different
* Object type for the ID. Using a String ID manager might be the most flexible for these
* tests.
* Basic idea of auto converting the type is below:
*
* String idSchemaType = graph.getSchema().getEntity(label).getVertex();
* String idTypeName = graph.getSchema().getType(idSchemaType).getFullClassString();
* if (!idTypeName.equals(idValue.getClass().getName())) {
* LOGGER.warn("Vertex ID is not the correct type for the schema: " + idValue);
* idValue = graph.getSchema().getType(idSchemaType).getClazz().cast(idValue);
* }
*/

final GafferPopVertex vertex = new GafferPopVertex(label, idValue, this);
ElementHelper.attachProperties(vertex, VertexProperty.Cardinality.list, keyValues);
addVertex(vertex);
Expand Down Expand Up @@ -701,7 +682,6 @@ public <T> T execute(final OperationChain<T> opChain) {

try {
LOGGER.info("GafferPop operation chain called: {}", opChain.toOverviewString());
LOGGER.info("USER IS: " + variables.getUser().getUserId());
return graph.execute(opChain, variables.getUser());
} catch (final Exception e) {
LOGGER.error("Operation chain failed: {}", e.getMessage());
Expand All @@ -711,7 +691,15 @@ public <T> T execute(final OperationChain<T> opChain) {

/**
* Sets the {@link GafferPopGraphVariables} to default values for this
* graph optionally preserving the previous user.
* graph.
*/
public void setDefaultVariables() {
setDefaultVariables(false);
}

/**
* Sets the {@link GafferPopGraphVariables} to default values for this
* graph optionally preserving the current user.
*
* @param preserveUser keep the current set user.
*/
Expand All @@ -731,14 +719,6 @@ public void setDefaultVariables(final boolean preserveUser) {
variables.set(GafferPopGraphVariables.LAST_OPERATION_CHAIN, new OperationChain<Object>());
}

/**
* Sets the {@link GafferPopGraphVariables} to default values for this
* graph.
*/
public void setDefaultVariables() {
setDefaultVariables(false);
}

/**
* Get the underlying Gaffer graph this GafferPop graph is connected to.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2024 Crown Copyright
* Copyright 2017-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,6 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
import org.apache.tinkerpop.gremlin.jsr223.ConcurrentBindings;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
Expand Down Expand Up @@ -60,8 +59,9 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -98,7 +98,7 @@ public class GremlinController {

private static final Logger LOGGER = LoggerFactory.getLogger(GremlinController.class);
private static final String GENERAL_ERROR_MSG = "Gremlin query failed: ";

// Shared thread pool for executing gremlin queries in
private final ExecutorService executorService = Context.taskWrapping(Executors.newFixedThreadPool(8));
private final AbstractUserFactory userFactory;
private final Long requestTimeout;
Expand Down Expand Up @@ -246,7 +246,7 @@ public ResponseEntity<StreamingResponseBody> cypherExecute(
public static JSONObject getGafferPopExplanation(final GafferPopGraph graphInstance) {
JSONObject result = new JSONObject();
// Get the last operation chain that ran
LinkedList<Operation> operations = new LinkedList<>();
List<Operation> operations = new ArrayList<>();
((GafferPopGraphVariables) graphInstance.variables())
.getLastOperationChain()
.getOperations()
Expand Down Expand Up @@ -279,10 +279,9 @@ public static JSONObject getGafferPopExplanation(final GafferPopGraph graphInsta
*/
private GremlinExecutor setUpExecutor(final GafferPopGraph graphInstance) {
final ConcurrentBindings bindings = new ConcurrentBindings();
final GraphTraversalSource g = graphInstance.traversal();

// Set up the executor
bindings.putIfAbsent("g", g);
bindings.putIfAbsent("g", graphInstance.traversal());
return GremlinExecutor.build()
.addPlugins("gremlin-groovy", plugins)
.evaluationTimeout(requestTimeout)
Expand Down Expand Up @@ -335,9 +334,8 @@ private Pair<Object, JSONObject> runGremlinQuery(final String gremlinQuery, fina

// Provide an debug explanation for the query that just ran
span.addEvent("Request complete");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{}", pair.getRight());
}
LOGGER.debug("{}", pair.getRight());

} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
span.setStatus(StatusCode.ERROR, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -85,7 +85,7 @@ public class GremlinWebSocketHandler extends BinaryWebSocketHandler {
new SimpleEntry<>(SerTokens.MIME_GRAPHSON_V3, new GraphSONMessageSerializerV3()),
new SimpleEntry<>(SerTokens.MIME_JSON, new GraphSONMessageSerializerV3()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

// Shared thread pool for executing gremlin queries in
private final ExecutorService executorService = Context.taskWrapping(Executors.newFixedThreadPool(8));
private final AbstractUserFactory userFactory;
private final Long requestTimeout;
Expand Down Expand Up @@ -137,10 +137,9 @@ protected void handleBinaryMessage(final WebSocketSession session, final BinaryM
*/
private GremlinExecutor setUpExecutor(final GafferPopGraph graphInstance) {
final ConcurrentBindings bindings = new ConcurrentBindings();
final GraphTraversalSource g = graphInstance.traversal();

// Set up the executor
bindings.putIfAbsent("g", g);
bindings.putIfAbsent("g", graphInstance.traversal());
return GremlinExecutor.build()
.addPlugins("gremlin-groovy", plugins)
.evaluationTimeout(requestTimeout)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Crown Copyright
* Copyright 2024-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit d039e97

Please sign in to comment.