org.janusgraph.core.JanusGraph Java Examples
The following examples show how to use
org.janusgraph.core.JanusGraph.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarvelGraphFactory.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 6 votes |
private static void process(final JanusGraph graph, final Appeared appeared) { Vertex comicBookVertex = get(graph, COMIC_BOOK, appeared.getComicBook()); if (null == comicBookVertex) { REGISTRY.counter("error.missingComicBook." + appeared.getComicBook()).inc(); comicBookVertex = graph.addVertex(); comicBookVertex.property(COMIC_BOOK, appeared.getComicBook()); } Vertex characterVertex = get(graph, CHARACTER, appeared.getCharacter()); if (null == characterVertex) { REGISTRY.counter("error.missingCharacter." + appeared.getCharacter()).inc(); characterVertex = graph.addVertex(); characterVertex.property(CHARACTER, appeared.getCharacter()); characterVertex.property(WEAPON, WEAPONS.get(RANDOM.nextInt(WEAPONS.size()))); } characterVertex.addEdge(APPEARED, comicBookVertex); }
Example #2
Source File: GraphFactory.java From egeria with Apache License 2.0 | 6 votes |
/** * Set the config for Janus Graph. * * @param connectionProperties - POJO for the configuration used to create the connector. * @return JanusGraph instance with schema and indexes */ public JanusGraph openGraph(ConnectionProperties connectionProperties) throws JanusConnectorException { final String methodName = "openGraph"; JanusGraph janusGraph; final String graphType = (String) connectionProperties.getConfigurationProperties().get("graphType"); JanusGraphFactory.Builder config = janusFactoryBeans.getJanusFactory(connectionProperties); try { janusGraph = config.open(); return initializeGraph(janusGraph, graphType); } catch (Exception e) { log.error("A connection with the graph database could not be established with the provided configuration", e); JanusConnectorErrorCode errorCode = JanusConnectorErrorCode.CANNOT_OPEN_GRAPH_DB; String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(e.getMessage(), methodName, GraphFactory.class.getName()); throw new JanusConnectorException(GraphFactory.class.getName(), methodName, errorMessage, errorCode.getSystemAction(), errorCode.getUserAction()); } }
Example #3
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 6 votes |
public AtlasJanusGraph(JanusGraph graphInstance) { //determine multi-properties once at startup JanusGraphManagement mgmt = null; try { mgmt = graphInstance.openManagement(); Iterable<PropertyKey> keys = mgmt.getRelationTypes(PropertyKey.class); for (PropertyKey key : keys) { if (key.cardinality() != Cardinality.SINGLE) { multiProperties.add(key.name()); } } } finally { if (mgmt != null) { mgmt.rollback(); } } janusGraph = (StandardJanusGraph) graphInstance; }
Example #4
Source File: EdgeLoaderWorker.java From janusgraph-utils with Apache License 2.0 | 6 votes |
public EdgeLoaderWorker(final Iterator<Map<String, String>> records, final Map<String, Object> propertiesMap, final JanusGraph graph) { super(records, propertiesMap, graph); this.currentRecord = 0; this.defaultEdgeLabel = (String) propertiesMap.get(Constants.EDGE_LABEL_MAPPING); this.edgeLabelFieldName = null; COMMIT_COUNT = Config.getConfig().getEdgeRecordCommitCount(); if (propertiesMap.values().contains(Constants.EDGE_LABEL_MAPPING)) { for (String propName : propertiesMap.keySet()) { if (Constants.EDGE_LABEL_MAPPING.equals(propertiesMap.get(propName))) { this.edgeLabelFieldName = propName; break; } } } }
Example #5
Source File: AtlasJanusGraphDatabase.java From atlas with Apache License 2.0 | 6 votes |
public static JanusGraph getGraphInstance() { if (graphInstance == null) { synchronized (AtlasJanusGraphDatabase.class) { if (graphInstance == null) { Configuration config; try { config = getConfiguration(); } catch (AtlasException e) { throw new RuntimeException(e); } graphInstance = initJanusGraph(config); atlasGraphInstance = new AtlasJanusGraph(); validateIndexBackend(config); } } } return graphInstance; }
Example #6
Source File: SchemaLoader.java From janusgraph-utils with Apache License 2.0 | 6 votes |
public static void main(String[] args) { if (null == args || args.length < 2) { System.err.println("Usage: SchemaLoader <janusgraph-config-file> <schema-file>"); System.exit(1); } String configFile = args[0]; String schemaFile = args[1]; // use custom or default config file to get JanusGraph JanusGraph g = JanusGraphFactory.open(configFile); try { new SchemaLoader().loadSchema(g, schemaFile); } catch (Exception e) { System.out.println("Failed to import schema due to " + e.getMessage()); } finally { g.close(); } }
Example #7
Source File: VertexLoaderWorker.java From janusgraph-utils with Apache License 2.0 | 6 votes |
public VertexLoaderWorker(final Iterator<Map<String, String>> records, final Map<String, Object> propertiesMap, final JanusGraph graph) { super(records, propertiesMap, graph); this.currentRecord = 0; this.defaultVertexLabel = (String) propertiesMap.get(Constants.VERTEX_LABEL_MAPPING); this.vertexLabelFieldName = null; COMMIT_COUNT = Config.getConfig().getVertexRecordCommitCount(); if (propertiesMap.values().contains(Constants.VERTEX_LABEL_MAPPING)) { // find the vertex for (String propName : propertiesMap.keySet()) { if (Constants.VERTEX_LABEL_MAPPING.equals(propertiesMap.get(propName))) { this.vertexLabelFieldName = propName; break; } } } }
Example #8
Source File: LoadData.java From janusgraph-visualization with Apache License 2.0 | 5 votes |
public static void main(String[] args) { ClassPathResource classPathResource = new ClassPathResource("janusgraph.properties"); File file = classPathResource.getFile(); String path = file.getPath(); JanusGraph graph = JanusGraphFactory.open(path); GraphTraversalSource g = graph.traversal(); g.V().drop().iterate(); g.tx().commit(); graph.tx().commit(); GraphOfTheGodsFactory.load(graph); graph.close(); }
Example #9
Source File: MarvelGraphFactory.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
private static Vertex get(final JanusGraph graph, final String key, final String value) { final GraphTraversalSource g = graph.traversal(); final Iterator<Vertex> it = g.V().has(key, value); if (it.hasNext()) { return it.next(); } return null; }
Example #10
Source File: ScenarioTests.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
private static void createHotelSchema(final JanusGraph graph) { //another issue, you should only try to create the schema once. //you use uniqueness constraints, so you need to define the schema up front with the unique() call, //but if you did not use uniqueness constraints, you could just let JanusGraph create the schema for you. final JanusGraphManagement mgmt = graph.openManagement(); final PropertyKey brandtypePropertyKey = mgmt.makePropertyKey("brandtype").dataType(String.class).make(); mgmt.buildIndex("brandtypeIndex", Vertex.class).addKey(brandtypePropertyKey).unique().buildCompositeIndex(); final PropertyKey namePropertyKey = mgmt.makePropertyKey("name").dataType(String.class).make(); mgmt.buildIndex("nameIndex", Vertex.class).addKey(namePropertyKey).unique().buildCompositeIndex(); mgmt.makeEdgeLabel(Relationship.hotelBrandType.name()).multiplicity(Multiplicity.MANY2ONE).make(); mgmt.makeEdgeLabel(Relationship.instanceOf.name()).multiplicity(Multiplicity.MANY2ONE).make(); mgmt.commit(); }
Example #11
Source File: OldTimeline.java From janusgraph_tutorial with Apache License 2.0 | 5 votes |
public static void main(String argv[]) throws Exception { JanusGraph graph = JanusGraphFactory.open(Schema.CONFIG_FILE); HadoopQueryRunner q = new HadoopQueryRunner(graph.traversal(), "testUser1"); int runs = 10; for(int i =0; i < runs; i++) { LOGGER.info("Previous timeline (run {} of {})", i+1, runs); q.printTimeline(q.getTimeline2(10)); } q.close(); graph.close(); }
Example #12
Source File: NewTimeline.java From janusgraph_tutorial with Apache License 2.0 | 5 votes |
public static void main(String argv[]) throws Exception { JanusGraph graph = JanusGraphFactory.open(Schema.CONFIG_FILE); HadoopQueryRunner q = new HadoopQueryRunner(graph.traversal(), "testUser1"); int runs = 10; for(int i =0; i < runs; i++) { LOGGER.info("New timeline (run {} of {})", i+1, runs); q.printTimeline(q.getTimeline3(10)); } q.close(); graph.close(); }
Example #13
Source File: MarvelTest.java From dynamodb-janusgraph-storage-backend with Apache License 2.0 | 5 votes |
protected static void loadData(final JanusGraph graph, final int numLines) throws Exception { Preconditions.checkArgument(numLines >= 1, "Need to test with at least one line"); // it takes a long time to process all 100,000 lines so we can // run a subset as a unit test. final int lines = Integer.valueOf(System.getProperty("MarvelTestLines", String.valueOf(numLines))); MarvelGraphFactory.load(graph, lines, false /*report*/); }
Example #14
Source File: AtlasJanusGraph.java From atlas with Apache License 2.0 | 5 votes |
@Override public void clear() { JanusGraph graph = getGraph(); if (graph.isOpen()) { // only a shut down graph can be cleared graph.close(); } try { JanusGraphFactory.drop(graph); } catch (BackendException ignoreEx) { } }
Example #15
Source File: AtlasJanusGraphDatabase.java From atlas with Apache License 2.0 | 5 votes |
@VisibleForTesting static JanusGraph initJanusGraph(Configuration config) { try { return JanusGraphFactory.open(config); } catch (JanusGraphException e) { LOG.warn("JanusGraphException: {}", e.getMessage()); if (e.getMessage().startsWith(OLDER_STORAGE_EXCEPTION)) { LOG.info("Newer client is being used with older janus storage version. Setting allow-upgrade=true and reattempting connection"); config.addProperty("graph.allow-upgrade", true); return JanusGraphFactory.open(config); } else { throw new RuntimeException(e); } } }
Example #16
Source File: BatchImport.java From janusgraph-utils with Apache License 2.0 | 5 votes |
public static void main(String args[]) throws Exception { if (null == args || args.length < 4) { System.err.println( "Usage: BatchImport <janusgraph-config-file> <data-files-directory> <schema.json> <data-mapping.json> [skipSchema]"); System.exit(1); } JanusGraph graph = JanusGraphFactory.open(args[0]); if (!(args.length > 4 && args[4].equals("skipSchema"))) new SchemaLoader().loadSchema(graph, args[2]); new DataLoader(graph).loadVertex(args[1], args[3]); new DataLoader(graph).loadEdges(args[1], args[3]); graph.close(); }
Example #17
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 5 votes |
public GraphContextImpl create(boolean enableListeners) { FileUtils.deleteQuietly(graphDir.toFile()); JanusGraph janusGraph = initializeJanusGraph(true, enableListeners); initializeJanusIndexes(janusGraph); createFramed(janusGraph); fireListeners(); return this; }
Example #18
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 5 votes |
public GraphContextImpl load() { JanusGraph janusGraph = initializeJanusGraph(false, false); createFramed(janusGraph); fireListeners(); return this; }
Example #19
Source File: DataFileLoader.java From janusgraph-utils with Apache License 2.0 | 5 votes |
private void startWorkers(Iterator<CSVRecord> iter, long targetRecordCount, WorkerPool workers) throws Exception { while (iter.hasNext()) { long currentRecord = 0; List<Map<String, String>> sub = new ArrayList<Map<String, String>>(); while (iter.hasNext() && currentRecord < targetRecordCount) { sub.add(iter.next().toMap()); currentRecord++; } Constructor<Worker> constructor = workerClass.getConstructor(Iterator.class, Map.class, JanusGraph.class); Worker worker = constructor.newInstance(sub.iterator(), propertiesMap, graph); workers.submit(worker); } //main thread would wait here workers.wait4Finish(); }
Example #20
Source File: JavaExample.java From janusgraph-java-example with Apache License 2.0 | 5 votes |
public static void main(String[] args) { JanusGraph graph = JanusGraphFactory.open("conf/janusgraph-berkeleyje-lucene.properties"); GraphTraversalSource g = graph.traversal(); if (g.V().count().next() == 0) { // load the schema and graph data GraphOfTheGodsFactory.load(graph); } Map<Object, Object> saturnProps = g.V().has("name", "saturn").valueMap(true).next(); LOGGER.info(saturnProps.toString()); List<Edge> places = g.E().has("place", Geo.geoWithin(Geoshape.circle(37.97, 23.72, 50))).toList(); LOGGER.info(places.toString()); System.exit(0); }
Example #21
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Set up the indexes for the Janus Graph instance when type is mainGraph * * @param janusGraph - Janus Graph instance */ private void createIndexesMainGraph(JanusGraph janusGraph) { createCompositeIndexForProperty(PROPERTY_NAME_NODE_ID, PROPERTY_KEY_ENTITY_NODE_ID, true, janusGraph, Vertex.class); createCompositeIndexForProperty(PROPERTY_NAME_GUID, PROPERTY_KEY_ENTITY_GUID, false, janusGraph, Vertex.class); createCompositeIndexForProperty(PROPERTY_NAME_LABEL, PROPERTY_KEY_LABEL, false, janusGraph, Vertex.class); createCompositeIndexForProperty(PROPERTY_NAME_LABEL, PROPERTY_KEY_RELATIONSHIP_LABEL, false, janusGraph, Edge.class); }
Example #22
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Set up the indexes for the Janus Graph instance when type is bufferGraph * * @param janusGraph - Janus Graph instance */ private void createIndexesBuffer(JanusGraph janusGraph) { createCompositeIndexForProperty(PROPERTY_NAME_GUID, PROPERTY_KEY_ENTITY_GUID, true, janusGraph, Vertex.class); createCompositeIndexForProperty(PROPERTY_NAME_LABEL, PROPERTY_KEY_LABEL, false, janusGraph, Vertex.class); createCompositeIndexForProperty(PROPERTY_NAME_LABEL, PROPERTY_KEY_RELATIONSHIP_LABEL, false, janusGraph, Edge.class); createCompositeIndexForProperty(PROPERTY_NAME_GUID, PROPERTY_KEY_RELATIONSHIP_GUID, false, janusGraph, Edge.class); }
Example #23
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
private void createIndexes(JanusGraph janusGraph, String graphType) { if ("bufferGraph".equals(graphType)) { createIndexesBuffer(janusGraph); } if ("mainGraph".equals(graphType)) { createIndexesMainGraph(janusGraph); } }
Example #24
Source File: GraphFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Set up the schema for the Janus Graph instance * * @param janusGraph - Janus Graph instance * @param graphType - type of the graph to be initiated */ private JanusGraph initializeGraph(JanusGraph janusGraph, String graphType) throws JanusConnectorException { final String methodName = "initializeGraph"; log.info("Updating graph schema, if necessary"); try { JanusGraphManagement management = janusGraph.openManagement(); Set<String> vertexLabels = new HashSet<>(); Set<String> relationshipsLabels = new HashSet<>(); if ("bufferGraph".equals(graphType)) { vertexLabels = schemaBasedOnGraphType(VertexLabelsBufferGraph.class); relationshipsLabels = schemaBasedOnGraphType(EdgeLabelsBufferGraph.class); } if ("mainGraph".equals(graphType)) { vertexLabels = schemaBasedOnGraphType(VertexLabelsMainGraph.class); relationshipsLabels = schemaBasedOnGraphType(EdgeLabelsMainGraph.class); } checkAndAddLabelVertex(management, vertexLabels); checkAndAddLabelEdge(management, relationshipsLabels); //TODO define properties management.commit(); createIndexes(janusGraph, graphType); return janusGraph; } catch (Exception e) { log.error("{} failed during graph initialize operation with error: {}", graphType, e); JanusConnectorErrorCode errorCode = JanusConnectorErrorCode.GRAPH_INITIALIZATION_ERROR; String errorMessage = errorCode.getErrorMessageId() + errorCode.getFormattedErrorMessage(e.getMessage(), methodName, GraphFactory.class.getName()); throw new JanusConnectorException(GraphFactory.class.getName(), methodName, errorMessage, errorCode.getSystemAction(), errorCode.getUserAction()); } }
Example #25
Source File: IndexingFactory.java From egeria with Apache License 2.0 | 5 votes |
/** * Creates the indexes for the properties of vertices. * * @param propertyName - property name * @param propertyKeyName - the property name that is stored in the graph * @param unique - if the propery name is unique or not * @param graph - graph instance to create the indexes */ protected void createCompositeIndexForProperty(String propertyName, String propertyKeyName, boolean unique, JanusGraph graph, Class type) { String indexName = "vertexIndexComposite" + propertyKeyName; log.info("INDEX to be created {}", indexName); this.graph = graph; checkIndex(indexName,propertyName,propertyKeyName,unique,type); }
Example #26
Source File: WindupFrame.java From windup with Eclipse Public License 1.0 | 4 votes |
/** * Gets the wrapped graph itself, allowing access to the underlying JanusGraph for raw queries. */ default WrappedFramedGraph<JanusGraph> getWrappedGraph() { return (WrappedFramedGraph<JanusGraph>)getGraph(); }
Example #27
Source File: IterationAutomicCommitTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public WrappedFramedGraph<JanusGraph> getFramed() { return delegate.getFramed(); }
Example #28
Source File: IterationAutomicCommitTest.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public JanusGraph getGraph() { return delegate.getGraph(); }
Example #29
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 4 votes |
private void createFramed(JanusGraph janusGraph) { this.graph = janusGraph; final ClassLoader compositeClassLoader = classLoaderProvider.getCompositeClassLoader(); final ReflectionCache reflections = new ReflectionCache(); Set<MethodHandler> handlers = new HashSet<>(); handlers.add(new MapInPropertiesHandler()); handlers.add(new MapInAdjacentPropertiesHandler()); handlers.add(new MapInAdjacentVerticesHandler()); handlers.add(new SetInPropertiesHandler()); handlers.add(new JavaHandlerHandler()); handlers.add(new WindupPropertyMethodHandler()); handlers.add(new WindupAdjacencyMethodHandler()); AnnotationFrameFactory frameFactory = new AnnotationFrameFactory(compositeClassLoader, reflections, handlers); /* * We override a couple of key methods here, just to insure that we always have access to the change events. * * Hopefully this will be fixed in a future version of Ferma. * * https://github.com/Syncleus/Ferma/issues/44 */ framed = new DelegatingFramedGraph<JanusGraph>(janusGraph, frameFactory, this.graphTypeManager) { @Override public <T> T addFramedVertex(final ClassInitializer<T> initializer, final Object... keyValues) { final Vertex vertex; final T framedVertex; if( keyValues != null ) { vertex = this.getBaseGraph().addVertex(keyValues); framedVertex = frameNewElement(vertex, initializer); } else { vertex = this.getBaseGraph().addVertex(); framedVertex = frameNewElement(vertex, initializer); } GraphContextImpl.this.mutationListener.vertexAdded(vertex); return framedVertex; } @Override public <T> T addFramedVertexExplicit(final ClassInitializer<T> initializer) { Vertex vertex = this.getBaseGraph().addVertex(); final T framedVertex = frameNewElementExplicit(vertex, initializer); GraphContextImpl.this.mutationListener.vertexAdded(vertex); return framedVertex; } }; }
Example #30
Source File: GraphContextImpl.java From windup with Eclipse Public License 1.0 | 4 votes |
private JanusGraph initializeJanusGraph(boolean createMode, boolean enableListeners) { LOG.fine("Initializing graph."); Path lucene = graphDir.resolve("graphsearch"); Path berkeley = graphDir.resolve("titangraph"); // TODO: Externalize this. conf = new BaseConfiguration(); // Sets a unique id in order to fix WINDUP-697. This causes Titan to not attempt to generate and ID, // as the Titan id generation code fails on machines with broken network configurations. conf.setProperty("graph.unique-instance-id", "windup_" + System.nanoTime() + "_" + RandomStringUtils.randomAlphabetic(6)); conf.setProperty("storage.directory", berkeley.toAbsolutePath().toString()); conf.setProperty("storage.backend", "berkeleyje"); // Sets the berkeley cache to a relatively small value to reduce the memory footprint. // This is actually more important than performance on some of the smaller machines out there, and // the performance decrease seems to be minimal. conf.setProperty("storage.berkeleydb.cache-percentage", 1); // Set READ UNCOMMITTED to improve performance conf.setProperty("storage.berkeleydb.lock-mode", LockMode.READ_UNCOMMITTED); conf.setProperty("storage.berkeleydb.isolation-level", BerkeleyJEStoreManager.IsolationLevel.READ_UNCOMMITTED); // Increase storage write buffer since we basically do a large bulk load during the first phases. // See http://s3.thinkaurelius.com/docs/titan/current/bulk-loading.html conf.setProperty("storage.buffer-size", "4096"); // Turn off transactions to improve performance conf.setProperty("storage.transactions", false); conf.setProperty("ids.block-size", 25000); // conf.setProperty("ids.flush", true); // conf.setProperty("", false); // // turn on a db-cache that persists across txn boundaries, but make it relatively small conf.setProperty("cache.db-cache", true); conf.setProperty("cache.db-cache-clean-wait", 0); conf.setProperty("cache.db-cache-size", .09); conf.setProperty("cache.db-cache-time", 0); conf.setProperty("index.search.backend", "lucene"); conf.setProperty("index.search.directory", lucene.toAbsolutePath().toString()); writeToPropertiesFile(conf, graphDir.resolve("TitanConfiguration.properties").toFile()); JanusGraph janusGraph = JanusGraphFactory.open(conf); /* * We only need to setup the eventing system when initializing a graph, not when loading it later for * reporting. */ if (enableListeners) { TraversalStrategies graphStrategies = TraversalStrategies.GlobalCache .getStrategies(StandardJanusGraph.class) .clone(); // Remove any old listeners if (graphStrategies.getStrategy(EventStrategy.class) != null) graphStrategies.removeStrategies(EventStrategy.class); graphStrategies.addStrategies(EventStrategy.build().addListener(mutationListener).create()); TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, graphStrategies); mutationListener.setGraph(this); } return janusGraph; }