def __save_service_relations(self, tenant, service_relations_list, old_new_service_id_map):
     new_service_relation_list = []
     if service_relations_list:
         for relation in service_relations_list:
             relation.pop("ID")
             new_service_relation = TenantServiceRelation(**relation)
             new_service_relation.tenant_id = tenant.tenant_id
             new_service_relation.service_id = old_new_service_id_map[relation["service_id"]]
             new_service_relation.dep_service_id = old_new_service_id_map[relation["dep_service_id"]]
             new_service_relation_list.append(new_service_relation)
         TenantServiceRelation.objects.bulk_create(new_service_relation_list)
 def dep_services(self, service_relation):
     dep_relation_repo.delete_service_relation(self.tenant.tenant_id, self.service.service_id)
     if not service_relation:
         return
     relations = []
     for relation in service_relation:
         relation.pop("ID")
         new_service_relation = TenantServiceRelation(**relation)
         relations.append(new_service_relation)
     TenantServiceRelation.objects.bulk_create(relations)
示例#3
0
 def _create_component_deps(self, component_ids):
     component_deps = []
     for snap in self.snapshot["components"]:
         component_deps.extend([
             TenantServiceRelation(**dep)
             for dep in snap["service_relation"]
         ])
     # filter out the component dependencies which dep_service_id does not belong to the components
     return [
         dep for dep in component_deps
         if dep.dep_service_id in component_ids
     ]
示例#4
0
    def _create_component_deps(self, components):
        """
        组件唯一标识: cpt.component_source.service_share_uuid
        组件模板唯一标识: tmpl.get("service_share_uuid")
        被依赖组件唯一标识: dep["dep_service_key"]
        """
        components = {
            cpt.component_source.service_share_uuid: cpt.component
            for cpt in components
        }
        original_components = {
            cpt.component_source.service_share_uuid: cpt.component
            for cpt in self.original_app.components()
        }

        deps = []
        for tmpl in self.app_template.get("apps", []):
            for dep in tmpl.get("dep_service_map_list", []):
                component_key = tmpl.get("service_share_uuid")
                component = components.get(component_key)
                if not component:
                    continue

                dep_component_key = dep["dep_service_key"]
                dep_component = components.get(
                    dep_component_key) if components.get(
                        dep_component_key) else original_components.get(
                            dep_component_key)
                if not dep_component:
                    logger.info(
                        "The component({}) cannot find the dependent component({})"
                        .format(component_key, dep_component_key))
                    continue

                dep = TenantServiceRelation(
                    tenant_id=component.tenant_id,
                    service_id=component.service_id,
                    dep_service_id=dep_component.service_id,
                    dep_service_type="application",
                    dep_order=0,
                )
                deps.append(dep)
        return deps
 def __save_service_relations(self, tenant, service_relations_list,
                              old_new_service_id_map, same_team,
                              same_region):
     new_service_relation_list = []
     if service_relations_list:
         for relation in service_relations_list:
             relation.pop("ID")
             new_service_relation = TenantServiceRelation(**relation)
             new_service_relation.tenant_id = tenant.tenant_id
             new_service_relation.service_id = old_new_service_id_map[
                 relation["service_id"]]
             if old_new_service_id_map.get(relation["dep_service_id"]):
                 new_service_relation.dep_service_id = old_new_service_id_map[
                     relation["dep_service_id"]]
             elif same_team and same_region:
                 # check new app region is same as old app
                 new_service_relation.dep_service_id = relation[
                     "dep_service_id"]
             else:
                 continue
             new_service_relation_list.append(new_service_relation)
         TenantServiceRelation.objects.bulk_create(
             new_service_relation_list)
示例#6
0
 def create_tenant_service_relation(self, **kwargs):
     tenant_service_relation = TenantServiceRelation(**kwargs)
     tenant_service_relation.save()
     return tenant_service_relation
示例#7
0
 def init(self):
     self.sources = [
         Tenants(),
         TenantRegionInfo(),
         TenantRegionResource(),
         ServiceInfo(),
         TenantServiceInfo(),
         TenantServiceInfoDelete(),
         TenantServiceLog(),
         TenantServiceRelation(),
         TenantServiceEnv(),
         TenantServiceAuth(),
         TenantServiceExtendMethod(),
         ServiceDomain(),
         ServiceDomainCertificate(),
         PermRelService(),
         PermRelTenant(),
         PhoneCode(),
         TenantServiceL7Info(),
         TenantServiceEnvVar(),
         TenantServicesPort(),
         TenantServiceMountRelation(),
         TenantServiceVolume(),
         TenantServiceConfigurationFile(),
         ServiceGroup(),
         ServiceGroupRelation(),
         ImageServiceRelation(),
         ComposeServiceRelation(),
         ServiceRule(),
         ServiceRuleHistory(),
         ServiceCreateStep(),
         ServiceProbe(),
         ConsoleConfig(),
         TenantEnterprise(),
         TenantEnterpriseToken(),
         TenantServiceGroup(),
         ServiceTcpDomain(),
         ThirdPartyServiceEndpoints(),
         ServiceWebhooks(),
         GatewayCustomConfiguration(),
         ConsoleSysConfig(),
         RainbondCenterApp(),
         RainbondCenterAppInherit(),
         RainbondCenterPlugin(),
         ServiceShareRecord(),
         EnterpriseUserPerm(),
         TenantUserRole(),
         TenantUserPermission(),
         TenantUserRolePermission(),
         PermGroup(),
         ServiceRelPerms(),
         AppExportRecord(),
         UserMessage(),
         AppImportRecord(),
         GroupAppBackupRecord(),
         GroupAppMigrateRecord(),
         GroupAppBackupImportRecord(),
         Applicants(),
         DeployRelation(),
         ServiceBuildSource(),
         TenantServiceBackup(),
         AppUpgradeRecord(),
         ServiceUpgradeRecord(),
         RegionConfig(),
         CloundBangImages(),
         Announcement(),
     ]