Search in sources :

Example 81 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project sdc by onap.

the class JanusGraphGenericDaoTest method testStringSearch.

@Test
public void testStringSearch() {
    JanusGraph graph;
    BaseConfiguration conf = new BaseConfiguration();
    conf.setProperty("storage.backend", "inmemory");
    graph = JanusGraphFactory.open(conf);
    // JanusGraphManagement graphMgt = graph.getManagementSystem();
    JanusGraphManagement graphMgt = graph.openManagement();
    PropertyKey propKey = graphMgt.makePropertyKey("string1").dataType(String.class).make();
    graphMgt.buildIndex("string1", Vertex.class).addKey(propKey).unique().buildCompositeIndex();
    propKey = graphMgt.makePropertyKey("string2").dataType(String.class).make();
    graphMgt.buildIndex("string2", Vertex.class).addKey(propKey).unique().buildCompositeIndex();
    graphMgt.commit();
    log.debug("**** predicat index search non case");
    Iterable<JanusGraphVertex> vertices = graph.query().has("string1", Text.REGEX, "my new string 1").vertices();
    Iterator<JanusGraphVertex> iter = vertices.iterator();
    while (iter.hasNext()) {
        Vertex ver = iter.next();
        // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
        log.debug("{}", janusGraphDao.getProperties(ver));
    }
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) PropertyKey(org.janusgraph.core.PropertyKey) Test(org.junit.jupiter.api.Test)

Example 82 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.

the class ManageSchemaTest method addNewIndex.

@Test
public void addNewIndex() throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    String content = " {\r\n" + "    \"name\" : \"equipment-name\",\r\n" + "    \"unique\" : false,\r\n" + "    \"properties\" : [ {\r\n" + "      \"name\" : \"equipment-name\",\r\n" + "      \"cardinality\" : \"SINGLE\",\r\n" + "      \"typeClass\" : \"java.lang.String\"\r\n" + "    } ]\r\n" + "  }";
    DBIndex index = mapper.readValue(content, DBIndex.class);
    ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph, auditorFactory, schemaVersions, edgeIngestor);
    JanusGraphManagement mgmt = graph.openManagement();
    Set<String> instances = mgmt.getOpenInstances();
    System.out.println(instances);
    schema.updateIndex(index);
    graph.close();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) ManageJanusGraphSchema(org.onap.aai.db.schema.ManageJanusGraphSchema) DBIndex(org.onap.aai.db.schema.DBIndex) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 83 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.

the class ManageSchemaTest method closeRunningInstances.

/*
	@Test
	public void populateEmptyGraph() {
		ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph);
		schema.buildSchema();
	}
	
	@Test
	public void modifyIndex() {
		ManageJanusGraphSchema schema = new ManageJanusGraphSchema(graph);
		schema.buildSchema();
		Vertex v = graph.addVertex();
		v.setProperty("aai-node-type", "pserver");
		v.setProperty("hostname", "test1");
		v.setProperty("internet-topology", "test2");
		graph.commit();
		DBIndex index = new DBIndex();
		index.setName("internet-topology");
		index.setUnique(false);
		schema.updateIndex(index);
		
	}
	*/
@Test
public void closeRunningInstances() {
    JanusGraphManagement mgmt = graph.openManagement();
    Set<String> instances = mgmt.getOpenInstances();
    for (String instance : instances) {
        if (!instance.contains("(current)")) {
            mgmt.forceCloseInstance(instance);
        }
    }
    mgmt.commit();
    graph.close();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Test(org.junit.Test)

Example 84 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.

the class MigrateBadWidgetModelsPartOneTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("BUNDLECONFIG_DIR", "src/test/resources");
    JanusGraphManagement janusgraphManagement = graph.openManagement();
    g = graph.traversal();
    loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    createFirstVertexAndRelatedVertexes();
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    GraphTraversalSource traversal = g;
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    Mockito.doReturn(janusgraphManagement).when(adminSpy).getManagementSystem();
    migration = new MockMigrateBadWidgetModelsPartOne(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
    migration.run();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine) Before(org.junit.Before)

Example 85 with JanusGraphManagement

use of org.janusgraph.core.schema.JanusGraphManagement in project aai-graphadmin by onap.

the class ContainmentDeleteOtherVPropertyMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
    JanusGraphManagement janusgraphManagement = graph.openManagement();
    tx = graph.newTransaction();
    g = tx.traversal();
    loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    Vertex v = g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "delcontains-test-vnf").next();
    Vertex v2 = g.addV().property("aai-node-type", "l-interface").property("interface-name", "delcontains-test-lint").next();
    Edge e = v.addEdge("hasLInterface", v2, EdgeProperty.CONTAINS.toString(), AAIDirection.OUT.toString(), EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString());
    Vertex v3 = g.addV().property("aai-node-type", "allotted-resource").next();
    Edge e2 = v2.addEdge("uses", v3, EdgeProperty.CONTAINS.toString(), AAIDirection.NONE.toString(), EdgeProperty.DELETE_OTHER_V.toString(), AAIDirection.NONE.toString());
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    GraphTraversalSource traversal = g;
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    Mockito.doReturn(janusgraphManagement).when(adminSpy).getManagementSystem();
    migration = new ContainmentDeleteOtherVPropertyMigration(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions, "/edgeMigrationTestRules.json");
    migration.run();
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before)

Aggregations

JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)92 PropertyKey (org.janusgraph.core.PropertyKey)44 Test (org.junit.jupiter.api.Test)26 JanusGraphIndex (org.janusgraph.core.schema.JanusGraphIndex)24 JanusGraph (org.janusgraph.core.JanusGraph)23 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)20 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)17 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)12 HashMap (java.util.HashMap)9 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 Test (org.junit.Test)8 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)8 TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)8 JanusGraphBaseTest (org.janusgraph.graphdb.JanusGraphBaseTest)7 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)6 EdgeLabel (org.janusgraph.core.EdgeLabel)6 Map (java.util.Map)5 JanusGraphException (org.janusgraph.core.JanusGraphException)5