dts-dance 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dts-dance
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: dts dance lib
5
5
  Keywords: observation,tools
6
6
  Requires-Python: >=3.12
7
- Requires-Dist: boto3<2.0.0,>=1.42.27
7
+ Requires-Dist: boto3<2.0.0,>=1.42.29
8
8
  Requires-Dist: loguru<0.8.0,>=0.7.3
9
9
  Requires-Dist: pyyaml<7.0.0,>=6.0.3
10
10
  Requires-Dist: requests<3.0.0,>=2.32.5
@@ -0,0 +1,14 @@
1
+ dtsdance/__init__.py,sha256=Yl_jEZ5weYfcrklnDvwB4wSgCOvMBLRRgWx0gHs3qfM,49
2
+ dtsdance/bytecloud.py,sha256=CQNebRy8UlILYmY8XhHhmEfW-WwW7SAlUh387X4OnY8,5646
3
+ dtsdance/dflow.py,sha256=XB6RClJzs9B5fhLofYvb5JazBF-iDfbtv1ETH6ENNUo,7074
4
+ dtsdance/dsyncer.py,sha256=3Oj1Ko5FuB_sUm9Hj-hBy95wee3b6TH2FXKoPFGsakM,11193
5
+ dtsdance/feishu_base.py,sha256=2j4ZM4PFqJ-9EhC6DQ1OmAg--3VBGZyyRuxyjL0j6OU,3733
6
+ dtsdance/feishu_table.py,sha256=ZUeoKrM4nmm5hFhc3vWOVYeLP390orm-284Od92G4iQ,8424
7
+ dtsdance/metrics_fe.py,sha256=hzIl5BJmuCrkqJOHELVzXm3YAqrPttbyVkKBglS4mgQ,18978
8
+ dtsdance/s3.py,sha256=Bh-cwLksfO5PewNtIzE_Md3rRLDLI1DUVoOD7Pou5T8,1294
9
+ dtsdance/spacex_bytedts.py,sha256=83lUU9sFPsvmZ0zLCGG_V6vMYXePKbEUeG1d6qfkQhE,2575
10
+ dtsdance/tcc_inner.py,sha256=6Tuq_r2nNCK_HC4hqEGh7UVAa8kDtuIcU95WBu4zuFQ,1623
11
+ dtsdance/tcc_open.py,sha256=Qb_ue3xH0CSsoReItdFKuvW7JsDTfFkDNIB_4zjzSQI,6893
12
+ dts_dance-0.2.2.dist-info/METADATA,sha256=ZRzPIxPE0Y4uJRTwBK2_PukFRUBuHb8xkuxQPGQnOjo,793
13
+ dts_dance-0.2.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
+ dts_dance-0.2.2.dist-info/RECORD,,
dtsdance/bytecloud.py CHANGED
@@ -22,13 +22,14 @@ class ByteCloudClient:
22
22
  # 每小时刷新一次,单位为秒
23
23
  _REFRESH_INTERVAL = 1 * 60 * 60
24
24
 
25
- def __init__(self, sites: dict[str, SiteConfig]):
25
+ def __init__(self, enable_jwt_cache: bool, sites: dict[str, SiteConfig] | None = None) -> None:
26
26
  """
27
27
  初始化 ByteCloud Client
28
28
  从配置文件加载所有环境的信息,并为每个环境初始化 JWT 令牌
29
29
  sites 中保存内容 list[(name, endpoint, svc_account, svc_secret)]
30
30
  """
31
- self.sites = sites
31
+ self.enable_jwt_cache = enable_jwt_cache
32
+ self.sites = sites if sites is not None else {}
32
33
 
33
34
  # 初始化线程锁,用于保护 jwt_tokens 的并发访问
34
35
  self.token_lock = threading.Lock()
@@ -36,11 +37,14 @@ class ByteCloudClient:
36
37
  # 初始化 JWT 令牌缓存,按环境名称索引
37
38
  self.jwt_tokens: Dict[str, str] = {}
38
39
 
39
- # 更新所有环境的 JWT 令牌
40
- self._refresh_tokens()
40
+ if enable_jwt_cache:
41
+ logger.info("启用 JWT 令牌缓存")
41
42
 
42
- # 启动 JWT 令牌刷新线程
43
- self._start_refresh_thread()
43
+ # 更新所有环境的 JWT 令牌
44
+ self._refresh_tokens()
45
+
46
+ # 启动 JWT 令牌刷新线程
47
+ self._start_refresh_thread()
44
48
 
45
49
  def _start_refresh_thread(self):
46
50
  """
@@ -131,11 +135,15 @@ class ByteCloudClient:
131
135
  """
132
136
  获取指定站点的 JWT 令牌
133
137
  """
134
- # 使用线程锁保护并发访问
135
- with self.token_lock:
136
- if site not in self.jwt_tokens:
137
- raise KeyError(f"站点 {site} JWT 令牌不存在")
138
- return self.jwt_tokens[site]
138
+ if self.enable_jwt_cache:
139
+ # 使用线程锁保护并发访问
140
+ with self.token_lock:
141
+ if site not in self.jwt_tokens:
142
+ raise KeyError(f"站点 {site} 的 JWT 令牌不存在")
143
+ return self.jwt_tokens[site]
144
+ else:
145
+ site_config = self.get_site_config(site)
146
+ return self._acquire_jwt_token(site_config.endpoint, site_config.svc_secret)
139
147
 
140
148
  def build_request_headers(self, site: str) -> dict[str, str]:
141
149
  """
@@ -150,7 +158,7 @@ class ByteCloudClient:
150
158
  jwt_token = self.get_jwt_token(site)
151
159
  return {"Content-Type": "application/json", "x-jwt-token": jwt_token}
152
160
 
153
- def get_site_info(self, site: str) -> SiteConfig:
161
+ def get_site_config(self, site: str) -> SiteConfig:
154
162
  """
155
163
  获取指定环境的信息
156
164
 
dtsdance/dflow.py CHANGED
@@ -64,7 +64,7 @@ class DFlowClient:
64
64
  dict[str, Any]: DFlow 任务信息,包含 create_time 等字段
65
65
  """
66
66
  # 构建 API URL
67
- site_info = self.bytecloud_client.get_site_info(site)
67
+ site_info = self.bytecloud_client.get_site_config(site)
68
68
  url = f"{site_info.endpoint}/api/v1/bytedts/api/bytedts/v3/DescribeTaskInfo"
69
69
 
70
70
  # 构建请求数据
@@ -106,7 +106,7 @@ class DFlowClient:
106
106
  dict[str, Any]: DFlow 进程信息,包含 create_time 等字段
107
107
  """
108
108
  # 构建 API URL
109
- site_info = self.bytecloud_client.get_site_info(site)
109
+ site_info = self.bytecloud_client.get_site_config(site)
110
110
  url = f"{site_info.endpoint}/api/v1/bytedts/api/bytedts/v3/DescribeDFlowDetail"
111
111
 
112
112
  # 构建请求数据
@@ -149,7 +149,7 @@ class DFlowClient:
149
149
  str: DFlow 任务详情页面的 URL
150
150
  """
151
151
  # 根据环境生成对应的 scope 参数
152
- site_info = self.bytecloud_client.get_site_info(site)
152
+ site_info = self.bytecloud_client.get_site_config(site)
153
153
  return f"{site_info.endpoint}/bytedts/datasync/detail/{task_id}?scope={site}"
154
154
 
155
155
  def init_resources(self, site: str, ctrl_env: str) -> bool:
@@ -164,7 +164,7 @@ class DFlowClient:
164
164
  bool: CTRL 环境资源初始化结果
165
165
  """
166
166
  # 构建 API URL
167
- site_info = self.bytecloud_client.get_site_info(site)
167
+ site_info = self.bytecloud_client.get_site_config(site)
168
168
  url = f"{site_info.endpoint}/api/v1/bytedts/api/bytedts/v3/InitSystemResource"
169
169
 
170
170
  # 构建请求数据
@@ -189,7 +189,7 @@ class DFlowClient:
189
189
  list[str]: CTRL 环境资源列表
190
190
  """
191
191
  # 构建 API URL
192
- site_info = self.bytecloud_client.get_site_info(site)
192
+ site_info = self.bytecloud_client.get_site_config(site)
193
193
  url = f"{site_info.endpoint}/api/v1/bytedts/api/bytedts/v3/DescribeResources"
194
194
 
195
195
  # 构建请求数据
dtsdance/dsyncer.py CHANGED
@@ -89,7 +89,7 @@ class DSyncerClient:
89
89
  dict[str, str]: DSyncer 任务的 rocket_mq_connection 信息,只包含 cluster、topic 和 group 字段
90
90
  """
91
91
  # 构建 API URL
92
- site_info = self.bytecloud_client.get_site_info(site)
92
+ site_info = self.bytecloud_client.get_site_config(site)
93
93
  url = f"{site_info.endpoint}/api/v1/dsyncer/openapi/taskinfo/{task_id}/"
94
94
 
95
95
  # 准备请求头
@@ -102,7 +102,7 @@ class DSyncerClient:
102
102
  获取迁移后的 DFlow 任务信息
103
103
  """
104
104
  # 构建 API URL
105
- site_info = self.bytecloud_client.get_site_info(site)
105
+ site_info = self.bytecloud_client.get_site_config(site)
106
106
  url = f"{site_info.endpoint}/api/v1/dsyncer/openapi/taskinfo/{task_id}/migrate/"
107
107
 
108
108
  # 准备请求头
@@ -144,7 +144,7 @@ class DSyncerClient:
144
144
  Returns:
145
145
  str: DSyncer 任务详情页面的 URL
146
146
  """
147
- site_info = self.bytecloud_client.get_site_info(site)
147
+ site_info = self.bytecloud_client.get_site_config(site)
148
148
  return DSyncer_Task_Detail_URL.format(endpoint=site_info.endpoint, task_id=task_id)
149
149
 
150
150
  def generate_task_grafana_url(self, task_id: str, change_time: str) -> str:
@@ -208,7 +208,7 @@ class DSyncerClient:
208
208
  bool: 如果任务正在迁移中,返回 True;否则返回 False
209
209
  """
210
210
  # 构建 API URL
211
- site_info = self.bytecloud_client.get_site_info(site)
211
+ site_info = self.bytecloud_client.get_site_config(site)
212
212
  url = f"{site_info.endpoint}/api/v1/dsyncer/secret_api/task/migrate/check"
213
213
 
214
214
  # 准备请求头
@@ -230,7 +230,7 @@ class DSyncerClient:
230
230
  执行回滚
231
231
  """
232
232
  # 构建 API URL
233
- site_info = self.bytecloud_client.get_site_info(site)
233
+ site_info = self.bytecloud_client.get_site_config(site)
234
234
  url = f"{site_info.endpoint}/api/v1/dsyncer/secret_api/task/rollback_migrate2dsyncer/"
235
235
 
236
236
  # 准备请求头
@@ -249,7 +249,7 @@ class DSyncerClient:
249
249
  标记迁移成功
250
250
  """
251
251
  # 构建 API URL
252
- site_info = self.bytecloud_client.get_site_info(site)
252
+ site_info = self.bytecloud_client.get_site_config(site)
253
253
  url = f"{site_info.endpoint}/api/v1/dsyncer/secret_api/task/mark_migrate_success/"
254
254
 
255
255
  # 准备请求头
@@ -271,7 +271,7 @@ class DSyncerClient:
271
271
  Optional[str]: 错误信息,成功时返回None,失败时返回错误信息
272
272
  """
273
273
  # 构建 API URL
274
- site_info = self.bytecloud_client.get_site_info(site)
274
+ site_info = self.bytecloud_client.get_site_config(site)
275
275
  url = f"{site_info.endpoint}/api/v1/dsyncer/secret_api/task/migrate2dflow/single"
276
276
 
277
277
  # 准备请求头
@@ -5,7 +5,7 @@ from loguru import logger
5
5
 
6
6
 
7
7
  class GatewayInfo(NamedTuple):
8
- mgr_env: str
8
+ mgr_name: str
9
9
  ctrl_name: str
10
10
  gateway_endpoint: str
11
11
  auth_user: str
@@ -26,7 +26,7 @@ class SpaceXClient:
26
26
  self.bytecloud_client = bytecloud_client
27
27
 
28
28
  def list_mgr(self, site: str) -> list[Any]:
29
- site_info = self.bytecloud_client.get_site_info(site)
29
+ site_info = self.bytecloud_client.get_site_config(site)
30
30
  url = f"{site_info.endpoint_bytedts_spacex}/bytedts/v1/queryServerMeta"
31
31
 
32
32
  try:
@@ -41,10 +41,11 @@ class SpaceXClient:
41
41
  raise
42
42
 
43
43
  def register_gateway(self, site: str, gateway_info: GatewayInfo) -> bool:
44
- site_info = self.bytecloud_client.get_site_info(site)
44
+ site_info = self.bytecloud_client.get_site_config(site)
45
45
  url = f"{site_info.endpoint_bytedts_spacex}/bytedts/v1/registryGateway"
46
46
  data_raw = {
47
- "server_region": gateway_info.mgr_env,
47
+ "region": gateway_info.mgr_name,
48
+ "server_region": gateway_info.mgr_name,
48
49
  "cluster_region": gateway_info.ctrl_name,
49
50
  "cluster_name": gateway_info.ctrl_name,
50
51
  "server_domain": gateway_info.gateway_endpoint,
@@ -55,6 +56,10 @@ class SpaceXClient:
55
56
  "frontend_password": gateway_info.auth_password,
56
57
  "gw_meta_db": gateway_info.gw_meta_db,
57
58
  "gateway_type": "psm",
59
+ "runtime_psm": "bytedts.dflow.rownott",
60
+ "tao_service_name": "inf.bytedts.agent",
61
+ "tao_service_node_id": 1071,
62
+ "unified_tao_service": 1,
58
63
  }
59
64
  try:
60
65
  response = requests.post(url, json=data_raw, headers=self.bytecloud_client.build_request_headers(site))
dtsdance/tcc_inner.py CHANGED
@@ -24,7 +24,7 @@ class TCCInnerClient:
24
24
  """
25
25
  List TCC configurations.
26
26
  """
27
- site_info = self.bytecloud_client.get_site_info(site)
27
+ site_info = self.bytecloud_client.get_site_config(site)
28
28
  url = f"{site_info.endpoint}/api/v3/tcc/bcc/config/list_v2"
29
29
 
30
30
  data_raw = {
@@ -1,14 +0,0 @@
1
- dtsdance/__init__.py,sha256=Yl_jEZ5weYfcrklnDvwB4wSgCOvMBLRRgWx0gHs3qfM,49
2
- dtsdance/bytecloud.py,sha256=SN82KIYAfq16s06-HUoj37PbgSbUa7MoFFcah2kaXOk,5213
3
- dtsdance/dflow.py,sha256=N9u7uB9UyUbB2FswBezXB9SbwmlDr3PWhY_eUZJeQ-8,7064
4
- dtsdance/dsyncer.py,sha256=X59sKDvK6rDeumCajepcqSSJysDfvJByYZAhcdOyNLw,11179
5
- dtsdance/feishu_base.py,sha256=2j4ZM4PFqJ-9EhC6DQ1OmAg--3VBGZyyRuxyjL0j6OU,3733
6
- dtsdance/feishu_table.py,sha256=ZUeoKrM4nmm5hFhc3vWOVYeLP390orm-284Od92G4iQ,8424
7
- dtsdance/metrics_fe.py,sha256=hzIl5BJmuCrkqJOHELVzXm3YAqrPttbyVkKBglS4mgQ,18978
8
- dtsdance/s3.py,sha256=Bh-cwLksfO5PewNtIzE_Md3rRLDLI1DUVoOD7Pou5T8,1294
9
- dtsdance/spacex.py,sha256=eYPx3-VKgPK6-IO8-HPuX0-mxsM6kt1HMZqyDA_KPbw,2340
10
- dtsdance/tcc_inner.py,sha256=xy3N1N3BNl1oc2oMNHKhnsj47rAKOOJ-aXw8GtA2De8,1621
11
- dtsdance/tcc_open.py,sha256=Qb_ue3xH0CSsoReItdFKuvW7JsDTfFkDNIB_4zjzSQI,6893
12
- dts_dance-0.2.1.dist-info/METADATA,sha256=QQohyobEcAlWjdpCDwPBXzYlSRBZxeGcV-xfN9_ladU,793
13
- dts_dance-0.2.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
- dts_dance-0.2.1.dist-info/RECORD,,