Beispiel #1
0
 def reload_stack_root_config(self, now):
     """
     Force reload & apply configuration for stack root changes
     Args:
         now (float): Current time
     """
     dps = dp_preparsed_parser(self.meta_dp_state.top_conf, self.meta_dp_state)
     self._apply_configs(dps, now, None)
Beispiel #2
0
    def maintain_stack_root(self, now):
        """Maintain current stack root and return True if stack root changes."""
        for valve in self.valves.values():
            if valve.dp.dyn_running:
                self.meta_dp_state.dp_last_live_time[valve.dp.name] = now

        stacked_dps = [valve.dp for valve in self.valves.values() if valve.dp.stack_root_name]
        if not stacked_dps:
            return False

        candidate_stack_roots_names = stacked_dps[0].stack_roots_names
        candidate_dps = [dp for dp in stacked_dps if dp.name in candidate_stack_roots_names]
        healthy_stack_roots_names = self.healthy_stack_roots(now, candidate_dps)

        if healthy_stack_roots_names:
            new_stack_root_name = self.meta_dp_state.stack_root_name
            # Only pick a new root if the current one is unhealthy.
            if self.meta_dp_state.stack_root_name not in healthy_stack_roots_names:
                new_stack_root_name = healthy_stack_roots_names[0]
        else:
            # Pick the first candidate if no roots are healthy
            new_stack_root_name = candidate_stack_roots_names[0]

        stack_change = False
        if self.meta_dp_state.stack_root_name != new_stack_root_name:
            self.logger.info('stack root changed from %s to %s' % (
                self.meta_dp_state.stack_root_name, new_stack_root_name))
            if self.meta_dp_state.stack_root_name:
                stack_change = True
                prev_root = [dp for dp in stacked_dps if dp.name == self.meta_dp_state.stack_root_name]
                labels = prev_root[0].base_prom_labels()
                self.metrics.is_dp_stack_root.labels(**labels).set(0)
            self.meta_dp_state.stack_root_name = new_stack_root_name
            dpids = [dp.dp_id for dp in stacked_dps if dp.name == new_stack_root_name]
            self.metrics.faucet_stack_root_dpid.set(dpids[0])
        else:
            inconsistent_dps = [
                dp.name for dp in stacked_dps
                if dp.stack_root_name != self.meta_dp_state.stack_root_name]
            if inconsistent_dps:
                self.logger.info('stack root on %s inconsistent' % inconsistent_dps)
                stack_change = True

        if stack_change:
            self.logger.info(
                'root now %s (all candidates %s, healthy %s)' % (
                    self.meta_dp_state.stack_root_name,
                    candidate_stack_roots_names,
                    healthy_stack_roots_names))
            dps = dp_preparsed_parser(self.meta_dp_state.top_conf, self.meta_dp_state)
            self._apply_configs(dps, now, None)
        root_dps = [dp for dp in stacked_dps if dp.name == new_stack_root_name]
        labels = root_dps[0].base_prom_labels()
        self.metrics.is_dp_stack_root.labels(**labels).set(1)
        return stack_change