Search in sources :

Example 1 with DBSerializer

use of org.onap.aai.serialization.db.DBSerializer in project aai-graphadmin by onap.

the class VertexMergeTest method setUp.

@Before
public void setUp() throws Exception {
    graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
    tx = graph.newTransaction();
    g = tx.traversal();
    loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    JanusGraphManagement mgmt = graph.openManagement();
    mgmt.makePropertyKey("test-list").dataType(String.class).cardinality(Cardinality.SET).make();
    mgmt.commit();
    Vertex pserverSkeleton = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1").property("source-of-truth", "AAI-EXTENSIONS").property("fqdn", "test1.com").property("test-list", "value1").next();
    Vertex pInterface1 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface1").property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface1").next();
    Vertex pInterface2 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface2").property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2").next();
    Vertex pInterface2Secondary = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface2").property("special-prop", "value").property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2").next();
    Vertex lInterface1 = g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1").property("special-prop", "value").property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2/l-interfaces/l-interface/l-interface1").next();
    Vertex lInterface1Canopi = g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1").property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2/l-interfaces/l-interface/l-interface1").next();
    Vertex logicalLink = g.addV().property("aai-node-type", "logical-link").property("link-name", "logical-link1").property(AAIProperties.AAI_URI, "/network/logical-links/logical-link/logical-link1").next();
    Vertex pserverCanopi = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1").property("source-of-truth", "CANOPI-WS").property("fqdn", "test2.com").property("test-list", "value2").next();
    Vertex complex1 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complex1").property("source-of-truth", "RO").next();
    Vertex complex2 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complex2").property("source-of-truth", "RCT").next();
    Vertex vserver1 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver1").property("source-of-truth", "RO").next();
    Vertex vserver2 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver2").property("source-of-truth", "RCT").next();
    Vertex vserver3 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver3").property("source-of-truth", "RCT").next();
    Vertex vserver4 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver4").property("source-of-truth", "RCT").next();
    Vertex vserver5 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver5").property("source-of-truth", "RCT").next();
    edgeSerializer.addEdge(g, pserverSkeleton, complex1);
    edgeSerializer.addEdge(g, pserverSkeleton, vserver1);
    edgeSerializer.addEdge(g, pserverSkeleton, vserver2);
    edgeSerializer.addTreeEdge(g, pserverSkeleton, pInterface1);
    edgeSerializer.addTreeEdge(g, pserverSkeleton, pInterface2Secondary);
    edgeSerializer.addTreeEdge(g, pInterface2Secondary, lInterface1);
    edgeSerializer.addEdge(g, lInterface1, logicalLink);
    edgeSerializer.addEdge(g, pserverCanopi, complex2);
    edgeSerializer.addEdge(g, pserverCanopi, vserver3);
    edgeSerializer.addEdge(g, pserverCanopi, vserver4);
    edgeSerializer.addEdge(g, pserverCanopi, vserver5);
    edgeSerializer.addTreeEdge(g, pserverCanopi, pInterface2);
    edgeSerializer.addTreeEdge(g, pInterface2, lInterface1Canopi);
    Map<String, Set<String>> forceCopy = new HashMap<>();
    Set<String> forceSet = new HashSet<>();
    forceSet.add("fqdn");
    forceCopy.put("pserver", forceSet);
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    GraphTraversalSource traversal = g;
    GraphTraversalSource readOnly = g;
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
    DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "Merge test");
    VertexMerge merge = new VertexMerge.Builder(loader, spy, serializer).edgeSerializer(edgeSerializer).build();
    merge.performMerge(pserverCanopi, pserverSkeleton, forceCopy, basePath);
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DBSerializer(org.onap.aai.serialization.db.DBSerializer) 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 2 with DBSerializer

use of org.onap.aai.serialization.db.DBSerializer in project aai-graphadmin by onap.

the class QueryConsumer method processExecuteQuery.

public Response processExecuteQuery(String content, @PathParam("version") String versionParam, @PathParam("uri") @Encoded String uri, @DefaultValue("graphson") @QueryParam("format") String queryFormat, @DefaultValue("no_op") @QueryParam("subgraph") String subgraph, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
    String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId");
    String queryProcessor = headers.getRequestHeaders().getFirst("QueryProcessor");
    QueryProcessorType processorType = this.processorType;
    Response response = null;
    TransactionalGraphEngine dbEngine = null;
    try {
        this.checkQueryParams(info.getQueryParameters());
        Format format = Format.getFormat(queryFormat);
        if (queryProcessor != null) {
            processorType = QueryProcessorType.valueOf(queryProcessor);
        }
        SubGraphStyle subGraphStyle = SubGraphStyle.valueOf(subgraph);
        JsonParser parser = new JsonParser();
        JsonObject input = parser.parse(content).getAsJsonObject();
        JsonElement gremlinElement = input.get("gremlin");
        JsonElement dslElement = input.get("dsl");
        String gremlin = "";
        String dsl = "";
        SchemaVersion version = new SchemaVersion(versionParam);
        traversalUriHttpEntry.setHttpEntryProperties(version);
        dbEngine = traversalUriHttpEntry.getDbEngine();
        if (gremlinElement != null) {
            gremlin = gremlinElement.getAsString();
        }
        if (dslElement != null) {
            dsl = dslElement.getAsString();
        }
        GenericQueryProcessor processor;
        StopWatch.conditionalStart();
        if (!dsl.equals("")) {
            processor = new GenericQueryProcessor.Builder(dbEngine).queryFrom(dsl, "dsl").queryProcessor(dslQueryProcessor).processWith(processorType).create();
        } else {
            processor = new GenericQueryProcessor.Builder(dbEngine).queryFrom(gremlin, "gremlin").processWith(processorType).create();
        }
        String result = "";
        List<Object> vertices = processor.execute(subGraphStyle);
        DBSerializer serializer = new DBSerializer(version, dbEngine, introspectorFactoryType, sourceOfTruth);
        FormatFactory ff = new FormatFactory(traversalUriHttpEntry.getLoader(), serializer, schemaVersions, basePath);
        Formatter formater = ff.get(format, info.getQueryParameters());
        result = formater.output(vertices).toString();
        LOGGER.info("Completed");
        response = Response.status(Status.OK).type(MediaType.APPLICATION_JSON).entity(result).build();
    } catch (AAIException e) {
        response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, e);
    } catch (Exception e) {
        AAIException ex = new AAIException("AAI_4000", e);
        response = consumerExceptionResponseGenerator(headers, info, HttpMethod.GET, ex);
    } finally {
        if (dbEngine != null) {
            dbEngine.rollback();
        }
    }
    return response;
}
Also used : GenericQueryProcessor(org.onap.aai.rest.search.GenericQueryProcessor) FormatFactory(org.onap.aai.serialization.queryformats.FormatFactory) DBSerializer(org.onap.aai.serialization.db.DBSerializer) SchemaVersion(org.onap.aai.setup.SchemaVersion) Formatter(org.onap.aai.serialization.queryformats.Formatter) JsonObject(com.google.gson.JsonObject) AAIException(org.onap.aai.exceptions.AAIException) QueryProcessorType(org.onap.aai.rest.search.QueryProcessorType) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) Format(org.onap.aai.serialization.queryformats.Format) JsonElement(com.google.gson.JsonElement) AAIException(org.onap.aai.exceptions.AAIException) JsonObject(com.google.gson.JsonObject) SubGraphStyle(org.onap.aai.serialization.queryformats.SubGraphStyle) JsonParser(com.google.gson.JsonParser)

Example 3 with DBSerializer

use of org.onap.aai.serialization.db.DBSerializer in project aai-graphadmin by onap.

the class SendMigrationNotifications method initFields.

private void initFields() {
    this.loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
    this.engine = new JanusGraphDBEngine(queryStyle, loader);
    try {
        this.serializer = new DBSerializer(version, this.engine, introspectorFactoryType, this.eventSource);
    } catch (AAIException e) {
        throw new RuntimeException("could not create serializer", e);
    }
    this.notificationHelper = new NotificationHelper(loader, serializer, loaderFactory, schemaVersions, engine, requestId, this.eventSource);
}
Also used : DBSerializer(org.onap.aai.serialization.db.DBSerializer) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine) NotificationHelper(org.onap.aai.migration.NotificationHelper) AAIException(org.onap.aai.exceptions.AAIException)

Example 4 with DBSerializer

use of org.onap.aai.serialization.db.DBSerializer in project aai-aai-common by onap.

the class DataCopyTest method verifyNestedSideEffect.

@Test
public void verifyNestedSideEffect() throws AAIException, IllegalArgumentException, SecurityException, IOException {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
    final Introspector obj = loader.unmarshal("customer", this.getJsonString("nested-case.json"));
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.tx()).thenReturn(g);
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
    when(prop.orElse(null)).thenReturn(obj.getURI());
    when(uriQuery.isDependent()).thenReturn(false);
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
    Vertex v = serializer.createNewVertex(obj);
    serializer.serializeToDb(obj, v, uriQuery, obj.getURI(), "test");
    assertEquals("nested value populated", "testValue", g.traversal().V().has("service-instance-id", "nested-instance-key").next().property("persona-model-version").orElse(""));
    g.tx().rollback();
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector)

Example 5 with DBSerializer

use of org.onap.aai.serialization.db.DBSerializer in project aai-aai-common by onap.

the class DataCopyTest method expectedMissingPropertyExceptionInURI.

@Test
public void expectedMissingPropertyExceptionInURI() throws AAIException, UnsupportedEncodingException {
    final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
    final Introspector obj = loader.introspectorFromName("generic-vnf");
    obj.setValue("vnf-id", "myId");
    obj.setValue("model-invariant-id", "key1");
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    Graph g = graph.newTransaction();
    GraphTraversalSource traversal = g.traversal();
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
    when(prop.orElse(null)).thenReturn(obj.getURI());
    DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
    SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataCopy.class).build();
    thrown.expect(AAIMissingRequiredPropertyException.class);
    runner.execute(obj, self);
}
Also used : TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Graph(org.apache.tinkerpop.gremlin.structure.Graph) JanusGraph(org.janusgraph.core.JanusGraph) DBSerializer(org.onap.aai.serialization.db.DBSerializer) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector)

Aggregations

DBSerializer (org.onap.aai.serialization.db.DBSerializer)40 TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)25 Introspector (org.onap.aai.introspection.Introspector)19 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)18 Graph (org.apache.tinkerpop.gremlin.structure.Graph)16 JanusGraph (org.janusgraph.core.JanusGraph)16 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)15 Loader (org.onap.aai.introspection.Loader)15 Test (org.junit.Test)13 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)12 JsonObject (com.google.gson.JsonObject)7 AAIException (org.onap.aai.exceptions.AAIException)7 UrlBuilder (org.onap.aai.serialization.queryformats.utils.UrlBuilder)7 URI (java.net.URI)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 AAIUnknownObjectException (org.onap.aai.introspection.exceptions.AAIUnknownObjectException)4 SchemaVersion (org.onap.aai.setup.SchemaVersion)4 Format (org.onap.aai.serialization.queryformats.Format)3 FormatFactory (org.onap.aai.serialization.queryformats.FormatFactory)3 Formatter (org.onap.aai.serialization.queryformats.Formatter)3