コード例 #1
0
ファイル: test_rfh2_put_get.py プロジェクト: comtech-et/pymqi
    def setUp(self):
        """ Create a new queue manager (TESTPMQI).
        Must be run as a user that has 'mqm' access.

        """

        self.single_rfh2_message = \
        open("messages/single_rfh2.dat", "rb").read()
        self.single_rfh2_message_not_well_formed = \
        self.single_rfh2_message[0:117] + self.single_rfh2_message[121:]

        self.multiple_rfh2_message = \
        open("messages/multiple_rfh2.dat", "rb").read()
        self.multiple_rfh2_message_not_well_formed = \
        self.multiple_rfh2_message[0:117] + self.multiple_rfh2_message[121:]

        queue_manager = "QM01"
        channel = "SVRCONN.1"
        socket = "localhost(31414)"
        queue_name = "RFH2.TEST"

        self.qmgr = None
        try:
            if pymqi.__mqbuild__ == 'server':
                self.qmgr = pymqi.QueueManager('QM01')
            else:
                self.qmgr = pymqi.QueueManager(None)
                self.qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, socket)
            self.put_queue = pymqi.Queue(self.qmgr, queue_name)
            self.get_queue = pymqi.Queue(self.qmgr, queue_name)
            self.clear_queue(self.get_queue)
        except Exception as e:
            raise e
コード例 #2
0
    def setUp(self):
        """ Create a new queue manager (TESTPMQI).
        Must be run as a user that has 'mqm' access.

        """

        self.single_rfh2_message = open(
            os.path.join(self.messages_dir, "single_rfh2.dat"), "rb").read()
        self.single_rfh2_message_not_well_formed = \
            self.single_rfh2_message[0:117] + self.single_rfh2_message[121:]

        self.multiple_rfh2_message = open(
            os.path.join(self.messages_dir, "multiple_rfh2.dat"), "rb").read()
        self.multiple_rfh2_message_not_well_formed = \
            self.multiple_rfh2_message[0:117] + self.multiple_rfh2_message[121:]

        queue_manager = config.MQ.QM.NAME
        channel = config.MQ.QM.CHANNEL
        conn_info = "%s(%s)" % (config.MQ.QM.HOST, config.MQ.QM.PORT)
        queue_name = config.MQ.QUEUE.QUEUE_NAMES['TestRFH2PutGet']

        self.qmgr = None
        if pymqi.__mqbuild__ == 'server':
            self.qmgr = pymqi.QueueManager(queue_manager)
        else:
            self.qmgr = pymqi.QueueManager(None)
            self.qmgr.connect_tcp_client(queue_manager,
                                         pymqi.cd(),
                                         channel,
                                         conn_info,
                                         user=config.MQ.QM.USER,
                                         password=config.MQ.QM.PASSWORD)
        self.put_queue = pymqi.Queue(self.qmgr, queue_name)
        self.get_queue = pymqi.Queue(self.qmgr, queue_name)
        self.clear_queue(self.get_queue)
コード例 #3
0
ファイル: test_queue_manager.py プロジェクト: Majoros/pymqi
def test_is_connected():
    """ Makes sure the QueueManager's 'is_connected' property works as expected.
    """
    with Replacer() as r:
        queue_manager = uuid4().hex
        channel = uuid4().hex
        host = uuid4().hex
        port = "1431"
        conn_info = "%s(%s)" % (host, port)

        for expected in(True, False):

            def _connectTCPClient(*ignored_args, **ignored_kwargs):
                pass

            def _getattr(self, name):
                if expected:
                    class _DummyMethod(object):
                        pass
                    # The mere fact of not raising an exception will suffice
                    # for QueueManager._is_connected to understand it as an
                    # all's OK condition.
                    return _DummyMethod
                else:
                    raise Exception()

            r.replace('pymqi.QueueManager.connectTCPClient', _connectTCPClient)
            r.replace('pymqi.PCFExecute.__getattr__', _getattr)

            qmgr = pymqi.QueueManager(None)
            qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, conn_info)

            eq_(qmgr.is_connected, expected)
コード例 #4
0
ファイル: test_rfh2_put_get.py プロジェクト: hjoukl/pymqi
    def setUp(self):
        """ Create a new queue manager (TESTPMQI).
        Must be run as a user that has 'mqm' access.

        """

        self.single_rfh2_message = open(
            os.path.join(self.messages_dir, "single_rfh2.dat"), "rb").read()
        self.single_rfh2_message_not_well_formed = \
            self.single_rfh2_message[0:117] + self.single_rfh2_message[121:]

        self.multiple_rfh2_message = open(
            os.path.join(self.messages_dir, "multiple_rfh2.dat"), "rb").read()
        self.multiple_rfh2_message_not_well_formed = \
            self.multiple_rfh2_message[0:117] + self.multiple_rfh2_message[121:]

        queue_manager = config.MQ.QM.NAME
        channel = config.MQ.QM.CHANNEL
        conn_info = "%s(%s)" % (config.MQ.QM.HOST, config.MQ.QM.PORT)
        queue_name = config.MQ.QUEUE.QUEUE_NAMES['TestRFH2PutGet']

        self.qmgr = None
        if pymqi.__mqbuild__ == 'server':
            self.qmgr = pymqi.QueueManager(queue_manager)
        else:
            self.qmgr = pymqi.QueueManager(None)
            self.qmgr.connect_tcp_client(
                queue_manager, pymqi.cd(), channel, conn_info,
                user=config.MQ.QM.USER, password=config.MQ.QM.PASSWORD)
        self.put_queue = pymqi.Queue(self.qmgr, queue_name)
        self.get_queue = pymqi.Queue(self.qmgr, queue_name)
        self.clear_queue(self.get_queue)
コード例 #5
0
ファイル: test_queue_manager.py プロジェクト: dsuch/pymqi
 def test_connect_tcp_client_no_credentials(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(
         self.qm_name, pymqi.cd(), self.channel, self.conn_info, user=None,
         password=None)
     self.assertTrue(qmgr.is_connected)
     qmgr.disconnect()
コード例 #6
0
ファイル: test_queue_manager.py プロジェクト: dsuch/pymqi
 def test_disconnect(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(
         self.qm_name, pymqi.cd(), self.channel, self.conn_info, user=self.user,
         password=self.password)
     self.assertTrue(qmgr.is_connected)
     qmgr.disconnect()
     self.assertFalse(qmgr.is_connected)
コード例 #7
0
ファイル: test_queue_manager.py プロジェクト: dsuch/pymqi
 def test_get_handle_connected(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(
         self.qm_name, pymqi.cd(), self.channel, self.conn_info, user=self.user,
         password=self.password)
     handle = qmgr.get_handle()
     # assertIsInstance is available >= Python2.7
     self.assertTrue(isinstance(handle, int))
コード例 #8
0
ファイル: test_queue_manager.py プロジェクト: dsuch/pymqi
 def test_inquire(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(
         self.qm_name, pymqi.cd(), self.channel, self.conn_info, user=self.user,
         password=self.password)
     attribute = pymqi.CMQC.MQCA_Q_MGR_NAME
     expected_value = utils.py3str2bytes(self.qm_name)
     attribute_value = qmgr.inquire(attribute)
     self.assertEqual(len(attribute_value), pymqi.CMQC.MQ_Q_MGR_NAME_LENGTH)  
     self.assertEqual(attribute_value.strip(), expected_value)
コード例 #9
0
 def test_connect_tcp_client(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(self.qm_name,
                             pymqi.cd(),
                             self.channel,
                             self.conn_info,
                             user=self.user,
                             password=self.password)
     self.assertTrue(qmgr.is_connected)
     qmgr.disconnect()
コード例 #10
0
 def test_connect_tcp_client_conection_list(self):
     qmgr = pymqi.QueueManager(None)
     self.conn_info = '127.0.0.1(22),{0}'.format(self.conn_info)
     qmgr.connect_tcp_client(self.qm_name,
                             pymqi.cd(),
                             self.channel,
                             self.conn_info,
                             user=self.user,
                             password=self.password)
     self.assertTrue(qmgr.is_connected)
     qmgr.disconnect()
コード例 #11
0
 def test_get_handle_connected(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(self.qm_name,
                             pymqi.cd(),
                             self.channel,
                             self.conn_info,
                             user=self.user,
                             password=self.password)
     handle = qmgr.get_handle()
     # assertIsInstance is available >= Python2.7
     self.assertTrue(isinstance(handle, int))
コード例 #12
0
ファイル: test_queue_manager.py プロジェクト: dsuch/pymqi
 def test_put1(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(
         self.qm_name, pymqi.cd(), self.channel, self.conn_info, user=self.user,
         password=self.password)
     input_msg = b'Hello world!'
     qmgr.put1(self.queue_name, input_msg)
     # now get the message from the queue
     queue = pymqi.Queue(qmgr, self.queue_name)
     result_msg = queue.get()
     self.assertEqual(input_msg, result_msg)
コード例 #13
0
 def test_inquire(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(self.qm_name,
                             pymqi.cd(),
                             self.channel,
                             self.conn_info,
                             user=self.user,
                             password=self.password)
     attribute = pymqi.CMQC.MQCA_Q_MGR_NAME
     expected_value = utils.py3str2bytes(self.qm_name)
     attribute_value = qmgr.inquire(attribute)
     self.assertEqual(len(attribute_value), pymqi.CMQC.MQ_Q_MGR_NAME_LENGTH)
     self.assertEqual(attribute_value.strip(), expected_value)
コード例 #14
0
 def test_put1(self):
     qmgr = pymqi.QueueManager(None)
     qmgr.connect_tcp_client(self.qm_name,
                             pymqi.cd(),
                             self.channel,
                             self.conn_info,
                             user=self.user,
                             password=self.password)
     input_msg = b'Hello world!'
     qmgr.put1(self.queue_name, input_msg)
     # now get the message from the queue
     queue = pymqi.Queue(qmgr, self.queue_name)
     result_msg = queue.get()
     self.assertEqual(input_msg, result_msg)
コード例 #15
0
    def test_is_connected(self):
        """Makes sure the QueueManager's 'is_connected' property works as
        expected.
        """
        # uses a mock so no real connection to a queue manager will be
        # established - the parameters below are basically moot
        with Replacer() as r:
            queue_manager = uuid4().hex
            channel = uuid4().hex
            host = uuid4().hex
            port = "1431"
            conn_info = "%s(%s)" % (host, port)
            user = "******"
            password = "******"

            for expected in (True, False):

                # noinspection PyUnusedLocal
                def _connect_tcp_client(*ignored_args, **ignored_kwargs):
                    pass

                # noinspection PyUnusedLocal
                def _getattr(self2, name):
                    if expected:

                        class _DummyMethod(object):
                            pass

                        # The mere fact of not raising an exception will suffice
                        # for QueueManager._is_connected to understand it as an
                        # all's OK condition.
                        return _DummyMethod
                    else:
                        raise Exception()

                r.replace('pymqi.QueueManager.connect_tcp_client',
                          _connect_tcp_client)
                r.replace('pymqi.PCFExecute.__getattr__', _getattr)

                qmgr = pymqi.QueueManager(None)
                qmgr.connect_tcp_client(queue_manager, pymqi.cd(), channel,
                                        conn_info, user, password)

                eq_(qmgr.is_connected, expected)
コード例 #16
0
ファイル: test_queue_manager.py プロジェクト: dsuch/pymqi
    def test_is_connected(self):
        """Makes sure the QueueManager's 'is_connected' property works as
        expected.
        """
        # uses a mock so no real connection to a queue manager will be
        # established - the parameters below are basically moot
        with Replacer() as r:
            queue_manager = uuid4().hex
            channel = uuid4().hex
            host = uuid4().hex
            port = "1431"
            conn_info = "%s(%s)" % (host, port)
            user = "******"
            password = "******"

            for expected in(True, False):

                # noinspection PyUnusedLocal
                def _connect_tcp_client(*ignored_args, **ignored_kwargs):
                    pass

                # noinspection PyUnusedLocal
                def _getattr(self2, name):
                    if expected:
                        class _DummyMethod(object):
                            pass
                        # The mere fact of not raising an exception will suffice
                        # for QueueManager._is_connected to understand it as an
                        # all's OK condition.
                        return _DummyMethod
                    else:
                        raise Exception()

                r.replace('pymqi.QueueManager.connect_tcp_client',
                          _connect_tcp_client)
                r.replace('pymqi.PCFExecute.__getattr__', _getattr)

                qmgr = pymqi.QueueManager(None)
                qmgr.connect_tcp_client(
                    queue_manager, pymqi.cd(), channel, conn_info, user,
                    password)

                eq_(qmgr.is_connected, expected)
コード例 #17
0
ファイル: test_queue_manager.py プロジェクト: vikki1107/pymqi
def test_is_connected():
    """ Makes sure the QueueManager's 'is_connected' property works as expected.
    """
    with Replacer() as r:
        queue_manager = uuid4().hex
        channel = uuid4().hex
        host = uuid4().hex
        port = "1431"
        conn_info = "%s(%s)" % (host, port)

        for expected in (True, False):

            def _connectTCPClient(*ignored_args, **ignored_kwargs):
                pass

            def _getattr(self, name):
                if expected:

                    class _DummyMethod(object):
                        pass

                    # The mere fact of not raising an exception will suffice
                    # for QueueManager._is_connected to understand it as an
                    # all's OK condition.
                    return _DummyMethod
                else:
                    raise Exception()

            r.replace('pymqi.QueueManager.connectTCPClient', _connectTCPClient)
            r.replace('pymqi.PCFExecute.__getattr__', _getattr)

            qmgr = pymqi.QueueManager(None)
            qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel,
                                  conn_info)

            eq_(qmgr.is_connected, expected)
コード例 #18
0
 def run(self):
      
     #logging.debug("in run") 
     
     while True:
         try:
             
             #logging.debug("before connect %s %s %s" % (self.queue_manager_name, self.server_connection_channel, self.socket))
             file_pid = str(open("/tmp/%s_current.pid" % self.config_name.replace("://", "-"), "r").read())
             #logging.debug("%%%%%% this pid:" + str(self.getName()) + " File pid:" + str(file_pid))    
             if self.getName().strip() != file_pid.strip():
                 #logging.debug("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                 done = True
                 sys.exit(1)
             else:
                 pass
                 #logging.debug("!!! NOT Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
             
             if self._qm is None:
                 self._qm = pymqi.QueueManager(None)
                 logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                
                 self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                 logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
             else:
                 if not self.persistent_connection: 
                     self._qm = pymqi.QueueManager(None)
                     logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                    
                     self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                     logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                 else:
                     if not self._qm._is_connected():
                         self._qm = pymqi.QueueManager(None)
                         logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                         
                         self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                         logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                         
             queues = []
             logging.debug("Queue name list: %s" % str(self.queue_name_list))
             
             for queue_name in self.queue_name_list:
                 try:
                     queues.append((queue_name, pymqi.Queue(self._qm, queue_name, CMQC.MQOO_INPUT_SHARED)))
                     #logging.debug("queue loop.  queue name:" + str(queue_name))
                 except Exception, ex:
                     logging.error("Unable to open queue:" + str(queue_name) + " Exception: " + str(ex))
                 
             get_opts = pymqi.gmo(Options = CMQC.MQGMO_FAIL_IF_QUIESCING)
             
             #logging.debug("after get_opts") 
             msg_desc = pymqi.md()
             #logging.debug("Start get")
             for (queue_name, queue_obj) in queues:
                 #logging.debug("queue = %s " % queue_name)
                 #logging.debug("Current tid:" + str(self.getName()) + " queue:" + queue_name)
                 #logging.debug("Check pid: queue:" + queue_name)
       
                 file_pid = str(open("/tmp/%s_current.pid" % self.config_name.replace("://", "-"), "r").read())
                 #logging.debug("%%%%%% this pid:" + str(self.getName()) + " File pid:" + str(file_pid))    
                 if self.getName().strip() != file_pid.strip():
                     #open("/opt/esb/stop.txt", "a").write("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                     #logging.debug("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                     done = True
                     sys.exit(1)
                 else:
                     pass
                     #logging.debug("!!! NOT Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                 
                 done = False
                 while not done:
                    
                     try:
                       
                         logging.debug("Before MQGET")
                         msg_desc['MsgId'] = ''
                         msg_desc['CorrelId'] = '' 
                         msg_data = queue_obj.get(None, msg_desc, get_opts)   
                         logging.debug("Got message. ")# MQMD:" + str(msg_desc.get()) + "MSG:" + msg_data)
                         
                         handle_output(self.splunk_host, self.queue_manager_name, queue_name, msg_data, msg_desc, False,  **self.kw)  
                         logging.debug("Handled output")
                     except pymqi.MQMIError, e:
                         if e.reason == 2033:
                             logging.debug("Done! 2033. No more messages!")
                             done = True
                         else:
                             logging.error("MQ Exception occurred: %s " % (str(e)))
                             done = True
                 
                 queue_obj.close()
                            
             if not self.persistent_connection:    
                 self._qm.disconnect()
コード例 #19
0
    def run(self):

        while True:
            try:
                # logging.debug("before connect %s %s %s" %
                # (self.queue_manager_name, self.server_conn_chl,
                #  self.socket))
                file_pid = open(
                    "/tmp/%s_current.pid" %
                    (self.config_name.replace("://", "-") + "_" +
                     str(self.thread_id)), "r").read().decode()
                logging.debug("%%%%%% this pid:" + str(self.getName()) +
                              " File pid:" + str(file_pid))

                if self.getName().strip() != file_pid.strip():
                    # logging.debug("$$$$ Stopping... this pid:" +
                    # str(self.getName()) + " File pid:" + str(file_pid))
                    done = True
                    sys.exit(1)
                else:
                    pass
                    # logging.debug("!!! NOT Stopping... this pid:" +
                    # str(self.getName()) + " File pid:" + str(file_pid))

                cd = pymqi.cd()
                #set the max message length to maximum
                cd["MaxMsgLength"] = 104857600

                if self._qm is None:
                    self._qm = pymqi.QueueManager(None)
                    logging.debug("Connecting to " +
                                  str(self.queue_manager_name) +
                                  " using channel " +
                                  str(self.server_conn_chl) + " and address " +
                                  self.socket + ".")

                    self._qm.connect_tcp_client(self.queue_manager_name, cd,
                                                self.server_conn_chl,
                                                self.socket, self.mq_user_name,
                                                self.mq_password)

                    logging.debug("Successfully Connected to " +
                                  self.queue_manager_name + " using channel " +
                                  self.server_conn_chl + " and address " +
                                  self.socket + ".")
                else:
                    if not self.persistent_connection:
                        self._qm = pymqi.QueueManager(None)
                        logging.debug("Connecting to " +
                                      str(self.queue_manager_name) +
                                      " using channel " +
                                      str(self.server_conn_chl) +
                                      " and address " + self.socket + ".")

                        self._qm.connect_tcp_client(self.queue_manager_name,
                                                    cd, self.server_conn_chl,
                                                    self.socket,
                                                    self.mq_user_name,
                                                    self.mq_password)

                        logging.debug("Successfully Connected to " +
                                      self.queue_manager_name +
                                      " using channel " +
                                      self.server_conn_chl + " and address " +
                                      self.socket + ".")
                    else:
                        if not self._qm._is_connected():
                            self._qm = pymqi.QueueManager(None)
                            logging.debug("Connecting to " +
                                          str(self.queue_manager_name) +
                                          " using channel " +
                                          str(self.server_conn_chl) +
                                          " and address " + self.socket + ".")

                            self._qm.connect_tcp_client(
                                self.queue_manager_name, cd,
                                self.server_conn_chl, self.socket,
                                self.mq_user_name, self.mq_password)
                            logging.debug("Successfully Connected to " +
                                          self.queue_manager_name +
                                          " using channel " +
                                          self.server_conn_chl +
                                          " and address " + self.socket + ".")

                queues = []
                logging.debug("Queue name list: %s" %
                              str(self.queue_name_list))

                for queue_name in self.queue_name_list:
                    try:
                        queues.append((queue_name,
                                       pymqi.Queue(self._qm, queue_name,
                                                   CMQC.MQOO_INPUT_SHARED)))
                        # logging.debug("queue loop.  queue name:" +
                        #               str(queue_name))
                    except Exception as ex:
                        logging.error("Unable to open queue:" +
                                      str(queue_name) + " Exception: " +
                                      str(ex))

                get_opts = pymqi.gmo(Options=CMQC.MQGMO_FAIL_IF_QUIESCING)

                # logging.debug("after get_opts")
                msg_desc = pymqi.md()
                # logging.debug("Start get")
                for (queue_name, queue_obj) in queues:
                    # logging.debug("queue = %s " % queue_name)
                    # logging.debug("Current tid:" +
                    #                str(self.getName()) +
                    #                " queue:" + queue_name)
                    # logging.debug("Check pid: queue:" + queue_name)

                    file_pid = str(
                        open(
                            "/tmp/%s_current.pid" %
                            (self.config_name.replace("://", "-") + "_" +
                             str(self.thread_id)), "r").read())
                    # logging.debug("%%%%%% this pid:" + str(self.getName()) +
                    #              " File pid:" + str(file_pid))
                    if self.getName().strip() != file_pid.strip():
                        # logging.debug("$$$$ Stopping... this pid:" +
                        #               str(self.getName()) +
                        #               " File pid:" + str(file_pid))
                        done = True
                        sys.exit(1)
                    else:
                        pass
                        # logging.debug("!!! NOT Stopping... this pid:" +
                        #               str(self.getName()) + " File pid:" +
                        #               str(file_pid))

                    done = False
                    while not done:

                        try:

                            logging.debug("Before MQGET")
                            msg_desc['MsgId'] = CMQC.MQMI_NONE
                            msg_desc['CorrelId'] = CMQC.MQCI_NONE
                            msg_data = queue_obj.get(None, msg_desc, get_opts)
                            logging.debug("Got message. ")
                            # MQMD:" + str(msg_desc.get()) + "MSG:" + msg_data)

                            handle_output(self.splunk_host,
                                          self.queue_manager_name, queue_name,
                                          msg_data, msg_desc, False, **self.kw)
                            logging.debug("Handled output")
                        except pymqi.MQMIError as e:
                            if e.reason == 2033:
                                logging.debug("Done! 2033. No more messages!")
                                done = True
                            else:
                                logging.error("MQ Exception occurred: %s " %
                                              (str(e)))
                                done = True

                    queue_obj.close()

                if not self.persistent_connection:
                    self._qm.disconnect()
            except pymqi.MQMIError as e:
                if e.reason == 2033:
                    pass
                else:
                    logging.error("MQ Exception occurred: %s " % (str(e)))
                    if self._qm is not None:
                        if not self.persistent_connection \
                           and self._qm._is_connected():
                            self._qm.disconnect()

            except:  # catch *all* exceptions
                e = sys.exc_info()[1]
                logging.error("Stopping. Exception in QueuePoller: %s" %
                              str(e))
                sys.exit(1)

            time.sleep(float(self.mqinput_interval))
コード例 #20
0
    def run(self):
        done = False
        while not done:
            try:
                # logging.debug("before connect %s %s %s" %
                # (self.queue_manager_name,
                # self.server_conn_chl, self.socket))
                file_pid = str(
                    open(
                        "/tmp/%s_current.pid" %
                        self.config_name.replace("://", "-"), "r").read())
                # logging.debug("%%%%%% this pid:" + str(self.getName()) +
                # " File pid:" + str(file_pid))
                if self.getName().strip() != file_pid.strip():
                    # another thrread has started and this one is not done.
                    # stop..
                    # logging.debug("$$$$ Stopping... this pid:" +
                    # str(self.getName()) + " File pid:" + str(file_pid))
                    done = True
                    sys.exit(1)
                else:
                    pass
                    # logging.debug("!!! NOT Stopping... this pid:" +
                    # str(self.getName()) + " File pid:" + str(file_pid))

                if self._qm is None:
                    self._qm = pymqi.QueueManager(None)
                    logging.debug("Connecting to " + self.queue_manager_name +
                                  self.server_conn_chl)

                    self._qm.connectTCPClient(self.queue_manager_name,
                                              pymqi.cd(), self.server_conn_chl,
                                              self.socket, self.mq_user_name,
                                              self.mq_password)
                    logging.debug("Successfully Connected to " +
                                  self.queue_manager_name +
                                  self.server_conn_chl)
                else:
                    if not self.persistent_connection:
                        self._qm = pymqi.QueueManager(None)
                        logging.debug("Connecting to " +
                                      self.queue_manager_name +
                                      self.server_conn_chl)

                        self._qm.connectTCPClient(self.queue_manager_name,
                                                  pymqi.cd(),
                                                  self.server_conn_chl,
                                                  self.socket,
                                                  self.mq_user_name,
                                                  self.mq_password)
                        logging.debug("Successfully Connected to " +
                                      str(self.queue_manager_name) +
                                      str(self.server_conn_chl))
                    else:
                        if not self._qm._is_connected():
                            self._qm = pymqi.QueueManager(None)
                            logging.debug("Connecting to " +
                                          str(self.queue_manager_name) +
                                          str(self.server_conn_chl))

                            self._qm.connectTCPClient(self.queue_manager_name,
                                                      pymqi.cd(),
                                                      self.server_conn_chl,
                                                      self.socket,
                                                      self.mq_user_name,
                                                      self.mq_password)
                            logging.debug("Successfully Connected to " +
                                          str(self.queue_manager_name) +
                                          str(self.server_conn_chl))

                logging.debug("channel name list: %s" %
                              str(self.channel_name_list))

                pcf = pymqi.PCFExecute(self._qm)
                # logging.debug("Start get")
                for channel_name in self.channel_name_list:
                    """
                    file_pid = str(open("/tmp/%s_current.pid" %
                    self.config_name.replace("://", "-"), "r").read())
                    #logging.debug("%%%%%% this pid:" + str(self.getName()) +
                    # " File pid:" + str(file_pid))
                    if self.getName().strip() != file_pid.strip():
                        # logging.debug("$$$$ Stopping... this pid:" +
                        # str(self.getName()) + " File pid:" + str(file_pid))
                        done = True
                        sys.exit(1)
                    else:
                        pass
                        # logging.debug("!!! NOT Stopping... this pid:" +
                        # str(self.getName()) + " File pid:" + str(file_pid))
                    """

                    get_chs_args = {
                        pymqi.CMQCFC.MQCACH_CHANNEL_NAME: channel_name
                    }

                    try:
                        pcf_response = \
                            pcf.MQCMD_INQUIRE_CHANNEL_STATUS(get_chs_args)

                    except pymqi.MQMIError as e:
                        if e.comp == pymqi.CMQC.MQCC_FAILED and \
                           e.reason == pymqi.CMQC.MQRC_UNKNOWN_OBJECT_NAME:
                            logging.info("Channel '%s' does not exist." %
                                         channel_name)
                        else:
                            if e.comp == pymqi.CMQC.MQCC_FAILED and \
                               e.reason == \
                                    pymqi.CMQCFC.MQRCCF_CHL_STATUS_NOT_FOUND:
                                logging.info("No status for channel '%s'." %
                                             channel_name)
                            else:
                                raise
                    else:
                        handle_output(self.splunk_host,
                                      self.queue_manager_name, channel_name,
                                      pcf_response, **self.kw)

                if not self.persistent_connection:
                    self._qm.disconnect()
            except pymqi.MQMIError as e:
                logging.error("MQ Exception occurred: %s " % (str(e)))
                if self._qm is not None:
                    if not self.persistent_connection and \
                       self._qm._is_connected():
                        self._qm.disconnect()

            except:  # catch *all* exceptions
                e = sys.exc_info()[1]
                logging.error("Stopping.  Exception occurred in \
                    ChannelStatusPoller: %s" % str(e))
                sys.exit(1)

            time.sleep(float(self.mqinput_interval))
コード例 #21
0
ファイル: mq_to_kinesis.py プロジェクト: ruyleite/case
import pymqi
import datetime
import boto3
import json

#Connect with MQSeries

queue_manager = "QUEUE_MANAGER_NAME"
channel = "SVRCONN.1"
host = "mq.meudominio.com"
port = "1434"
conn_info = "%s(%s)" % (host, port)

qmgr = pymqi.QueueManager(None)
qmgr.connectTCPClient(queue_manager, pymqi.cd(), channel, conn_info)
getQ = pymqi.Queue(qmgr, 'QNAME')

#Connect with Kinesis
kinesis = boto3.client('kinesis')

fieldspecs = [
    ('card_number', 0, 16),
    ('tran_datetime', 16, 14),
    ('value', 30, 15),
    ('pdv_id', 45, 10),
    ('status', 56, 1),
]

json_field = []

for field in fieldspecs:
コード例 #22
0
 def run(self):
     
     
     done = False 
     while not done:
         try:            
             #logging.debug("before connect %s %s %s" % (self.queue_manager_name, self.server_connection_channel, self.socket))
             file_pid = str(open("/tmp/%s_current.pid" % self.config_name.replace("://", "-"), "r").read())
             #logging.debug("%%%%%% this pid:" + str(self.getName()) + " File pid:" + str(file_pid))    
             if self.getName().strip() != file_pid.strip():
                 # another thrread has started and this one is not done.   stop..
                 #logging.debug("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                 done = True
                 sys.exit(1)
             else:
                 pass
                 #logging.debug("!!! NOT Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
             
             if self._qm is None:
                 self._qm = pymqi.QueueManager(None)
                 logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                
                 self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                 logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
             else:
                 if not self.persistent_connection: 
                     self._qm = pymqi.QueueManager(None)
                     logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                    
                     self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                     logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                 else:
                     if not self._qm._is_connected():
                         self._qm = pymqi.QueueManager(None)
                         logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                         
                         self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                         logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                         
             logging.debug("channel name list: %s" % str(self.channel_name_list))
             
             pcf = pymqi.PCFExecute(self._qm)
             #logging.debug("Start get")
             for channel_name in self.channel_name_list:
                 """
                 file_pid = str(open("/tmp/%s_current.pid" % self.config_name.replace("://", "-"), "r").read())
                 #logging.debug("%%%%%% this pid:" + str(self.getName()) + " File pid:" + str(file_pid))    
                 if self.getName().strip() != file_pid.strip():
                     #open("/opt/esb/stop.txt", "a").write("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                     #logging.debug("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                     done = True
                     sys.exit(1)
                 else:
                     pass
                     #logging.debug("!!! NOT Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                 """
                 
                 get_chs_args = {pymqi.CMQCFC.MQCACH_CHANNEL_NAME: channel_name}
                 
                 try:
                     pcf_response = pcf.MQCMD_INQUIRE_CHANNEL_STATUS(get_chs_args)
                     
                 except pymqi.MQMIError, e:
                     if e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQC.MQRC_UNKNOWN_OBJECT_NAME:
                         logging.info("Channel '%s' does not exist." % channel_name)
                     else:
                         if e.comp == pymqi.CMQC.MQCC_FAILED and e.reason == pymqi.CMQCFC.MQRCCF_CHL_STATUS_NOT_FOUND:
                             logging.debug("No status for channel '%s'." % channel_name)
                         raise
                 else:
                     handle_output(self.splunk_host, self.queue_manager_name, channel_name, pcf_response,  **self.kw)  
                 
             if not self.persistent_connection:    
                 self._qm.disconnect()
         except pymqi.MQMIError, e:
             logging.error("MQ Exception occurred: %s " % (str(e)))  
             if self._qm is not None:
                 if not self.persistent_connection and self._qm._is_connected():
                     self._qm.disconnect()