コード例 #1
0
    def daemon(self):
        try:
            # The protocol needs to be instantiated in the monitor thread itself (to avoid concurrency issues with the protocol object each
            # thread uses a different instance as per the SingletonPerThread model.
            protocol_util = get_protocol_util()
            protocol = protocol_util.get_protocol()
            health_service = HealthService(protocol.get_endpoint())
            periodic_operations = [
                ResetPeriodicLogMessages(),
                ReportNetworkErrors(),
                PollResourceUsage(),
                SendHostPluginHeartbeat(protocol, health_service),
                SendImdsHeartbeat(protocol_util, health_service)
            ]

            report_network_configuration_changes = ReportNetworkConfigurationChanges()
            if conf.get_monitor_network_configuration_changes():
                periodic_operations.append(report_network_configuration_changes)
            else:
                logger.info("Monitor.NetworkConfigurationChanges is disabled.")
                report_network_configuration_changes.log_network_configuration()

            while not self.stopped():
                try:
                    for op in periodic_operations:
                        op.run()
                finally:
                    PeriodicOperation.sleep_until_next_operation(periodic_operations)
        except Exception as e:
            logger.error("An error occurred in the monitor thread; will exit the thread.\n{0}", ustr(e))
コード例 #2
0
    def daemon(self):
        periodic_operations = [
            _CollectAndEnqueueEvents(self._send_telemetry_events_handler)
        ]

        is_etp_enabled = get_supported_feature_by_name(
            SupportedFeatureNames.ExtensionTelemetryPipeline).is_supported
        logger.info(
            "Extension Telemetry pipeline enabled: {0}".format(is_etp_enabled))
        if is_etp_enabled:
            periodic_operations.append(
                _ProcessExtensionEvents(self._send_telemetry_events_handler))

        logger.info("Successfully started the {0} thread".format(
            self.get_thread_name()))
        while not self.stopped():
            try:
                for periodic_op in periodic_operations:
                    periodic_op.run()

            except Exception as error:
                logger.warn(
                    "An error occurred in the Telemetry Extension thread main loop; will skip the current iteration.\n{0}",
                    ustr(error))
            finally:
                PeriodicOperation.sleep_until_next_operation(
                    periodic_operations)
コード例 #3
0
    def daemon(self):
        try:
            if self.protocol_util is None or self.protocol is None:
                self.init_protocols()

            if self.imds_client is None:
                self.init_imds_client()

            while not self.stopped():
                try:
                    self.protocol.update_host_plugin_from_goal_state()

                    for op in self._periodic_operations:  # pylint: disable=C0103
                        op.run()

                except Exception as e:  # pylint: disable=C0103
                    logger.error(
                        "An error occurred in the monitor thread main loop; will skip the current iteration.\n{0}",
                        ustr(e))
                finally:
                    PeriodicOperation.sleep_until_next_operation(
                        self._periodic_operations)
        except Exception as e:  # pylint: disable=C0103
            logger.error(
                "An error occurred in the monitor thread; will exit the thread.\n{0}",
                ustr(e))
コード例 #4
0
 def monitor(self):
     try:
         # The initialization of ProtocolUtil for the Environment thread should be done within the thread itself rather
         # than initializing it in the ExtHandler thread. This is done to avoid any concurrency issues as each
         # thread would now have its own ProtocolUtil object as per the SingletonPerThread model.
         self.protocol_util = get_protocol_util()
         self._protocol = self.protocol_util.get_protocol()
         while not self.stopped:
             try:
                 for op in self._periodic_operations:
                     op.run()
             except Exception as e:
                 logger.error("An error occurred in the environment thread main loop; will skip the current iteration.\n{0}", ustr(e))
             finally:
                 PeriodicOperation.sleep_until_next_operation(self._periodic_operations)
     except Exception as e:
         logger.error("An error occurred in the environment thread; will exit the thread.\n{0}", ustr(e))
コード例 #5
0
    def daemon(self, init_data=False):
        try:
            if init_data:
                self.init_protocols()

            while not self.stopped():
                try:
                    for op in self._periodic_operations:  # pylint: disable=C0103
                        op.run()
                except Exception as e:  # pylint: disable=C0103
                    logger.error(
                        "An error occurred in the log collection thread main loop; "
                        "will skip the current iteration.\n{0}", ustr(e))
                finally:
                    PeriodicOperation.sleep_until_next_operation(
                        self._periodic_operations)
        except Exception as e:  # pylint: disable=C0103
            logger.error(
                "An error occurred in the log collection thread; will exit the thread.\n{0}",
                ustr(e))
コード例 #6
0
ファイル: monitor.py プロジェクト: vyadavmsft/WALinuxAgent
    def daemon(self, init_data=False):
        try:
            if init_data:
                self.init_protocols()
                self.init_imds_client()

            while not self.stopped():
                try:
                    self.protocol.update_host_plugin_from_goal_state()

                    for op in self._periodic_operations:
                        op.run()

                except Exception as e:
                    logger.error(
                        "An error occurred in the monitor thread main loop; will skip the current iteration.\n{0}",
                        ustr(e))
                finally:
                    PeriodicOperation.sleep_until_next_operation(
                        self._periodic_operations)
        except Exception as e:
            logger.error(
                "An error occurred in the monitor thread; will exit the thread.\n{0}",
                ustr(e))
コード例 #7
0
ファイル: env.py プロジェクト: narrieta/WALinuxAgent
    def daemon(self):
        try:
            # The initialization of the protocol needs to be done within the environment thread itself rather
            # than initializing it in the ExtHandler thread. This is done to avoid any concurrency issues as each
            # thread would now have its own ProtocolUtil object as per the SingletonPerThread model.
            protocol_util = get_protocol_util()
            protocol = protocol_util.get_protocol()
            osutil = get_osutil()

            periodic_operations = [
                RemovePersistentNetworkRules(osutil),
                MonitorDhcpClientRestart(osutil),
                CleanupGoalStateHistory()
            ]

            if conf.enable_firewall():
                periodic_operations.append(EnableFirewall(osutil, protocol))
            if conf.get_root_device_scsi_timeout() is not None:
                periodic_operations.append(SetRootDeviceScsiTimeout(osutil))
            if conf.get_monitor_hostname():
                periodic_operations.append(MonitorHostNameChanges(osutil))
            while not self.stopped:
                try:
                    for op in periodic_operations:
                        op.run()
                except Exception as e:
                    logger.error(
                        "An error occurred in the environment thread main loop; will skip the current iteration.\n{0}",
                        ustr(e))
                finally:
                    PeriodicOperation.sleep_until_next_operation(
                        periodic_operations)
        except Exception as e:
            logger.error(
                "An error occurred in the environment thread; will exit the thread.\n{0}",
                ustr(e))