コード例 #1
0
 def initProcesses(self, numCoordinator, numWorkerPerCoordinator):
     try:
         coordinators = da.new(coordinator.Coordinator, num=numCoordinator)
         clients = da.new(client.Client)
         db = da.new(database.Database)
         if (len(sys.argv) < 3):
             self.output('Improper Arguments')
             return (-1)
         objectCoordMap = dict()
         objectCoordMap['movieA'] = random.randint(0, (numCoordinator - 1))
         objectCoordMap['customerA'] = random.randint(
             0, (numCoordinator - 1))
         dbLoad = sys.argv[1]
         args = []
         args.append(dbLoad)
         da.setup(db, args)
         self.output('DbEmulator process set up')
         da.setup(coordinators, (numWorkerPerCoordinator,
                                 list(coordinators), db, objectCoordMap))
         self.output('Coordinators have been setup')
         da.setup(clients,
                  (list(coordinators), sys.argv[2], objectCoordMap))
         self.output('Client process has been set up')
         da.start(clients)
         da.start(coordinators)
         da.start(db)
         self.output('Started all processes')
         return 0
     except:
         self.output('STACK TRACE')
         self.output(traceback.print_exc())
         return (-1)
コード例 #2
0
 def init_all_processes(self, config):
     try:
         cl = da.import_da('client')
         co = da.import_da('coordinator')
         d = da.import_da('database')
     except ImportError:
         self.output('Error in import', sep='|')
     try:
         coord = da.new(co.Coordinator, num=config.num_coordinator)
         data = da.new(d.Database, num=1)
         clie = da.new(cl.Client, num=config.num_client)
     except:
         self.output('Error in process creation')
     try:
         coord_list = list(coord)
         data_list = list(data)
         counter = 0
         for a in clie:
             da.setup(a, (config, coord_list, counter))
             counter += 1
         da.setup(coord, (config, coord_list, 0, data, None, None))
         m = list()
         m.append(self.data_file)
         da.setup(data, m)
     except:
         self.output('Error in setup')
     try:
         da.start(clie)
         da.start(coord)
         da.start(data)
     except:
         self.output('Error in starting processes')
コード例 #3
0
ファイル: orig.py プロジェクト: sghosh1991/Asynch
def main():
    nprocs = (int(sys.argv[1]) if (len(sys.argv) > 1) else 10)
    nrounds = (int(sys.argv[2]) if (len(sys.argv) > 2) else 1)
    central = da.new(X, num=1)
    for p in central:
        da.setup({p}, (nrounds, nprocs, central))
    da.start(central)
    ps = da.new(P, num=nprocs)
    lucky = ps.pop()
    da.setup(ps, ((ps | {lucky}), False, nrounds, central))
    da.setup({lucky}, ((ps | {lucky}), True, nrounds, central))
    da.start((ps | {lucky}))
コード例 #4
0
ファイル: ramutex.py プロジェクト: sghosh1991/Asynch
def main():
    nprocs = (int(sys.argv[1]) if (len(sys.argv) > 1) else 10)
    nrounds = (int(sys.argv[2]) if (len(sys.argv) > 2) else 1)
    da.config(clock='Lamport')
    ps = da.new(P, num=nprocs)
    mainProc = da.new(X, num=1)
    for p in mainProc:
        da.setup({p}, (nprocs, {}, mainProc))
    da.start(mainProc)
    for p in ps:
        da.setup({p}, ((ps - {p}), nrounds, {}, mainProc))
    da.start(ps)
コード例 #5
0
ファイル: orig.py プロジェクト: sghosh1991/Asynch
def main():
    nprocs = (int(sys.argv[1]) if (len(sys.argv) > 1) else 10)
    nrequests = (int(sys.argv[2]) if (len(sys.argv) > 2) else 1)
    da.config(channel='fifo', clock='Lamport')
    ps = da.new(P, num=nprocs)
    for p in ps:
        da.setup(p, ((ps - {p}), nrequests))
    da.start(ps)
コード例 #6
0
def main():
    init = da.new(Init)
    da.setup(init, ())
    da.start(init)
    try:
        while True:
            pass
    except KeyboardInterrupt:
        self.output('SYSTEM EXITING')
        sys.exit((-1))
 def run(self):
     num_sub_co = (int(sys.argv[1]) if (len(sys.argv) > 1) else 3)
     num_res_co = (int(sys.argv[1]) if (len(sys.argv) > 1) else 3)
     sub_co = da.new(Sub_Co, num=num_sub_co)
     res_co = da.new(Res_Co, num=num_res_co)
     list_sub_coords = [p for p in sub_co]
     list_res_coords = [p for p in res_co]
     sub_IDs = ['sub1', 'sub2', 'sub3']
     res_IDs = ['res1', 'res2', 'res3']
     sub_dict = {}
     res_dict = {}
     for i in range(3):
         sub_dict[sub_IDs[i]] = list_sub_coords[i]
     for i in range(3):
         res_dict[res_IDs[i]] = list_res_coords[i]
     app = da.new(Application, [sub_dict, sub_IDs, res_dict, res_IDs], num=1)
     da.start(sub_co)
     da.start(res_co)
     da.start(app)
コード例 #8
0
def main():
    conf_file = (sys.argv[1] if (len(sys.argv) > 1) else '../tests/test/conf2.json')
    policy_file = (sys.argv[2] if (len(sys.argv) > 2) else '../tests/policy/policy2.xml')
    data_file = (sys.argv[3] if (len(sys.argv) > 3) else '../tests/data/data2.json')
    attr_file = (sys.argv[4] if (len(sys.argv) > 4) else '../tests/attr/attr2.json')
    random_input = (sys.argv[5] if (len(sys.argv) > 5) else False)
    print(random_input)
    m = da.new(Main)
    da.setup(m, (conf_file, policy_file, data_file, attr_file, random_input))
    da.start(m)
コード例 #9
0
 def run(self):
     config_file_name = (str(sys.argv[1]) if
                         (len(sys.argv) > 1) else 'basic.config')
     db_config_file = (str(sys.argv[2]) if
                       (len(sys.argv) > 2) else 'dbconfig.config')
     log_file_name = (config_file_name.strip().split('.')[0] + '.log')
     self.output(log_file_name)
     logging.getLogger('').handlers = []
     logging.basicConfig(filename=log_file_name,
                         filemode='w',
                         level=logging.INFO)
     master = da.new(Master, [config_file_name, db_config_file], num=1)
     da.start(master)
コード例 #10
0
 def setup(self, config, coord_list, worker_count, data, work_list):
     self.config = config
     self.coord_list = coord_list
     self.worker_count = worker_count
     self.data = data
     self.work_list = work_list
     self.subj_attr_dict = {}
     self.res_attr_dict = {}
     self.tentative_dict = {}
     work = da.new(w.Worker, num=self.config.num_workers)
     self.work_list = list(work)
     da.setup(work, (self.coord_list, self.config.policy_file, self.data))
     da.start(work)
 def setup(self, config, coord_list, worker_count, data, work_list, sta):
     self.config = config
     self.coord_list = coord_list
     self.worker_count = worker_count
     self.data = data
     self.work_list = work_list
     self.sta = sta
     work = da.new(w.Worker, num=self.config.num_workers)
     da.setup(work, (self.coord_list, self.config))
     da.start(work)
     self.work_list = list(work)
     self.attrVersionDict = {}
     self.pendingReadReq = {}
     self.currRunningWriteReq = {}
     self.sta = staticAnalysis.StaticAnalysis(self.config.attr_file, self.coord_list)
     self.common = None
コード例 #12
0
 def setup(self, numWorkers, coordinators, database, objectCoordMap):
     self.numWorkers = numWorkers
     self.coordinators = coordinators
     self.database = database
     self.objectCoordMap = objectCoordMap
     workers = da.new(worker.Worker, num=self.numWorkers)
     da.setup(workers,
              (self.coordinators, self.database, '../config/policy.xml'))
     da.start(workers)
     self.versionMap = dict()
     self.cachedUpdates = dict()
     self.readQueue = list()
     self.writeQueue = list()
     self.objectCoordMap = self.objectCoordMap
     self.workers = list(workers)
     self.workerNumber = 0
     self.numWorkers = self.numWorkers
 def run(self):
     sub_co = da.new(Sub_Co, num=1)
     app = da.new(Application, num=3)
     da.setup(app, sub_co)
     da.start(sub_co)
     da.start(app)
コード例 #14
0
 def run(self):
     config = configparser.ConfigParser()
     config.read(self._state.config_file_name)
     self.output(str(config.sections()))
     master_section = config['Master']
     num_of_workers = int(master_section['num_of_workers'])
     num_of_sub_co = int(master_section['num_of_sub_co'])
     num_of_res_co = int(master_section['num_of_res_co'])
     sub_id_section = config['sub-id-list']
     res_id_section = config['res-id-list']
     hashMap = {}
     workers = da.new(Worker, [], num=num_of_workers)
     sub_co = da.new(Sub_Co, [], num=num_of_sub_co)
     res_co = da.new(Res_Co, [workers], num=num_of_res_co)
     dbEmulator = da.new(DB_Emulator, [workers, self._state.db_config_file],
                         num=1)
     sub_co_list = [p for p in sub_co]
     res_co_list = [p for p in res_co]
     sub_id_list = sub_id_section['sub_id_list'].strip().split(',')
     res_id_list = res_id_section['res_id_list'].strip().split(',')
     i = 0
     for sub_id in sub_id_list:
         hashMap[sub_id] = sub_co_list[i]
         i = (i + 1)
         i = (i % num_of_sub_co)
     i = 0
     for res_id in res_id_list:
         hashMap[res_id] = res_co_list[i]
         i = (i + 1)
         i = (i % num_of_res_co)
     self.output(('Mapping: ' + str(hashMap)))
     app_section = config['Application']
     num_of_requests = int(app_section['num_of_request'])
     self.output(('number of Request:' + str(num_of_requests)))
     for i in range(1, (num_of_requests + 1)):
         req = app_section[str(i)].strip().split(',')
         sub_attrs = {}
         res_attrs = {}
         for elem in req:
             elem = elem.split('=')
             if (elem[0].strip() == 'sub_id'):
                 sub_id = elem[1]
                 sub_id_list.append(sub_id)
             elif ((elem[0].strip() == 'sub_attrs')
                   and (not (elem[1].strip() == 'None'))):
                 sub_attrs_list = elem[1].split('|')
                 for e in sub_attrs_list:
                     sub_attrs[e.split(':')[0]] = e.split(':')[1]
             elif (elem[0].strip() == 'res_id'):
                 res_id = elem[1]
                 res_id_list.append(res_id)
             elif ((elem[0].strip() == 'res_attrs')
                   and (not (elem[1].strip() == 'None'))):
                 res_attrs_list = elem[1].split('|')
                 for e in res_attrs_list:
                     res_attrs[e.split(':')[0]] = e.split(':')[1]
             elif (elem[0].strip() == 'action'):
                 action = elem[1]
         req = Request(sub_id, res_id, hashMap, sub_attrs, res_attrs,
                       action)
         app = da.new(Application,
                      [hashMap, sub_co, res_co, self.id, dbEmulator, req],
                      num=1)
         self.output(str(app))
         da.start(app)
     da.start((((sub_co | res_co) | workers) | dbEmulator))
     super()._label('_st_label_2820', block=False)
     _st_label_2820 = 0
     while (_st_label_2820 == 0):
         _st_label_2820 += 1
         if (len([
                 p for (_, (_, _, p), (_ConstantPattern2841_, )
                        ) in self._MasterReceivedEvent_0
                 if (_ConstantPattern2841_ == 'okay')
         ]) == num_of_requests):
             _st_label_2820 += 1
         else:
             super()._label('_st_label_2820', block=True)
             _st_label_2820 -= 1
     self._send(('done', ), (((sub_co | res_co) | workers) | dbEmulator))
     self.output((str(self.id) + ' shutting Down'))