示例#1
0
    def registerToMaster(self):
            try:
                bootmaster = StandingCall(copy_ref_with_timeout(self.master,config.BOOTSTRAP_CONTACT_TIMEOUT), 1, max_repeat=config.BOOTSTRAP_CONTACT_REPEAT)

                self.wid,file_server_ior = bootmaster.registerWorker(self.uuid,1) # ordinary workers have capacity 1

                file_server = self.program.orb.string_to_object(file_server_ior)
                
                from diane.FileTransfer import FileTransferClient
                self.ftc = FileTransferClient(file_server,self.uuid)
                import diane.workspace
                # collect and upload vcard
                vcard = self.make_vcard()
                file('vcard.txt','w').write(repr(vcard))
                self.ftc.upload('vcard.txt',os.path.join(diane.workspace.workerSubdir(self.wid),'vcard.txt'))

                #TEST - multiple registrations
                #for i in range(1000):
                #    self.wid = self.master.registerWorker(self._this())
                #logger.info('master ping %s',str(self.master.ping()))

                self.heartbeat_thread = HeartbeatThread(self,self.master)
                self.heartbeat_thread.start()
            except CORBA.TRANSIENT:
                logger.error('unable to establish connection to the master after timeout=%d seconds'%config.BOOTSTRAP_CONTACT_TIMEOUT)
                raise
            except DIANE_CORBA.XHangup:
                logger.warning('I was refused a registration (my peer_id=%s)',self.uuid)
                raise
示例#2
0
    def run(self):

        import MSGWrap
        
        from diane.config import log_configuration
        log_configuration(title='initial configuration')        

        msg_data = { '_worker_uuid' : self.uuid }

        try:
            self.registerToMaster()

            master = StandingCall(self.master, config.HEARTBEAT_DELAY, should_stop = self.should_stop)
            
            
            app_boot,app_init = master.get_init_data(self.uuid) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'get_init_data',self.uuid)
            _boot = streamer.loads(app_boot)
            msg_data['_master_uuid'] = _boot.master_uuid
            msg_data['_runid'] = _boot.runid
            import os
            msg_data['ganga_job_uuid'] = self.ganga_job_uuid

            # FIXME: if worker restart enabled, save diane.config.__all_configs and restore it after run has finished
            MSGWrap.sendStatus('_worker_create_application_proxy_start', msg_data)
            self.application = create_application_proxy(app_boot,app_init,agent=self)
            MSGWrap.sendStatus('_worker_create_application_proxy_finish', msg_data)
            
            self.program.registerAtExitHandler(self.finalize_application)
            
            MSGWrap.sendStatus('_worker_initialize_start', msg_data)
            app_init_output = self.application.initialize(app_init)
            MSGWrap.sendStatus('_worker_initialize_finish', msg_data)

            # config may have been updated and the value of config.HEARTBEAT_DELAY may have changed -> need to create the object again
            # FIXME: use a REFERENCE to config.HEARTBEAT_DELAY
            master = StandingCall(self.master, config.HEARTBEAT_DELAY, should_stop = self.should_stop)

            master.put_init_result(self.uuid,app_init_output,0) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'put_init_result',self.uuid,app_init_output,0)

            while not self.should_stop():
                time.sleep(config.PULL_REQUEST_DELAY) # PENDING: this parameter should be dynamically controlled by the master
                tid,task_data = master.get_task_data(self.uuid) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'get_task_data',self.uuid)
                try:
                    msg_data['tid'] = tid
                    MSGWrap.sendStatus('_worker_do_work_start', msg_data)
                    task_result = self.application.do_work(task_data)
                    MSGWrap.sendStatus('_worker_do_work_finish', msg_data)
                    error = 0
                except diane.application.ApplicationFailure,x: # recoverable problem
                    task_result = streamer.dumps(x)
                    error = 1
                    #FIXME: reporting failure is not yet well-defined
                
                master.put_task_result(self.uuid,tid,task_result,error) #(config.HEARTBEAT_DELAY,-1,self.should_stop,self.master,'put_task_result',self.uuid,tid,task_result,error)

        except diane.application.ApplicationFailure,x: # recoverable problem but raised by the application init
            pass