def add_service_dependency(self, tenant, service, dep_service_id): dep_service_relation = dep_relation_repo.get_depency_by_serivce_id_and_dep_service_id(tenant.tenant_id, service.service_id, dep_service_id) if dep_service_relation: return 412, u"当前应用已被关联", None dep_service = service_repo.get_service_by_tenant_and_id(tenant.tenant_id, dep_service_id) is_duplicate = self.__is_env_duplicate(tenant, service, dep_service) if is_duplicate: return 412, u"要关联的应用的变量与已关联的应用变量重复,请修改后再试", None if service.create_status == "complete": task = {} task["dep_service_id"] = dep_service_id task["tenant_id"] = tenant.tenant_id task["dep_service_type"] = dep_service.service_type task["enterprise_id"] = tenant.enterprise_id region_api.add_service_dependency(service.service_region, tenant.tenant_name, service.service_alias, task) tenant_service_relation = { "tenant_id": tenant.tenant_id, "service_id": service.service_id, "dep_service_id": dep_service_id, "dep_service_type": dep_service.service_type, "dep_order": 0, } dep_relation = dep_relation_repo.add_service_dependency(**tenant_service_relation) return 200, u"success", dep_relation
def add_service_dependency(self, tenant, service, dep_service_id, open_inner=None, container_port=None, user_name=''): dep_service_relation = dep_relation_repo.get_depency_by_serivce_id_and_dep_service_id( tenant.tenant_id, service.service_id, dep_service_id) if dep_service_relation: return 212, "当前组件已被关联", None dep_service = service_repo.get_service_by_tenant_and_id( tenant.tenant_id, dep_service_id) # 开启对内端口 if open_inner: self.__open_port(tenant, dep_service, container_port, user_name) else: # 校验要依赖的组件是否开启了对内端口 open_inner_services = port_repo.get_service_ports( tenant.tenant_id, dep_service.service_id).filter(is_inner_service=True) if not open_inner_services: service_ports = port_repo.get_service_ports( tenant.tenant_id, dep_service.service_id) port_list = [ service_port.container_port for service_port in service_ports ] return 201, "要关联的组件暂未开启对内端口,是否打开", port_list is_duplicate = self.__is_env_duplicate(tenant, service, dep_service) if is_duplicate: return 412, "要关联的组件的变量与已关联的组件变量重复,请修改后再试", None if service.create_status == "complete": task = dict() task["dep_service_id"] = dep_service_id task["tenant_id"] = tenant.tenant_id task["dep_service_type"] = dep_service.service_type task["enterprise_id"] = tenant.enterprise_id task["operator"] = user_name region_api.add_service_dependency(service.service_region, tenant.tenant_name, service.service_alias, task) tenant_service_relation = { "tenant_id": tenant.tenant_id, "service_id": service.service_id, "dep_service_id": dep_service_id, "dep_service_type": dep_service.service_type, "dep_order": 0, } dep_relation = dep_relation_repo.add_service_dependency( **tenant_service_relation) # component dependency change, will change export network governance plugin configuration if service.create_status == "complete": from console.services.plugin import app_plugin_service app_plugin_service.update_config_if_have_export_plugin( tenant, service) return 200, "success", dep_relation
def add_service_dependency(self, tenant, service, dep_service_id, open_inner=None, container_port=None): dep_service_relation = dep_relation_repo.get_depency_by_serivce_id_and_dep_service_id( tenant.tenant_id, service.service_id, dep_service_id) if dep_service_relation: return 212, u"当前应用已被关联", None dep_service = service_repo.get_service_by_tenant_and_id( tenant.tenant_id, dep_service_id) # 开启对内端口 if open_inner: tenant_service_port = port_service.get_service_port_by_port( dep_service, int(container_port)) code, msg, data = port_service.manage_port( tenant, dep_service, dep_service.service_region, int(tenant_service_port.container_port), "open_inner", tenant_service_port.protocol, tenant_service_port.port_alias) if code != 200: return 412, u"开启对内端口失败", None # 校验要依赖的服务是否开启了对内端口 open_inner_services = port_repo.get_service_ports( tenant.tenant_id, dep_service.service_id).filter(is_inner_service=True) if not open_inner_services: service_ports = port_repo.get_service_ports( tenant.tenant_id, dep_service.service_id) port_list = [ service_port.container_port for service_port in service_ports ] return 201, u"要关联的服务暂未开启对内端口,是否打开", port_list is_duplicate = self.__is_env_duplicate(tenant, service, dep_service) if is_duplicate: return 412, u"要关联的应用的变量与已关联的应用变量重复,请修改后再试", None if service.create_status == "complete": task = dict() task["dep_service_id"] = dep_service_id task["tenant_id"] = tenant.tenant_id task["dep_service_type"] = dep_service.service_type task["enterprise_id"] = tenant.enterprise_id region_api.add_service_dependency(service.service_region, tenant.tenant_name, service.service_alias, task) tenant_service_relation = { "tenant_id": tenant.tenant_id, "service_id": service.service_id, "dep_service_id": dep_service_id, "dep_service_type": dep_service.service_type, "dep_order": 0, } dep_relation = dep_relation_repo.add_service_dependency( **tenant_service_relation) return 200, u"success", dep_relation
def create_service_relation(self, tenant, service, dep_service_id): """ raise ErrDepServiceNotFound raise ServiceRelationAlreadyExist raise InnerPortNotFound """ self.check_relation(service.tenant_id, service.service_id, dep_service_id) dep_service = service_repo.get_service_by_tenant_and_id(tenant.tenant_id, dep_service_id) tenant_service_relation = { "tenant_id": tenant.tenant_id, "service_id": service.service_id, "dep_service_id": dep_service_id, "dep_service_type": dep_service.service_type, "dep_order": 0, } return dep_relation_repo.add_service_dependency(**tenant_service_relation)
def add_service_dependency(self, tenant, service, dep_service_id, open_inner=None, container_port=None): dep_service_relation = dep_relation_repo.get_depency_by_serivce_id_and_dep_service_id( tenant.tenant_id, service.service_id, dep_service_id) if dep_service_relation: return 212, u"当前组件已被关联", None dep_service = service_repo.get_service_by_tenant_and_id( tenant.tenant_id, dep_service_id) # 开启对内端口 if open_inner: openServicePorts = [] if container_port: tenant_service_port = port_service.get_service_port_by_port( dep_service, int(container_port)) openServicePorts.append(tenant_service_port) else: ports = port_service.get_service_ports(dep_service) if ports: openServicePorts.extend(ports) for tenant_service_port in openServicePorts: code, msg, data = port_service.manage_port( tenant, dep_service, dep_service.service_region, int(tenant_service_port.container_port), "open_inner", tenant_service_port.protocol, tenant_service_port.port_alias) if code != 200: logger.warning( "auto open depend service inner port faliure {}". format(msg)) else: logger.debug( "auto open depend service inner port success ") else: # 校验要依赖的组件是否开启了对内端口 open_inner_services = port_repo.get_service_ports( tenant.tenant_id, dep_service.service_id).filter(is_inner_service=True) if not open_inner_services: service_ports = port_repo.get_service_ports( tenant.tenant_id, dep_service.service_id) port_list = [ service_port.container_port for service_port in service_ports ] return 201, u"要关联的组件暂未开启对内端口,是否打开", port_list is_duplicate = self.__is_env_duplicate(tenant, service, dep_service) if is_duplicate: return 412, u"要关联的组件的变量与已关联的组件变量重复,请修改后再试", None if service.create_status == "complete": task = dict() task["dep_service_id"] = dep_service_id task["tenant_id"] = tenant.tenant_id task["dep_service_type"] = dep_service.service_type task["enterprise_id"] = tenant.enterprise_id region_api.add_service_dependency(service.service_region, tenant.tenant_name, service.service_alias, task) tenant_service_relation = { "tenant_id": tenant.tenant_id, "service_id": service.service_id, "dep_service_id": dep_service_id, "dep_service_type": dep_service.service_type, "dep_order": 0, } dep_relation = dep_relation_repo.add_service_dependency( **tenant_service_relation) return 200, u"success", dep_relation