/** * 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; }
@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); }
/** * 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(); }
@BeforeClass public static void setUp() { originalConfig = Config.getInstance(); CompositeConfiguration config = new CompositeConfiguration(originalConfig); MapConfiguration overrides = new MapConfiguration(new HashMap<String, Object>()); overrides.setProperty(ConfigurationProperties.DEVELOPER_DEBUG_ENABLED, "true"); overrides.setProperty(ConfigurationProperties.DEVELOPER_VALIDATE_XML, "true"); config.addConfiguration(overrides); Config.setConfiguration(config); }
/** * Loads configuration from system defined arguments, i.e. -Dapi.x.y.z=abc. */ public Configuration fromSystem() { MapConfiguration mapConfig = setupConfiguration(new MapConfiguration((Properties) System.getProperties().clone())); // Disables trimming so system properties that include whitespace (such as line.separator) will // be preserved. mapConfig.setTrimmingDisabled(true); return mapConfig; }
private Configuration loadBootstrapConfiguration() { MapConfiguration globalConfiguration = new MapConfiguration(new HashMap<String, Object>()); ClassLoader classLoader = SeedReflectionUtils.findMostCompleteClassLoader(); if (classLoader == null) { throw SeedException.createNew(CoreErrorCode.UNABLE_TO_FIND_CLASSLOADER); } try { Enumeration<URL> urls = classLoader.getResources(SEED_BOOTSTRAP_PATH); while (urls.hasMoreElements()) { URL url = urls.nextElement(); globalConfiguration.append(new PropertiesConfiguration(url)); } } catch (Exception e) { throw SeedException.wrap(e, CoreErrorCode.UNEXPECTED_EXCEPTION); } return new MapConfiguration(new ImmutableMap.Builder<String, Object>().putAll(globalConfiguration.getMap()).build()); }
private AbstractMetricFixtureAdapter<?> newMetricFixtureAdapter( MapConfiguration config, OutputStream out, OutputStream err) throws IllegalAccessException, InstantiationException { Preconditions.checkNotNull(config); Preconditions.checkNotNull(out); Preconditions.checkNotNull(err); // All implementations of the MetricFixtureAdapter must have a no-argument // c'tor. LOG.info("Instantiating new metric fixture of class " + config.getString(OPT_ADAPTER_CLASS.getLongOpt())); Class<?> adapterClass = (Class<?>) config.getProperty(ADAPTER_CLASS_CONFIG); Preconditions.checkNotNull(adapterClass); return (AbstractMetricFixtureAdapter<?>) adapterClass.newInstance(); }
@Override protected void addPropertyDirect(String key, Object value) { Object previousValue = getProperty(key); if (previousValue == null) { map.put(key, value); } else if (previousValue instanceof List) { // the value is added to the existing list // Note: This is problematic. See header comment! ((List<Object>) previousValue).add(value); } else { // the previous value is replaced by a list containing the previous value and the new value List<Object> list = new ArrayList<Object>(); list.add(previousValue); list.add(value); map.put(key, list); } }
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(); }
@BeforeClass public static void setUp() { originalConfig = Config.getInstance(); CompositeConfiguration config = new CompositeConfiguration(originalConfig); MapConfiguration overrides = new MapConfiguration(new HashMap<String, Object>()); overrides.setProperty(ConfigurationProperties.INTEGRITY_ERROR_MODE, "true"); config.addConfiguration(overrides); Config.setConfiguration(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)); }
/** * Loads configuration from system defined arguments, i.e. -Dapi.x.y.z=abc. */ public Configuration fromSystem() { MapConfiguration mapConfig = setupConfiguration(new MapConfiguration((Properties) System.getProperties().clone())); // Disables trimming so system properties that include whitespace (such as line.separator) will // be preserved. mapConfig.setTrimmingDisabled(true); return mapConfig; }
@Override protected void addPropertyDirect(String key, Object value) { Object previousValue = getProperty(key); if (previousValue == null) { map.put(key, value); } else if (previousValue instanceof List) { // the value is added to the existing list // Note: This is problematic. See header comment! ((List<Object>) previousValue).add(value); } else { // the previous value is replaced by a list containing the previous value and the new value List<Object> list = new ArrayList<Object>(); list.add(previousValue); list.add(value); map.put(key, list); } }
/** * 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))); }
public SenseiServerBuilder(Resource confDir, Map<String, Object> properties) throws Exception { _senseiConfFile = null; _senseiConf = new MapConfiguration(properties); ((MapConfiguration) _senseiConf).setDelimiterParsingDisabled(true); pluginRegistry = SenseiPluginRegistry.build(_senseiConf); pluginRegistry.start(); processRelevanceFunctionPlugins(pluginRegistry); _gateway = pluginRegistry.getBeanByFullPrefix(SENSEI_GATEWAY, SenseiGateway.class); _schemaDoc = loadSchema(confDir); _senseiSchema = SenseiSchema.build(_schemaDoc); }
@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); }
@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); } }