Beispiel #1
0
    def __init__(self, aggr_config: Optional[AggrConfigDict] = None, pack_id: str = ""):
        super().__init__()
        if aggr_config is None:
            aggr_config = self.schema()().dump({})
        self.id = aggr_config["id"]

        self.customer = aggr_config.get("customer")
        self.pack_id = pack_id
        self.node = BINodeGenerator(aggr_config["node"])
        self.groups = BIAggregationGroups(aggr_config["groups"])
        self.computation_options = BIAggregationComputationOptions(
            aggr_config["computation_options"])
        self.aggregation_visualization = aggr_config["aggregation_visualization"]
Beispiel #2
0
 def create_trees_from_schema(cls, schema_config: Dict[str, Any]) -> BICompiledAggregation:
     branches = [BIRule.create_tree_from_schema(config) for config in schema_config["branches"]]
     aggregation_id = schema_config["id"]
     computation_options = BIAggregationComputationOptions(schema_config["computation_options"])
     aggregation_visualization = schema_config["aggregation_visualization"]
     groups = BIAggregationGroups(schema_config["groups"])
     return BICompiledAggregation(aggregation_id, branches, computation_options,
                                  aggregation_visualization, groups)
Beispiel #3
0
 def __init__(self,
              aggr_config: Optional[Dict[str, Any]] = None,
              pack_id: str = ""):
     super().__init__()
     if aggr_config is None:
         aggr_config = self.schema()().dump({}).data
     self.id = aggr_config["id"]
     # TODO: may be None -> SCOPE_GLOBAL
     self.customer = aggr_config.get("customer")
     self.pack_id = pack_id
     self.node = BINodeGenerator(aggr_config["node"])
     self.groups = BIAggregationGroups(aggr_config["groups"])
     self.computation_options = BIAggregationComputationOptions(
         aggr_config["computation_options"])
     self.aggregation_visualization = aggr_config[
         "aggregation_visualization"]
Beispiel #4
0
class BIAggregation:
    def __init__(self,
                 aggr_config: Optional[AggrConfigDict] = None,
                 pack_id: str = ""):
        super().__init__()
        if aggr_config is None:
            aggr_config = self.schema()().dump({})
        self.id = aggr_config["id"]

        self.customer = aggr_config.get("customer")
        self.pack_id = pack_id
        self.node = BINodeGenerator(aggr_config["node"])
        self.groups = BIAggregationGroups(aggr_config["groups"])
        self.computation_options = BIAggregationComputationOptions(
            aggr_config["computation_options"])
        self.aggregation_visualization = aggr_config[
            "aggregation_visualization"]

    @classmethod
    def schema(cls) -> Type["BIAggregationSchema"]:
        return BIAggregationSchema

    def serialize(self):
        return {
            "id": self.id,
            "customer": self.customer,
            "groups": self.groups.serialize(),
            "node": self.node.serialize(),
            "aggregation_visualization": self.aggregation_visualization,
            "computation_options": self.computation_options.serialize(),
        }

    def clone(self) -> "BIAggregation":
        aggregation_config = self.schema()().dump(self)
        return BIAggregation(aggregation_config)

    def compile(self, bi_searcher: ABCBISearcher) -> BICompiledAggregation:
        compiled_branches: List[BICompiledRule] = []
        if not self.computation_options.disabled:
            branches = self.node.compile({}, bi_searcher)

            # Each sub-branch represents one BI Aggregation with an unique name
            # The postprocessing phase takes care of the "remaining services" action
            for branch in branches:
                services_of_host: Dict[HostName, Set[ServiceName]] = {}
                for _site, host_name, service_description in branch.required_elements(
                ):
                    if service_description is None:
                        continue
                    services_of_host.setdefault(host_name,
                                                set()).add(service_description)
                branch.compile_postprocess(branch, services_of_host,
                                           bi_searcher)

            compiled_branches = self._verify_all_branches_start_with_rule(
                branches)

        return BICompiledAggregation(
            self.id,
            compiled_branches,
            self.computation_options,
            self.aggregation_visualization,
            self.groups,
        )

    def _verify_all_branches_start_with_rule(self,
                                             branches) -> List[BICompiledRule]:
        new_branches: List[BICompiledRule] = [
            x for x in branches if isinstance(x, BICompiledRule)
        ]
        assert len(branches) == len(new_branches)
        return new_branches

    @classmethod
    def create_trees_from_schema(
            cls, schema_config: Dict[str, Any]) -> BICompiledAggregation:
        branches = [
            BIRule.create_tree_from_schema(config)
            for config in schema_config["branches"]
        ]
        aggregation_id = schema_config["id"]
        computation_options = BIAggregationComputationOptions(
            schema_config["computation_options"])
        aggregation_visualization = schema_config["aggregation_visualization"]
        groups = BIAggregationGroups(schema_config["groups"])
        return BICompiledAggregation(aggregation_id, branches,
                                     computation_options,
                                     aggregation_visualization, groups)