Exemple #1
0
 def rearrange(component_id):
     graphs = component_graph_repo.list(component_id)
     sequence = 0
     for graph in graphs:
         graph.sequence = sequence
         graph.save()
         sequence += 1
Exemple #2
0
 def _next_sequence(component_id):
     graphs = component_graph_repo.list(component_id=component_id)
     if not graphs:
         return 0
     sequences = [graph.sequence for graph in graphs]
     sequences.sort()
     return sequences[len(sequences) - 1] + 1
Exemple #3
0
    def _create_components(self, app_id, upgrade_group_id):
        components = group_service.list_components_by_upgrade_group_id(app_id, upgrade_group_id)
        component_ids = [cpt.component_id for cpt in components]

        http_rules = self._list_http_rules(component_ids)
        tcp_rules = self._list_tcp_rules(component_ids)

        result = []
        # TODO(huangrh): get the attributes at once, don't get it iteratively
        for cpt in components:
            component_source = service_source_repo.get_service_source(cpt.tenant_id, cpt.service_id)
            envs = env_var_repo.get_service_env(cpt.tenant_id, cpt.service_id)
            ports = port_repo.get_service_ports(cpt.tenant_id, cpt.service_id)
            volumes = volume_repo.get_service_volumes_with_config_file(cpt.service_id)
            config_files = volume_repo.get_service_config_files(cpt.service_id)
            probes = probe_repo.list_probes(cpt.service_id)
            monitors = service_monitor_repo.list_by_service_ids(cpt.tenant_id, [cpt.service_id])
            graphs = component_graph_repo.list(cpt.service_id)
            component = Component(
                cpt,
                component_source,
                envs,
                ports,
                volumes,
                config_files,
                probes,
                None,
                monitors,
                graphs, [],
                http_rules=http_rules.get(cpt.component_id),
                tcp_rules=tcp_rules.get(cpt.component_id),
                support_labels=self.support_labels)
            result.append(component)
        return result
Exemple #4
0
 def exchange_graphs(self, component_id, graph_ids):
     sequence = 0
     graph_id_map = dict()
     # Mapping graph ID to graph
     old_graphs = component_graph_repo.list(component_id)
     for old_graph in old_graphs:
         graph_id_map[old_graph.graph_id] = old_graph
     # modified sequence
     for graph_id in graph_ids:
         if not graph_id_map.get(graph_id):
             raise AbortRequest(msg="wrong number of graph_id {}".format(graph_id), msg_show="该图表不存在")
         graph_id_map[graph_id].sequence = sequence
         sequence += 1
     # update model
     for graph in old_graphs:
         graph.save()
Exemple #5
0
    def component_graph_changes(self, component_graphs):
        if not component_graphs:
            return None

        old_graphs = component_graph_repo.list(self.service.service_id)
        old_promqls = [graph.promql for graph in old_graphs if old_graphs]
        add = []
        for graph in component_graphs:
            try:
                new_promql = promql_service.add_or_update_label(self.service.service_id, graph.get("promql"))
            except AbortRequest as e:
                logger.warning("promql: {}, {}".format(graph.get("promql"), e))
                continue
            if new_promql not in old_promqls:
                add.append(graph)
        if not add:
            return None
        return {"add": add}
    def get_service_details(self, tenant, service):
        service_base = service.to_dict()
        service_labels = service_label_repo.get_service_labels(
            service.service_id)
        service_domains = domain_repo.get_service_domains(service.service_id)
        http_rule_configs = configuration_repo.list_by_rule_ids(
            [sd.http_rule_id for sd in service_domains])
        service_tcpdomains = tcp_domain.get_service_tcpdomains(
            service.service_id)
        service_probes = probe_repo.get_service_probe(service.service_id)
        service_source = service_source_repo.get_service_source(
            tenant.tenant_id, service.service_id)
        service_auths = auth_repo.get_service_auth(service.service_id)
        service_env_vars = env_var_repo.get_service_env(
            tenant.tenant_id, service.service_id)
        service_compile_env = compile_env_repo.get_service_compile_env(
            service.service_id)
        service_extend_method = extend_repo.get_extend_method_by_service(
            service)
        service_mnts = mnt_repo.get_service_mnts(tenant.tenant_id,
                                                 service.service_id)
        service_volumes = volume_repo.get_service_volumes_with_config_file(
            service.service_id)
        service_config_file = volume_repo.get_service_config_files(
            service.service_id)
        service_ports = port_repo.get_service_ports(tenant.tenant_id,
                                                    service.service_id)
        service_relation = dep_relation_repo.get_service_dependencies(
            tenant.tenant_id, service.service_id)
        service_monitors = service_monitor_repo.get_component_service_monitors(
            tenant.tenant_id, service.service_id)
        component_graphs = component_graph_repo.list(service.service_id)
        # plugin
        service_plugin_relation = app_plugin_relation_repo.get_service_plugin_relation_by_service_id(
            service.service_id)
        service_plugin_config = service_plugin_config_repo.get_service_plugin_all_config(
            service.service_id)
        # third_party_service
        third_party_service_endpoints = service_endpoints_repo.get_service_endpoints_by_service_id(
            service.service_id)
        if service.service_source == "third_party":
            if not third_party_service_endpoints:
                raise ServiceHandleException(
                    msg="third party service endpoints can't be null",
                    msg_show="第三方组件实例不可为空")
        app_info = {
            "component_id":
            service.component_id,
            "service_base":
            service_base,
            "service_labels": [label.to_dict() for label in service_labels],
            "service_domains":
            [domain.to_dict() for domain in service_domains],
            "http_rule_configs":
            [config.to_dict() for config in http_rule_configs],
            "service_tcpdomains":
            [tcpdomain.to_dict() for tcpdomain in service_tcpdomains],
            "service_probes": [probe.to_dict() for probe in service_probes],
            "service_source":
            service_source.to_dict() if service_source else None,
            "service_auths": [auth.to_dict() for auth in service_auths],
            "service_env_vars":
            [env_var.to_dict() for env_var in service_env_vars],
            "service_compile_env":
            service_compile_env.to_dict() if service_compile_env else None,
            "service_extend_method":
            service_extend_method.to_dict() if service_extend_method else None,
            "service_mnts": [mnt.to_dict() for mnt in service_mnts],
            "service_plugin_relation": [
                plugin_relation.to_dict()
                for plugin_relation in service_plugin_relation
            ],
            "service_plugin_config":
            [config.to_dict() for config in service_plugin_config],
            "service_relation":
            [relation.to_dict() for relation in service_relation],
            "service_volumes":
            [volume.to_dict() for volume in service_volumes],
            "service_config_file":
            [config_file.to_dict() for config_file in service_config_file],
            "service_ports": [port.to_dict() for port in service_ports],
            "third_party_service_endpoints":
            [endpoint.to_dict() for endpoint in third_party_service_endpoints],
            "service_monitors":
            [monitor.to_dict() for monitor in service_monitors],
            "component_graphs":
            [graph.to_dict() for graph in component_graphs]
        }
        plugin_ids = [pr.plugin_id for pr in service_plugin_relation]

        return app_info, plugin_ids
Exemple #7
0
 def list_component_graphs(component_id):
     graphs = component_graph_repo.list(component_id)
     return [graph.to_dict() for graph in graphs]