Java Code Examples for org.janusgraph.core.JanusGraphFactory#open()

The following examples show how to use org.janusgraph.core.JanusGraphFactory#open() . 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: SchemaLoader.java    From janusgraph-utils with Apache License 2.0 6 votes vote down vote up
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 2
Source File: LoadData.java    From janusgraph-visualization with Apache License 2.0 5 votes vote down vote up
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 3
Source File: JavaExample.java    From janusgraph-java-example with Apache License 2.0 5 votes vote down vote up
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 4
Source File: BatchImport.java    From janusgraph-utils with Apache License 2.0 5 votes vote down vote up
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 5
Source File: AtlasJanusGraphDatabase.java    From atlas with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: ComputeWeightVertexProgram.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
@Override
public void workerIterationStart(final Memory memory) {
  LOGGER.info("workerIterationStart");
  // TODO: add method in GraphEtl that allows us to simply copy from config to properties.
  graph = JanusGraphFactory.open(configuration);
  g = graph.traversal();
  sevenDaysAgo = (new Date()).getTime() - (1000 * 60 * 60 * 24 * 7);
  count = 0;
  min = -10;
  max = 0;
}
 
Example 7
Source File: CreateWeightIndex.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the graph and the graph management interface.
 *
 * @param configFile
 */
public CreateWeightIndex(String configFile) {
  LOGGER.info("Connecting graph");
  graph = JanusGraphFactory.open(configFile);
  LOGGER.info("Getting management");
  mgt = graph.openManagement();
}
 
Example 8
Source File: NewTimeline.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
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 9
Source File: OldTimeline.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
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 10
Source File: CreateSupernodes.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the graph connection.
 *
 * @param configFile
 */
public CreateSupernodes(String configFile) throws Exception {
  graph = JanusGraphFactory.open(configFile);
  faker = new Faker();
  queryRunner = new QueryRunner(graph.traversal(), "test");

  Calendar cal = Calendar.getInstance();
  cal.add(Calendar.YEAR, -1);
  oneYearAgo = cal.getTime();
}
 
Example 11
Source File: LoadData.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the graph connection.
 *
 * @param configFile
 */
public LoadData(String configFile) {
  graph = JanusGraphFactory.open(configFile);
  faker = new Faker();

  Calendar cal = Calendar.getInstance();
  cal.add(Calendar.MONTH, -1);
  oneMonthAgo = cal.getTime();
}
 
Example 12
Source File: ScenarioTests.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 5 votes vote down vote up
/**
 * This test is to demonstrate performance in response to a report of elevated latency for committing 30 vertices.
 * http://stackoverflow.com/questions/42899388/titan-dynamodb-local-incredibly-slow-8s-commit-for-30-vertices
 * @throws BackendException in case cleanUpTables fails
 */
@Test
public void performanceTest() throws BackendException {
    final Graph graph = JanusGraphFactory.open(TestGraphUtil.instance.createTestGraphConfig(BackendDataModel.MULTI));
    IntStream.of(30).forEach(i -> graph.addVertex(LABEL));
    final Stopwatch watch = Stopwatch.createStarted();
    graph.tx().commit();
    System.out.println("Committing took " + watch.stop().elapsed(TimeUnit.MILLISECONDS) + " ms");
    TestGraphUtil.instance.cleanUpTables();
}
 
Example 13
Source File: ScenarioTests.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 5 votes vote down vote up
private void tripleIngestBase(final BiConsumer<StandardJanusGraph, List<Triple>> writer) throws BackendException {
    final Stopwatch watch = Stopwatch.createStarted();
    final StandardJanusGraph graph = (StandardJanusGraph) JanusGraphFactory.open(TestGraphUtil.instance.createTestGraphConfig(BackendDataModel.MULTI));
    log.info("Created graph in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    watch.reset();
    watch.start();
    createHotelSchema(graph);
    log.info("Created schema in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");

    watch.reset();
    watch.start();
    final URL url = ScenarioTests.class.getClassLoader().getResource("META-INF/HotelTriples.txt");
    Preconditions.checkNotNull(url);
    final List<Triple> lines;
    try (CSVReader reader = new CSVReader(new InputStreamReader(url.openStream()))) {
        lines = reader.readAll().stream()
            .map(Triple::new)
            .collect(Collectors.toList());
    } catch (IOException e) {
        throw new IllegalStateException("Error processing triple file", e);
    }
    log.info("Read file into Triple objects in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    watch.reset();
    watch.start();
    writer.accept(graph, lines);
    log.info("Added objects in " + watch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    TestGraphUtil.instance.cleanUpTables();
}
 
Example 14
Source File: BuiltinQueries.java    From janusgraph_tutorial with Apache License 2.0 4 votes vote down vote up
/**
 * Run every example query, outputting results via @LOGGER
 *
 * @param argv
 * @throws Exception
 */
public static void main(String[] argv) throws Exception {
  JanusGraph graph = JanusGraphFactory.open(Schema.CONFIG_FILE);
  GraphTraversalSource graphTraversalSource = graph.traversal();

  QueryRunner queryRunner = new QueryRunner(graphTraversalSource, "testUser0");

  LOGGER.info("Initialized the builtin query executor");

  queryRunner.runQueries();

  queryRunner.close();

  graph.close();

  System.exit(0);
}
 
Example 15
Source File: GraphContextImpl.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
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;
}