Configuration Manager - JanusGraph Reference - Remote Access

This page has been generated by maven-confluence-plugin


Table Of Content

Use JanusGraph Embedded

Below the necessary steps to setup accessing JanusGraph Gremlin Server from a spring application

Declare Maven dependencies

<dependency>
  <groupId>com.wba.configurationmanager-library</groupId>
  <artifactId>cfgmgr-janus-spring</artifactId>
  <version>3.2-SNAPSHOT</version>
</dependency>


Use in Spring

Create an instance of Janus ClusterManagement

@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");
    }


Configure spring application
In the application properties we have to set the file of Janus configuration file

graph.janus.config-file=conf/remote.yaml

Janus Graph configuration for accessing to Gremlin Server

#
# 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]
  }
}


Labels

rx rx Delete
configuration configuration Delete
graphdb graphdb Delete
janusgraph janusgraph Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.