/** * Creates a {@link JanusGraph} configuration stored in the {@link ConfigurationManagementGraph} * graph and a {@link JanusGraph} graph reference according to the single * Template Configuration previously created by the {@link ConfigurationManagementGraph} API; * A configuration for this graph must not already exist, and a Template Configuration must * exist. If the Template Configuration does not include its * backend's respective keyspace/table/storage_directory parameter, we set the keyspace/table * to the supplied graphName or we append the graphName to the supplied * storage_root parameter. * * @param graphName * * @return JanusGraph */ public static synchronized JanusGraph create(final String graphName) { final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance(); final Map<String, Object> graphConfigMap = configManagementGraph.getConfiguration(graphName); Preconditions.checkState(null == graphConfigMap, String.format("Configuration for graph %s already exists.", graphName)); final Map<String, Object> templateConfigMap = configManagementGraph.getTemplateConfiguration(); Preconditions.checkState(null != templateConfigMap, "Please create a template Configuration using the ConfigurationManagementGraph#createTemplateConfiguration API."); templateConfigMap.put(ConfigurationManagementGraph.PROPERTY_GRAPH_NAME, graphName); templateConfigMap.put(ConfigurationManagementGraph.PROPERTY_CREATED_USING_TEMPLATE, true); final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance(); Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG); final CommonsConfiguration config = new CommonsConfiguration(new MapConfiguration(templateConfigMap)); final JanusGraph g = (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfiguration(config))); configManagementGraph.createConfiguration(new MapConfiguration(templateConfigMap)); return g; }
/** * Open a {@link JanusGraph} using a previously created Configuration using the * {@link ConfigurationManagementGraph} API. A corresponding configuration must exist. * * <p>NOTE: If your configuration corresponding to this graph does not contain information about * the backend's keyspace/table/storage directory, then we set the keyspace/table to the * graphName or set the storage directory to the storage_root + /graphName.</p> * * @param graphName * * @return JanusGraph */ public static JanusGraph open(String graphName) { final ConfigurationManagementGraph configManagementGraph = getConfigGraphManagementInstance(); final Map<String, Object> graphConfigMap = configManagementGraph.getConfiguration(graphName); Preconditions.checkState(null != graphConfigMap, "Please create configuration for this graph using the ConfigurationManagementGraph#createConfiguration API."); final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance(); Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG); final CommonsConfiguration config = new CommonsConfiguration(new MapConfiguration(graphConfigMap)); return (JanusGraph) jgm.openGraph(graphName, (String gName) -> new StandardJanusGraph(new GraphDatabaseConfiguration(config))); }
@Test public void instanceIdShouldEqualHostnamePlusSuffix() throws UnknownHostException { final Map<String, Object> map = new HashMap<String, Object>(); map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true); map.put(UNIQUE_INSTANCE_ID_SUFFIX.toStringWithoutRoot(), 1); final MapConfiguration config = new MapConfiguration(map); final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph.openManagement().getOpenInstances().size(), 1); assertEquals(graph.openManagement().getOpenInstances().toArray()[0], Inet4Address.getLocalHost().getHostName() + "1"); graph.close(); } }
@Test public void instanceIdShouldEqualHostname() throws UnknownHostException { final Map<String, Object> map = new HashMap<String, Object>(); map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true); final MapConfiguration config = new MapConfiguration(map); final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph.openManagement().getOpenInstances().size(), 1); assertEquals(graph.openManagement().getOpenInstances().toArray()[0], Inet4Address.getLocalHost().getHostName()); graph.close(); }
@Test public void testMetricsHelperRegistration() { listenerOneOkay = false; listenerTwoOkay = false; Map<String, String> configKeys = new HashMap<String, String>(); configKeys.put("pinot.broker.metrics.metricsRegistryRegistrationListeners", ListenerOne.class.getName() + "," + ListenerTwo.class.getName()); Configuration configuration = new MapConfiguration(configKeys); MetricsRegistry registry = new MetricsRegistry(); // Initialize the MetricsHelper and create a new timer MetricsHelper.initializeMetrics(configuration.subset("pinot.broker.metrics")); MetricsHelper.registerMetricsRegistry(registry); MetricsHelper.newTimer(registry, new MetricName(MetricsHelperTest.class, "dummy"), TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS); // Check that the two listeners fired assertTrue(listenerOneOkay); assertTrue(listenerTwoOkay); } }
@Test public void graphShouldNotOpenWithSameInstanceId() { final Map<String, Object> map = new HashMap<String, Object>(); map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), "not-unique"); final MapConfiguration config = new MapConfiguration(map); final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph1.openManagement().getOpenInstances().size(), 1); assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique"); thrown.expect(JanusGraphException.class); final String err = "A JanusGraph graph with the same instance id [not-unique] is already open. Might required forced shutdown."; thrown.expectMessage(equalTo(err)); final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); graph1.close(); }
@Test public void graphShouldOpenWithSameInstanceId() { final Map<String, Object> map = new HashMap<String, Object>(); map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); map.put(UNIQUE_INSTANCE_ID.toStringWithoutRoot(), "not-unique"); map.put(REPLACE_INSTANCE_IF_EXISTS.toStringWithoutRoot(), true); final MapConfiguration config = new MapConfiguration(map); final StandardJanusGraph graph1 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph1.openManagement().getOpenInstances().size(), 1); assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique"); final StandardJanusGraph graph2 = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph1.openManagement().getOpenInstances().size(), 1); assertEquals(graph1.openManagement().getOpenInstances().toArray()[0], "not-unique"); assertEquals(graph2.openManagement().getOpenInstances().size(), 1); assertEquals(graph2.openManagement().getOpenInstances().toArray()[0], "not-unique"); graph1.close(); graph2.close(); }
@Override public Configuration getConfiguration() { return new MapConfiguration(options); }
@Override public TraversalStrategyProxy<T> createObject(final Map<String, Object> data) { return new TraversalStrategyProxy<>(this.clazz, new MapConfiguration(data)); } }
@Override public TraversalStrategyProxy<T> createObject(final Map<String, Object> data) { return new TraversalStrategyProxy<>(this.clazz, new MapConfiguration(data)); } }
@Override public Configuration getConfiguration() { final Map<String, Object> map = new HashMap<>(); if (null != this.vertexCriterion) map.put(VERTICES, this.vertexCriterion); if (null != this.edgeCriterion) map.put(EDGES, this.edgeCriterion); if (null != this.vertexPropertyCriterion) map.put(VERTEX_PROPERTIES, this.vertexPropertyCriterion); map.put(CHECK_ADJACENT_VERTICES, this.checkAdjacentVertices); return new MapConfiguration(map); }
@Override public Configuration getConfiguration() { final Map<String, Object> map = new HashMap<>(); map.put(STRATEGY, HaltedTraverserStrategy.class.getCanonicalName()); map.put(HALTED_TRAVERSER_FACTORY, this.haltedTraverserFactory.getCanonicalName()); return new MapConfiguration(map); }
@Override public Configuration getConfiguration() { final Map<String, Object> map = new HashMap<>(); map.put(STRATEGY, ElementIdStrategy.class.getCanonicalName()); map.put(ID_PROPERTY_KEY, this.idPropertyKey); map.put(ID_MAKER, this.idMaker); return new MapConfiguration(map); } }
@Override public Configuration getConfiguration() { return new MapConfiguration(Collections.singletonMap(MATCH_ALGORITHM, null != this.matchAlgorithmClass.getDeclaringClass() ? this.matchAlgorithmClass.getCanonicalName().replace("." + this.matchAlgorithmClass.getSimpleName(), "$" + this.matchAlgorithmClass.getSimpleName()) : this.matchAlgorithmClass.getCanonicalName())); }
@Override public Configuration getConfiguration() { final Map<String, Object> map = new HashMap<>(); map.put(STRATEGY, PartitionStrategy.class.getCanonicalName()); map.put(INCLUDE_META_PROPERTIES, this.includeMetaProperties); if (null != this.writePartition) map.put(WRITE_PARTITION, this.writePartition); if (null != this.readPartitions) map.put(READ_PARTITIONS, this.readPartitions); if (null != this.partitionKey) map.put(PARTITION_KEY, this.partitionKey); return new MapConfiguration(map); }
@Override protected TraversalStrategy readValue(final ByteBuf buffer, final GraphBinaryReader context) throws SerializationException { final Class<TraversalStrategy> clazz = context.readValue(buffer, Class.class, false); final Map config = context.readValue(buffer, Map.class, false); return new TraversalStrategyProxy(clazz, new MapConfiguration(config)); }
/** * Initializes a configuration object from the contents of a map. The returned object can be * further configured with subsequent calls to other methods on this class. * * @param properties * a map containing the configuration properties to use * @since 1.9.0 */ public static ClientConfiguration fromMap(Map<String,String> properties) { MapConfiguration mapConf = new MapConfiguration(properties); mapConf.setListDelimiter('\0'); return new ClientConfiguration(Collections.singletonList(mapConf)); }
public ProgramVertexProgramStep(final Traversal.Admin traversal, final VertexProgram vertexProgram) { super(traversal); this.configuration = new HashMap<>(); final MapConfiguration base = new MapConfiguration(this.configuration); base.setDelimiterParsingDisabled(true); vertexProgram.storeState(base); this.toStringOfVertexProgram = vertexProgram.toString(); this.traverserRequirements = vertexProgram.getTraverserRequirements(); }
/** * Open a graph. See each {@link org.apache.tinkerpop.gremlin.structure.Graph} instance for its configuration options. * * @param configuration A {@link java.util.Map} based configuration that will be converted to an {@link org.apache.commons.configuration.Configuration} object * via {@link org.apache.commons.configuration.MapConfiguration} and passed to the appropriate overload. * @return A Graph instance. */ public static Graph open(final Map configuration) { if (null == configuration) throw Graph.Exceptions.argumentCanNotBeNull("configuration"); return open(new MapConfiguration(configuration)); }
@Override public VertexProgram generateProgram(final Graph graph, final Memory memory) { final MapConfiguration base = new MapConfiguration(this.configuration); base.setDelimiterParsingDisabled(true); PureTraversal.storeState(base, ROOT_TRAVERSAL, TraversalHelper.getRootTraversal(this.getTraversal()).clone()); base.setProperty(STEP_ID, this.getId()); if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS)) TraversalVertexProgram.storeHaltedTraversers(base, memory.get(TraversalVertexProgram.HALTED_TRAVERSERS)); return VertexProgram.createVertexProgram(graph, base); }