예제 #1
0
def __create_remote_Conc__(Mgr, RemoteEnvId, CallingModule, ConcClass, *args,
                           **kwargs):
    ''' low-level support for Conc creation in another Env '''

    ConcId = _ConcIdMgr.new()
    NewConcAddr = ConcAddr(my_EnvId(), ConcId, RemoteEnvId)

    ConcClassProxy = proxy(ConcClass, ConcClass.__name__ + 'Name',
                           CallingModule)
    NewProxy = ConcClassProxy(NewConcAddr)
    NewName = Name(NewProxy, ConcClass.__name__, CallingModule.__name__)

    # create proxy for remote Env
    EnvConcAddr = ConcAddr(CORPSMGR_ENVID, ENVMGR_CONCID, RemoteEnvId)
    RemoteEnv = EnvName(EnvConcAddr)

    # request object creation in remote Env
    kwargs['ConcAddr'] = NewConcAddr
    kwargs['Mgr'] = Mgr

    FutRes = RemoteEnv.rem2loc_create_Conc(NewConcAddr, CallingModule.__name__,
                                           ConcClass.__name__, *args, **kwargs)

    try:
        Ret = FutRes.Ret

    except:
        ei = exc_info()
        ftb = format_exception(ei[0], ei[1], ei[2])
        raise AsyncExecutionError(ei[0].__name__, ei[1], ''.join(ftb))

    return NewName
예제 #2
0
    def __init__(self, EnvId, CorpsMgrQueue, ConfigDelta):
        #from time import perf_counter
        #t1 = perf_counter()

        apply_config_delta('ConfigGlobals', ConfigDelta)

        from ConfigGlobals import Logging_Format, Logging_Datefmt, Logging_Level
        basicConfig(format=Logging_Format, datefmt=Logging_Datefmt, level=Logging_Level)

        # Self-initialize
        ConcId = _ConcIdMgr.new()
        assert ConcId == ENVMGR_CONCID, f'EnvMgr in Env {EnvId} has ConcId {ConcId} and not {ENVMGR_CONCID}'

        self.ConcAddr = ConcAddr(CORPSMGR_ENVID, ConcId, EnvId)
        self.EnvId = EnvId
        set_EnvStatus(MajorStatus.Booting)

        super().__init__()

        # Init some EnvGlobals
        set_EnvId(EnvId)

        # Make sure thread-local data knows the Conc it's assigned to
        TheThread.TheConcAddr = self.ConcAddr

        # Make sure we can be found
        _Addr2Conc.register(self, self.ConcAddr)

        # Startup the TcpConnector and get our port number from it
        TheEnvRecord = copy(DefaultEnvRecord)
        EnvQueue = queue.Queue()

        TheEnvRecord.NetwFactory.new_connector(TheEnvRecord.IpAddr, EnvQueue)
        Port = EnvQueue.get()

        # Initialize our EnvRecord and register it in the EnvTable
        TheEnvRecord.Port = Port
        set_MyPort(Port)        # another EnvGlobal
        _EnvTable.register(EnvId, TheEnvRecord)

        # If we are not the CorpsMgr's Env we need to provide the CorpsMgr our XferEnvRecord
        if EnvId != CORPSMGR_ENVID:
            OurXferEnvRecord = XferEnvRecord(EnvId, TheEnvRecord.IpAddr, TheEnvRecord.Port)
            CorpsMgrQueue.put(OurXferEnvRecord)

        # The thread is no longer assigned, so cleanup
        TheThread.TheConcAddr = NullConcAddr

        set_EnvStatus(MajorStatus.Running)
        info(f'{self} initialized')
예제 #3
0
    def __init__(self, EnvId, CorpsMgrQueue, ConfigFiles):
        load_config('ConfigGlobals', ConfigFiles)

        from ConfigGlobals import Logging_Format, Logging_Datefmt, Logging_Level
        basicConfig(format=Logging_Format,
                    datefmt=Logging_Datefmt,
                    level=Logging_Level)

        # Self-initialize
        ConcId = _ConcIdMgr.new()
        assert ConcId == ENVMGR_CONCID, f'EnvMgr in Env {EnvId} has ConcId {ConcId} and not {ENVMGR_CONCID}'

        self.ConcAddr = ConcAddr(CORPSMGR_ENVID, ConcId, EnvId)
        self.EnvId = EnvId

        super().__init__()

        # Init some EnvGlobals
        set_EnvId(EnvId)
        set_EnvMgrAddr(self.ConcAddr)

        # Make sure thread-local data knows the Conc it's assigned to
        TheThread.TheConcAddr = self.ConcAddr

        # Make sure we can be found
        _Addr2Conc.register(self, self.ConcAddr)

        # Startup the TcpConnector and get our port number from it
        TheEnvRecord = copy(DefaultEnvRecord)
        EnvQueue = queue.Queue()

        TheEnvRecord.NetwFactory.new_connector(TheEnvRecord.IPAddr, EnvQueue)
        Port = EnvQueue.get()

        # Initialize our EnvRecord and register it in the EnvTable
        TheEnvRecord.Port = Port
        set_MyPort(Port)  # another EnvGlobal
        _EnvTable.register(EnvId, TheEnvRecord)

        # If we are not the CorpsMgr's Env we need to provide the CorpsMgr our
        #   EnvRecord Spec Tuple: 0: LocEnvId, 1: IPAddr, 2: Port
        if EnvId != CORPSMGR_ENVID:
            CorpsMgrQueue.put([EnvId, TheEnvRecord.IPAddr, TheEnvRecord.Port])

        # The thread is no longer assigned, so cleanup
        TheThread.TheConcAddr = NullConcAddr

        info(f'EnvMgr {self.my_Name()} Env {EnvId} initialized')
예제 #4
0
def __create_local_Conc(Mgr, CallingModule, ConcClass, *args, **kwargs):
    ''' low-level support for Conc creation in this Env '''

    ConcId = _ConcIdMgr.new()
    NewConcAddr = ConcAddr(my_EnvId(), ConcId, my_EnvId())

    ConcClassProxy = proxy(ConcClass, ConcClass.__name__ + 'Name',
                           CallingModule)
    NewProxy = ConcClassProxy(NewConcAddr)
    NewName = Name(NewProxy, ConcClass.__name__, CallingModule.__name__)

    ConcClassInModule = getattr(CallingModule, ConcClass.__name__)

    kwargs['ConcAddr'] = NewConcAddr
    NewConc = ConcClassInModule(*args, **kwargs)

    _Addr2Conc.register(NewConc, NewConcAddr)

    return NewName
예제 #5
0
    def __init__(self):
        # Startup the EnvMgr and CorpsMgr first to get the ConcIds right
        MgrEnv = Env(CORPSMGR_ENVID, None, self.ConfigFiles)
        MgrCorps = CorpsMgr(self.ConfigFiles)

        # Self-initialize
        ConcId = _ConcIdMgr.new()
        assert ConcId == CORPS_CONCID, f'Corps has ConcId {ConcId} and not {CORPS_CONCID}'

        self.ConcAddr = ConcAddr(CORPSMGR_ENVID, ConcId, CORPSMGR_ENVID)
        super().__init__()

        # Make sure thread-local data knows the Conc it's assigned to
        TheThread.TheConcAddr = self.ConcAddr

        # Make sure we can be found
        _Addr2Conc.register(self, self.ConcAddr)

        info(f'Corps {self.my_Name()} initialized, starting...')

        # The thread is no longer assigned, so cleanup
        TheThread.TheConcAddr = NullConcAddr
예제 #6
0
def __create_remote_Conc(Mgr, RemoteEnvId, CallingModule, ConcClass, *args,
                         **kwargs):
    ''' low-level support for Conc creation in another Env '''

    ConcId = _ConcIdMgr.new()
    NewConcAddr = ConcAddr(my_EnvId(), ConcId, RemoteEnvId)

    ConcClassProxy = proxy(ConcClass, ConcClass.__name__ + 'Name',
                           CallingModule)
    NewProxy = ConcClassProxy(NewConcAddr)
    NewName = Name(NewProxy, ConcClass.__name__, CallingModule.__name__)

    # create proxy for remote Env
    EnvConcAddr = ConcAddr(CORPSMGR_ENVID, ENVMGR_CONCID, RemoteEnvId)
    RemoteEnv = EnvName(EnvConcAddr)

    # call rem2loc_create_Conc
    kwargs['ConcAddr'] = NewConcAddr
    FutRes = RemoteEnv.rem2loc_create_Conc(NewConcAddr, CallingModule.__name__,
                                           ConcClass.__name__, *args, **kwargs)
    Ret = FutRes.Ret

    return NewName
예제 #7
0
    def __init__(self, ConfigFiles):
        # Import the Config data here to make sure we get the version loaded by EnvMgr
        from ConfigGlobals import NumEnvs

        assert NumEnvs < MAX_ENVID - MIN_ENVID + 1, f'Number of Envs must be less than {MAX_ENVID-MIN_ENVID+1}'

        # Self-initialize
        ConcId = _ConcIdMgr.new()
        assert ConcId == CORPSMGR_CONCID, f'CorpsMgr has ConcId {ConcId} and not {CORPSMGR_CONCID}'

        self.ConcAddr = ConcAddr(CORPSMGR_ENVID, ConcId, CORPSMGR_ENVID)
        super().__init__()

        # Make sure thread-local data knows the Conc it's assigned to
        TheThread.TheConcAddr = self.ConcAddr

        # Make sure we can be found
        _Addr2Conc.register(self, self.ConcAddr)

        # Build a list of Envs' list of EnvRecord Spec Tuple: 0: LocEnvId, 1: IPAddr, 2: Port
        # Ours first, the other Envs as we receive them off the Queue
        EnvRecordSpecs = []
        OurEnvRecord = _EnvTable.get(CORPSMGR_ENVID)
        EnvRecordSpecs.append(
            [CORPSMGR_ENVID, OurEnvRecord.IPAddr, OurEnvRecord.Port])

        # Boot all other Envs in this Corps and get their EnvRecord Spec
        # ...Everything is on this Host
        CorpsMgrQueue = Queue()
        for i in range(NumEnvs - 1):
            NewEnvId = i + MIN_ENVID + 1
            NewEnv = Process(target=Env,
                             args=(NewEnvId, CorpsMgrQueue, ConfigFiles))
            NewEnv.start()

            EnvMsgList = CorpsMgrQueue.get()
            EnvRecordSpecs.append(EnvMsgList)

            # Create an EnvRecord and add to our EnvTable
            NewEnvRecord = EnvRecord(DefaultEnvRecord.MsgHdlrFactory,
                                     DefaultEnvRecord.NetwFactory,
                                     EnvMsgList[1], EnvMsgList[2])
            _EnvTable.register(NewEnvId, NewEnvRecord)

        info(f'CorpsMgr {self.my_Name()} EnvTable:\n{_EnvTable}')

        # Send EnvRecordSpecs to all Envs except ours
        for i in range(NumEnvs - 1):
            RemoteEnvId = i + MIN_ENVID + 1
            EnvConcAddr = ConcAddr(CORPSMGR_ENVID, ENVMGR_CONCID, RemoteEnvId)
            RemoteEnv = EnvName(EnvConcAddr)

            FutRes = RemoteEnv.init_EnvTable(EnvRecordSpecs)
            Ret = FutRes.Ret

            assert Ret == True,\
                        f'CorpsMgr {self.my_Name()} Process {getpid()} error initing EnvTable in Env {RemoteEnvId}'

        info(f'CorpsMgr {self.my_Name()} initialized, starting...')

        # The thread is no longer assigned, so cleanup
        TheThread.TheConcAddr = NullConcAddr
예제 #8
0
    def __init__(self, ConfigDelta):
        ''' Init a Corps, including all of its initial Envs (except its own - Corps Conc has already booted Env 0). '''

        # Import the Config data here to make sure we get the version loaded by EnvMgr
        from ConfigGlobals import NumEnvs
        print(f'{self} initing with {NumEnvs} Envs')
        assert NumEnvs < MAX_ENVID-MIN_ENVID+1, f'Number of Envs must be less than {MAX_ENVID-MIN_ENVID+1}'

        # Self-initialize
        ConcId = _ConcIdMgr.new()
        assert ConcId == CORPSMGR_CONCID, f'CorpsMgr has ConcId {ConcId} and not {CORPSMGR_CONCID}'

        self.ConcAddr = ConcAddr(CORPSMGR_ENVID, ConcId, CORPSMGR_ENVID)
        super().__init__()
        self.MajorStatus = MajorStatus.Booting

        # Make sure thread-local data knows the Conc it's assigned to
        TheThread.TheConcAddr = self.ConcAddr

        # Make sure we can be found
        _Addr2Conc.register(self, self.ConcAddr)

        # todo: make tuple into a named tuple or a data class?
        # Build a list of Envs' list of EnvRecord specs with indexes: 0: LocEnvId, 1: IpAddr, 2: Port
        # Ours first, the other Envs as we receive them off the Queue
        XferEnvRecords = []
        OurEnvRecord = _EnvTable.get(CORPSMGR_ENVID)
        OurXferEnvRecord = XferEnvRecord(CORPSMGR_ENVID, OurEnvRecord.IpAddr, OurEnvRecord.Port)
        XferEnvRecords.append(OurXferEnvRecord)

        # Boot all other Envs in this Corps and get their EnvRecord Spec
        # ...Everything is on this Host
        #from time import perf_counter
        EnvIds = EnvIdGen(MIN_ENVID_plus_1, NumEnvs-1)
        #tot_t = 0
        for NewEnvId in EnvIds:
            #t1 = perf_counter()
            CorpsMgrQueue = Queue()
            NewEnv = Process(target=Env, args=(NewEnvId, CorpsMgrQueue, ConfigDelta))

            NewEnv.start()

            NewXferEnvRecord = CorpsMgrQueue.get()
            #t2 = perf_counter()
            #tot_t += (t2 - t1)
            #print(f'CorpsMgr init Env {NewEnvId} in {t2-t1} seconds')

            assert NewXferEnvRecord.LocEnvId == NewEnvId, \
                                f'CorpsMgr __init__ returned Envid {NewXferEnvRecord.LocEnvId} vs expected {NewEnvId}'
            XferEnvRecords.append(NewXferEnvRecord)

            # Create an EnvRecord and add to our EnvTable
            NewEnvRecord = EnvRecord(DefaultEnvRecord.MsgHdlrFactory, DefaultEnvRecord.NetwFactory, \
                                                                        NewXferEnvRecord.IpAddr, NewXferEnvRecord.Port)
            _EnvTable.register(NewEnvId, NewEnvRecord)

        #print(f'CorpsMgr {self.ConcAddr} init: queue get {NumEnvs-1} Env processes in {tot_t} seconds')

        info(f'{self} EnvTable:\n{_EnvTable}')

        # Send EnvRecordSpecs to all Envs except ours
        EnvNames = EnvNameGen(MIN_ENVID_plus_1, NumEnvs-1)
        FutRets = []
        for RemoteEnv in EnvNames:
            FutRets.append(RemoteEnv.init_EnvTable(XferEnvRecords))

        # todo: handle the exception
        for FutRet in FutRets:
            Ret = FutRet.Ret    # will blow up if we have an exception

        # We're up!
        self.MajorStatus = MajorStatus.Running
        info(f'{self} initialized, starting...')

        # The thread is no longer assigned, so cleanup
        TheThread.TheConcAddr = NullConcAddr