use of org.neo4j.driver.v1.Config in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method translating.
@Test
public void translating() {
Config config = Config.build().withTranslation(TranslatorFlavor.gremlinServer()).toConfig();
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config);
try (Session session = driver.session()) {
StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count");
int count = result.single().get("count").asInt();
assertThat(count).isEqualTo(4);
}
}
use of org.neo4j.driver.v1.Config in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method invalidSyntaxInTranslation.
@Test
public void invalidSyntaxInTranslation() {
Config config = Config.build().withTranslation(TranslatorFlavor.gremlinServer()).toConfig();
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config);
try (Session session = driver.session()) {
StatementResult result = session.run("INVALID");
Throwable throwable = catchThrowable(result::list);
assertThat(throwable).hasMessageContaining("Invalid input");
}
}
use of org.neo4j.driver.v1.Config in project cypher-for-gremlin by opencypher.
the class CypherGremlinNeo4jDriver method createUseDriver.
@Test
public void createUseDriver() throws Exception {
int port = gremlinServer.getPort();
// freshReadmeSnippet: createConfiguration
Config config = Config.build().withTranslation().toConfig();
String uri = "//localhost:" + port;
Driver driver = GremlinDatabase.driver(uri, config);
// freshReadmeSnippet: useDriver
try (Session session = driver.session()) {
StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.message = $message " + "RETURN a.message", parameters("message", "Hello"));
String message = result.single().get(0).asString();
assertThat(message).isEqualTo("Hello");
}
// freshReadmeSnippet: useDriver
}
use of org.neo4j.driver.v1.Config in project open-kilda by telstra.
the class FlowJanitor method main.
/**
* With the right URL, username, password, and method keyword, the methods above can be called.
*/
@SuppressWarnings({ "squid:S106", "squid:S1135" })
public static void main(String[] args) {
Options options = new Options();
options.addOption(Option.builder("url").required(true).hasArg().desc("The URL of the Neo4J DB - i.e. bolt://neo..:7474").build());
options.addOption(Option.builder("u").required(true).hasArg().longOpt("user").desc("The Neo4J username - e.g. neo4j").build());
options.addOption(Option.builder("p").required(true).hasArg().longOpt("password").desc("The Neo4J password - e.g. neo4j").build());
options.addOption(Option.builder("nburl").required(true).hasArg().desc("The URL of the Neo4J DB - i.e. http://northboud..:8080").build());
options.addOption(Option.builder("nbu").required(true).hasArg().longOpt("user").desc("The Neo4J username - e.g. kilda").build());
options.addOption(Option.builder("nbp").required(true).hasArg().longOpt("password").desc("The Neo4J password - e.g. kilda").build());
options.addOption(Option.builder("a").required(true).hasArg().longOpt("action").desc("The action to take - e.g. ountDuplicateCookies").build());
options.addOption(Option.builder("v").required(false).longOpt("verbose").desc("Where appropriate, return a verbose response").build());
CommandLine commandLine;
CommandLineParser parser = new DefaultParser();
Driver driver = null;
try {
commandLine = parser.parse(options, args);
FlowJanitor.Config config = new FlowJanitor.Config();
config.neoUrl = commandLine.getOptionValue("url");
config.neoUser = commandLine.getOptionValue("u");
config.neoPswd = commandLine.getOptionValue("p");
config.nbUrl = commandLine.getOptionValue("nburl");
config.nbUser = commandLine.getOptionValue("nbu");
config.nbPswd = commandLine.getOptionValue("nbp");
config.action = commandLine.getOptionValue("a");
driver = GraphDatabase.driver(config.neoUrl, AuthTokens.basic(config.neoUser, config.neoPswd));
if (config.action.equals("DeDupeFlows")) {
Session session = driver.session();
StatementResult result = session.run(DUPLICATE_FLOWS_QUERY);
Map<String, List<Long>> flowsToUpdate = new HashMap<>();
for (Record record : result.list()) {
String flowid = record.get("affected_flow_id").asString();
List<Long> priors = flowsToUpdate.computeIfAbsent(flowid, empty -> new ArrayList<>());
priors.add(record.get("affected_flow_cookie").asLong());
}
session.close();
System.out.println("flowsToUpdate.size() = " + flowsToUpdate.size());
System.out.println("flowsToUpdate = " + flowsToUpdate);
System.out.println("Will De-Dupe the Flows");
String authString = config.nbUser + ":" + config.nbPswd;
String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes());
Client client = ClientBuilder.newClient();
for (String flowid : flowsToUpdate.keySet()) {
/*
* Get the Flows .. call NB for each
*/
sleep();
System.out.println("RUNNING: flowid = " + flowid);
WebTarget webTarget = client.target(config.nbUrl + "flows").path(flowid);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON).header("Authorization", "Basic " + authStringEnc);
Response response = invocationBuilder.get(Response.class);
if (response.getStatus() != 200) {
throw new IllegalStateException("Failed : HTTP error code : " + response.getStatus());
}
String output = response.readEntity(String.class);
System.out.println("output = " + output);
System.exit(0);
}
} else {
// TODO: switch, based on action
Session session = driver.session();
StatementResult result = session.run(DUPLICATE_COOKIES_QUERY);
List<String> flowsToUpdate = new ArrayList<>();
for (Record record : result.list()) {
flowsToUpdate.add(record.get("affected_flow_id").asString());
}
session.close();
System.out.println("flowsToUpdate.size() = " + flowsToUpdate.size());
System.out.println("flowsToUpdate = " + flowsToUpdate);
System.exit(0);
FlowJanitor.updateFlows(config, flowsToUpdate);
}
} catch (ParseException exception) {
System.out.print("Parse error: ");
System.out.println(exception.getMessage());
// automatically generate the help statement
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("FlowJanitor", options);
} finally {
if (driver != null) {
driver.close();
}
}
}
Aggregations