Ejemplo n.º 1
0
    def __init__(self, default=True):
        """
        default: bool
        ret:     None
        """

        simple_base = super(Session, self)
        simple_base.__init__()

        self._logger = ru.get_logger('radical.saga')

        # if the default session is expected, we point our context list to the
        # shared list of the default session singleton.  Otherwise, we create
        # a private list which is not populated.

        # a session also has a lease manager, for adaptors in this session to use.

        if default:
            default_session = DefaultSession()
            self.contexts = copy.deepcopy(default_session.contexts)
            self._lease_manager = default_session._lease_manager
        else:
            self.contexts = _ContextList(session=self)

            # FIXME: at the moment, the lease manager is owned by the session.
            # Howevwer, the pty layer is the main user of the lease manager,
            # and we thus keep the lease manager options in the pty subsection.
            # So here we are, in the session, evaluating the pty config options...
            config = self.get_config('saga.utils.pty')
            self._lease_manager = ru.LeaseManager(
                max_pool_size=config['connection_pool_size'].get_value(),
                max_pool_wait=config['connection_pool_wait'].get_value(),
                max_obj_age=config['connection_pool_ttl'].get_value())
Ejemplo n.º 2
0
    def __init__(self):

        # the default session picks up default contexts, from all context
        # adaptors.  To implemented, we have to do some legwork: get the engine,
        # dig through the registered context adaptors, and ask each of them for
        # default contexts.

        self.contexts = _ContextList()
        self._logger = rul.getLogger('saga', 'DefaultSession')

        # FIXME: at the moment, the lease manager is owned by the session.
        # Howevwer, the pty layer is the main user of the lease manager,
        # and we thus keep the lease manager options in the pty subsection.
        # So here we are, in the session, evaluating the pty config options...
        config = saga.engine.engine.Engine().get_config('saga.utils.pty')
        self._lease_manager = ru.LeaseManager(
            max_pool_size=config['connection_pool_size'].get_value(),
            max_pool_wait=config['connection_pool_wait'].get_value(),
            max_obj_age=config['connection_pool_ttl'].get_value())

        _engine = saga.engine.engine.Engine()

        if not 'saga.Context' in _engine._adaptor_registry:
            self._logger.warn("no context adaptors found")
            return

        for schema in _engine._adaptor_registry['saga.Context']:
            for info in _engine._adaptor_registry['saga.Context'][schema]:

                default_ctxs = []

                try:
                    default_ctxs = info[
                        'adaptor_instance']._get_default_contexts()

                except se.SagaException as e:
                    self._logger.debug   ("adaptor %s failed to provide default" \
                                          "contexts: %s" % (info['adaptor_name'], e))
                    continue

                for default_ctx in default_ctxs:

                    try:
                        self.contexts.append(ctx=default_ctx, session=self)
                        self._logger.debug   ("default context [%-20s] : %s" \
                                         %   (info['adaptor_name'], default_ctx))

                    except se.SagaException as e:
                        self._logger.debug   ("skip default context [%-20s] : %s : %s" \
                                         %   (info['adaptor_name'], default_ctx, e))
                        continue
Ejemplo n.º 3
0
    def __init__(self):

        # the default session picks up default contexts, from all context
        # adaptors.  To implemented, we have to do some legwork: get the engine,
        # dig through the registered context adaptors, and ask each of them for
        # default contexts.

        self.contexts = _ContextList()
        self._lease_manager = ru.LeaseManager()
        self._logger = rul.getLogger('saga', 'DefaultSession')

        _engine = saga.engine.engine.Engine()

        if not 'saga.Context' in _engine._adaptor_registry:
            self._logger.warn("no context adaptors found")
            return

        for schema in _engine._adaptor_registry['saga.Context']:
            for info in _engine._adaptor_registry['saga.Context'][schema]:

                default_ctxs = []

                try:
                    default_ctxs = info[
                        'adaptor_instance']._get_default_contexts()

                except se.SagaException as e:
                    self._logger.debug   ("adaptor %s failed to provide default" \
                                          "contexts: %s" % (info['adaptor_name'], e))
                    continue

                for default_ctx in default_ctxs:

                    try:
                        self.contexts.append(ctx=default_ctx, session=self)
                        self._logger.debug   ("default context [%-20s] : %s" \
                                         %   (info['adaptor_name'], default_ctx))

                    except se.SagaException as e:
                        self._logger.debug   ("skip default context [%-20s] : %s : %s" \
                                         %   (info['adaptor_name'], default_ctx, e))
                        continue
Ejemplo n.º 4
0
        def test(self):

            self.lm = ru.LeaseManager(SIZE)

            iw_thread_1 = threading.Thread(target=self.iw_thread,
                                           kwargs={
                                               'uid': 1,
                                               'pool': 'pool1'
                                           })
            iw_thread_2 = threading.Thread(target=self.iw_thread,
                                           kwargs={
                                               'uid': 2,
                                               'pool': 'pool2'
                                           })
            ow_thread_1 = threading.Thread(target=self.ow_thread,
                                           kwargs={
                                               'uid': 1,
                                               'pool': 'pool1'
                                           })
            ow_thread_2 = threading.Thread(target=self.ow_thread,
                                           kwargs={
                                               'uid': 2,
                                               'pool': 'pool2'
                                           })
            mon_thread = threading.Thread(target=self.mon_thread,
                                          kwargs={
                                              'uid': 1,
                                              'pool': 'pool1'
                                          })
            iw_thread_1.start()
            iw_thread_2.start()
            ow_thread_1.start()
            ow_thread_2.start()
            mon_thread.start()

            iw_thread_1.join()
            iw_thread_2.join()
            ow_thread_1.join()
            ow_thread_2.join()
            mon_thread.join()
Ejemplo n.º 5
0
    def __init__(self, default=True):
        """
        default: bool
        ret:     None
        """

        simple_base = super(Session, self)
        simple_base.__init__()

        # if the default session is expected, we point our context list to the
        # shared list of the default session singleton.  Otherwise, we create
        # a private list which is not populated.

        # a session also has a lease manager, for adaptors in this session to use.

        if default:
            default_session = _DefaultSession()
            self.contexts = default_session.contexts
            self._lease_manager = default_session._lease_manager
        else:
            self.contexts = _ContextList(session=self)
            self._lease_manager = ru.LeaseManager()
Ejemplo n.º 6
0
        def test(self):

            self.lm = ru.LeaseManager(SIZE)
            # self.lm2 = ru.LeaseManager()

            iw_thread_1 = threading.Thread(target=self.iw_thread,
                                           kwargs={
                                               'id': 1,
                                               'pool': 'pool1'
                                           })
            iw_thread_1.start()  # thread will run until lock check

            iw_thread_2 = threading.Thread(target=self.iw_thread,
                                           kwargs={
                                               'id': 2,
                                               'pool': 'pool2'
                                           })
            iw_thread_2.start()  # thread will run until lock check

            ow_thread_1 = threading.Thread(target=self.ow_thread,
                                           kwargs={
                                               'id': 1,
                                               'pool': 'pool1'
                                           })
            ow_thread_1.start()  # thread will run until lock check

            ow_thread_2 = threading.Thread(target=self.ow_thread,
                                           kwargs={
                                               'id': 2,
                                               'pool': 'pool2'
                                           })
            ow_thread_2.start()  # thread will run until lock check

            mon_thread = threading.Thread(target=self.mon_thread,
                                          kwargs={
                                              'id': 1,
                                              'pool': 'pool1'
                                          })
            mon_thread.start()  # thread will run until lock check