Search in sources :

Example 26 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-graphadmin by onap.

the class MigrateVnfcModelVersionIdTest 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, schemaVersions.getDefaultVersion());
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    Vertex vnfc1 = g.addV().property("aai-node-type", "vnfc").property("model-version-id", "vnfc-version-id-1").property("vnfcName", "vnfc-name-1").property("nfcNamingCode", "naming-code-1").property("nfcFunction", "function-1").property("model-version-id", "vnfc-version-id-1").next();
    Vertex vnfc2 = g.addV().property("aai-node-type", "vnfc").property("model-version-id-local", "vnfc-version-id-1").property("vnfcName", "vnfc-name-2").property("nfcNamingCode", "naming-code-1").property("nfcFunction", "function-2").property("model-version-id-local", "vnfc-version-id-2").next();
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    GraphTraversalSource traversal = g;
    GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance()));
    when(spy.tx()).thenReturn(tx);
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
    migration = new MigrateVnfcModelVersionId(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
    migration.run();
}
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) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine)

Example 27 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-graphadmin by onap.

the class MigrateMissingFqdnOnPserversTest 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, schemaVersions.getDefaultVersion());
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    pserver1 = g.addV().property("aai-node-type", MigrateMissingFqdnOnPservers.PSERVER_NODE_TYPE).property(MigrateMissingFqdnOnPservers.PSERVER_HOSTNAME, "hostname1.com").property(MigrateMissingFqdnOnPservers.PSERVER_SOURCEOFTRUTH, "RO").next();
    pserver2 = g.addV().property("aai-node-type", MigrateMissingFqdnOnPservers.PSERVER_NODE_TYPE).property(MigrateMissingFqdnOnPservers.PSERVER_HOSTNAME, "hostname2.com").property(MigrateMissingFqdnOnPservers.PSERVER_FQDN, "").next();
    pserver3 = g.addV().property("aai-node-type", MigrateMissingFqdnOnPservers.PSERVER_NODE_TYPE).property(MigrateMissingFqdnOnPservers.PSERVER_HOSTNAME, "akr1").property(MigrateMissingFqdnOnPservers.PSERVER_SOURCEOFTRUTH, "RO").property(MigrateMissingFqdnOnPservers.PSERVER_FQDN, "akr1").next();
    pserver4 = g.addV().property("aai-node-type", MigrateMissingFqdnOnPservers.PSERVER_NODE_TYPE).property(MigrateMissingFqdnOnPservers.PSERVER_HOSTNAME, "hostname1").property(MigrateMissingFqdnOnPservers.PSERVER_SOURCEOFTRUTH, "RO").property(MigrateMissingFqdnOnPservers.PSERVER_FQDN, "").next();
    pserver5 = g.addV().property("aai-node-type", MigrateMissingFqdnOnPservers.PSERVER_NODE_TYPE).property(MigrateMissingFqdnOnPservers.PSERVER_HOSTNAME, "hostname2").property(MigrateMissingFqdnOnPservers.PSERVER_SOURCEOFTRUTH, "RO").next();
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    GraphTraversalSource traversal = g;
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    migration = new MigrateMissingFqdnOnPservers(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
    migration.run();
}
Also used : 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 28 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-graphadmin by onap.

the class MigrateSdnaIvlanDataTest method setUp.

@Before
public void setUp() throws Exception {
    g = tx.traversal();
    loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    System.setProperty("BUNDLECONFIG_DIR", "src/test/resources");
    // PNF -  pnf1
    Vertex pnf1 = g.addV().property("aai-node-type", "pnf").property("pnf-name", "pnf1").next();
    // P-INTERFACE - "11111.1"
    Vertex pInterface1 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "11111.1").next();
    // LAG-INTERFACE - lag-interface1
    Vertex lagInterface1 = g.addV().property("aai-node-type", "lag-interface").property("interface-name", "lag-interface1").next();
    // CONFIGURATION - "test/evc/one"
    Vertex configuration1 = g.addV().property("aai-node-type", "configuration").property("configuration-id", "test/evc/one").next();
    // CONFIGURATION - "test/evc/one-1"
    Vertex configuration1_1 = g.addV().property("aai-node-type", "configuration").property("configuration-id", "test/evc/one-1").next();
    // CONFIGURATION - "test/evc/one-2"
    Vertex configuration1_2 = g.addV().property("aai-node-type", "configuration").property("configuration-id", "test/evc/one-2").next();
    // FORWARDER - "test/evc/one" sequence 1
    Vertex forwarder1_1 = g.addV().property("aai-node-type", "forwarder").property("sequence", 1).property("forwarder-role", "ingress").next();
    // FORWARDER - "test/evc/one"  sequence 2
    Vertex forwarder1_2 = g.addV().property("aai-node-type", "forwarder").property("sequence", 2).property("forwarder-role", "ingress").next();
    // FORWARDING-PATH - "test/evc/one"
    Vertex forwardingPath1 = g.addV().property("aai-node-type", "forwarding-path").property("forwarding-path-id", "test/evc/one").property("forwarding-path-name", "test/evc/one").next();
    // EVC - "test/evc/one"
    Vertex evc = g.addV().property("aai-node-type", "evc").property("evc-id", "test/evc/one").next();
    // FORWARDER-EVC - "test/evc/one-1"
    Vertex fwdEvc1_1 = g.addV().property("aai-node-type", "forwarder-evc").property("forwarder-evc-id", "test/evc/one-1").next();
    // FORWARDER-EVC - "test/evc/one-2"
    Vertex fwdEvc1_2 = g.addV().property("aai-node-type", "forwarder-evc").property("forwarder-evc-id", "test/evc/one-2").next();
    // pnf -> p-interface -> forwarder -> configuration -> forwarder-evc
    // pnf1 -> pInterface1 -> forwarder1_1 -> configuration1_1 -> fwdEvc1_1
    edgeSerializer.addTreeEdge(g, pnf1, pInterface1);
    edgeSerializer.addEdge(g, pInterface1, forwarder1_1);
    edgeSerializer.addEdge(g, forwarder1_1, configuration1_1);
    edgeSerializer.addEdge(g, forwardingPath1, configuration1);
    edgeSerializer.addTreeEdge(g, forwarder1_1, forwardingPath1);
    edgeSerializer.addTreeEdge(g, forwarder1_2, forwardingPath1);
    edgeSerializer.addTreeEdge(g, configuration1_1, fwdEvc1_1);
    // pnf -> lag-interface -> forwarder -> configuration -> forwarder-evc
    // pnf1 -> lagInterface1 -> forwarder1_2 -> configuration1_2 -> fwdEvc1_2
    edgeSerializer.addTreeEdge(g, pnf1, lagInterface1);
    edgeSerializer.addEdge(g, forwarder1_2, configuration1_2);
    edgeSerializer.addEdge(g, lagInterface1, forwarder1_2);
    edgeSerializer.addTreeEdge(g, configuration1_2, fwdEvc1_2);
    TransactionalGraphEngine spy = spy(dbEngine);
    TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
    GraphTraversalSource traversal = g;
    GraphTraversalSource readOnly = tx.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance()));
    when(spy.tx()).thenReturn(tx);
    when(spy.asAdmin()).thenReturn(adminSpy);
    when(adminSpy.getTraversalSource()).thenReturn(traversal);
    when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly);
    migration = new MigrateSdnaIvlanData(spy, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
    migration.run();
}
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) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine) Before(org.junit.Before)

Example 29 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine 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 30 with TransactionalGraphEngine

use of org.onap.aai.serialization.engines.TransactionalGraphEngine in project aai-aai-common by onap.

the class HttpTestUtil method doPatch.

public Response doPatch(String uri, String payload) throws UnsupportedEncodingException, AAIException {
    this.init();
    Response response = null;
    boolean success = true;
    TransactionalGraphEngine dbEngine = null;
    try {
        if (uri.startsWith("/aai/")) {
            uri = uri.substring(5);
        }
        logger.info("Starting the put request for the uri {} with payload {}", uri, payload);
        String[] arr = uri.split("/");
        SchemaVersion version = null;
        if (arr.length > 1) {
            if (arr[0].matches("^v\\d+")) {
                version = new SchemaVersion(arr[0]);
                uri = uri.replaceAll("^v\\d+", "");
            }
        }
        if (version == null) {
            version = schemaVersions.getDefaultVersion();
        }
        Mockito.when(uriInfo.getPath()).thenReturn(uri);
        if (notification != null) {
            traversalHttpEntry.setHttpEntryProperties(version, notification, notificationDepth);
        } else {
            traversalHttpEntry.setHttpEntryProperties(version);
        }
        Loader loader = traversalHttpEntry.getLoader();
        dbEngine = traversalHttpEntry.getDbEngine();
        URI uriObject = UriBuilder.fromPath(uri).build();
        URIToObject uriToObject = new URIToObject(loader, uriObject);
        String objType = uriToObject.getEntityName();
        QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
        logger.info("Unmarshalling the payload to this {}", objType);
        Introspector obj;
        HttpMethod httpMethod;
        obj = loader.unmarshal(objType, payload, org.onap.aai.restcore.MediaType.getEnum("application/json"));
        httpMethod = HttpMethod.MERGE_PATCH;
        this.validateIntrospector(obj, loader, uriObject, httpMethod);
        DBRequest dbRequest = new DBRequest.Builder(httpMethod, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION").rawRequestContent(payload).build();
        List<DBRequest> dbRequestList = new ArrayList<>();
        dbRequestList.add(dbRequest);
        Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
        response = responsesTuple.getValue1().get(0).getValue1();
    } catch (AAIException e) {
        response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, e);
        success = false;
    } catch (Exception e) {
        AAIException ex = new AAIException("AAI_4000", e);
        response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, ex);
        success = false;
    } finally {
        if (success) {
            if (response != null) {
                if ((response.getStatus() / 100) == 2) {
                    logger.info("Successfully completed the PUT request with status {} and committing it to DB", response.getStatus());
                } else {
                    logFailure(HttpMethod.PUT, response);
                }
            }
            dbEngine.commit();
        } else {
            if (response != null) {
                logFailure(HttpMethod.PUT, response);
            }
            dbEngine.rollback();
        }
    }
    return response;
}
Also used : SchemaVersion(org.onap.aai.setup.SchemaVersion) Loader(org.onap.aai.introspection.Loader) Introspector(org.onap.aai.introspection.Introspector) URI(java.net.URI) AAIException(org.onap.aai.exceptions.AAIException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) QueryParser(org.onap.aai.parsers.query.QueryParser) URIToObject(org.onap.aai.parsers.uri.URIToObject) DBRequest(org.onap.aai.rest.db.DBRequest) AAIException(org.onap.aai.exceptions.AAIException) HttpMethod(org.onap.aai.restcore.HttpMethod)

Aggregations

TransactionalGraphEngine (org.onap.aai.serialization.engines.TransactionalGraphEngine)86 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)60 JanusGraphDBEngine (org.onap.aai.serialization.engines.JanusGraphDBEngine)45 Loader (org.onap.aai.introspection.Loader)42 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)33 Before (org.junit.Before)31 Test (org.junit.Test)24 Introspector (org.onap.aai.introspection.Introspector)23 Graph (org.apache.tinkerpop.gremlin.structure.Graph)18 Matchers.containsString (org.hamcrest.Matchers.containsString)18 JanusGraph (org.janusgraph.core.JanusGraph)18 DBSerializer (org.onap.aai.serialization.db.DBSerializer)18 AAIException (org.onap.aai.exceptions.AAIException)9 JanusGraphManagement (org.janusgraph.core.schema.JanusGraphManagement)8 SchemaVersion (org.onap.aai.setup.SchemaVersion)8 URI (java.net.URI)6 QueryParser (org.onap.aai.parsers.query.QueryParser)6 JsonObject (com.google.gson.JsonObject)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 URIToObject (org.onap.aai.parsers.uri.URIToObject)4