9. JanusGraph ConfiguredGraphFactory

ConfiguredGraphFactory can be used to configure JanusGraph Server. ConfiguredGraphFactory is a diagram of the access method, similar to JanusGraphFactory. These figures factory class provides a method of dynamic management hosted on the server of FIG.

1 Overview

JanusGraphFactory is a class that provides access to a way of drawing each time to access your diagram by configuring the Configuration object.

ConfiguredGraphFactory provides an access ConfigurationManagementGraph you use to create a configuration diagram of the way. It also provides a way to manage the layout drawing.

ConfigurationManagementGraph allows you to manage the configuration diagram.

JanusGraphManager is an internal service component, you can track a reference map, provided that your map is configured to use it.

2. ConfiguredGraphFactory and JanusGraphFactory

However, one important difference between these two FIG factory class:

  • Only when the service starts you have used ConfigurationManagementGraph API to configure your server up, ConfiguredGraphFactory can be used.

The advantage of using ConfiguredGraphFactory are:

  • You only need to provide a String to access your map, rather than JanusGraphFactory- it asks you each time you open the map must specify the back-end information when accessing the graphics to be used.
  • If your ConfigurationManagementGraph distributed storage backend configuration, the configuration of your chart JanusGraph available to all nodes in the cluster use.

How 3. ConfiguredGraphFactory work

Figure ConfiguredGraphFactory provide access method in the following two cases:

  • You have to use ConfigurationManagementGraph # createConfiguration configured to create a specific diagram objects. In this scenario, the use of previously created for this configuration diagram Open Graph.
  • You have created a template configured to use ConfigurationManagementGraph # createTemplateConfiguration. In this case, we passed all the properties in the template configuration store and copy the relevant graphName additional properties to create configured to map you created, and then open the map based on the specific configuration.

4. FIG Access

You can use ConfiguredGraphFactory.create ( "graphName") or ConfiguredGraphFactory.open ( "graphName"). Read the following section on ConfigurationManagementGraph to learn more differences between these two approaches place.

You can also use bindings to access the map. For more information, see Section 9.10 "Graph and Traversal Bindings" section.

The list of FIG.

ConfiguredGraphFactory.getGraphNames () will return a set of names you use ConfigurationManagementGraph API to create a diagram of the configuration.

On the other hand, JanusGraphFactory.getGraphNames () returns an array of FIG name you instantiate, and the reference is stored in JanusGraphManager.

6. Delete map

ConfiguredGraphFactory.drop ( "graphName") will delete map database, deleting all data storage and index. This figure may be open or closed with (deletion will be closed as part of). In addition, it will also remove ConfigurationManagementGraph any existing configuration diagram.

note:

  • This is an irreversible operation, it removes all the map and index data.
  • Assuming that each node in the right configuration to use JanusGraphManager, to ensure that the cluster nodes all figures represent all JanusGraph JanusGraphManager graphics cache on are the same, this will delete each node in the cluster diagram. Learn more about this feature and how to configure the service to use this feature.

7. Configure JanusGraph services ConfiguredGraphFactory

In order to use ConfiguredGraphFactory, you must use ConfigurationManagementGraph API to configure your service. To do this, you must configure the map variable named "ConfigurationManagementGraph" in the graphs of your YAML file service. E.g:

graphManager: org.janusgraph.graphdb.management.JanusGraphManager
graphs: {
  ConfigurationManagementGraph: conf/JanusGraph-configurationmanagement.properties
}

In this example, we will use the property ConfigurationManagementGraph FIG conf / JanusGraph-configurationmanagement.properties stored configuration, e.g., as follows:

gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=cql
graph.graphname=ConfigurationManagementGraph
storage.hostname=127.0.0.1

If successful startup and ConfigurationManagementGraph GremlinServer is instantiated successfully, all available on Singleton is ConfigurationManagementGraph API will also perform the operations of FIG. Further, this figure can be used ConfiguredGraphFactory the create / open access to the configuration of FIG.

note:

pom.xml JanusGraph contained in this release dependencies as optional, but ConfiguredGraphFactory used JanusGraphManager, it relies org.apache.tinkerpop: gremlin-server. So if you encounter an error NoClassDefFoundError, be sure to make this prompt to add a dependency in pom.xml.

8. ConfigurationManagementGraph

ConfigurationManagementGraph is a Singleton, allows you to use ConfiguredGraphFactory create update configuration / / remove FIG. See above on configuring the service to use the API.

Note: ConfiguredGraphFactory provides a way to manage the configuration of FIG via ConfigurationManagementGraph, thus corresponding ConfiguredGraphFactory static methods you can use, instead of a single embodiment operates itself. For example, you can use ConfiguredGraphFactory.removeTemplateConfiguration () instead ConfiguredGraphFactory.getInstance (). RemoveTemplateConfiguration ().

8.1 Configuration FIG.

ConfigurationManagementGraph single embodiment allows you to create an open configuration by specific properties graph.graphname FIG. E.g:

map = new HashMap<String, Object>();
map.put("storage.backend", "cql");
map.put("storage.hostname", "127.0.0.1");
map.put("graph.graphname", "graph1");
ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));

Then, you can use the following ways to access this chart on any JanusGraph node:

ConfiguredGraphFactory.open("graph1");
8.2. Template configuration

ConfigurationManagementGraph also allows you to create a template configuration, you can create many of the figures using the same configuration templates. E.g:

map = new HashMap<String, Object>();
map.put("storage.backend", "cql");
map.put("storage.hostname", "127.0.0.1");
ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));

Once this is done, you can create a chart using a template configuration:

ConfiguredGraphFactory.create("graph2");

This method will first configuration associated with the template by copying all properties and stored in the configuration of this particular figure up to create a new configuration for the "graph2". This means you can access this chart JanusGraph on any node in the following ways:

ConfiguredGraphFactory.open("graph2");
8.3 Update configuration

Configuration interaction JanusGraphFactory and ConfiguredGraphFactory all interactions with all defined attributes graph.graphname by JanusGraphManager track in a given JVM is created on the figures quoted. It as a graphics buffer. for this reason:

Any updates showing the arrangement will result in expulsion from JanusGraph related graphics cluster map cache on each node, assuming that each node is properly configured to use JanusGraphManager. Learn more about this feature and how to configure the server to use this feature.

As the graphical configuration using a template created using the first copy and create methods to create a configuration for the graphics, which means:

Any updates to a particular chart using a template configuration created can be guaranteed to take effect on a particular chart until:

  1. Delete configuration: ConfiguredGraphFactory.removeConfiguration ( "graph2");
  2. Use template configuration to recreate the map: ConfiguredGraphFactory.create ( "graph2");
8.4. Example update
  1. We Cassandra migrate data to a new server with a new IP address:

    map = new HashMap();
    map.put("storage.backend", "cql");
    map.put("storage.hostname", "127.0.0.1");
    map.put("graph.graphname", "graph1");
    ConfiguredGraphFactory.createConfiguration(new
    MapConfiguration(map));
    
    g1 = ConfiguredGraphFactory.open("graph1");
    
    // Update configuration
    map = new HashMap();
    map.put("storage.hostname", "10.0.0.1");
    ConfiguredGraphFactory.updateConfiguration("graph1",
    map);
    
    // We are now guaranteed to use the updated configuration
    g1 = ConfiguredGraphFactory.open("graph1");
    
  2. We've added a Elasticsearch node in the settings:

    map = new HashMap();
    map.put("storage.backend", "cql");
    map.put("storage.hostname", "127.0.0.1");
    map.put("graph.graphname", "graph1");
    ConfiguredGraphFactory.createConfiguration(new
    MapConfiguration(map));
    
    g1 = ConfiguredGraphFactory.open("graph1");
    
    // Update configuration
    map = new HashMap();
    map.put("index.search.backend", "elasticsearch");
    map.put("index.search.hostname", "127.0.0.1");
    map.put("index.search.elasticsearch.transport-scheme", "http");
    ConfiguredGraphFactory.updateConfiguration("graph1",
    map);
    
    // We are now guaranteed to use the updated configuration
    g1 = ConfiguredGraphFactory.open("graph1");
    
  3. Update graphical updated template configuration created configuration:

    map = new HashMap();
    map.put("storage.backend", "cql");
    map.put("storage.hostname", "127.0.0.1");
    ConfiguredGraphFactory.createTemplateConfiguration(new
    MapConfiguration(map));
    
    g1 = ConfiguredGraphFactory.create("graph1");
    
    // Update template configuration
    map = new HashMap();
    map.put("index.search.backend", "elasticsearch");
    map.put("index.search.hostname", "127.0.0.1");
    map.put("index.search.elasticsearch.transport-scheme", "http");
    ConfiguredGraphFactory.updateTemplateConfiguration(new
    MapConfiguration(map));
    
    // Remove Configuration
    ConfiguredGraphFactory.removeConfiguration("graph1");
    
    // Recreate
    ConfiguredGraphFactory.create("graph1");
    // Now this graph's configuration is guaranteed to be updated
    

    9. JanusGraphManager

    JanusGraphManager is a follow TinkerPop graphManager specification Singleton.

    In particular, JanusGraphManager provide:

    • A coordinating mechanism, for the given example of figures quoted node JanusGraph
    • Tracking the reference pattern (or cache)

    Graph.graphname created using any graphics attribute will pass JanusGraphManager, instantiated in a corresponding manner. FIG chart reference will also be stored in cache on the JVM.

    Thus, using the property graph.graphname opened on any relevant JVM instantiated FIG retrieved from the cache of FIG.

    This is why the update configuration requires several steps to ensure the correctness of the reasons.

    9.1. How to use JanusGraphManager

    This is a new configuration option that can be used when defining property in the configuration that defines how to access the graphics. The configurations include this attribute will result achieved by instantiating graphical JanusGraphManager (process explained above).

    For backward compatibility, this parameter is not supported by any but the graphics are available on the server object graph .yaml file start, JanusGraphManager key figures will be provided by the diagram shows that bind. For example, if your .yaml FIG objects are as follows:

    graphManager: org.janusgraph.graphdb.management.JanusGraphManager
    graphs {
      graph1: conf/graph1.properties,
      graph2: conf/graph2.properties
    }
    

    However conf / graph1.properties and conf / graph2.properties not contain attributes graph.graphname, then these are stored in FIG JanusGraphManager, so graph2 respectively graph1 and bind gremlin as script execution.

    9.2. Note

    For convenience, if your configuration file specifies graph.graphname, but not configured back-end storage directory, tablename or keyspacename, the pertinent parameters are automatically set to the value of graph.graphname. However, if you configure one of the parameters, it takes precedence value. If you do not configure the default is configured using default values.

    A special case is storage.root configuration items. This is a new configuration, will be used for specifying the root directory of any backend require local storage directory access. If this parameter, you must also provide graph.graphname property, this will be the absolute storage directory path plus graph.graphname storage.root path.

    Here are some examples of use:

    • My Cassandra backend template configuration created in order to use this configuration to create each graphic obtained with the method of the String supplied to the plant <graphName>equivalent of a unique key space:

      map = new HashMap();
      map.put("storage.backend", "cql");
      map.put("storage.hostname", "127.0.0.1");
      ConfiguredGraphFactory.createTemplateConfiguration(new
      MapConfiguration(map));
      
      g1 = ConfiguredGraphFactory.create("graph1"); //keyspace === graph1
      g2 = ConfiguredGraphFactory.create("graph2"); //keyspace === graph2
      g3 = ConfiguredGraphFactory.create("graph3"); //keyspace === graph3
      
    • My BerkeleyJE template configuration backend created in order to use this configuration to create each graphic are equivalent to obtain a <storage.root> / <graph.graphname>unique storage directory:

      map = new HashMap();
      map.put("storage.backend", "berkeleyje");
      map.put("storage.root", "/data/graphs");
      ConfiguredGraphFactory.createTemplateConfiguration(new
      MapConfiguration(map));
      
      g1 = ConfiguredGraphFactory.create("graph1"); //storage directory === /data/graphs/graph1
      g2 = ConfiguredGraphFactory.create("graph2"); //storage directory === /data/graphs/graph2
      g3 = ConfiguredGraphFactory.create("graph3"); //storage directory === /data/graphs/graph3
      

    10. Graph and Traversal Bindings

    ConfiguredGraphFactory created using a graphical program execution context bound to the Gremlin Server through "graph.graphname" attribute, and graphics referred to by traversing <graphname> _traversalbound to a context. This means that, after the first Create / Open drawing in subsequent connection to the server, you can <graphname>and <graphname> _traversalreference attribute access graph and traverse.

    Learn more about this feature and how to configure the server to use this feature.

    note:

    • If you use the Gremlin and the console session connections Gremlin connect to a remote server, you must re-connect to the server to bind variables. The same is true for any session of WebSocket connection.
    • JanusGraphManager rebinding stored every 20 seconds on each graphic ConfigurationManagementGraph (or you have created the configuration of graphics). This means ConfigredGraphFactory create graphics and goes through the binding will be available on all JanusGraph nodes delayed up to 20 seconds. It also means that after the server is restarted, binding on the node can still be used.
    10.1 Binding Example
    gremlin> :remote connect tinkerpop.server conf/remote.yaml
    ==>Configured localhost/127.0.0.1:8182
    gremlin> :remote console
    ==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
    gremlin> ConfiguredGraphFactory.open("graph1")
    ==>standardjanusgraph[cassandrathrift:[127.0.0.1]]
    gremlin> graph1
    ==>standardjanusgraph[cassandrathrift:[127.0.0.1]]
    gremlin> graph1_traversal
    ==>graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]], standard]
    

    11. Sample

    Session connection is recommended when creating Configured Graph Factory template. If the session connection is not used, it must be sent to the server as a single line to create graphical templates semicolon factory configuration. For more information on sessions, see Section 7.1.1.1 "is connected to the Gremlin Server".

    gremlin> :remote connect tinkerpop.server conf/remote.yaml session
    ==>Configured localhost/127.0.0.1:8182
    
    gremlin> :remote console
    ==>All scripts will now be sent to Gremlin Server - [localhost:8182]-[5206cdde-b231-41fa-9e6c-69feac0fe2b2] - type ':remote console' to return to local mode
    
    gremlin> ConfiguredGraphFactory.open("graph");
    Please create configuration for this graph using the
    ConfigurationManagementGraph API.
    
    gremlin> ConfiguredGraphFactory.create("graph");
    Please create a template Configuration using the
    ConfigurationManagementGraph API.
    
    gremlin> map = new HashMap();
    gremlin> map.put("storage.backend", "cql");
    gremlin> map.put("storage.hostname", "127.0.0.1");
    gremlin> map.put("GraphName", "graph1");
    gremlin> ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
    Please include in your configuration the property "graph.graphname".
    
    gremlin> map = new HashMap();
    gremlin> map.put("storage.backend", "cql");
    gremlin> map.put("storage.hostname", "127.0.0.1");
    gremlin> map.put("graph.graphname", "graph1");
    gremlin> ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));
    ==>null
    
    gremlin> ConfiguredGraphFactory.open("graph1").vertices();
    
    gremlin> map = new HashMap(); map.put("storage.backend",
    "cql"); map.put("storage.hostname", "127.0.0.1");
    gremlin> map.put("graph.graphname", "graph1");
    gremlin> ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
    Your template configuration may not contain the property
    "graph.graphname".
    
    gremlin> map = new HashMap();
    gremlin> map.put("storage.backend",
    "cql"); map.put("storage.hostname", "127.0.0.1");
    gremlin> ConfiguredGraphFactory.createTemplateConfiguration(new MapConfiguration(map));
    ==>null
    
    // Each graph is now acting in unique keyspaces equivalent to the
    graphnames.
    gremlin> g1 = ConfiguredGraphFactory.open("graph1");
    gremlin> g2 = ConfiguredGraphFactory.create("graph2");
    gremlin> g3 = ConfiguredGraphFactory.create("graph3");
    gremlin> g2.addVertex();
    gremlin> l = [];
    gremlin> l << g1.vertices().size();
    ==>0
    gremlin> l << g2.vertices().size();
    ==>1
    gremlin> l << g3.vertices().size();
    ==>0
    
    // After a graph is created, you must access it using .open()
    gremlin> g2 = ConfiguredGraphFactory.create("graph2"); g2.vertices().size();
    Configuration for graph "graph2" already exists.
    
    gremlin> g2 = ConfiguredGraphFactory.open("graph2"); g2.vertices().size();
    ==>1
    

Welcome to sweep the code number of public attention, better communication
Welcome to sweep the code number of public attention, better communication

Published 115 original articles · won praise 67 · Views 100,000 +

Guess you like

Origin blog.csdn.net/meifannao789456/article/details/92108306