Search in sources :

Example 1 with TransactionalGraphEngine

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

the class SchemaMod method execute.

public void execute(String[] args) {
    logger = LoggerFactory.getLogger(SchemaMod.class.getSimpleName());
    // NOTE -- We're just working with properties that are used for NODES
    // for now.
    String propName = "";
    String targetDataType = "";
    String targetIndexInfo = "";
    String preserveDataFlag = "";
    String consistencyLockFlag = "";
    String commitBlockSizeStr = "";
    long commitBlockSize = 120000;
    String usageString = "Usage: SchemaMod propertyName targetDataType targetIndexInfo preserveDataFlag consistencyLockFlag [blockSize] \n";
    if (args.length == 5) {
        propName = args[0];
        targetDataType = args[1];
        targetIndexInfo = args[2];
        preserveDataFlag = args[3];
        consistencyLockFlag = args[4];
    } else if (args.length == 6) {
        propName = args[0];
        targetDataType = args[1];
        targetIndexInfo = args[2];
        preserveDataFlag = args[3];
        consistencyLockFlag = args[4];
        commitBlockSizeStr = args[5];
    } else {
        String emsg = "Incorrect number of Parameters passed.  \n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    }
    if (propName.equals("")) {
        String emsg = "Bad parameter - propertyName cannot be empty.  \n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    } else if (!targetDataType.equals("String") && !targetDataType.equals("Set<String>") && !targetDataType.equals("Integer") && !targetDataType.equals("Long") && !targetDataType.equals("Boolean")) {
        String emsg = "Unsupported targetDataType.  We only support String, Set<String>, Integer, Long or Boolean for now.\n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    } else if (!targetIndexInfo.equals("uniqueIndex") && !targetIndexInfo.equals("index") && !targetIndexInfo.equals("noIndex")) {
        String emsg = "Unsupported IndexInfo.  We only support: 'uniqueIndex', 'index' or 'noIndex'.\n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    }
    try {
        if (!commitBlockSizeStr.equals("")) {
            // They're over-riding the commitBlockSize
            commitBlockSize = Long.parseLong(commitBlockSizeStr);
        }
    } catch (NumberFormatException nfe) {
        String emsg = "NumberFormatException - Bad block size passed in: [" + commitBlockSizeStr + "]. ";
        logAndPrint(logger, emsg);
        System.exit(1);
    }
    try {
        AAIConfig.init();
        ErrorLogHelper.loadProperties();
    } catch (Exception ae) {
        String emsg = "Problem with either AAIConfig.init() or ErrorLogHelper.LoadProperties(). ";
        logAndPrint(logger, emsg + "[" + ae.getMessage() + "]");
        System.exit(1);
    }
    logAndPrint(logger, ">>> Processing will begin in 5 seconds (unless interrupted). <<<");
    try {
        // Give them a chance to back out of this
        Thread.sleep(5000);
    } catch (java.lang.InterruptedException ie) {
        logAndPrint(logger, " DB Schema Update has been aborted. ");
        System.exit(1);
    }
    logAndPrint(logger, "    ---- NOTE --- about to open graph (takes a little while)\n");
    SchemaVersion version = schemaVersions.getDefaultVersion();
    QueryStyle queryStyle = QueryStyle.TRAVERSAL;
    ModelType introspectorFactoryType = ModelType.MOXY;
    Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
    TransactionalGraphEngine engine = null;
    try {
        engine = new JanusGraphDBEngine(queryStyle, loader);
        SchemaModInternalBatch internal = new SchemaModInternalBatch(engine, logger, propName, targetDataType, targetIndexInfo, Boolean.parseBoolean(preserveDataFlag), Boolean.parseBoolean(consistencyLockFlag), commitBlockSize);
        internal.execute();
        engine.startTransaction();
        engine.tx().close();
        logAndPrint(logger, "------ Completed the SchemaMod -------- ");
    } catch (Exception e) {
        String emsg = "Not able to complete the requested SchemaMod \n";
        logAndPrint(logger, e.getMessage());
        logAndPrint(logger, emsg);
        System.exit(1);
    }
}
Also used : SchemaVersion(org.onap.aai.setup.SchemaVersion) Loader(org.onap.aai.introspection.Loader) QueryStyle(org.onap.aai.serialization.engines.QueryStyle) AAIException(org.onap.aai.exceptions.AAIException) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine) ModelType(org.onap.aai.introspection.ModelType)

Example 2 with TransactionalGraphEngine

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

the class SchemaMod4Hist method execute.

public void execute(String[] args) {
    // Set the logging file properties to be used by EELFManager
    Properties props = System.getProperties();
    props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_SCHEMA_MOD_LOGBACK_PROPS);
    props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_BUNDLECONFIG);
    Logger logger = LoggerFactory.getLogger(SchemaMod4Hist.class.getSimpleName());
    MDC.put("logFilenameAppender", SchemaMod4Hist.class.getSimpleName());
    // NOTE -- We're just working with properties that are used for NODES
    // for now.
    String propName = "";
    String targetDataType = "";
    String targetIndexInfo = "";
    String preserveDataFlag = "";
    String usageString = "Usage: SchemaMod4Hist propertyName targetDataType targetIndexInfo preserveDataFlag \n";
    if (args.length != 4) {
        String emsg = "Four Parameters are required.  \n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    } else {
        propName = args[0];
        targetDataType = args[1];
        targetIndexInfo = args[2];
        // Note - even if they pass in "false", History will preserve the data
        preserveDataFlag = args[3];
    }
    if (propName.equals("")) {
        String emsg = "Bad parameter - propertyName cannot be empty.  \n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    } else if (!targetDataType.equals("String") && !targetDataType.equals("Set<String>") && !targetDataType.equals("Integer") && !targetDataType.equals("Long") && !targetDataType.equals("Boolean")) {
        String emsg = "Unsupported targetDataType.  We only support String, Set<String>, Integer, Long or Boolean for now.\n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    } else if (!targetIndexInfo.equals("index") && !targetIndexInfo.equals("noIndex")) {
        String emsg = "Unsupported IndexInfo.  We only support: 'index' or 'noIndex' for History db.\n" + usageString;
        logAndPrint(logger, emsg);
        System.exit(1);
    }
    try {
        AAIConfig.init();
        ErrorLogHelper.loadProperties();
    } catch (Exception ae) {
        String emsg = "Problem with either AAIConfig.init() or ErrorLogHelper.LoadProperties(). ";
        logAndPrint(logger, emsg + "[" + ae.getMessage() + "]");
        System.exit(1);
    }
    // Give a big warning if the DbMaps.PropertyDataTypeMap value does not
    // agree with what we're doing
    String warningMsg = "";
    if (!warningMsg.equals("")) {
        logAndPrint(logger, "\n>>> WARNING <<<< ");
        logAndPrint(logger, ">>> " + warningMsg + " <<<");
    }
    logAndPrint(logger, ">>> Processing will begin in 5 seconds (unless interrupted). <<<");
    try {
        // Give them a chance to back out of this
        Thread.sleep(5000);
    } catch (java.lang.InterruptedException ie) {
        logAndPrint(logger, " DB Schema Update has been aborted. ");
        System.exit(1);
    }
    logAndPrint(logger, "    ---- NOTE --- about to open graph (takes a little while)\n");
    SchemaVersion version = schemaVersions.getDefaultVersion();
    QueryStyle queryStyle = QueryStyle.TRAVERSAL;
    ModelType introspectorFactoryType = ModelType.MOXY;
    Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
    TransactionalGraphEngine engine = null;
    try {
        engine = new JanusGraphDBEngine(queryStyle, loader);
        // NOTE - no matter what they passed in, we're passing in "true" for the
        // preserve-data-flag last parameter since this is for HISTORY.
        SchemaModInternal4Hist internal = new SchemaModInternal4Hist(engine, logger, propName, targetDataType, targetIndexInfo, true);
        internal.execute();
        engine.startTransaction();
        engine.tx().close();
        logAndPrint(logger, "------ Completed the SchemaMod -------- ");
    } catch (Exception e) {
        String emsg = "Not able to complete the requested SchemaMod4Hist \n";
        logAndPrint(logger, e.getMessage());
        logAndPrint(logger, emsg);
        System.exit(1);
    }
}
Also used : SchemaVersion(org.onap.aai.setup.SchemaVersion) Loader(org.onap.aai.introspection.Loader) QueryStyle(org.onap.aai.serialization.engines.QueryStyle) Properties(java.util.Properties) Logger(org.slf4j.Logger) AAIException(org.onap.aai.exceptions.AAIException) TransactionalGraphEngine(org.onap.aai.serialization.engines.TransactionalGraphEngine) JanusGraphDBEngine(org.onap.aai.serialization.engines.JanusGraphDBEngine) ModelType(org.onap.aai.introspection.ModelType)

Example 3 with TransactionalGraphEngine

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

the class PserverDedupWithDifferentSourcesOfTruthTest 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);
    // Scn1 empty RCT move everything over
    pserverRCT = g.addV().property("aai-node-type", "pserver").property("hostname", "pserverRCT").property("source-of-truth", "RCT").property("fqdn", "tttt.bbbb.cccc.dddd").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCT").property("resource-version", "1").next();
    Vertex pserverRO = g.addV().property("aai-node-type", "pserver").property("hostname", "tttt.RoHostname").property("source-of-truth", "RO").property("aai-uri", "/cloud-infrastructure/pservers/pserver/tttt.RoHostname").property("resource-version", "2").next();
    pIntRo = g.addV().property("aai-node-type", "p-interface").property("interface-name", "pIntRo").property("aai-uri", "/cloud-infrastructure/pservers/pserver/tttt.RoHostname/p-interfaces/p-interface/pIntRo").next();
    lInterfaceRo = g.addV().property("aai-node-type", "l-interface").property("interface-name", "lInterfaceRo").property("aai-uri", "/cloud-infrastructure/pservers/pserver/tttt.RoHostname/p-interfaces/p-interface/pIntRo/l-interfaces/l-interface/lInterfaceRo").next();
    complexRO = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complexRO").property("aai-uri", "/cloud-infrastructure/complexes/complex/complexRO").next();
    // physical-link tests
    // 1. p-int does not exist on RCT, p-int and p-link moves from RO to RCT
    pintPlinkScn1 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "pintPlinkScn1").property("aai-uri", "/cloud-infrastructure/pservers/pserver/tttt.RoHostname/p-interfaces/p-interface/pintPlinkScn1").next();
    Vertex pLinkScn1 = g.addV().property("aai-node-type", "physical-link").property("link-name", "pLinkScn1").property("service-provider-bandwidth-up-value", 0).property("service-provider-bandwidth-up-units", "empty").property("service-provider-bandwidth-down-value", 0).property("service-provider-bandwidth-down-units", "empty").property("aai-uri", "/network/physical-links/physical-link/pLinkScn1").next();
    edgeSerializer.addTreeEdge(g, pserverRO, pintPlinkScn1);
    edgeSerializer.addEdge(g, pintPlinkScn1, pLinkScn1);
    // 2. p-int matches on RCT, p-int and p-link don't move from RO to RCT
    Vertex pserverROSPlinkScn4 = g.addV().property("aai-node-type", "pserver").property("hostname", "Scn4.pserverROSPlinkScn4").property("source-of-truth", "RO").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn4.pserverROSPlinkScn4").property("resource-version", "4").next();
    pserverRCTPlinkScn4 = g.addV().property("aai-node-type", "pserver").property("hostname", "pserverRCTPlinkScn4").property("source-of-truth", "RCT").property("fqdn", "Scn4.pserverRCTPlinkScn4").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTPlinkScn4").property("resource-version", "3").next();
    samePintScn4RO = g.addV().property("aai-node-type", "p-interface").property("interface-name", "pintPlinkScn4").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn4.pserverROSPlinkScn4/p-interfaces/p-interface/pintPlinkScn4").next();
    Vertex plinkScn2 = g.addV().property("aai-node-type", "physical-link").property("link-name", "plinkScn2").property("service-provider-bandwidth-up-value", 0).property("service-provider-bandwidth-up-units", "empty").property("service-provider-bandwidth-down-value", 0).property("service-provider-bandwidth-down-units", "empty").property("aai-uri", "/network/physical-links/physical-link/pLinkScn2").next();
    samePintScn4RCT = g.addV().property("aai-node-type", "p-interface").property("interface-name", "pintPlinkScn4").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTPlinkScn4/p-interfaces/p-interface/pintPlinkScn4").next();
    edgeSerializer.addTreeEdge(g, pserverROSPlinkScn4, samePintScn4RO);
    edgeSerializer.addEdge(g, samePintScn4RO, plinkScn2);
    edgeSerializer.addTreeEdge(g, pserverRCTPlinkScn4, samePintScn4RCT);
    // End physical-links tests
    // Scn2 RCT has children already
    pserverRCTScn2 = g.addV().property("aai-node-type", "pserver").property("hostname", "pserverRCTScn2").property("source-of-truth", "RCT").property("fqdn", "Scn2.pserverRCTScn2").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTScn2").property("resource-version", "3").next();
    pIntRctScn2 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "pIntRctScn2").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTScn2/p-interfaces/p-interface/pIntRctScn2").next();
    lInterfaceRctScn2 = g.addV().property("aai-node-type", "l-interface").property("interface-name", "lInterfaceRctScn2").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTScn2/p-interfaces/p-interface/pIntRctScn2/l-interfaces/l-interface/lInterfaceRctScn2").next();
    complexRctScn2 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complexRctScn2").property("aai-uri", "/cloud-infrastructure/complexes/complex/complexRctScn2").next();
    Vertex pserverROScn2 = g.addV().property("aai-node-type", "pserver").property("hostname", "Scn2.pserverROScn2").property("source-of-truth", "RO").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn2.pserverROScn2").property("resource-version", "4").next();
    pIntRoScn2 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "pIntRoScn2").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn2.pserverROScn2/p-interfaces/p-interface/pIntRoScn2").next();
    lInterfaceRoScn2 = g.addV().property("aai-node-type", "l-interface").property("interface-name", "lInterfaceRoScn2").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn2.pserverROScn2/p-interfaces/p-interface/pIntRoScn2/l-interfaces/l-interface/lInterfaceRoScn2").next();
    complexROScn2 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complexROScn2").property("aai-uri", "/cloud-infrastructure/complexes/complex/complexROScn2").next();
    // Scn1
    edgeSerializer.addTreeEdge(g, pserverRO, pIntRo);
    edgeSerializer.addTreeEdge(g, pIntRo, lInterfaceRo);
    edgeSerializer.addEdge(g, pserverRO, complexRO);
    // Scn2
    edgeSerializer.addTreeEdge(g, pserverRCTScn2, pIntRctScn2);
    edgeSerializer.addTreeEdge(g, pIntRctScn2, lInterfaceRctScn2);
    edgeSerializer.addEdge(g, pserverRCTScn2, complexRctScn2);
    edgeSerializer.addTreeEdge(g, pserverROScn2, pIntRoScn2);
    edgeSerializer.addTreeEdge(g, pIntRoScn2, lInterfaceRoScn2);
    edgeSerializer.addEdge(g, pserverROScn2, complexROScn2);
    // Scn3
    pserverRCTScn3 = g.addV().property("aai-node-type", "pserver").property("hostname", "pserverRCTScn3").property("source-of-truth", "RCT").property("fqdn", "Scn3.pserverRCTScn3").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTScn3").property("resource-version", "3").next();
    complexScn3 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complexScn3").property("aai-uri", "/cloud-infrastructure/complexes/complex/complexScn3").next();
    pserverROScn3 = g.addV().property("aai-node-type", "pserver").property("hostname", "Scn3.pserverROScn3").property("source-of-truth", "RO").property("fqdn", "Scn2.pserverRCTScn2").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn3.pserverROScn3").property("resource-version", "4").next();
    edgeSerializer.addEdge(g, pserverRCTScn3, complexScn3);
    edgeSerializer.addEdge(g, pserverROScn3, complexScn3);
    // Verify manytoOne edge scenario
    pserverRCTScn6 = g.addV().property("aai-node-type", "pserver").property("hostname", "pserverRCTScn6").property("source-of-truth", "RCT").property("fqdn", "Scn6.pserverRCTScn6").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserverRCTScn6").property("resource-version", "1").next();
    zoneScn61 = g.addV().property("aai-node-type", "zone").property("zone-id", "zone-61").property("aai-uri", "/network/zones/zone/zone-61").next();
    pserverROScn6 = g.addV().property("aai-node-type", "pserver").property("hostname", "Scn6.pserverROScn6").property("source-of-truth", "RO").property("fqdn", "Scn6.pserverRCTScn6").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn6.pserverROScn6").property("resource-version", "4").next();
    zoneScn62 = g.addV().property("aai-node-type", "zone").property("zone-id", "zone-62").property("aai-uri", "/network/zones/zone/zone-62").next();
    edgeSerializer.addEdge(g, pserverRCTScn6, zoneScn61);
    edgeSerializer.addEdge(g, pserverROScn6, zoneScn62);
    // Verify manyToMany edge scenario
    Vertex gvnf1 = g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "vnf-1").property("aai-uri", "/cloud-infrastructure/pservers/pserver/Scn6.pserverROScn6").next();
    Vertex gvnf2 = g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "vnf-2").property("aai-uri", "/network/generic-vnfs/generic-vnf/vnf-2").next();
    edgeSerializer.addEdge(g, pserverRCTScn6, gvnf1);
    edgeSerializer.addEdge(g, pserverROScn6, gvnf2);
    // Verify empty string scenario
    Vertex pserver1EmptyFirstToken = g.addV().property("aai-node-type", "pserver").property("hostname", ".pserver1EmptyFirstToken").property("source-of-truth", "RO").property("fqdn", "sameScn1.rrrr.tttt.yyyy").property("aai-uri", "/cloud-infrastructure/pservers/pserver/.pserver1EmptyFirstToken").property("resource-version", "1").next();
    Vertex pserver1EmptyFirstTokenFqdn = g.addV().property("aai-node-type", "pserver").property("hostname", "pserver1EmptyFirstTokenFqdn").property("source-of-truth", "RCT").property("fqdn", ".rrrr.tttt.yyyy").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserver1EmptyFirstTokenFqdn").property("resource-version", "1").next();
    // lag-interfaces
    Vertex roP1 = g.addV().property("aai-node-type", "pserver").property("hostname", "pserver.ro").property("source-of-truth", "RO").property("fqdn", "pserver.rrrr.tttt.yyyy").property("aai-uri", "/cloud-infrastructure/pservers/pserver/pserver.ro").property("resource-version", "1").next();
    Vertex rctP1 = g.addV().property("aai-node-type", "pserver").property("hostname", "rctP1").property("source-of-truth", "RCT").property("fqdn", "pserver.rrrr.tttt.yyyy").property("aai-uri", "/cloud-infrastructure/pservers/pserver/rctP1").property("resource-version", "3").next();
    // lagint11 does not have a match on rctP1. So, expect this to move to rctP1. Add test
    Vertex lagint11 = g.addV().property("aai-node-type", "lag-interface").property("interface-name", "lagint11").property("aai-uri", "/cloud-infrastructure/pservers/pserver/roP1/lag-interfaces/lag-interface/lagint11").next();
    edgeSerializer.addTreeEdge(g, roP1, lagint11);
    // lagint12 matches with lagint31 on rctP3
    Vertex lagint12 = g.addV().property("aai-node-type", "lag-interface").property("interface-name", "lagint12").property("aai-uri", "/cloud-infrastructure/pservers/pserver/roP1/lag-interfaces/lag-interface/lagint12").next();
    Vertex lagint31 = g.addV().property("aai-node-type", "lag-interface").property("interface-name", "lagint12").property("aai-uri", "/cloud-infrastructure/pservers/pserver/rctP3/lag-interfaces/lag-interface/lagint12").next();
    edgeSerializer.addTreeEdge(g, roP1, lagint12);
    edgeSerializer.addTreeEdge(g, rctP1, lagint31);
    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 PserverDedupWithDifferentSourcesOfTruth(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 4 with TransactionalGraphEngine

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

the class MigrateBooleanDefaultsToFalseTest method setup.

@Before
public void setup() throws Exception {
    g = tx.traversal();
    loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
    dbEngine = new JanusGraphDBEngine(queryStyle, loader);
    // generic-vnf
    g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "generic-vnf0").next();
    g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "generic-vnf1").property("is-closed-loop-disabled", "").next();
    g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "generic-vnf2").property("is-closed-loop-disabled", true).next();
    g.addV().property("aai-node-type", "generic-vnf").property("vnf-id", "generic-vnf3").property("is-closed-loop-disabled", false).next();
    // vnfc
    g.addV().property("aai-node-type", "vnfc").property("vnfc-name", "vnfc0").next();
    g.addV().property("aai-node-type", "vnfc").property("vnfc-name", "vnfc1").property("is-closed-loop-disabled", "").next();
    g.addV().property("aai-node-type", "vnfc").property("vnfc-name", "vnfc2").property("is-closed-loop-disabled", true).next();
    g.addV().property("aai-node-type", "vnfc").property("vnfc-name", "vnfc3").property("is-closed-loop-disabled", false).next();
    // vserver
    g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver0").next();
    g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver1").property("is-closed-loop-disabled", "").next();
    g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver2").property("is-closed-loop-disabled", true).next();
    g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver3").property("is-closed-loop-disabled", false).next();
    // l3-network
    g.addV().property("aai-node-type", "l3-network").property("network-id", "l3-network0").property("network-name", "l3-network-name0").next();
    g.addV().property("aai-node-type", "l3-network").property("network-id", "l3-network1").property("network-name", "l3-network-name1").property("is-bound-to-vpn", "").property("is-provider-network", "").property("is-shared-network", "").property("is-external-network", "").next();
    g.addV().property("aai-node-type", "l3-network").property("network-id", "l3-network2").property("network-name", "l3-network-name2").property("is-bound-to-vpn", true).property("is-provider-network", true).property("is-shared-network", true).property("is-external-network", true).next();
    g.addV().property("aai-node-type", "l3-network").property("network-id", "l3-network3").property("network-name", "l3-network-name3").property("is-bound-to-vpn", false).property("is-provider-network", false).property("is-shared-network", false).property("is-external-network", false).next();
    // subnet
    g.addV().property("aai-node-type", "subnet").property("subnet-id", "subnet0").next();
    g.addV().property("aai-node-type", "subnet").property("subnet-id", "subnet1").property("dhcp-enabled", "").next();
    g.addV().property("aai-node-type", "subnet").property("subnet-id", "subnet2").property("dhcp-enabled", true).next();
    g.addV().property("aai-node-type", "subnet").property("subnet-id", "subnet3").property("dhcp-enabled", false).next();
    // l-interface
    g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface0").property("in-maint", false).next();
    g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1").property("in-maint", false).property("is-port-mirrored", "").property("is-ip-unnumbered", "").next();
    g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface2").property("in-maint", false).property("is-port-mirrored", true).property("is-ip-unnumbered", true).next();
    g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface3").property("in-maint", false).property("is-port-mirrored", false).property("is-ip-unnumbered", false).next();
    // vf-module
    g.addV().property("aai-node-type", "vf-module").property("vf-module-id", "vf-module0").next();
    g.addV().property("aai-node-type", "vf-module").property("vf-module-id", "vf-module1").property("is-base-vf-module", "").next();
    g.addV().property("aai-node-type", "vf-module").property("vf-module-id", "vf-module2").property("is-base-vf-module", true).next();
    g.addV().property("aai-node-type", "vf-module").property("vf-module-id", "vf-module3").property("is-base-vf-module", false).next();
    // vlan
    g.addV().property("aai-node-type", "vlan").property("vlan-interface", "vlan0").next();
    g.addV().property("aai-node-type", "vlan").property("vlan-interface", "vlan1").property("is-ip-unnumbered", "").next();
    g.addV().property("aai-node-type", "vlan").property("vlan-interface", "vlan2").property("is-ip-unnumbered", true).next();
    g.addV().property("aai-node-type", "vlan").property("vlan-interface", "vlan3").property("is-ip-unnumbered", false).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 BooleanDefaultMigrator(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 5 with TransactionalGraphEngine

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

the class MigrateCloudRegionUpgradeCycleTest 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);
    System.setProperty("BUNDLECONFIG_DIR", "src/test/resources");
    cloudRegion1 = g.addV().property("aai-node-type", MigrateCloudRegionUpgradeCycle.CLOUD_REGION_NODE_TYPE).property(MigrateCloudRegionUpgradeCycle.CLOUD_REGION_ID, "akr1").property(MigrateCloudRegionUpgradeCycle.CLOUD_OWNER, "att-aic").property(MigrateCloudRegionUpgradeCycle.UPGRADE_CYCLE, "Test").next();
    cloudRegion2 = g.addV().property("aai-node-type", MigrateCloudRegionUpgradeCycle.CLOUD_REGION_NODE_TYPE).property(MigrateCloudRegionUpgradeCycle.CLOUD_REGION_ID, "amsnl1b").property(MigrateCloudRegionUpgradeCycle.CLOUD_OWNER, "att-aic").next();
    cloudRegion3 = g.addV().property("aai-node-type", MigrateCloudRegionUpgradeCycle.CLOUD_REGION_NODE_TYPE).property(MigrateCloudRegionUpgradeCycle.CLOUD_REGION_ID, "alp1").property(MigrateCloudRegionUpgradeCycle.CLOUD_OWNER, "Test").property(MigrateCloudRegionUpgradeCycle.UPGRADE_CYCLE, "server1").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 MigrateCloudRegionUpgradeCycle(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)

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