{tip} ~This page has been generated by [maven-confluence-plugin|https://github.com/bsorrentino/maven-confluence-plugin/]~ {tip}
----
\\
h1.Table Of Content
{toc:minLevel=2}
h2.Use JanusGraph Embedded
Below the necessary steps to setup accessing *JanusGraph Gremlin Server* from a spring application
h3.Declare Maven dependencies
{code:xml}
<dependency>
<groupId>com.wba.configurationmanager-library</groupId>
<artifactId>cfgmgr-janus-spring</artifactId>
<version>3.2-SNAPSHOT</version>
</dependency>
{code}
h3.Use in Spring
*Create an instance of Janus ClusterManagement*
{code:java}
@SpringBootApplication
@ComponentScan(basePackages = { "com.wba.cfgmgr" })
public class JanusGraphPoc implements CommandLineRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(JanusGraphPoc.class);
@Autowired
private ClusterManagement clusterManagement;
public static void main(final String[] args) {
SpringApplication.run(JanusGraphPoc.class, args).close();
}
@Override
public void run(final String... args) throws Exception {
try (final GraphSession graphSession = clusterManagement.getCluster().connect()) {
final GraphTraversalSource g = graphSession.G();
// get vertices by label
buildGraphTraversal(g).toList().stream().forEach(vertex -> LOGGER.info(vertex.label()));
// get all properties
buildGraphTraversal(g).valueMap(true).toList().stream().forEach(propertyMap -> {
LOGGER.info("");
for (Map.Entry<Object, Object> propertyEntry : propertyMap.entrySet()) {
LOGGER.info(propertyEntry.getKey() + ": " + propertyEntry.getValue());
}
});
// using predicates
LOGGER.info("");
LOGGER.info("Number of \"PRODUCT_ORDERING\", \"PRODUCT_RANGING\" and \"GRID_OVERRIDES\" templates "
+ "having code f2a2090f-2609-49b7-b8b1-3a0bb4bb66e1 or f2a2090f-2609-49b7-b8b1-3a0bb4bb66e2: "
+ buildGraphTraversal(g).has("code",
P.within(
UUID.fromString("f2a2090f-2609-49b7-b8b1-3a0bb4bb66e1"),
UUID.fromString("f2a2090f-2609-49b7-b8b1-3a0bb4bb66e2")))
.toList().size());
}
}
private GraphTraversal<Vertex, Vertex> buildGraphTraversal(final GraphTraversalSource g) {
return g.V().hasLabel("PRODUCT_ORDERING", "PRODUCT_RANGING", "GRID_OVERRIDES");
}
{code}
*Configure spring application*
In the application properties we have to set the file of Janus configuration file
{noformat}graph.janus.config-file=conf/remote.yaml
{noformat}
*Janus Graph configuration for accessing to Gremlin Server*
{noformat}
#
# file: conf/remote.yaml
#
hosts: [rxdevenv1.walgreens.com]
port: 80
serializer: {
className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0,
config: {
serializeResultToString: false,
ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry]
}
}
{noformat}
----
\\
h1.Table Of Content
{toc:minLevel=2}
h2.Use JanusGraph Embedded
Below the necessary steps to setup accessing *JanusGraph Gremlin Server* from a spring application
h3.Declare Maven dependencies
{code:xml}
<dependency>
<groupId>com.wba.configurationmanager-library</groupId>
<artifactId>cfgmgr-janus-spring</artifactId>
<version>3.2-SNAPSHOT</version>
</dependency>
{code}
h3.Use in Spring
*Create an instance of Janus ClusterManagement*
{code:java}
@SpringBootApplication
@ComponentScan(basePackages = { "com.wba.cfgmgr" })
public class JanusGraphPoc implements CommandLineRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(JanusGraphPoc.class);
@Autowired
private ClusterManagement clusterManagement;
public static void main(final String[] args) {
SpringApplication.run(JanusGraphPoc.class, args).close();
}
@Override
public void run(final String... args) throws Exception {
try (final GraphSession graphSession = clusterManagement.getCluster().connect()) {
final GraphTraversalSource g = graphSession.G();
// get vertices by label
buildGraphTraversal(g).toList().stream().forEach(vertex -> LOGGER.info(vertex.label()));
// get all properties
buildGraphTraversal(g).valueMap(true).toList().stream().forEach(propertyMap -> {
LOGGER.info("");
for (Map.Entry<Object, Object> propertyEntry : propertyMap.entrySet()) {
LOGGER.info(propertyEntry.getKey() + ": " + propertyEntry.getValue());
}
});
// using predicates
LOGGER.info("");
LOGGER.info("Number of \"PRODUCT_ORDERING\", \"PRODUCT_RANGING\" and \"GRID_OVERRIDES\" templates "
+ "having code f2a2090f-2609-49b7-b8b1-3a0bb4bb66e1 or f2a2090f-2609-49b7-b8b1-3a0bb4bb66e2: "
+ buildGraphTraversal(g).has("code",
P.within(
UUID.fromString("f2a2090f-2609-49b7-b8b1-3a0bb4bb66e1"),
UUID.fromString("f2a2090f-2609-49b7-b8b1-3a0bb4bb66e2")))
.toList().size());
}
}
private GraphTraversal<Vertex, Vertex> buildGraphTraversal(final GraphTraversalSource g) {
return g.V().hasLabel("PRODUCT_ORDERING", "PRODUCT_RANGING", "GRID_OVERRIDES");
}
{code}
*Configure spring application*
In the application properties we have to set the file of Janus configuration file
{noformat}graph.janus.config-file=conf/remote.yaml
{noformat}
*Janus Graph configuration for accessing to Gremlin Server*
{noformat}
#
# file: conf/remote.yaml
#
hosts: [rxdevenv1.walgreens.com]
port: 80
serializer: {
className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0,
config: {
serializeResultToString: false,
ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry]
}
}
{noformat}