示例#1
0
    def __init__(self,
                 configFile=None,
                 controller=None,
                 engines=None,
                 numEngines=0,
                 sshx=None):
        if configFile is None:
            ipdir = cutils.getIpythonDir()
            configFile = os.path.join(ipdir, 'clusterconf.py')

        execfile(configFile, self)
        self.pop('__builtins__', '')

        if controller is not None:
            self['controller'] = controller

        if sshx is not None:
            self['sshx'] = sshx

        self['ncluster'] = self.get('ncluster', False)

        if engines is not None:
            if isinstance(engines, dict):
                self['engines'] = engines
            elif isinstance(engines, list):
                self['engines'] = dict()
                for e in engines:
                    self['engines'][e] = numEngines
        elif numEngines > 0:
            for e in self['engines'].keys():
                self['engines'][e] = numEngines
示例#2
0
    def resolveFilePath(self, filename, ipythondir = None):
        """Resolve filenames into absolute paths.

        This function looks in the following directories in order:

        1.  In the current working directory or by absolute path with ~ expanded
        2.  In ipythondir if that is set
        3.  In the IPYTHONDIR environment variable if it exists
        4.  In the ~/.ipython directory

        Note: The IPYTHONDIR is also used by the trunk version of IPython so
               changing it will also affect it was well.
        """

        # In cwd or by absolute path with ~ expanded
        trythis = os.path.expanduser(filename)
        if os.path.isfile(trythis):
            return trythis

        # In ipythondir if it is set
        if ipythondir is not None:
            trythis = ipythondir + '/' + filename
            if os.path.isfile(trythis):
                return trythis        

        trythis = getIpythonDir() + '/' + filename
        if os.path.isfile(trythis):
            return trythis

        return None
示例#3
0
 def _getEngineInfoLogFile(self):
     # Store all logs inside the ipython directory
     ipdir = cutils.getIpythonDir()
     pjoin = os.path.join
     logdir_base = pjoin(ipdir, 'log')
     if not os.path.isdir(logdir_base):
         os.makedirs(logdir_base)
     logfile = os.path.join(logdir_base,
                            'ipcontroller-%s-engine-info.log' % os.getpid())
     return logfile
示例#4
0
def clusterRemote(opt, arg):
    """Start a remote cluster over SSH"""

    # Load the remote cluster configuration
    clConfig = {}
    execfile(opt.clusterfile, clConfig)
    contConfig = clConfig['controller']
    engConfig = clConfig['engines']
    # Determine where to find sshx:
    sshx = clConfig.get('sshx', os.environ.get('IPYTHON_SSHX', 'sshx'))

    # Store all logs inside the ipython directory
    ipdir = cutils.getIpythonDir()
    pjoin = os.path.join

    logfile = opt.logfile
    if logfile is None:
        logdir_base = pjoin(ipdir, 'log')
        ensureDir(logdir_base)
        logfile = pjoin(logdir_base, 'ipcluster')

    # Append this script's PID to the logfile name always
    logfile = '%s-%s' % (logfile, os.getpid())

    print 'Starting controller:'
    # Controller data:
    xsys = os.system

    contHost = contConfig['host']
    contLog = '%s-con-%s-' % (logfile, contHost)
    cmd = "ssh %s '%s' 'ipcontroller --logfile %s' &" % \
          (contHost,sshx,contLog)
    #print 'cmd:<%s>' % cmd  # dbg
    xsys(cmd)
    time.sleep(2)

    print 'Starting engines:   '
    for engineHost, engineData in engConfig.iteritems():
        if isinstance(engineData, int):
            numEngines = engineData
        else:
            raise NotImplementedError(
                'port configuration not finished for engines')

        print 'Sarting %d engines on %s' % (numEngines, engineHost)
        engLog = '%s-eng-%s-' % (logfile, engineHost)
        for i in range(numEngines):
            cmd = "ssh %s '%s' 'ipengine --controller-ip %s --logfile %s' &" % \
                      (engineHost,sshx,contHost,engLog)
            #print 'cmd:<%s>' % cmd  # dbg
            xsys(cmd)
        # Wait after each host a little bit
        time.sleep(1)

    startMsg(contConfig['host'])
示例#5
0
def stop(clusterno=0):
    # short cut
    configFile = None
    if clusterno:
        configFile = 'clusterconf%d.py' % clusterno
        ipdir = cutils.getIpythonDir()
        configFile = os.path.join(ipdir, configFile)

    cl = Cluster(ClusterConfig(configFile=configFile))
    cl.connect()
    cl.stop(dt=1.0, waitafter=8.0)
    return cl
示例#6
0
    def __init__(self, clusterConfig, dt=0.5, use_mpd=False):
        self.dt = dt
        self.use_mpd = use_mpd
        self.max_wait_time = 300

        # read configuration
        self.sshx = clusterConfig.getSSHX()
        self.contHost = clusterConfig.getControllerHost()
        self.engine_port = clusterConfig.getEnginePort()
        self.rc_port = clusterConfig.getRemoteControllerPort()
        self.task_port = clusterConfig.getTaskControllerPort()
        self.engines = clusterConfig.getEngines()
        self.ncluster = clusterConfig.getNcluster()

        # setup logfile
        ipdir = cutils.getIpythonDir()
        logdir_base = os.path.join(ipdir, 'log')
        if not os.path.isdir(logdir_base):
            os.makedirs(logdir_base)
        logfile = os.path.join(logdir_base, 'ipcluster')
        self.logfile = '%s-%s' % (logfile, os.getpid())
        self.__running = False
示例#7
0
def clusterLocal(opt, arg):
    """Start a cluster on the local machine."""

    # Store all logs inside the ipython directory
    ipdir = cutils.getIpythonDir()
    pjoin = os.path.join

    logfile = opt.logfile
    if logfile is None:
        logdir_base = pjoin(ipdir, 'log')
        ensureDir(logdir_base)
        logfile = pjoin(logdir_base, 'ipcluster-')

    print 'Starting controller:',
    controller = Popen(['ipcontroller', '--logfile', logfile])
    print 'Controller PID:', controller.pid

    print 'Starting engines:   ',
    time.sleep(3)

    englogfile = '%s%s-' % (logfile, controller.pid)
    engines = [
        Popen(['ipengine', '--logfile', englogfile]) for i in range(opt.n)
    ]
    eids = [e.pid for e in engines]
    print 'Engines PIDs:  ', eids
    print 'Log files: %s*' % englogfile

    proc_ids = eids + [controller.pid]
    procs = engines + [controller]

    grpid = os.getpgrp()
    try:
        startMsg('127.0.0.1')
        print 'You can also hit Ctrl-C to stop it, or use from the cmd line:'
        print
        print 'kill -INT', grpid
        print
        try:
            while True:
                time.sleep(5)
        except:
            pass
    finally:
        print 'Stopping cluster.  Cleaning up...'
        cleanup(stop, controller, engines)
        for i in range(4):
            time.sleep(i + 2)
            nZombies = numAlive(controller, engines)
            if nZombies == 0:
                print 'OK: All processes cleaned up.'
                break
            print 'Trying again, %d processes did not stop...' % nZombies
            cleanup(kill, controller, engines)
            if numAlive(controller, engines) == 0:
                print 'OK: All processes cleaned up.'
                break
        else:
            print '*' * 75
            print 'ERROR: could not kill some processes, try to do it',
            print 'manually.'
            zombies = []
            if controller.returncode is None:
                print 'Controller is alive: pid =', controller.pid
                zombies.append(controller.pid)
            liveEngines = [e for e in engines if e.returncode is None]
            for e in liveEngines:
                print 'Engine is alive:     pid =', e.pid
                zombies.append(e.pid)
            print
            print 'Zombie summary:', ' '.join(map(str, zombies))
示例#8
0
 def writeDefaultConfigFile(self):
     ipdir = getIpythonDir()
     fname = ipdir + '/' + self.filename
     if not os.path.isfile(fname):
         print "Writing the configuration file to: " + fname
         self.writeConfigObjToFile(fname)
示例#9
0
#-------------------------------------------------------------------------------

from ipython1.external.configobj import ConfigObj
from ipython1.config.cutils import getIpythonDir
from ipython1.config.api import ConfigObjManager

defaultNotebookConfig = ConfigObj()

#-------------------------------------------------------------------------------
# Notebook Configuration
#-------------------------------------------------------------------------------

notebookConfig = {
    'engineInterface': 'ipython1.kernel.engineservice.IEngineQueued',
    'networkInterfaces': {
        'http': {
            'interface':
            'ipython1.notebook.notebookhttp.IHTTPNotebookServerFactory',
            'ip': '',
            'port': 8008
        }
    },
    'defaultDBMode': "sqlite///",
    'activeDB': "sqlite:///%s/ipnotebooks.db" % (getIpythonDir()),
    'externalDBs': []
}

defaultNotebookConfig['notebook'] = notebookConfig

configManager = ConfigObjManager(defaultNotebookConfig,
                                 'ipython1.notebook.ini')