Example #1
0
    def handle(self, _batch_size=PUBSUB.DEFAULT.GET_BATCH_SIZE):
        input = self.request.input
        batch_size = input.batch_size or _batch_size

        with closing(self.odb.session()) as session:
            msg_list = get_messages(session, self.server.cluster_id, input.sub_key, batch_size, utcnow_as_ms())

            for elem in msg_list:
                ext_pub_time = datetime_from_ms(elem.ext_pub_time) if elem.ext_pub_time else None

                self.response.payload.append({
                    'msg_id': elem.msg_id,
                    'correl_id': elem.correl_id,
                    'in_reply_to': elem.in_reply_to,
                    'priority': elem.priority,
                    'size': elem.size,
                    'data_format': elem.data_format,
                    'mime_type': elem.mime_type,
                    'data': elem.data,
                    'expiration': elem.expiration,
                    'expiration_time': datetime_from_ms(elem.expiration_time),
                    'ext_client_id': elem.ext_client_id,
                    'ext_pub_time': ext_pub_time,
                    'topic_name': elem.topic_name,
                    'recv_time': datetime_from_ms(elem.recv_time),
                    'delivery_count': elem.delivery_count,
                })

            # We need to commit the session because the underlying query issued SELECT FOR UPDATE
            session.commit()
Example #2
0
    def handle(self):
        with closing(self.odb.session()) as session:
            self.response.payload[:] = self.get_data(session)

        for item in self.response.payload.zato_output:
            item.pub_time = datetime_from_ms(item.pub_time)
            item.ext_pub_time = datetime_from_ms(
                item.ext_pub_time) if item.ext_pub_time else ''
Example #3
0
    def get_data(self, session):
        result = self._search(pubsub_endpoint_summary_list, session,
                              self.request.input.cluster_id, False)
        for item in result:

            if item.last_seen:
                item.last_seen = datetime_from_ms(item.last_seen)

            if item.last_deliv_time:
                item.last_deliv_time = datetime_from_ms(item.last_deliv_time)

        return result
Example #4
0
    def handle(self):
        with closing(self.odb.session()) as session:

            item = pubsub_message(session, self.request.input.cluster_id, self.request.input.msg_id).\
                first()

            if item:
                item.pub_time = datetime_from_ms(item.pub_time)
                item.ext_pub_time = datetime_from_ms(item.ext_pub_time) if item.ext_pub_time else ''
                item.expiration_time = datetime_from_ms(item.expiration_time) if item.expiration_time else ''
                self.response.payload = item
            else:
                raise NotFound(self.cid, 'No such message `{}`'.format(self.request.input.msg_id))
Example #5
0
    def handle(self):
        with closing(self.odb.session()) as session:
            item = pubsub_endpoint_queue(session,
                                         self.request.input.cluster_id,
                                         self.request.input.id)

            self._add_queue_depths(session, item)
            item.creation_time = datetime_from_ms(item.creation_time)
            if item.last_interaction_time:
                item.last_interaction_time = datetime_from_ms(
                    item.last_interaction_time)

            self.response.payload = item
Example #6
0
    def handle(self):
        response = []

        with closing(self.odb.session()) as session:

            # Get last pub time for that specific endpoint to this very topic
            last_data = pubsub_publishers_for_topic(
                session, self.request.input.cluster_id,
                self.request.input.topic_id).all()

            for item in last_data:
                item.last_seen = datetime_from_ms(item.last_pub_time)
                item.last_pub_time = datetime_from_ms(item.last_pub_time)
                response.append(item)

        self.response.payload[:] = response
Example #7
0
    def handle(self, _utcnow=datetime.utcnow):
        input = self.request.input

        with closing(self.odb.session()) as session:
            item = session.query(PubSubMessage).\
                filter(PubSubMessage.cluster_id==input.cluster_id).\
                filter(PubSubMessage.pub_msg_id==input.msg_id).\
                first()

            if not item:
                self.response.payload.found = False
                return

            item.data = input.data.encode('utf8')
            item.data_prefix = input.data[:2048].encode('utf8')
            item.data_prefix_short = input.data[:64].encode('utf8')
            item.size = len(input.data)
            item.expiration = get_expiration(self.cid, input)
            item.priority = get_priority(self.cid, input)

            item.pub_correl_id = input.correl_id
            item.in_reply_to = input.in_reply_to
            item.mime_type = input.mime_type

            if item.expiration:
                item.expiration_time = item.pub_time + (item.expiration * 1000)
            else:
                item.expiration_time = None

            session.add(item)
            session.commit()

            self.response.payload.found = True
            self.response.payload.size = item.size
            self.response.payload.expiration_time = datetime_from_ms(item.expiration_time) if item.expiration_time else None
Example #8
0
    def handle(self,
               _channel=CHANNEL.WEBSPHERE_MQ,
               _data_format=DATA_FORMAT.DICT,
               ts_format='YYYYMMDDHHmmssSS'):
        request = loads(self.request.raw_request)
        msg = request['msg']
        service_name = request['service_name']

        # Make MQ-level attributes easier to handle
        correlation_id = unhexlify(
            msg['correlation_id']) if msg['correlation_id'] else None
        expiration = datetime_from_ms(
            msg['expiration']) if msg['expiration'] else None

        timestamp = '{}{}'.format(msg['put_date'], msg['put_time'])
        timestamp = arrow_get(timestamp,
                              ts_format).replace(tzinfo='UTC').datetime

        self.invoke(service_name,
                    msg['text'],
                    _channel,
                    wmq_ctx={
                        'msg_id': unhexlify(msg['msg_id']),
                        'correlation_id': correlation_id,
                        'timestamp': timestamp,
                        'put_time': msg['put_time'],
                        'put_date': msg['put_date'],
                        'expiration': expiration,
                        'reply_to': msg['reply_to'],
                    })
Example #9
0
    def handle(self):
        response = []

        with closing(self.odb.session()) as session:

            for item in self.get_data(session):

                self._add_queue_depths(session, item)
                item.creation_time = datetime_from_ms(item.creation_time)

                if item.last_interaction_time:
                    item.last_interaction_time = datetime_from_ms(
                        item.last_interaction_time)
                response.append(item)

        self.response.payload[:] = response
Example #10
0
    def handle(self):
        input = self.request.input
        response = []

        with closing(self.odb.session()) as session:

            # Get last pub time for that specific endpoint to this very topic
            last_data = session.query(
                PubSubTopic.id.label('topic_id'),
                PubSubTopic.name, PubSubTopic.is_active,
                PubSubTopic.is_internal, PubSubTopic.name,
                PubSubTopic.max_depth_gd,
                PubSubTopic.max_depth_non_gd,
                PubSubEndpointTopic.last_pub_time,
                PubSubEndpointTopic.pub_msg_id.label('last_msg_id'),
                PubSubEndpointTopic.pub_correl_id.label('last_correl_id'),
                PubSubEndpointTopic.in_reply_to.label('last_in_reply_to'),
                PubSubEndpointTopic.ext_client_id,
                ).\
                filter(PubSubEndpointTopic.topic_id==PubSubTopic.id).\
                filter(PubSubEndpointTopic.endpoint_id==input.endpoint_id).\
                filter(PubSubEndpointTopic.cluster_id==self.request.input.cluster_id).\
                all()

            for item in last_data:
                item.last_pub_time = datetime_from_ms(item.last_pub_time)
                response.append(item)

        self.response.payload[:] = response
Example #11
0
    def handle(self):
        with closing(self.odb.session()) as session:
            topic = pubsub_topic(session, self.request.input.cluster_id,
                                 self.request.input.id)

        if topic.last_pub_time:
            topic.last_pub_time = datetime_from_ms(topic.last_pub_time)

        self.response.payload = topic
Example #12
0
    def handle(self):

        with closing(self.odb.session()) as session:

            item = pubsub_queue_message(session, self.request.input.cluster_id, self.request.input.msg_id).\
                first()

            if item:
                item.expiration = item.expiration or None
                for name in('expiration_time', 'recv_time', 'ext_pub_time', 'last_delivery_time'):
                    value = getattr(item, name, None)
                    if value:
                        setattr(item, name, datetime_from_ms(value))

                self.response.payload = item
            else:
                raise NotFound(self.cid, 'No such message `{}`'.format(self.request.input.msg_id))
Example #13
0
 def __repr__(self):
     return '<Msg sk:{} id:{} ext:{} exp:{} gd:{}>'.format(
         self.sub_key, self.pub_msg_id, self.ext_client_id, datetime_from_ms(self.expiration_time), self.has_gd)
Example #14
0
def response_hook(service, input, instance, attrs, service_type):
    if service_type == 'get_list':
        for item in service.response.payload:
            if item.last_pub_time:
                item.last_pub_time = datetime_from_ms(item.last_pub_time)