Esempio n. 1
0
    def wrap_function(self, *args, **kwargs):

        if 'ttype' in kwargs and kwargs['ttype'] != None:

            if not kwargs['ttype'] in (st.SYNC, st.ASYNC, st.TASK):
                # cannot handle that ttype value, do not call async methods
                ttype = kwargs['ttype']
                msg   = " %s: async %s() called with invalid tasktype (%s)" \
                      % (self.__class__.__name__, sync_function.__name__, str(ttype))
                raise se.BadParameter(msg)

            # call async method flavor
            try:
                async_function_name = "%s_async" % sync_function.__name__
                async_function = getattr(self, async_function_name)

            except AttributeError:
                msg = " %s: async %s() not implemented" \
                    % (self.__class__.__name__, sync_function.__name__)
                raise se.NotImplemented(msg)

            else:
                # 'self' not needed, getattr() returns member function
                return async_function(*args, **kwargs)

        # no ttype, or ttype==None -- make sure it's gone, and call default sync
        # function
        if 'ttype' in kwargs:
            del kwargs['ttype']

        return sync_function(self, *args, **kwargs)
Esempio n. 2
0
 def wrap_function(self, *args, **kwargs):
     raise se.NotImplemented ("%s.%s is not implemented for %s.%s (%s)" \
             %  (self.get_api ().__class__.__name__,
                 inspect.stack ()[1][3],
                 self._adaptor._name,
                 self.__class__.__name__,
                 inspect.getmembers (cpi_sync_function)[15][1]))
Esempio n. 3
0
    def wrap_function (self, *args, **kwargs) :

        my_ttype = None
        my_call  = None
        my_args  = ()


        if not 'ttype' in kwargs :
            msg = " %s: async %s() called with no tasktype" \
                % (self.__class__.__name__, cpi_async_function.__name__)
            raise se.BadParameter (msg)


        ttype = kwargs['ttype']
        del kwargs['ttype']


        if not ttype in (st.SYNC, st.ASYNC, st.TASK) :
            # cannot handle that ttype value, do not call async methods
            msg = " %s: async %s() called with invalid tasktype (%s)" \
                % (self.__class__.__name__, cpi_async_function.__name__, str(ttype))
            raise se.BadParameter (msg)


        cpi_sync_function_name = None
        cpi_sync_function      = None

        # find sync method flavor
        try :
            cpi_sync_function_name = re.sub ("_async$", "", cpi_async_function.__name__)
            cpi_sync_function      = getattr (self, cpi_sync_function_name)

        except AttributeError :
            msg = " %s: sync %s() not implemented" \
                % (self.__class__.__name__, cpi_sync_function.__name__)
            raise se.NotImplemented (msg)


        # got the sync call, wrap it in a task
        c = { '_call'   : cpi_sync_function,
              '_args'   : args, 
              '_kwargs' : kwargs }   # no ttype!

        return st.Task (self, cpi_sync_function_name, c, ttype)
Esempio n. 4
0
    def wrap_function (self, *args, **kwargs) :

        if 'ttype' in kwargs and kwargs['ttype'] != None :

            if not kwargs['ttype'] in (st.SYNC, st.ASYNC, st.TASK) :
                # cannot handle that ttype value, do not call async methods
                ttype = kwargs['ttype']
                msg   = " %s: async %s() called with invalid tasktype (%s)" \
                      % (self.__class__.__name__, sync_function.__name__, str(ttype))
                raise se.BadParameter (msg)

            # call async method flavor
            try :
                async_function_name = "%s_async"  %  sync_function.__name__
                async_function      = getattr (self, async_function_name)

            except AttributeError :
                msg = " %s: async %s() not implemented" \
                    % (self.__class__.__name__, sync_function.__name__)
                raise se.NotImplemented (msg)

            else :
                # 'self' not needed, getattr() returns member function
                return async_function (*args, **kwargs)
        
        # no ttype, or ttype==None -- make sure it's gone, and call default sync
        # function
        if 'ttype' in kwargs : 
            del kwargs['ttype']

        # only some functions will provide metrics, and thus need the _from_task
        # parameter -- strip that as well if its not needed
        if '_from_task' in kwargs:
            if not '_from_task' in inspect.getargspec (sync_function).args:
                del(kwargs['_from_task'])

        return sync_function (self, *args, **kwargs)
Esempio n. 5
0
    def bind_adaptor(self, api_instance, ctype, schema, preferred_adaptor,
                     *args, **kwargs):
        '''
        Look for a suitable adaptor class to bind to, instantiate it, and
        initialize it.

        If 'preferred_adaptor' is not 'None', only that given adaptors is
        considered, and adaptor classes are only created from that specific
        adaptor.
        '''

        if not ctype in self._adaptor_registry:
            error_msg = "No adaptor found for '%s' and URL scheme %s://" \
                                  % (ctype, schema)
            self._logger.error(error_msg)
            raise se.NotImplemented(error_msg)

        if not schema in self._adaptor_registry[ctype]:
            error_msg = "No adaptor found for '%s' and URL scheme %s://" \
                                  % (ctype, schema)
            self._logger.error(error_msg)
            raise se.NotImplemented(error_msg)

        # cycle through all applicable adaptors, and try to instantiate
        # a matching one.
        exception = saga.NoSuccess("binding adaptor failed", api_instance)
        for info in self._adaptor_registry[ctype][schema]:

            cpi_cname = info['cpi_cname']
            cpi_class = info['cpi_class']
            adaptor_name = info['adaptor_name']
            adaptor_instance = info['adaptor_instance']

            try:

                # is this adaptor acceptable?
                if  preferred_adaptor != None         and \
                    preferred_adaptor != adaptor_instance :

                    # ignore this adaptor
                    self._logger.debug ("bind_adaptor for %s : %s != %s - ignore adaptor" \
                                     % (cpi_cname, preferred_adaptor, adaptor_instance))
                    continue

                # instantiate cpi
                cpi_instance = cpi_class(api_instance, adaptor_instance)

                # self._logger.debug("Successfully bound %s.%s to %s" \
                #                  % (adaptor_name, cpi_cname, api_instance))
                return cpi_instance

            except se.SagaException as e:
                # adaptor class initialization failed - try next one
                exception._add_exception(e)
                self._logger.info  ("bind_adaptor adaptor class ctor failed : %s.%s: %s" \
                                 % (adaptor_name, cpi_class, str(e)))
                continue
            except Exception as e:
                exception._add_exception(saga.NoSuccess(str(e), api_instance))
                self._logger.info ("bind_adaptor adaptor class ctor failed : %s.%s: %s" \
                                % (adaptor_name, cpi_class, str(e)))
                continue

        self._logger.error(
            "No suitable adaptor found for '%s' and URL scheme '%s'" %
            (ctype, schema))
        self._logger.info("%s" % (str(exception)))
        raise exception._get_exception_stack()
Esempio n. 6
0
def test_NotImplemented():
    try:
        raise se.NotImplemented('NotImplemented')
    except se.NotImplemented, e:
        assert e.get_message() == 'NotImplemented'
        assert str(e) == 'NotImplemented'
Esempio n. 7
0
    except se.NotImplemented:
        assert False
    except Exception, e:
        assert e.get_message() == 'SagaException'
        assert str(e) == 'SagaException'


def test_NotImplemented():
    try:
        raise se.NotImplemented('NotImplemented')
    except se.NotImplemented, e:
        assert e.get_message() == 'NotImplemented'
        assert str(e) == 'NotImplemented'

    try:
        raise se.NotImplemented('NotImplemented')
    except se.Timeout:
        assert False
    except Exception, e:
        assert e.get_message() == 'NotImplemented'
        assert str(e) == 'NotImplemented'


def test_IncorrectURL():
    try:
        raise se.IncorrectURL('IncorrectURL')
    except se.IncorrectURL, e:
        assert e.get_message() == 'IncorrectURL'
        assert str(e) == 'IncorrectURL'

    try:
Esempio n. 8
0
 def add_callback(self, key, cb):
     raise se.NotImplemented("Callbacks are not supported for this backend")