def _init_db_data(self,
                      db_name: str,
                      xml_files: Optional[List[str]] = None,
                      client: pyorient.OrientDB = None) -> pyorient.OrientDB:
        if xml_files is not None:
            for filepath in xml_files:
                json.dump(self.config, open(SWRI_CONFIG_FILE, 'w'), indent=4)

                importer = OrientDBXMLImporter(databaseName=db_name,
                                               configFile=SWRI_CONFIG_FILE,
                                               mdlFile=filepath)

                importer.import_xml()
                importer.orientDB_helper.close_database()

        if client is None:
            client = pyorient.OrientDB(self.host, self.port)
            client.connect('root', self.root_password)

        if client.db_exists(db_name):
            client.db_open(db_name, 'admin', 'admin')
        else:
            client.db_create(db_name, pyorient.DB_TYPE_GRAPH,
                             pyorient.STORAGE_TYPE_MEMORY)

        client.db_open(db_name, 'admin', 'admin')
        client.command('CREATE CLASS BBNEvaluationData EXTENDS V')
        client.command(
            'CREATE PROPERTY BBNEvaluationData.inputJsonData STRING')
        client.command(
            'CREATE PROPERTY BBNEvaluationData.outputJsonData STRING')
        client.command('CREATE PROPERTY BBNEvaluationData.currentState STRING')
        client.command(
            'CREATE PROPERTY BBNEvaluationData.currentStateInfo STRING')
        return client
Example #2
0
def main(database=None, config_file=None, mdl_file=None, constraints=None):
    """
    Connects to OrientDB database, discovers the 'TxOp' Children of 'RadioLinks', and modifies the start and end times
    :param (str) database: the name of the OrientDB database
    :param (str) config_file: path to the config file for OrientDB
    :return:
    """
    print(
        '****************       Calling and Restting OrientDB         ****************'
    )

    mdl_full_path = os.path.abspath(mdl_file)
    importer = MDLImporter(database, mdl_full_path, config_file)
    importer.import_xml()

    processor = BrassOrientDBHelper(database, config_file)
    processor.open_database(over_write=False)
    reset_orientdb_central_fq(processor)

    TxOp_nodes = processor.get_nodes_by_type('TxOp')
    # Brass process of applying constraints happens here
    updated_frequency = 4943000000
    new_fqhz = condition_str('CenterFrequencyHz', str(updated_frequency), '=')
    print(new_fqhz)

    TxOp_nodes = processor.get_nodes_by_type('TxOp')
    RANConfiguration_nodes = processor.get_nodes_by_type('RANConfiguration')
    for txop_node in TxOp_nodes:
        print(txop_node)
        print(
            '****************       Updating TxOp Node {0}         ****************'
            .format(txop_node._rid))
        processor.update_node(txop_node._rid, new_fqhz)

    for ran_node in RANConfiguration_nodes:
        print(ran_node)
        print(
            '****************       Updating RANConfiguration Node {0}         ****************'
            .format(ran_node._rid))
        processor.update_node(ran_node._rid, new_fqhz)

    # print('Post Modification')
    # TxOp_nodes = processor.get_nodes_by_type('TxOp')
    # RANConfiguration_nodes = processor.get_nodes_by_type('RANConfiguration')
    #
    # for txop_node in TxOp_nodes:
    #     print(txop_node)
    #
    # for ran_node in RANConfiguration_nodes:
    #     print(ran_node)

    processor.close_database()
    export = MDLExporter(database, "Scenario_2_Export.xml", config_file)
    export.export_xml()
    def load_xml_into_db(self, xml_filepath: str, db_identifier: str):
        json.dump(self.config, open(SWRI_CONFIG_FILE, 'w'), indent=4)

        importer = OrientDBXMLImporter(
            databaseName=db_identifier,
            configFile=SWRI_CONFIG_FILE,
            mdlFile=xml_filepath
        )

        importer.import_xml()
        importer.orientDB_helper.close_database()

        print('File    "' + xml_filepath + '" loaded into database "' + db_identifier + '".')
Example #4
0
def main(database=None, config_file=None, mdl_file=None):

    mdl_full_path = os.path.abspath(mdl_file)
    importer = MDLImporter(database, mdl_full_path, config_file)
    importer.import_xml()

    processor = BrassOrientDBHelper(database, config_file)
    processor.open_database(over_write=False)

    new_schedule = create_new_schedule()

    print("Final Schedule:\n")
    for c in new_schedule:
        c.print_transmission()
    processor.close_database()

    export = MDLExporter(database, "Scenario_4_Export.xml", config_file)
    export.export_xml()
Example #5
0
def main(database=None, config_file=None, mdl_file=None):
    """
    Connects to OrientDB database, discovers the 'TxOp' Children of 'RadioLinks', and modifies the start and end times
    :param (str) database: the name of the OrientDB database
    :param (str) config_file: path to the config file for OrientDB
    :return:
    """
    print('****************       Importing {0}          ****************'.
          format(mdl_file))
    importer = MDLImporter(databaseName=database,
                           configFile=config_file,
                           mdlFile=mdl_file)
    importer.import_xml()
    importer.orientDB_helper.close_database()

    exporter = MDLExporter(databaseName=database,
                           xmlfile="import_export_example.xml",
                           configFile=config_file)
    exporter.export_xml()
    exporter.orientDB_helper.close_database()
Example #6
0
json.dump(config, open(CONFIG_FILE, 'w'), indent=4)
# Merge the DAUInventory into the MDLRoot file to force the SwRI script to load it
print("Merging the DAUInventory into the MDLRoot")
process_output = subprocess.run([
    "sed", "/<\/NameValues>/{\n r " + dau_inventory_xml_file +
    "\n:a\nn\nba\n}", input_configuration_xml_file
],
                                stdout=subprocess.PIPE)
full_xml_document = process_output.stdout.decode()
out_file = open(MERGED_INPUT_XML_FILE, 'w')
out_file.write(full_xml_document)
out_file.flush()
out_file.close()
## Import the created file containing the inventory and the mdlroot
importer = OrientDBXMLImporter(databaseName=database_name,
                               configFile=CONFIG_FILE,
                               mdlFile=MERGED_INPUT_XML_FILE)
print("Importing the XML Data. Please wait...")
importer.import_xml()
importer.orientDB_helper.close_database()
# Create the evaluation data structure
client = pyorient.OrientDB(host, port)
client.connect('root', root_password)
# client.db_create('Scenario5', pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY)
client.db_open(database_name, 'root', root_password)
client.command('CREATE CLASS BBNEvaluationData EXTENDS V')
client.command('CREATE PROPERTY BBNEvaluationData.inputJsonData STRING')
client.command('CREATE PROPERTY BBNEvaluationData.outputJsonData STRING')
client.command('CREATE PROPERTY BBNEvaluationData.currentState STRING')
client.command('CREATE PROPERTY BBNEvaluationData.currentStateInfo STRING')
# Move some things around to restructure where the DAU Inventory is.
def main(database=None, config_file=None, mdl_file=None, constraints=None):
    """
    Instantiates a Processor object and passes in the orientDB database name.
    Instantiates a Constraints_Database object and passes in the orientDB database name for the system constraints.
    Pulls down constraints for simulation from the database
    Overwrites mdl in database with source mdl
    Calls create_new_schedule()
    Update database with new schedule
    Export new MLD

    :param database: name of an OrientDB
    :param config_file: location of the config file used to import
    :return:
    """

    # Open databases for MDL and System Constraints
    processor = BrassOrientDBHelper(database, config_file)
    constraints_database = BrassOrientDBHelper(constraints, config_file)

    constraints_database.open_database(over_write=False)
    scenarios = constraints_database.get_nodes_by_type("TestScenario")

    for scenario in scenarios:
        if scenario.name == "Test Scenario 1":
            scenario_1 = scenario

    constraints_list = constraints_database.get_child_nodes(
        scenario_1._rid, edgetype='HasConstraint')
    for constraint in constraints_list:
        if constraint.name == 'system wide constraint':
            system_constraints = constraint.constraint_data
            break
    constraints_database.close_database()

    # MDL Import Step
    mdl_full_path = os.path.abspath((mdl_file))
    importer = MDLImporter(database, mdl_full_path, config_file)
    importer.import_xml()
    # importer.import_mdl()
    processor.open_database(over_write=False)

    # Create new Schedule
    new_schedule, final_fitness = create_new_schedule(
        system_constraints=system_constraints)

    print("Final Schedule:\n")
    for c in new_schedule:
        c.print_transmission()

    # Begin Updating MDL Database
    txop_verties = processor.get_nodes_by_type("TxOp")
    radio_link_vertices = processor.get_nodes_by_type("RadioLink")

    radio_link_up_name = "GndRadio_to_TA"
    radio_link_down_name = "TA_to_GndRadio"

    for r in radio_link_vertices:
        if r.Name == radio_link_up_name:
            radio_link_up = r
        elif r.Name == radio_link_down_name:
            radio_link_down = r

    print(txop_verties)
    old_txop_list = [op._rid for op in txop_verties]
    processor.delete_nodes_by_rid(old_txop_list)

    txop_rids = []
    for TxOp in new_schedule:
        txop_properties = {
            "StopUSec": TxOp.get_end_time(),
            "TxOpTimeout": 255,
            "CenterFrequencyHz": 4919500000,
            "StartUSec": TxOp.get_start_time()
        }
        processor.create_node("TxOp", txop_properties)
        new_txop = processor.get_nodes_by_type("TxOp")
        for op in new_txop:
            if op._rid not in txop_rids:
                txop_rids.append(op._rid)
                new_op_rid = op._rid

        if TxOp.link_direction == 'down':
            radio_rid = radio_link_down._rid

        elif TxOp.link_direction == 'up':
            radio_rid = radio_link_up._rid

        processor.set_containment_relationship(parent_rid=radio_rid,
                                               child_rid=new_op_rid)

    processor.close_database()

    print("Fitness: {0}".format(final_fitness))
    print("Total Transmission Time: {0} microseconds per epoch".format(
        total_transmission_time(new_schedule)))

    print("Final Schedule:\n")
    for c in new_schedule:
        c.print_transmission()

    # Export Updated MDL

    # export = MDLExporter(database, config_file)
    export = MDLExporter(database, "Scenario_1_Export.xml", config_file)
    export.export_xml()