Esempio n. 1
0
    def __init__(self, url, session=None, logger=None, opts=None, posix=True):

        if logger: self.logger = logger
        else: self.logger = rul.getLogger('saga', 'PTYShell')

        if session: self.session = session
        else: self.session = ss.Session(default=True)

        if opts: self.options = opts
        else: self.options = dict()

        self.logger.debug("PTYShell init %s" % self)

        self.url = url  # describes the shell to run
        self.posix = posix  # /bin/sh compatible?
        self.latency = 0.0  # set by factory
        self.cp_slave = None  # file copy channel

        self.initialized = False

        self.pty_id = PTYShell._pty_id
        PTYShell._pty_id += 1

        self.cfg = self.session.get_config('saga.utils.pty')

        # get prompt pattern from options, config, or use default
        if 'prompt_pattern' in self.options:
            self.prompt = self.options['prompt_pattern']
        elif 'prompt_pattern' in self.cfg:
            self.prompt = self.cfg['prompt_pattern'].get_value()
        else:
            self.prompt = DEFAULT_PROMPT

        self.prompt_re = re.compile("^(.*?)%s" % self.prompt, re.DOTALL)
        self.logger.info("PTY prompt pattern: %s" % self.prompt)

        # we need a local dir for file staging caches.  At this point we use
        # $HOME, but should make this configurable (FIXME)
        self.base = os.environ['HOME'] + '/.saga/adaptors/shell/'

        try:
            os.makedirs(self.base)

        except OSError as e:
            if e.errno == errno.EEXIST and os.path.isdir(self.base):
                pass
            else:
                raise se.NoSuccess("could not create staging dir: %s" % e)

        self.factory = supsf.PTYShellFactory()
        self.pty_info = self.factory.initialize(self.url,
                                                self.session,
                                                self.prompt,
                                                self.logger,
                                                posix=self.posix)
        self.pty_shell = self.factory.run_shell(self.pty_info)

        self._trace('init : %s' % self.pty_shell.command)

        self.initialize()
Esempio n. 2
0
    def __init__(self,
                 url=None,
                 session=None,
                 _adaptor=None,
                 _adaptor_state={},
                 _ttype=None):
        """
        __init__(url)

        Create a new Manager instance. Connect to a remote resource management endpoint.

        :type  url: :class:`saga.Url`
        :param url: resource management endpoint
        """

        # param checks
        _url = surl.Url(url)
        scheme = _url.scheme.lower()

        if not session:
            session = ss.Session(default=True)

        self._base = super(Manager, self)
        self._base.__init__(scheme,
                            _adaptor,
                            _adaptor_state,
                            _url,
                            session,
                            ttype=_ttype)
Esempio n. 3
0
    def __init__(self,
                 rm=None,
                 session=None,
                 _adaptor=None,
                 _adaptor_state={},
                 _ttype=None):
        """
        __init__(rm, session)

        Create a new job.Service instance.
        
        :param rm:      resource manager URL
        :type  rm:      string or :class:`saga.Url`
        :param session: an optional session object with security contexts
        :type  session: :class:`saga.Session`
        :rtype:         :class:`saga.job.Service`
        """

        # job service instances are resource hogs.  Before attempting to create
        # a new instance, we attempt to clear out all old instances.   There is
        # some collateral damage: we cannot run the Python GC over only the
        # job.Service instances, but have to run it globally -- however,
        # compared to the latency introduced by the job service setup, this
        # should be a minor inconvenienve (tm)
        try:
            import gc
            gc.collect()

        except:
            pass

        # param checks
        self.valid = False
        url = surl.Url(rm)

        if not url.scheme:
            url.scheme = 'fork'

        if not url.host:
            url.host = 'localhost'

        if not session:
            session = ss.Session(default=True)

        scheme = url.scheme.lower()

        self._super = super(Service, self)
        self._super.__init__(scheme,
                             _adaptor,
                             _adaptor_state,
                             url,
                             session,
                             ttype=_ttype)

        self.valid = True
Esempio n. 4
0
    def __init__(self, url, session=None, logger=None, init=None, opts={}):

        # print 'new pty shell to %s' % url

        if logger: self.logger = logger
        else: self.logger = rul.getLogger('saga', 'PTYShell')

        if session: self.session = session
        else: self.session = ss.Session(default=True)

        self.logger.debug("PTYShell init %s" % self)

        self.url = url  # describes the shell to run
        self.init = init  # call after reconnect
        self.opts = opts  # options...
        self.latency = 0.0  # set by factory
        self.cp_slave = None  # file copy channel

        self.initialized = False

        # get prompt pattern from config
        self.cfg = self.session.get_config('saga.utils.pty')

        if 'prompt_pattern' in self.cfg:
            self.prompt = self.cfg['prompt_pattern'].get_value()
            self.prompt_re = re.compile("^(.*?)%s" % self.prompt, re.DOTALL)
        else:
            self.prompt = "[\$#%>\]]\s*$"
            self.prompt_re = re.compile("^(.*?)%s" % self.prompt, re.DOTALL)

        self.logger.info("PTY prompt pattern: %s" % self.prompt)

        # we need a local dir for file staging caches.  At this point we use
        # $HOME, but should make this configurable (FIXME)
        self.base = os.environ['HOME'] + '/.saga/adaptors/shell/'

        try:
            os.makedirs(self.base)

        except OSError as e:
            if e.errno == errno.EEXIST and os.path.isdir(self.base):
                pass
            else:
                raise se.NoSuccess("could not create staging dir: %s" % e)

        self.factory = supsf.PTYShellFactory()
        self.pty_info = self.factory.initialize(self.url, self.session,
                                                self.prompt, self.logger)
        self.pty_shell = self.factory.run_shell(self.pty_info)

        self.initialize()
Esempio n. 5
0
    def __init__(self,
                 url=None,
                 flags=None,
                 session=None,
                 _adaptor=None,
                 _adaptor_state={},
                 _ttype=None):
        '''
        :param url: Url of the (remote) entry
        :type  url: :class:`saga.Url` 

        flags:     flags enum
        session:   saga.Session
        ret:       obj

        Construct a new entry object

        The specified entry is expected to exist -- otherwise a DoesNotExist
        exception is raised.  Also, the URL must point to an entry (not to
        a directory), otherwise a BadParameter exception is raised.

        Example::

            # get an entry handle
            entry = saga.namespace.Entry("sftp://localhost/tmp/data/data.bin")
    
            # print the entry's url
            print entry.get_url ()
        '''

        self._session = session
        self._is_recursive = False  # recursion guard (FIXME: NOT THREAD SAFE)

        # param checks
        if not session:
            session = ss.Session(default=True)

        if not flags: flags = 0
        url = surl.Url(url)
        scheme = url.scheme.lower()

        self._base = super(Entry, self)
        self._base.__init__(scheme,
                            _adaptor,
                            _adaptor_state,
                            url,
                            flags,
                            session,
                            ttype=_ttype)
Esempio n. 6
0
    def create   (cls, url=None, flags=None, session=None, ttype=None) :
        '''
        url:       saga.Url
        flags:     saga.namespace.flags enum
        session:   saga.Session
        ttype:     saga.task.type enum
        ret:       saga.Task
        '''

        # param checks
        if  not flags : flags = 0
        if not session :
            session = ss.Session (default=True)

        return cls (url, flags, session, _ttype=ttype)._init_task
Esempio n. 7
0
    def create   (cls, rm=None, session=None, ttype=SYNC) :
        """ 
        create(rm=None, session=None)
        Create a new job.Service instance asynchronously.

        :param rm:      resource manager URL
        :type  rm:      string or :class:`saga.Url`
        :param session: an optional session object with security contexts
        :type  session: :class:`saga.Session`
        :rtype:         :class:`saga.Task`
        """

        # param checks
        if not session :
            session = ss.Session (default=True)

        url     = surl.Url (rm)
        scheme  = url.scheme.lower ()

        return cls (url, session, _ttype=ttype)._init_task
Esempio n. 8
0
def benchmark_init(name, func_pre, func_core, func_post):

    _benchmark = {}

    s = sess.Session(default=True)
    sut.lout('session was set up\n')

    # check if a config file was specified via '-c' command line option, and
    # read it, return the dict

    config_name = None

    for i, arg in enumerate(sys.argv[1:]):
        if arg == '-c' and len(sys.argv) > i + 2:
            config_name = sys.argv[i + 2]

    if not config_name:
        benchmark_eval(_benchmark, 'no configuration specified (-c <conf>')

    tc = sutc.TestConfig()
    tc.read_config(config_name)

    test_cfg = tc.get_test_config()
    bench_cfg = tc.get_benchmark_config()
    session = tc.session

    # SAGA_BENCHMARK_ environments will overwrite config settings
    if 'SAGA_BENCHMARK_CONCURRENCY' in os.environ:
        bench_cfg['concurrency'] = os.environ['SAGA_BENCHMARK_CONCURRENCY']

    if 'SAGA_BENCHMARK_ITERATIONS' in os.environ:
        bench_cfg['iterations'] = os.environ['SAGA_BENCHMARK_ITERATIONS']

    if 'SAGA_BENCHMARK_LOAD' in os.environ:
        bench_cfg['load'] = os.environ['SAGA_BENCHMARK_LOAD']

    # check benchmark settings for completeness, set some defaults
    if not 'concurrency' in bench_cfg:
        benchmark_eval(_benchmark, 'no concurrency configured')

    if not 'iterations' in bench_cfg:
        benchmark_eval(_benchmark, 'no iterations configured')

    if not 'url' in bench_cfg:
        if 'job_service_url' in test_cfg:
            bench_cfg['url'] = test_cfg['job_service_url']
        elif 'filesystem_url' in test_cfg:
            bench_cfg['url'] = test_cfg['filesystem_url']
        else:
            bench_cfg['url'] = 'n/a'

    _benchmark['url'] = bench_cfg['url']
    _benchmark['session'] = session
    _benchmark['test_cfg'] = test_cfg
    _benchmark['bench_cfg'] = bench_cfg

    _benchmark['bench_cfg']['pre'] = func_pre
    _benchmark['bench_cfg']['core'] = func_core
    _benchmark['bench_cfg']['post'] = func_post
    _benchmark['bench_cfg']['name'] = name
    _benchmark['bench_cfg']['cname'] = config_name

    benchmark_run(_benchmark)
    benchmark_eval(_benchmark)
Esempio n. 9
0
    def __init__ (self, id=None, session=None,
                  _adaptor=None, _adaptor_state={}, _ttype=None) : 
        """
        __init__(id=None, session=None)

        Create / reconnect to a resource.

        :param id: id of the resource
        :type  id: :class:`saga.Url`
        
        :param session: :class:`saga.Session`

        Resource class instances are usually created by calling :func:`acquire`
        on the :class:`saga.resource.Manager` class.  Already acquired resources
        are identified by a string typed identifier.  This constructor accepts
        such an identifier to create another representation of the same
        resource.  As the resource itself is new newly acquired, it can be in
        any state.  In particular, it can be in a final state, and thus be
        unusable.  Further, the resource may already have expired or failed, and
        the information about it may have been purged -- in that case the id
        will not be valid any longer, and a :class:`saga.BadParameter` exception
        will be raised.

        The session parameter is interpreted exactly as the session parameter on
        the :class:`saga.resource.Manager` constructor.
        """

        # set attribute interface properties

        import saga.attributes as sa

        self._attributes_extensible  (False)
        self._attributes_camelcasing (True)

        # register properties with the attribute interface

        self._attributes_register  (const.ID          , None, sa.ENUM,   sa.SCALAR, sa.READONLY)
        self._attributes_register  (const.RTYPE       , None, sa.ENUM,   sa.SCALAR, sa.READONLY)
        self._attributes_register  (const.STATE       , None, sa.ENUM,   sa.SCALAR, sa.READONLY)
        self._attributes_register  (const.STATE_DETAIL, None, sa.STRING, sa.SCALAR, sa.READONLY)
        self._attributes_register  (const.ACCESS      , None, sa.URL,    sa.SCALAR, sa.READONLY)
        self._attributes_register  (const.MANAGER     , None, sa.URL,    sa.SCALAR, sa.READONLY)
        self._attributes_register  (const.DESCRIPTION , None, sa.ANY,    sa.SCALAR, sa.READONLY)

        self._attributes_set_enums (const.STATE, [const.UNKNOWN ,
                                                  const.PENDING ,
                                                  const.ACTIVE  ,
                                                  const.CANCELED,
                                                  const.EXPIRED ,
                                                  const.FAILED  ,
                                                  const.FINAL   ])

        self._attributes_set_enums (const.RTYPE, [const.COMPUTE ,
                                                  const.STORAGE ,
                                                  const.NETWORK ])


        self._attributes_set_getter (const.ID          , self.get_id          )
        self._attributes_set_getter (const.RTYPE       , self.get_rtype       )
        self._attributes_set_getter (const.STATE       , self.get_state       )
        self._attributes_set_getter (const.STATE_DETAIL, self.get_state_detail)
        self._attributes_set_getter (const.ACCESS      , self.get_access      )
        self._attributes_set_getter (const.MANAGER     , self.get_manager     )
        self._attributes_set_getter (const.DESCRIPTION , self.get_description )


        # FIXME: we need the ID to be or to include an URL, as we don't have
        # a scheme otherwise, which means we can't select an adaptor.  Duh! :-/
        
        # FIXME: documentation for attributes is missing.

        # param checks
        scheme = None
        if  not id :
            if  not 'resource_schema' in _adaptor_state :
                raise se.BadParameter ("Cannot initialize resource without id" \
                                    % self.rtype)
            else :
                scheme = _adaptor_state['resource_schema']
        else :
            url    = surl.Url (id)
            scheme = url.scheme.lower ()


        if not session :
            session = ss.Session (default=True)

        self._base = super  (Resource, self)
        self._base.__init__ (scheme, _adaptor, _adaptor_state, 
                             id, session, ttype=_ttype)