def construct(self):
        # This is the working dir by now.
        sys.path.insert(0, '')

        self.start_mpi()
        self.start_logging()

        # Create the underlying shell class and EngineService
        shell_class = import_item(self.master_config.Global.shell_class)
        self.engine_service = EngineService(shell_class, mpi=mpi)

        self.exec_lines()

        # Create the service hierarchy
        self.main_service = service.MultiService()
        self.engine_service.setServiceParent(self.main_service)
        self.tub_service = Tub()
        self.tub_service.setServiceParent(self.main_service)
        # This needs to be called before the connection is initiated
        self.main_service.startService()

        # This initiates the connection to the controller and calls
        # register_engine to tell the controller we are ready to do work
        self.engine_connector = EngineConnector(self.tub_service)

        log.msg("Using furl file: %s" % self.master_config.Global.furl_file)

        reactor.callWhenRunning(self.call_connect)
Esempio n. 2
0
def make_tub(ip, port, secure, cert_file):
    """
    Create a listening tub given an ip, port, and cert_file location.
    
    :Parameters:
        ip : str
            The ip address that the tub should listen on.  Empty means all
        port : int
            The port that the tub should listen on.  A value of 0 means
            pick a random port
        secure: boolean
            Will the connection be secure (in the foolscap sense)
        cert_file:
            A filename of a file to be used for theSSL certificate
    """
    if secure:
        if have_crypto:
            tub = Tub(certFile=cert_file)
        else:
            raise SecurityError("OpenSSL is not available, so we can't run in secure mode, aborting")
    else:
        tub = UnauthenticatedTub()
    
    # Set the strport based on the ip and port and start listening
    if ip == '':
        strport = "tcp:%i" % port
    else:
        strport = "tcp:%i:interface=%s" % (port, ip)
    listener = tub.listenOn(strport)
    
    return tub, listener
Esempio n. 3
0
 def setUp(self):
 
     self.engines = []
         
     self.controller = cs.ControllerService()
     self.controller.startService()
     self.imultiengine = me.IMultiEngine(self.controller)
     self.itc = taskmodule.ITaskController(self.controller)
     self.itc.failurePenalty = 0
 
     self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)
     self.tc_referenceable = IFCTaskController(self.itc)
 
     self.controller_tub = Tub()
     self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
     self.controller_tub.setLocation('127.0.0.1:10105')
 
     mec_furl = self.controller_tub.registerReference(self.mec_referenceable)
     tc_furl = self.controller_tub.registerReference(self.tc_referenceable)
     self.controller_tub.startService()
 
     self.client_tub = ClientConnector()
     d = self.client_tub.get_multiengine_client(mec_furl)
     d.addCallback(self.handle_mec_client)
     d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl))
     d.addCallback(self.handle_tc_client)
     return d
Esempio n. 4
0
    def setUp(self):

        # Start a server and append to self.servers
        self.controller_reference = FCRemoteEngineRefFromService(self)
        self.controller_tub = Tub()
        self.controller_tub.listenOn('tcp:10111:interface=127.0.0.1')
        self.controller_tub.setLocation('127.0.0.1:10111')

        furl = self.controller_tub.registerReference(self.controller_reference)
        self.controller_tub.startService()

        # Start an EngineService and append to services/client
        self.engine_service = es.EngineService()
        self.engine_service.startService()
        self.engine_tub = Tub()
        self.engine_tub.startService()
        engine_connector = EngineConnector(self.engine_tub)
        d = engine_connector.connect_to_controller(self.engine_service, furl)
        # This deferred doesn't fire until after register_engine has returned and
        # thus, self.engine has been defined and the tets can proceed.
        return d
    def setUp(self):

        self.engines = []

        self.controller = ControllerService()
        self.controller.startService()
        self.imultiengine = IMultiEngine(self.controller)
        self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine)

        self.controller_tub = Tub()
        self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1')
        self.controller_tub.setLocation('127.0.0.1:10105')

        furl = self.controller_tub.registerReference(self.mec_referenceable)
        self.controller_tub.startService()

        self.client_tub = ClientConnector()
        d = self.client_tub.get_multiengine_client(furl)
        d.addCallback(self.handle_got_client)
        return d
Esempio n. 6
0
 def __init__(self):
     self._remote_refs = {}
     self.tub = Tub()
     self.tub.startService()
Esempio n. 7
0
def start_engine():
    """
    Start the engine, by creating it and starting the Twisted reactor.
    
    This method does:
    
        * If it exists, runs the `mpi_import_statement` to call `MPI_Init`
        * Starts the engine logging
        * Creates an IPython shell and wraps it in an `EngineService`
        * Creates a `foolscap.Tub` to use in connecting to a controller.
        * Uses the tub and the `EngineService` along with a Foolscap URL
          (or FURL) to connect to the controller and register the engine
          with the controller
    """
    kernel_config = kernel_config_manager.get_config_obj()
    core_config = core_config_manager.get_config_obj()

    # Execute the mpi import statement that needs to call MPI_Init
    global mpi
    mpikey = kernel_config['mpi']['default']
    mpi_import_statement = kernel_config['mpi'].get(mpikey, None)
    if mpi_import_statement is not None:
        try:
            exec mpi_import_statement in globals()
        except:
            mpi = None
    else:
        mpi = None

    # Start logging
    logfile = kernel_config['engine']['logfile']
    if logfile:
        logfile = logfile + str(os.getpid()) + '.log'
        try:
            openLogFile = open(logfile, 'w')
        except:
            openLogFile = sys.stdout
    else:
        openLogFile = sys.stdout
    log.startLogging(openLogFile)

    # Create the underlying shell class and EngineService
    shell_class = import_item(core_config['shell']['shell_class'])
    engine_service = EngineService(shell_class, mpi=mpi)
    shell_import_statement = core_config['shell']['import_statement']
    if shell_import_statement:
        try:
            engine_service.execute(shell_import_statement)
        except:
            log.msg("Error running import_statement: %s" % sis)

    # Create the service hierarchy
    main_service = service.MultiService()
    engine_service.setServiceParent(main_service)
    tub_service = Tub()
    tub_service.setServiceParent(main_service)
    # This needs to be called before the connection is initiated
    main_service.startService()

    # This initiates the connection to the controller and calls
    # register_engine to tell the controller we are ready to do work
    engine_connector = EngineConnector(tub_service)
    furl_file = kernel_config['engine']['furl_file']
    log.msg("Using furl file: %s" % furl_file)
    d = engine_connector.connect_to_controller(engine_service, furl_file)
    d.addErrback(lambda _: reactor.stop())

    reactor.run()
Esempio n. 8
0
def start_engine():
    """
    Start the engine, by creating it and starting the Twisted reactor.
    
    This method does:
    
        * If it exists, runs the `mpi_import_statement` to call `MPI_Init`
        * Starts the engine logging
        * Creates an IPython shell and wraps it in an `EngineService`
        * Creates a `foolscap.Tub` to use in connecting to a controller.
        * Uses the tub and the `EngineService` along with a Foolscap URL
          (or FURL) to connect to the controller and register the engine
          with the controller
    """
    kernel_config = kernel_config_manager.get_config_obj()
    core_config = core_config_manager.get_config_obj()

    # Execute the mpi import statement that needs to call MPI_Init
    global mpi
    mpikey = kernel_config['mpi']['default']
    mpi_import_statement = kernel_config['mpi'].get(mpikey, None)
    if mpi_import_statement is not None:
        try:
            exec mpi_import_statement in globals()
        except:
            mpi = None
    else:
        mpi = None

    # Start logging
    logfile = kernel_config['engine']['logfile']
    if logfile:
        logfile = logfile + str(os.getpid()) + '.log'
        try:
            openLogFile = open(logfile, 'w')
        except:
            openLogFile = sys.stdout
    else:
        openLogFile = sys.stdout
    log.startLogging(openLogFile)

    # Create the underlying shell class and EngineService
    shell_class = import_item(core_config['shell']['shell_class'])
    engine_service = EngineService(shell_class, mpi=mpi)
    shell_import_statement = core_config['shell']['import_statement']
    if shell_import_statement:
        try:
            engine_service.execute(shell_import_statement)
        except:
            log.msg("Error running import_statement: %s" %
                    shell_import_statement)

    # Create the service hierarchy
    main_service = service.MultiService()
    engine_service.setServiceParent(main_service)
    tub_service = Tub()
    tub_service.setServiceParent(main_service)
    # This needs to be called before the connection is initiated
    main_service.startService()

    # This initiates the connection to the controller and calls
    # register_engine to tell the controller we are ready to do work
    engine_connector = EngineConnector(tub_service)
    furl_file = kernel_config['engine']['furl_file']
    log.msg("Using furl file: %s" % furl_file)

    def call_connect(engine_service, furl_file):
        d = engine_connector.connect_to_controller(engine_service, furl_file)

        def handle_error(f):
            # If this print statement is replaced by a log.err(f) I get
            # an unhandled error, which makes no sense.  I shouldn't have
            # to use a print statement here.  My only thought is that
            # at the beginning of the process the logging is still starting up
            print "error connecting to controller:", f.getErrorMessage()
            reactor.callLater(0.1, reactor.stop)

        d.addErrback(handle_error)

    reactor.callWhenRunning(call_connect, engine_service, furl_file)
    reactor.run()