Пример #1
0
    def _process_msg(self, jsonMsg):
        """Parses the incoming message and handles appropriately"""
        self._log_debug(
            f"RealStorActuatorMsgHandler, _process_msg, jsonMsg: {jsonMsg}")

        if isinstance(jsonMsg, dict) is False:
            jsonMsg = json.loads(jsonMsg)

        # Parse out the uuid so that it can be sent back in Ack message
        uuid = None
        if jsonMsg.get("sspl_ll_msg_header").get("uuid") is not None:
            uuid = jsonMsg.get("sspl_ll_msg_header").get("uuid")
            self._log_debug(f"_processMsg, uuid: {uuid}")

        logger.debug(
            f"RealStorActuatorMsgHandler: _process_msg: jsonMsg: {jsonMsg}")
        if jsonMsg.get("actuator_request_type").get("storage_enclosure").get(
                "enclosure_request") is not None:
            enclosure_request = jsonMsg.get("actuator_request_type").get(
                "storage_enclosure").get("enclosure_request")
            self._log_debug(
                f"_processMsg, enclosure_request: {enclosure_request}")
            logger.debug(
                f"RealStorActuatorMsgHandler: _process_msg: INSIDE: jsonMsg: {jsonMsg}"
            )

            # Parse out the request field in the enclosure_request
            (request, fru) = enclosure_request.split(":", 1)
            request = request.strip()
            fru = fru.strip()

            if self._real_stor_actuator is None:
                try:
                    from actuators.impl.generic.realstor_encl import RealStorActuator
                    self._real_stor_actuator = RealStorActuator()
                except ImportError as e:
                    logger.warn("RealStor Actuator not loaded")
                    return

            # Perform the request and get the response
            real_stor_response = self._real_stor_actuator.perform_request(
                jsonMsg)
            self._log_debug(
                f"_process_msg, RealStor response: {real_stor_response}")

            json_msg = RealStorActuatorMsg(real_stor_response, uuid).getJson()
            self._write_internal_msgQ(EgressProcessor.name(), json_msg)
Пример #2
0
class RealStorActuatorMsgHandler(ScheduledModuleThread, InternalMsgQ):
    """Message Handler for controlling the RealStor actuator"""

    MODULE_NAME = "RealStorActuatorMsgHandler"
    PRIORITY = 2

    SYS_INFORMATION = 'SYSTEM_INFORMATION'
    SETUP = 'setup'

    UNSUPPORTED_REQUEST = "Unsupported Request"

    # Dependency list
    DEPENDENCIES = {
        "plugins": ["ServiceMsgHandler", "EgressProcessor", "DiskMsgHandler"],
        "rpms": []
    }

    @staticmethod
    def name():
        """ @return: name of the module."""
        return RealStorActuatorMsgHandler.MODULE_NAME

    @staticmethod
    def dependencies():
        """Returns a list of plugins and RPMs this module requires
           to function.
        """
        return RealStorActuatorMsgHandler.DEPENDENCIES

    def __init__(self):
        super(RealStorActuatorMsgHandler,
              self).__init__(self.MODULE_NAME, self.PRIORITY)
        # Flag to indicate suspension of module
        self._suspended = False

    def initialize(self, conf_reader, msgQlist, product):
        """initialize configuration reader and internal msg queues"""
        # Initialize ScheduledMonitorThread
        super(RealStorActuatorMsgHandler, self).initialize(conf_reader)

        # Initialize internal message queues for this module
        super(RealStorActuatorMsgHandler, self).initialize_msgQ(msgQlist)

        self._real_stor_actuator = None

        self._import_products(product)
        self.setup = Conf.get(GLOBAL_CONF, SETUP_KEY)

    def _import_products(self, product):
        """Import classes based on which product is being used"""
        if product.lower() in [x.lower() for x in enabled_products]:
            from zope.component import queryUtility
            self._queryUtility = queryUtility

    def run(self):
        """Run the module periodically on its own thread."""
        self._set_debug(True)
        self._set_debug_persist(True)

        # Do not proceed if module is suspended
        if self._suspended == True:
            self._scheduler.enter(1, self._priority, self.run, ())
            return
        self._log_debug("Start accepting requests")

        try:
            # Block on message queue until it contains an entry
            jsonMsg, _ = self._read_my_msgQ()
            if jsonMsg is not None:
                self._process_msg(jsonMsg)

            # Keep processing until the message queue is empty
            while not self._is_my_msgQ_empty():
                jsonMsg, _ = self._read_my_msgQ()
                if jsonMsg is not None:
                    self._process_msg(jsonMsg)

        except Exception as ae:
            # Log it and restart the whole process when a failure occurs
            logger.exception(f"RealStorActuatorMsgHandler restarting: {ae}")

        self._scheduler.enter(1, self._priority, self.run, ())
        self._log_debug("Finished processing successfully")

    def _process_msg(self, jsonMsg):
        """Parses the incoming message and handles appropriately"""
        self._log_debug(
            f"RealStorActuatorMsgHandler, _process_msg, jsonMsg: {jsonMsg}")

        if isinstance(jsonMsg, dict) is False:
            jsonMsg = json.loads(jsonMsg)

        # Parse out the uuid so that it can be sent back in Ack message
        uuid = None
        if jsonMsg.get("sspl_ll_msg_header").get("uuid") is not None:
            uuid = jsonMsg.get("sspl_ll_msg_header").get("uuid")
            self._log_debug(f"_processMsg, uuid: {uuid}")

        logger.debug(
            f"RealStorActuatorMsgHandler: _process_msg: jsonMsg: {jsonMsg}")
        if jsonMsg.get("actuator_request_type").get("storage_enclosure").get(
                "enclosure_request") is not None:
            enclosure_request = jsonMsg.get("actuator_request_type").get(
                "storage_enclosure").get("enclosure_request")
            self._log_debug(
                f"_processMsg, enclosure_request: {enclosure_request}")
            logger.debug(
                f"RealStorActuatorMsgHandler: _process_msg: INSIDE: jsonMsg: {jsonMsg}"
            )

            # Parse out the request field in the enclosure_request
            (request, fru) = enclosure_request.split(":", 1)
            request = request.strip()
            fru = fru.strip()

            if self._real_stor_actuator is None:
                try:
                    from actuators.impl.generic.realstor_encl import RealStorActuator
                    self._real_stor_actuator = RealStorActuator()
                except ImportError as e:
                    logger.warn("RealStor Actuator not loaded")
                    return

            # Perform the request and get the response
            real_stor_response = self._real_stor_actuator.perform_request(
                jsonMsg)
            self._log_debug(
                f"_process_msg, RealStor response: {real_stor_response}")

            json_msg = RealStorActuatorMsg(real_stor_response, uuid).getJson()
            self._write_internal_msgQ(EgressProcessor.name(), json_msg)

    def suspend(self):
        """Suspends the module thread. It should be non-blocking"""
        super(RealStorActuatorMsgHandler, self).suspend()
        self._suspended = True

    def resume(self):
        """Resumes the module thread. It should be non-blocking"""
        super(RealStorActuatorMsgHandler, self).resume()
        self._suspended = False

    def shutdown(self):
        """Clean up scheduler queue and gracefully shutdown thread"""
        super(RealStorActuatorMsgHandler, self).shutdown()