Esempio n. 1
0
    def _construct_product(self, client, token, id):
        try:
            slot = self.slots[token]
        except KeyError:
            raise OperationError(token='invalid-slot')

        field = SlotTypes.get(slot.slot)
        if field:
            self.products[token] = RequestProduct(
                title=slot.title,
                token=token,
                product=surrogate.construct(schema=scheme.Structure(
                    {'value': field[0](name=token)}),
                                            value={'value': id}))

            return
        try:
            product = surrogate.acquire(slot.slot, client=client, id=id)
        except GoneError:
            raise OperationError(token='invalid-product')
        except Exception:
            log(
                'exception',
                'failed to acquire product using id %r for token %r' %
                (id, token))
            raise OperationError(token='cannot-acquire-product')
        else:
            self.products[token] = RequestProduct(title=slot.title,
                                                  token=token,
                                                  product=product)
Esempio n. 2
0
File: request.py Progetto: siq/flux
    def initiate(self, session, data):
        Request = self.docket_entity.bind('docket.entity/1.0/flux/1.0/request')
        id = uniqid()

        attrs = data['input']
        try:
            attrs = self.operation['schema'].unserialize(attrs)
        except ValidationError:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='invalid-input')

        wait_for_completion = attrs.pop('wait_for_completion', True)
        if wait_for_completion:
            SubscribedTask.queue_http_task('complete-request-operation',
                self.flux.prepare('flux/1.0/request', 'task', None,
                    {'task': 'complete-request-operation', 'request_id': id,
                        'process_id': data['id']}),
                topic='request:completed',
                aspects={'id': id},
                timeout=259200)

        attrs['id'] = id
        try:
            request = Request.create(**attrs)
        except Exception:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='failed')

        if wait_for_completion:
            return self.executing()
        else:
            outcome = ('created' if request.status in ('pending', 'prepared') else 'failed')
            return self.outcome(outcome, {
                'request': surrogate.construct('flux.surrogates.request', request),})
Esempio n. 3
0
File: request.py Progetto: siq/flux
    def initiate(self, session, data):
        Request = self.docket_entity.bind('docket.entity/1.0/flux/1.0/request')
        id = uniqid()

        attrs = data['input']
        try:
            attrs = self.operation['schema'].unserialize(attrs)
        except ValidationError:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='invalid-input')

        wait_for_completion = attrs.pop('wait_for_completion', True)
        if wait_for_completion:
            SubscribedTask.queue_http_task(
                'complete-request-operation',
                self.flux.prepare(
                    'flux/1.0/request', 'task', None, {
                        'task': 'complete-request-operation',
                        'request_id': id,
                        'process_id': data['id']
                    }),
                topic='request:completed',
                aspects={'id': id},
                timeout=259200)

        attrs['id'] = id
        try:
            request = Request.create(**attrs)
        except Exception:
            log('exception', 'initiation of create-request operation failed')
            return self.invalidation(error='failed')

        if wait_for_completion:
            return self.executing()
        else:
            outcome = ('created' if request.status in ('pending', 'prepared')
                       else 'failed')
            return self.outcome(
                outcome, {
                    'request':
                    surrogate.construct('flux.surrogates.request', request),
                })
Esempio n. 4
0
File: request.py Progetto: siq/flux
    def complete(self, session, data):
        process_id = data['process_id']
        try:
            subject = RequestModel.load(session, id=data['request_id'])
        except NoResultFound:
            return self.push(process_id, self.outcome('failed'))

        products = {}
        for key, value in subject.products.iteritems():
            products[key] = value.extract_dict(attrs='title product')

        values = {'request': surrogate.construct('flux.surrogates.request', subject)}

        status = subject.status
        if status in ('completed', 'declined'):
            outcome = status
            values['products'] = products
        else:
            outcome = 'failed'

        self.push(process_id, self.outcome(outcome, values))
Esempio n. 5
0
File: request.py Progetto: siq/flux
    def complete(self, session, data):
        process_id = data['process_id']
        try:
            subject = RequestModel.load(session, id=data['request_id'])
        except NoResultFound:
            return self.push(process_id, self.outcome('failed'))

        products = {}
        for key, value in subject.products.iteritems():
            products[key] = value.extract_dict(attrs='title product')

        values = {
            'request': surrogate.construct('flux.surrogates.request', subject)
        }

        status = subject.status
        if status in ('completed', 'declined'):
            outcome = status
            values['products'] = products
        else:
            outcome = 'failed'

        self.push(process_id, self.outcome(outcome, values))
Esempio n. 6
0
File: request.py Progetto: siq/flux
    def _construct_product(self, client, token, id):
        try:
            slot = self.slots[token]
        except KeyError:
            raise OperationError(token='invalid-slot')

        field = SlotTypes.get(slot.slot)
        if field:
            self.products[token] = RequestProduct(
                title=slot.title, token=token,
                product=surrogate.construct(
                    schema=scheme.Structure({'value': field[0](name=token)}),
                    value={'value': id}))

            return
        try:
            product = surrogate.acquire(slot.slot, client=client, id=id)
        except GoneError:
            raise OperationError(token='invalid-product')
        except Exception:
            log('exception', 'failed to acquire product using id %r for token %r' % (id, token))
            raise OperationError(token='cannot-acquire-product')
        else:
            self.products[token] = RequestProduct(title=slot.title, token=token, product=product)
Esempio n. 7
0
File: python.py Progetto: esho/mesh
 def construct_surrogate(self, implementation, **params):
     return surrogate.construct(implementation, self._data, **params)