@ant-yasa/uast-parser-java-js 0.1.15-beta
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.
- package/.babelrc +12 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +38 -0
- package/.mocharc-integration.js +1 -0
- package/.mocharc.js +4 -0
- package/.prettierignore +1 -0
- package/.prettierrc +4 -0
- package/LEGAL.md +7 -0
- package/README.md +35 -0
- package/antlr/Java.g4 +1008 -0
- package/antlr/JavaLexer.g4 +241 -0
- package/antlr/JavaLexer_origin.g4 +241 -0
- package/antlr/JavaParser.g4 +765 -0
- package/antlr/JavaParser_origin.g4 +766 -0
- package/dist/package.json +73 -0
- package/dist/src/frontend/java/ASTBuilder.d.ts +171 -0
- package/dist/src/frontend/java/ASTBuilder.js +2369 -0
- package/dist/src/frontend/java/ASTBuilder.js.map +1 -0
- package/dist/src/frontend/java/ErrorListener.d.ts +9 -0
- package/dist/src/frontend/java/ErrorListener.js +24 -0
- package/dist/src/frontend/java/ErrorListener.js.map +1 -0
- package/dist/src/frontend/java/antlr/JavaLexer.d.ts +154 -0
- package/dist/src/frontend/java/antlr/JavaLexer.js +812 -0
- package/dist/src/frontend/java/antlr/JavaLexer.js.map +1 -0
- package/dist/src/frontend/java/antlr/JavaListener.d.ts +1393 -0
- package/dist/src/frontend/java/antlr/JavaListener.js +4 -0
- package/dist/src/frontend/java/antlr/JavaListener.js.map +1 -0
- package/dist/src/frontend/java/antlr/JavaParser.d.ts +2065 -0
- package/dist/src/frontend/java/antlr/JavaParser.js +15279 -0
- package/dist/src/frontend/java/antlr/JavaParser.js.map +1 -0
- package/dist/src/frontend/java/antlr/JavaVisitor.d.ts +892 -0
- package/dist/src/frontend/java/antlr/JavaVisitor.js +4 -0
- package/dist/src/frontend/java/antlr/JavaVisitor.js.map +1 -0
- package/dist/src/frontend/java/parser.d.ts +20 -0
- package/dist/src/frontend/java/parser.js +93 -0
- package/dist/src/frontend/java/parser.js.map +1 -0
- package/dist/src/frontend/java/testBuilder.d.ts +146 -0
- package/dist/src/frontend/java/testBuilder.js +464 -0
- package/dist/src/frontend/java/testBuilder.js.map +1 -0
- package/dist/src/frontend/java/types.d.ts +29 -0
- package/dist/src/frontend/java/types.js +3 -0
- package/dist/src/frontend/java/types.js.map +1 -0
- package/dist/src/frontend/javascript/parser.d.ts +8 -0
- package/dist/src/frontend/javascript/parser.js +1121 -0
- package/dist/src/frontend/javascript/parser.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +76 -0
- package/dist/src/index.js.map +1 -0
- package/output.txt +3820 -0
- package/package.json +73 -0
- package/tests/benchmark/base/class.js +32 -0
- package/tests/benchmark/base/class.js.json +1809 -0
- package/tests/benchmark/base/class_test.js +13 -0
- package/tests/benchmark/base/class_test.js.json +435 -0
- package/tests/benchmark/base/comment.js +21 -0
- package/tests/benchmark/base/comment.js.json +1443 -0
- package/tests/benchmark/base/demo.ts +1060 -0
- package/tests/benchmark/base/empty.js +4 -0
- package/tests/benchmark/base/empty.js.json +202 -0
- package/tests/benchmark/base/export.js +36 -0
- package/tests/benchmark/base/export.js.json +6345 -0
- package/tests/benchmark/base/export1.js +2 -0
- package/tests/benchmark/base/export1.js.json +251 -0
- package/tests/benchmark/base/export2.js +35 -0
- package/tests/benchmark/base/export2.js.json +3297 -0
- package/tests/benchmark/base/expressions.js +25 -0
- package/tests/benchmark/base/expressions.js.json +1654 -0
- package/tests/benchmark/base/for.js +7 -0
- package/tests/benchmark/base/for.js.json +738 -0
- package/tests/benchmark/base/function.js +15 -0
- package/tests/benchmark/base/function.js.json +1458 -0
- package/tests/benchmark/base/import.js +3 -0
- package/tests/benchmark/base/import.js.json +416 -0
- package/tests/benchmark/base/literal.js +27 -0
- package/tests/benchmark/base/literal.js.json +1234 -0
- package/tests/benchmark/base/param.js +4 -0
- package/tests/benchmark/base/param.js.json +410 -0
- package/tests/benchmark/base/parseerror.js +1 -0
- package/tests/benchmark/base/parseerror.js.json +191 -0
- package/tests/benchmark/base/patternlike.js +24 -0
- package/tests/benchmark/base/patternlike.js.json +3720 -0
- package/tests/benchmark/base/react.js +8 -0
- package/tests/benchmark/base/react.js.json +211 -0
- package/tests/benchmark/base/switch.js +11 -0
- package/tests/benchmark/base/switch.js.json +741 -0
- package/tests/benchmark/base/taint.ts +61 -0
- package/tests/benchmark/base/temp.js +311 -0
- package/tests/benchmark/base/temp.js.json +22170 -0
- package/tests/benchmark/base/tmp.js +134 -0
- package/tests/benchmark/base/tmp.js.json +15409 -0
- package/tests/benchmark/base/vardecl.js +9 -0
- package/tests/benchmark/base/vardecl.js.json +491 -0
- package/tests/index.js +43 -0
- package/tests/index.ts +66 -0
- package/tests/test.d.ts +0 -0
- package/tests/test.js +38 -0
- package/tests/test.ts +60 -0
- package/tsconfig.json +24 -0
- package/tsconfig.test.json +13 -0
- package/webpack.config.js +21 -0
|
@@ -0,0 +1,1060 @@
|
|
|
1
|
+
import { Service } from 'egg'
|
|
2
|
+
import { HostDAO } from '../dao/hostDAO'
|
|
3
|
+
import { ServiceDAO } from '../dao/serviceDAO'
|
|
4
|
+
import { ConfigDataDAO } from '../dao/configDataDAO';
|
|
5
|
+
import { ConfigGroupDAO } from '../dao/configGroupDAO';
|
|
6
|
+
import { throwCustomError } from '../errors'
|
|
7
|
+
import * as moment from 'moment'
|
|
8
|
+
|
|
9
|
+
const ERROR = require('../enums/errors')
|
|
10
|
+
const md5 = require('md5')
|
|
11
|
+
|
|
12
|
+
declare module 'egg' {
|
|
13
|
+
export interface IService {
|
|
14
|
+
summary: ServiceSummary;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class ServiceSummary extends Service {
|
|
19
|
+
public ret = {}
|
|
20
|
+
public async getSummary (serviceName: string) {
|
|
21
|
+
console.log(serviceName)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class RESOURCEMANAGER extends ServiceSummary {
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 根据rm的服务名查询rm的active的主机
|
|
29
|
+
*
|
|
30
|
+
* @param {any} rmServiceName //resource manager的服务名
|
|
31
|
+
* @returns
|
|
32
|
+
* @memberof RESOURCEMANAGER
|
|
33
|
+
*/
|
|
34
|
+
public async getRmActiveHostByRmServiceName (rmServiceName) {
|
|
35
|
+
let rmActiveHost = null
|
|
36
|
+
let serviceStatusRecord = await this.ctx.service.sql.select('service_status', {
|
|
37
|
+
where: {
|
|
38
|
+
idx_service_name: rmServiceName,
|
|
39
|
+
service_type: 'RESOURCEMANAGER'
|
|
40
|
+
},
|
|
41
|
+
columns: ['full_host_name']
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const options = {
|
|
45
|
+
method: 'GET',
|
|
46
|
+
timeout: 10000,
|
|
47
|
+
dataType: 'json'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < serviceStatusRecord.length; i++) {
|
|
51
|
+
let fullHostName = serviceStatusRecord[i].full_host_name
|
|
52
|
+
let url = 'http://' + fullHostName + ':8088/ws/v1/cluster/info'
|
|
53
|
+
try {
|
|
54
|
+
const ret = await this.ctx.curl(url, options)
|
|
55
|
+
if (ret.status === 200) { //返回成功
|
|
56
|
+
let data = ret.data
|
|
57
|
+
let haState = data.clusterInfo.haState
|
|
58
|
+
if (haState === 'ACTIVE') { //rm取得active的host
|
|
59
|
+
rmActiveHost = fullHostName
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
this.ctx.logger.info(err)
|
|
65
|
+
rmActiveHost = null
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return rmActiveHost
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 得到某个队列的任务列表
|
|
73
|
+
*
|
|
74
|
+
* @param {any} rmServiceName //resource manager的服务名
|
|
75
|
+
* @returns
|
|
76
|
+
* @memberof RESOURCEMANAGER
|
|
77
|
+
*/
|
|
78
|
+
public async getApps (rmActiveHost, queueName) {
|
|
79
|
+
const options = {
|
|
80
|
+
method: 'GET',
|
|
81
|
+
timeout: 10000,
|
|
82
|
+
dataType: 'json'
|
|
83
|
+
}
|
|
84
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/apps?queue=' + queueName
|
|
85
|
+
|
|
86
|
+
let apps = []
|
|
87
|
+
try {
|
|
88
|
+
const ret = await this.ctx.curl(url, options)
|
|
89
|
+
|
|
90
|
+
if (ret.status === 200) {
|
|
91
|
+
apps = ret.data.apps.app
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
this.ctx.logger.info(err)
|
|
95
|
+
apps = []
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return apps
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* token 目前通过 yarn-site.xml 的 yarn.resourcemanager.restful_api_tokens 配置,多个 token 之间逗号分隔
|
|
103
|
+
*
|
|
104
|
+
* @param {string} serviceName
|
|
105
|
+
* @param {string} rmActiveHost
|
|
106
|
+
* @memberof RESOURCEMANAGER
|
|
107
|
+
*/
|
|
108
|
+
private async getTokenOfSubmitPriority (serviceName: string, rmActiveHost: string) {
|
|
109
|
+
let ret = await this.ctx.dao.serviceStatus.selectOne({
|
|
110
|
+
idxServiceName: serviceName,
|
|
111
|
+
fullHostName: rmActiveHost
|
|
112
|
+
})
|
|
113
|
+
let configGroupId = ret.configGroupId
|
|
114
|
+
let currentVersion = await ConfigGroupDAO.getCurrentVersionById(configGroupId, this.ctx)
|
|
115
|
+
let configdataRecord = await ConfigDataDAO.getByConfigGroupIdAndVersion(configGroupId, currentVersion, this.ctx)
|
|
116
|
+
//多个 token 之间逗号分隔
|
|
117
|
+
let tokenStr = await this.ctx.service.config.getValueByFilekey(JSON.parse(configdataRecord.configData), 'yarn-site.xml', 'yarn.resourcemanager.restful_api_tokens')
|
|
118
|
+
let tokenArr = tokenStr.split(',')
|
|
119
|
+
return tokenArr
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 阻止某个队列的xx优先级以下的任务提交,含 xx 优先级
|
|
124
|
+
*
|
|
125
|
+
* @returns
|
|
126
|
+
* @memberof RESOURCEMANAGER
|
|
127
|
+
*/
|
|
128
|
+
public async setSubmitPriority (serviceName, rmActiveHost, queueName, priority) {
|
|
129
|
+
let tokenArr = await this.getTokenOfSubmitPriority(serviceName, rmActiveHost)
|
|
130
|
+
let token = tokenArr && tokenArr.length ? tokenArr[0] : ''
|
|
131
|
+
const options = {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
timeout: 1000,
|
|
134
|
+
dataType: 'json'
|
|
135
|
+
}
|
|
136
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/queue/' + queueName + '/submitPriority/' + priority + '?token=' + token
|
|
137
|
+
try {
|
|
138
|
+
const ret = await this.ctx.curl(url, options)
|
|
139
|
+
if (ret.status !== 200) {
|
|
140
|
+
throwCustomError(ERROR.E_YARN_REST_ERROR, {message: ret.data.diagnostics})
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
this.ctx.logger.info(err)
|
|
144
|
+
throw err
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public async killAppsUnderPriority (serviceName, rmActiveHost, queueName, priority) {
|
|
149
|
+
let tokenArr = await this.getTokenOfSubmitPriority(serviceName, rmActiveHost)
|
|
150
|
+
let token = tokenArr && tokenArr.length ? tokenArr[0] : ''
|
|
151
|
+
const options = {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
timeout: 1000,
|
|
154
|
+
dataType: 'json'
|
|
155
|
+
}
|
|
156
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/queue/' + queueName + '/killAppsUnderPriority/' + priority + '?token=' + token
|
|
157
|
+
try {
|
|
158
|
+
const ret = await this.ctx.curl(url, options)
|
|
159
|
+
if (ret.status !== 200) {
|
|
160
|
+
throwCustomError(ERROR.E_YARN_REST_ERROR, {message: ret.data.diagnostics})
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
this.ctx.logger.info(err)
|
|
164
|
+
throw err
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public async getSubmitPriorityOfQueue (rmActiveHost: string, queueName: string) {
|
|
169
|
+
let submitPriority = '-2147483648'
|
|
170
|
+
const options = {
|
|
171
|
+
method: 'GET',
|
|
172
|
+
timeout: 10000,
|
|
173
|
+
dataType: 'json'
|
|
174
|
+
}
|
|
175
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/queue/' + queueName + '/submitPriority'
|
|
176
|
+
try {
|
|
177
|
+
const ret = await this.ctx.curl(url, options)
|
|
178
|
+
if (ret.status === 200) { //返回成功
|
|
179
|
+
let data = ret.data
|
|
180
|
+
let priorityInfo = data.priorityInfo
|
|
181
|
+
submitPriority = priorityInfo
|
|
182
|
+
}
|
|
183
|
+
} catch (err) {
|
|
184
|
+
this.ctx.logger.info(err)
|
|
185
|
+
submitPriority = '未知'
|
|
186
|
+
}
|
|
187
|
+
return submitPriority
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public async getSummary (serviceName: string) {
|
|
191
|
+
const options = {
|
|
192
|
+
method: 'GET',
|
|
193
|
+
timeout: 10000,
|
|
194
|
+
dataType: 'json'
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let rmHost
|
|
198
|
+
let serviceStatusRecord = await this.ctx.service.sql.select('service_status', {
|
|
199
|
+
where: {
|
|
200
|
+
idx_service_name: serviceName,
|
|
201
|
+
service_type: 'RESOURCEMANAGER'
|
|
202
|
+
},
|
|
203
|
+
columns: ['full_host_name']
|
|
204
|
+
})
|
|
205
|
+
// serviceStatusRecord = [{
|
|
206
|
+
// full_host_name: 'antyarn1.inc.alipay.net'
|
|
207
|
+
// }]
|
|
208
|
+
// serviceStatusRecord = [{
|
|
209
|
+
// full_host_name: 'rm-dsaas.prefromoffice.alipay.net'
|
|
210
|
+
// }, {
|
|
211
|
+
// full_host_name: 'rm2-dsaas.prefromoffice.alipay.net'
|
|
212
|
+
// }]
|
|
213
|
+
//得到resourcemanager的Active和StandBy的RM
|
|
214
|
+
this.ret['haState'] = []
|
|
215
|
+
for (let i = 0; i < serviceStatusRecord.length; i++) {
|
|
216
|
+
let fullHostName = serviceStatusRecord[i].full_host_name
|
|
217
|
+
let url = 'http://' + fullHostName + ':8088/ws/v1/cluster/info'
|
|
218
|
+
try {
|
|
219
|
+
const ret = await this.ctx.curl(url, options)
|
|
220
|
+
if (ret.status === 200) { //返回成功
|
|
221
|
+
let data = ret.data
|
|
222
|
+
let haState = data.clusterInfo.haState
|
|
223
|
+
let state = data.clusterInfo.state
|
|
224
|
+
if (haState === 'ACTIVE') { //rm取得active的host
|
|
225
|
+
rmHost = fullHostName
|
|
226
|
+
this.ret['rmActiveHost'] = rmHost
|
|
227
|
+
}
|
|
228
|
+
this.ret['haState'].push({
|
|
229
|
+
rmHost: fullHostName,
|
|
230
|
+
state: state,
|
|
231
|
+
haState: haState
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
} catch (err) {
|
|
235
|
+
this.ctx.logger.info(err)
|
|
236
|
+
this.ret['haState'].push({
|
|
237
|
+
rmHost: fullHostName,
|
|
238
|
+
state: 'n/a',
|
|
239
|
+
haState: 'n/a'
|
|
240
|
+
})
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//得到metrics统计信息
|
|
244
|
+
try {
|
|
245
|
+
let url = 'http://' + rmHost + ':8088/ws/v1/cluster/metrics'
|
|
246
|
+
let ret = await this.ctx.curl(url, options)
|
|
247
|
+
|
|
248
|
+
if (ret.status === 200) { //返回成功
|
|
249
|
+
let data = ret.data
|
|
250
|
+
//得到NodeManagers Status的统计信息
|
|
251
|
+
let nmStatus = data.clusterMetrics.totalNodes + ' total / ' +
|
|
252
|
+
data.clusterMetrics.activeNodes + ' active / ' +
|
|
253
|
+
data.clusterMetrics.lostNodes + ' lost / ' +
|
|
254
|
+
data.clusterMetrics.unhealthyNodes + ' unhealthy / ' +
|
|
255
|
+
data.clusterMetrics.rebootedNodes + ' rebooted / ' +
|
|
256
|
+
data.clusterMetrics.decommissioningNodes + ' decommissioning / ' +
|
|
257
|
+
data.clusterMetrics.decommissionedNodes + ' decommissioned / ' +
|
|
258
|
+
data.clusterMetrics.shutdownNodes + ' shutdown'
|
|
259
|
+
//得到Applications的统计信息
|
|
260
|
+
let applicationStatus = data.clusterMetrics.appsSubmitted + ' submitted / ' +
|
|
261
|
+
data.clusterMetrics.appsCompleted + ' completed / ' +
|
|
262
|
+
data.clusterMetrics.appsPending + ' pending / ' +
|
|
263
|
+
data.clusterMetrics.appsRunning + ' running / ' +
|
|
264
|
+
data.clusterMetrics.appsFailed + ' failed / ' +
|
|
265
|
+
data.clusterMetrics.appsKilled + ' killed'
|
|
266
|
+
//得到Containers的统计信息
|
|
267
|
+
let containerStatus = data.clusterMetrics.containersAllocated + ' allocated / ' +
|
|
268
|
+
data.clusterMetrics.containersReserved + ' pending / ' +
|
|
269
|
+
data.clusterMetrics.containersPending + ' reserved'
|
|
270
|
+
//得到Cluster Memory的统计信息
|
|
271
|
+
let clusterMemoryStatus = (data.clusterMetrics.totalMB / 1024.0).toFixed(2) + ' GB total / ' +
|
|
272
|
+
(data.clusterMetrics.availableMB / 1014.0).toFixed(2) + ' GB available / ' +
|
|
273
|
+
(data.clusterMetrics.allocatedMB / 1024.0).toFixed(2) + ' GB allocated / ' +
|
|
274
|
+
(data.clusterMetrics.reservedMB / 1024.0).toFixed(2) + ' GB reserved'
|
|
275
|
+
this.ret['nmStatus'] = nmStatus
|
|
276
|
+
this.ret['applicationStatus'] = applicationStatus
|
|
277
|
+
this.ret['containerStatus'] = containerStatus
|
|
278
|
+
this.ret['clusterMemoryStatus'] = clusterMemoryStatus
|
|
279
|
+
}
|
|
280
|
+
} catch (err) {
|
|
281
|
+
this.ctx.logger.info(err)
|
|
282
|
+
this.ret['nmStatus'] = 'n/a total / n/a active / n/a lost / n/a unhealthy / n/a rebooted / n/a decommissioning / n/a decommissioned / n/a shutdown'
|
|
283
|
+
this.ret['applicationStatus'] = 'n/a submitted / n/a completed / n/a pending / n/a running / n/a failed / n/a killed'
|
|
284
|
+
this.ret['containerStatus'] = 'n/a allocated / n/a pending / n/a reserved'
|
|
285
|
+
this.ret['clusterMemoryStatus'] = 'n/a GB total / n/a GB available / n/a GB allocated / n/a GB reserved'
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//得到任务队列信息
|
|
289
|
+
try {
|
|
290
|
+
let url = 'http://' + rmHost + ':8088/ws/v1/cluster/scheduler'
|
|
291
|
+
let ret = await this.ctx.curl(url, options)
|
|
292
|
+
if (ret.status === 200) { //返回成功
|
|
293
|
+
this.ret['queue'] = []
|
|
294
|
+
let data = ret.data
|
|
295
|
+
//queue是队列数组
|
|
296
|
+
let root = data.scheduler.schedulerInfo.queueName
|
|
297
|
+
let queue = data.scheduler.schedulerInfo.queues.queue
|
|
298
|
+
|
|
299
|
+
for (let i = 0; i < queue.length; i++) {
|
|
300
|
+
let item = queue[i]
|
|
301
|
+
let queueName = root + '.' + item.queueName
|
|
302
|
+
let state = item.state
|
|
303
|
+
let numApplications = parseInt(item.numApplications)
|
|
304
|
+
let capacityInfo = []
|
|
305
|
+
if (item.capacities.queueCapacitiesByPartition && item.capacities.queueCapacitiesByPartition.length) {
|
|
306
|
+
const queueCapacitiesByPartition = item.capacities.queueCapacitiesByPartition
|
|
307
|
+
let partitionName = null
|
|
308
|
+
for (let i = 0; i < queueCapacitiesByPartition.length; i++) {
|
|
309
|
+
partitionName = queueCapacitiesByPartition[i].partitionName
|
|
310
|
+
? queueCapacitiesByPartition[i].partitionName : '<DEFAULT_PARTITION>'
|
|
311
|
+
let capacity = queueCapacitiesByPartition[i].capacity.toFixed(2)
|
|
312
|
+
let usedCapacity = queueCapacitiesByPartition[i].usedCapacity.toFixed(2)
|
|
313
|
+
let maxCapacity = queueCapacitiesByPartition[i].maxCapacity.toFixed(2)
|
|
314
|
+
let absoluteCapacity = queueCapacitiesByPartition[i].absoluteCapacity.toFixed(2)
|
|
315
|
+
let absoluteUsedCapacity = queueCapacitiesByPartition[i].absoluteUsedCapacity.toFixed(2)
|
|
316
|
+
let absoluteMaxCapacity = queueCapacitiesByPartition[i].absoluteMaxCapacity.toFixed(2)
|
|
317
|
+
capacityInfo.push({
|
|
318
|
+
partitionName,
|
|
319
|
+
capacity,
|
|
320
|
+
usedCapacity,
|
|
321
|
+
maxCapacity,
|
|
322
|
+
absoluteCapacity,
|
|
323
|
+
absoluteUsedCapacity,
|
|
324
|
+
absoluteMaxCapacity
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
let submitPriority = await this.getSubmitPriorityOfQueue(rmHost, queueName)
|
|
329
|
+
let queueItem = {
|
|
330
|
+
queueName,
|
|
331
|
+
state,
|
|
332
|
+
numApplications,
|
|
333
|
+
submitPriority,
|
|
334
|
+
capacityInfo
|
|
335
|
+
}
|
|
336
|
+
this.ret['queue'].push(queueItem)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} catch (err) {
|
|
340
|
+
this.ctx.logger.info(err)
|
|
341
|
+
this.ret['queue'] = []
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export class NODEMANAGER extends ServiceSummary {
|
|
347
|
+
/**
|
|
348
|
+
* 根据NM的serviceName查找RM的active主机
|
|
349
|
+
*
|
|
350
|
+
* @param {string} nmServiceName nm服务名
|
|
351
|
+
* @returns 返回active的RM主机名
|
|
352
|
+
* @memberof NODEMANAGER
|
|
353
|
+
*/
|
|
354
|
+
public async getActiveRmHostByNmServiceName (nmServiceName: string) {
|
|
355
|
+
let serviceRecord = await this.ctx.service.sql.select('service', {
|
|
356
|
+
where: {
|
|
357
|
+
idx_service_name: nmServiceName
|
|
358
|
+
},
|
|
359
|
+
columns: ['cluster_name']
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
let clusterName = serviceRecord.length ? serviceRecord[0].cluster_name : ''
|
|
363
|
+
|
|
364
|
+
//查询与 nodemanager 集群同一集群下的 resourcemanager 的service name
|
|
365
|
+
serviceRecord = await this.ctx.service.sql.select('service', {
|
|
366
|
+
where: {
|
|
367
|
+
cluster_name: clusterName,
|
|
368
|
+
idx_service_type: 'RESOURCEMANAGER'
|
|
369
|
+
},
|
|
370
|
+
columns: ['idx_service_name']
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
//同一YARN集群下的RM的serviceName
|
|
374
|
+
let rmServcieName = serviceRecord.length ? serviceRecord[0].idx_service_name : ''
|
|
375
|
+
let resourceManager = new RESOURCEMANAGER(this.ctx)
|
|
376
|
+
let rmActiveHost = await resourceManager.getRmActiveHostByRmServiceName(rmServcieName)
|
|
377
|
+
return rmActiveHost
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 返回该YARN集群中的队列信息
|
|
382
|
+
* 返回格式参考 https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_Scheduler_API
|
|
383
|
+
*
|
|
384
|
+
* @param {string} rmActiveHost //active的RM主机名
|
|
385
|
+
* @returns
|
|
386
|
+
* @memberof RESOURCEMANAGER
|
|
387
|
+
*/
|
|
388
|
+
public async getClusterQueuesByRmHost (rmActiveHost: string) {
|
|
389
|
+
const options = {
|
|
390
|
+
method: 'GET',
|
|
391
|
+
timeout: 10000,
|
|
392
|
+
dataType: 'json'
|
|
393
|
+
}
|
|
394
|
+
let queues = []
|
|
395
|
+
//得到任务队列信息
|
|
396
|
+
try {
|
|
397
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/scheduler'
|
|
398
|
+
let ret = await this.ctx.curl(url, options)
|
|
399
|
+
if (ret.status === 200) { //返回成功
|
|
400
|
+
let data = ret.data
|
|
401
|
+
queues = data.scheduler.schedulerInfo.queues.queue
|
|
402
|
+
}
|
|
403
|
+
} catch (err) {
|
|
404
|
+
this.ctx.logger.info(err)
|
|
405
|
+
queues = []
|
|
406
|
+
}
|
|
407
|
+
return queues
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
public async getPartitionsByNmServiceName (nmServiceName: string) {
|
|
411
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
412
|
+
// rmActiveHost = 'rm-dsaas.prefromoffice.alipay.net'
|
|
413
|
+
return this.getPartitionsByRmHost(rmActiveHost)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* 得到集群中所有的partition(label)
|
|
418
|
+
*
|
|
419
|
+
* @param {string} rmActiveHost //active的RM主机名
|
|
420
|
+
* @returns 返回partition数组
|
|
421
|
+
* @memberof NODEMANAGER
|
|
422
|
+
*/
|
|
423
|
+
public async getPartitionsByRmHost (rmActiveHost: string) {
|
|
424
|
+
const options = {
|
|
425
|
+
method: 'GET',
|
|
426
|
+
timeout: 10000,
|
|
427
|
+
dataType: 'json'
|
|
428
|
+
}
|
|
429
|
+
let partitions = []
|
|
430
|
+
//得到任务队列信息
|
|
431
|
+
try {
|
|
432
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/scheduler'
|
|
433
|
+
let ret = await this.ctx.curl(url, options)
|
|
434
|
+
if (ret.status === 200) { //返回成功
|
|
435
|
+
let data = ret.data
|
|
436
|
+
partitions = data.scheduler.schedulerInfo.partitions.map(item => item.partitionName)
|
|
437
|
+
}
|
|
438
|
+
} catch (err) {
|
|
439
|
+
this.ctx.logger.info(err)
|
|
440
|
+
partitions = []
|
|
441
|
+
}
|
|
442
|
+
return partitions
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* 查询nmServiceName下的所有node节点信息
|
|
447
|
+
* @param {string} nmServiceName //nodemanager的服务名
|
|
448
|
+
* @returns
|
|
449
|
+
* @memberof NODEMANAGER
|
|
450
|
+
*/
|
|
451
|
+
public async getClusterNodesByNmServiceName (nmServiceName: string) {
|
|
452
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
453
|
+
return this.getClusterNodesByRmHost(rmActiveHost)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 查询nmServiceName下的所有node节点信息
|
|
458
|
+
* 返回格式参考 https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_Nodes_API
|
|
459
|
+
*
|
|
460
|
+
* @param {string} rmActiveHost //active的RM主机名
|
|
461
|
+
* @returns
|
|
462
|
+
* @memberof NODEMANAGER
|
|
463
|
+
*/
|
|
464
|
+
public async getClusterNodesByRmHost (rmActiveHost: string) {
|
|
465
|
+
let nodes = []
|
|
466
|
+
const options = {
|
|
467
|
+
method: 'GET',
|
|
468
|
+
timeout: 10000,
|
|
469
|
+
dataType: 'json'
|
|
470
|
+
}
|
|
471
|
+
try {
|
|
472
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/nodes'
|
|
473
|
+
const ret = await this.ctx.curl(url, options)
|
|
474
|
+
if (ret.status === 200) { //返回成功
|
|
475
|
+
nodes = ret.data.nodes.node //node数组
|
|
476
|
+
}
|
|
477
|
+
} catch (err) {
|
|
478
|
+
nodes = []
|
|
479
|
+
}
|
|
480
|
+
return nodes
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* 查询node的信息
|
|
485
|
+
* 返回格式参考 https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html#Cluster_Node_API
|
|
486
|
+
*
|
|
487
|
+
* @param {string} rmActiveHost //active的RM主机名
|
|
488
|
+
* @param {string} nmFqdn //nm的主机长域名
|
|
489
|
+
* @returns 返回该node的详情信息
|
|
490
|
+
* @memberof NODEMANAGER
|
|
491
|
+
*/
|
|
492
|
+
public async getNodeInfo (nmServiceName: string, nmFqdn: string) {
|
|
493
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
494
|
+
let nodeInfo = null
|
|
495
|
+
const options = {
|
|
496
|
+
method: 'GET',
|
|
497
|
+
timeout: 10000,
|
|
498
|
+
dataType: 'json'
|
|
499
|
+
}
|
|
500
|
+
try {
|
|
501
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/nodes/' + nmFqdn + ':45454'
|
|
502
|
+
let ret = await this.ctx.curl(url, options)
|
|
503
|
+
if (ret.status === 200) { //返回成功
|
|
504
|
+
nodeInfo = ret.data.node
|
|
505
|
+
} else if (ret.status === 404) {
|
|
506
|
+
let record = await HostDAO.fullHostNameListMapHostNameListWithOrder([nmFqdn], this.ctx)
|
|
507
|
+
let hostName = record ? record[nmFqdn].hostName : ''
|
|
508
|
+
url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/nodes/' + hostName + ':45454'
|
|
509
|
+
ret = await this.ctx.curl(url, options)
|
|
510
|
+
if (ret.status === 200) {
|
|
511
|
+
nodeInfo = ret.data.node
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
} catch (err) {
|
|
515
|
+
this.ctx.logger.info(err)
|
|
516
|
+
nodeInfo = null
|
|
517
|
+
}
|
|
518
|
+
return nodeInfo
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* 得到集群中所有机器和label的对应关系
|
|
523
|
+
*
|
|
524
|
+
* @param {string} nmServiceName
|
|
525
|
+
* @returns
|
|
526
|
+
* @memberof NODEMANAGER
|
|
527
|
+
*/
|
|
528
|
+
public async getNodeToLabels (nmServiceName: string) {
|
|
529
|
+
// console.log('nmServiceName', nmServiceName)
|
|
530
|
+
// let rmActiveHost = 'antyarn1.inc.alipay.net'
|
|
531
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
532
|
+
let entry = []
|
|
533
|
+
const options = {
|
|
534
|
+
method: 'GET',
|
|
535
|
+
timeout: 10000,
|
|
536
|
+
dataType: 'json'
|
|
537
|
+
}
|
|
538
|
+
try {
|
|
539
|
+
let url = 'http://' + rmActiveHost + ':8088/ws/v1/cluster/get-node-to-labels'
|
|
540
|
+
let ret = await this.ctx.curl(url, options)
|
|
541
|
+
if (ret.status === 200) { //返回成功
|
|
542
|
+
entry = ret.data.nodeToLabels.entry
|
|
543
|
+
}
|
|
544
|
+
} catch (err) {
|
|
545
|
+
this.ctx.logger.info(err)
|
|
546
|
+
entry = []
|
|
547
|
+
}
|
|
548
|
+
return entry
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* 得到nm服务的某个机器的label
|
|
553
|
+
*
|
|
554
|
+
* @param {string} nmServiceName
|
|
555
|
+
* @param {string} nmFqdn
|
|
556
|
+
* @returns
|
|
557
|
+
* @memberof NODEMANAGER
|
|
558
|
+
*/
|
|
559
|
+
public async getLabelOfNode (nmServiceName: string, nmFqdn: string) {
|
|
560
|
+
let label = null
|
|
561
|
+
try {
|
|
562
|
+
let nodeToLabels = await this.getNodeToLabels(nmServiceName)
|
|
563
|
+
|
|
564
|
+
let record = await HostDAO.fullHostNameListMapHostNameListWithOrder([nmFqdn], this.ctx)
|
|
565
|
+
let hostName = record ? record[nmFqdn].hostName : ''
|
|
566
|
+
|
|
567
|
+
for (let i = 0; i < nodeToLabels.length; i++) {
|
|
568
|
+
let key = nodeToLabels[i].key
|
|
569
|
+
|
|
570
|
+
key = key.replace(':45454', '')
|
|
571
|
+
|
|
572
|
+
if (key === nmFqdn || key === hostName) {
|
|
573
|
+
label = nodeToLabels[i].value.nodeLabelInfo.name
|
|
574
|
+
break
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
} catch (err) {
|
|
578
|
+
this.ctx.logger.info(err)
|
|
579
|
+
label = null
|
|
580
|
+
}
|
|
581
|
+
return label
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* 查询机器标签为label的node列表
|
|
586
|
+
*
|
|
587
|
+
* @param {string} nmServiceName //nodemanager服务名
|
|
588
|
+
* @param {string[]} labelList //需要检索的label数组
|
|
589
|
+
* @returns
|
|
590
|
+
* @memberof NODEMANAGER
|
|
591
|
+
*/
|
|
592
|
+
public async getNodeListByLabel (nmServiceName: string, labelList: string[]) {
|
|
593
|
+
|
|
594
|
+
// rmActiveHost = 'rm2-dsaas.prefromoffice.alipay.net'
|
|
595
|
+
|
|
596
|
+
let nodeToLabels = await this.getNodeToLabels(nmServiceName)
|
|
597
|
+
let nodeHostList = []
|
|
598
|
+
nodeToLabels.map(item => {
|
|
599
|
+
let key = item.key
|
|
600
|
+
key = key.replace(':45454', '') //主机名
|
|
601
|
+
let label = item.value.nodeLabelInfo.name
|
|
602
|
+
if (labelList.indexOf(label) >= 0) {
|
|
603
|
+
nodeHostList.push(key)
|
|
604
|
+
}
|
|
605
|
+
})
|
|
606
|
+
|
|
607
|
+
//如果要查的分区包含默认分区
|
|
608
|
+
if (labelList.indexOf('<DEFAULT_PARTITION>') >= 0) {
|
|
609
|
+
let defaultPartitionNodeHostList = await this.searchDefaultPartitionNodeList(nmServiceName)
|
|
610
|
+
nodeHostList = nodeHostList.concat(defaultPartitionNodeHostList)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return nodeHostList
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
private async searchDefaultPartitionNodeList (nmServiceName: string) {
|
|
617
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
618
|
+
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
619
|
+
|
|
620
|
+
let defaultPartitionNodeHostList = []
|
|
621
|
+
nodes.map(item => {
|
|
622
|
+
if (!item.nodeLabels || !item.nodeLabels[0]) {
|
|
623
|
+
let nodeHostName = item.nodeHostName
|
|
624
|
+
defaultPartitionNodeHostList.push(nodeHostName)
|
|
625
|
+
}
|
|
626
|
+
})
|
|
627
|
+
return defaultPartitionNodeHostList
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* 根据nodemanager服务名得到集群元数据信息
|
|
632
|
+
*
|
|
633
|
+
* @param {string} nmServiceName //nm的服务名
|
|
634
|
+
* @returns 返回集群元数据信息
|
|
635
|
+
* @memberof NODEMANAGER
|
|
636
|
+
*/
|
|
637
|
+
public async getClusterMetaOfNodeList (nmServiceName: string) {
|
|
638
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
639
|
+
|
|
640
|
+
// rmActiveHost = 'rm2-dsaas.prefromoffice.alipay.net'
|
|
641
|
+
|
|
642
|
+
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
643
|
+
let queues = await this.getClusterQueuesByRmHost(rmActiveHost)
|
|
644
|
+
|
|
645
|
+
//记录每个label对应的有哪些队列
|
|
646
|
+
let labelQueues = {}
|
|
647
|
+
|
|
648
|
+
queues.map(item => {
|
|
649
|
+
let queueName = item.queueName
|
|
650
|
+
item.nodeLabels.map(label => {
|
|
651
|
+
if (labelQueues[label]) {
|
|
652
|
+
labelQueues[label].push(queueName)
|
|
653
|
+
} else {
|
|
654
|
+
labelQueues[label] = [queueName]
|
|
655
|
+
}
|
|
656
|
+
})
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
let hostList = nodes.map(item => {
|
|
660
|
+
let EXT = {}
|
|
661
|
+
let label = '<DEFAULT_PARTITION>' //默认标签
|
|
662
|
+
if (item.nodeLabels && item.nodeLabels.length) {
|
|
663
|
+
label = item.nodeLabels[0] //如果有标签,赋值为该标签值
|
|
664
|
+
}
|
|
665
|
+
EXT['partition'] = label
|
|
666
|
+
EXT['queue'] = labelQueues[label] ? labelQueues[label] : []
|
|
667
|
+
return {
|
|
668
|
+
hostname: item.nodeHostName,
|
|
669
|
+
EXT
|
|
670
|
+
}
|
|
671
|
+
})
|
|
672
|
+
|
|
673
|
+
return hostList
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
public async getLabelsOfNodeList (nmServiceName: string, nmFqdnList: string[]) {
|
|
677
|
+
let nodeToLabels = await this.getNodeToLabels(nmServiceName)
|
|
678
|
+
let map = {} //记录每个nmfqdn的label
|
|
679
|
+
for (let i = 0; i < nodeToLabels.length; i++) {
|
|
680
|
+
let key = nodeToLabels[i].key
|
|
681
|
+
key = key.replace(':45454', '')
|
|
682
|
+
|
|
683
|
+
if (nmFqdnList.indexOf(key) >= 0) {
|
|
684
|
+
let label = nodeToLabels[i].value.nodeLabelInfo.name
|
|
685
|
+
map[key] = label
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
let result = {}
|
|
690
|
+
for (let nmFqdn of nmFqdnList) {
|
|
691
|
+
let label = '<DEFAULT_PARTITION>'
|
|
692
|
+
if (map[nmFqdn]) {
|
|
693
|
+
label = map[nmFqdn]
|
|
694
|
+
}
|
|
695
|
+
if (!result[label]) {
|
|
696
|
+
result[label] = []
|
|
697
|
+
}
|
|
698
|
+
result[label].push(nmFqdn)
|
|
699
|
+
}
|
|
700
|
+
return result
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
public async getSummary (nmServiceName) {
|
|
704
|
+
// console.log('nmServiceName', nmServiceName)
|
|
705
|
+
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
706
|
+
// let rmActiveHost = 'antyarn1.inc.alipay.net'
|
|
707
|
+
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
708
|
+
|
|
709
|
+
this.ctx.logger.warn('nodes nodes nodes', JSON.stringify(nodes))
|
|
710
|
+
|
|
711
|
+
let labelStateCountMap = {} // 统计每个label下的每个状态的个数
|
|
712
|
+
|
|
713
|
+
let partitions = await this.getPartitionsByRmHost(rmActiveHost) //所有的label
|
|
714
|
+
|
|
715
|
+
this.ctx.logger.warn('partitions partitions partitions', JSON.stringify(partitions))
|
|
716
|
+
|
|
717
|
+
let allLabelStateCountMap = {
|
|
718
|
+
TOTAL: 0,
|
|
719
|
+
NEW: 0,
|
|
720
|
+
RUNNING: 0,
|
|
721
|
+
UNHEALTHY: 0,
|
|
722
|
+
DECOMMISSIONED: 0,
|
|
723
|
+
LOST: 0,
|
|
724
|
+
REBOOTED: 0
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (!nodes.length || !partitions.length) { //任意一个为空,直接返回
|
|
728
|
+
this.ret['labelStateCountMap'] = labelStateCountMap
|
|
729
|
+
this.ret['allLabelStateCountMap'] = allLabelStateCountMap
|
|
730
|
+
this.ret['partitions'] = partitions
|
|
731
|
+
this.ret['rmActiveHost'] = rmActiveHost
|
|
732
|
+
return
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
partitions = partitions.map(item => {
|
|
736
|
+
if (item === '') {
|
|
737
|
+
item = '<DEFAULT_PARTITION>'
|
|
738
|
+
}
|
|
739
|
+
if (!labelStateCountMap[item]) {
|
|
740
|
+
labelStateCountMap[item] = {
|
|
741
|
+
TOTAL: 0,
|
|
742
|
+
NEW: 0,
|
|
743
|
+
RUNNING: 0,
|
|
744
|
+
UNHEALTHY: 0,
|
|
745
|
+
DECOMMISSIONED: 0,
|
|
746
|
+
LOST: 0,
|
|
747
|
+
REBOOTED: 0
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return item
|
|
751
|
+
})
|
|
752
|
+
|
|
753
|
+
nodes.map(item => {
|
|
754
|
+
let label = (item.nodeLabels && item.nodeLabels[0]) ? item.nodeLabels[0] : '<DEFAULT_PARTITION>'
|
|
755
|
+
let state = item.state
|
|
756
|
+
labelStateCountMap[label][state] += 1
|
|
757
|
+
labelStateCountMap[label]['TOTAL'] += 1
|
|
758
|
+
|
|
759
|
+
allLabelStateCountMap[state] += 1
|
|
760
|
+
allLabelStateCountMap['TOTAL'] += 1
|
|
761
|
+
})
|
|
762
|
+
|
|
763
|
+
this.ret['labelStateCountMap'] = labelStateCountMap
|
|
764
|
+
this.ret['allLabelStateCountMap'] = allLabelStateCountMap
|
|
765
|
+
this.ret['partitions'] = partitions
|
|
766
|
+
this.ret['rmActiveHost'] = rmActiveHost
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
export class ZOOKEEPER extends ServiceSummary {
|
|
771
|
+
/**
|
|
772
|
+
* ZooKeeper Four Letter Word Command
|
|
773
|
+
*
|
|
774
|
+
* @param {string} flw //zk的四字命令
|
|
775
|
+
* @param {string} ip //执行该命令的ip地址
|
|
776
|
+
* @param {string} clientPort //执行该命令的ip地址
|
|
777
|
+
* @param {string} [extendCmd=''] //扩展命令
|
|
778
|
+
* @returns
|
|
779
|
+
* @memberof ZOOKEEPER
|
|
780
|
+
*/
|
|
781
|
+
public async zkflwcmd (flw: string, ip: string, clientPort: string = '2181', extendCmd = '') {
|
|
782
|
+
const co = require('co')
|
|
783
|
+
const { ctx } = this
|
|
784
|
+
let cmd = 'echo ' + flw + `|nc -w 10 localhost ${clientPort}` + extendCmd
|
|
785
|
+
let target = { ip: ip }
|
|
786
|
+
let ret
|
|
787
|
+
try {
|
|
788
|
+
ret = await co(function * () { return yield ctx.service.staragent.cmd(target, 'admin', cmd, true) })
|
|
789
|
+
} catch (err) {
|
|
790
|
+
this.ctx.logger.info(err)
|
|
791
|
+
ret = null
|
|
792
|
+
}
|
|
793
|
+
return ret
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
private async getClientPort(zkServiceName) {
|
|
797
|
+
let ret = await this.ctx.dao.serviceStatus.selectOne({
|
|
798
|
+
idxServiceName: zkServiceName,
|
|
799
|
+
})
|
|
800
|
+
let configGroupId = ret.configGroupId
|
|
801
|
+
let currentVersion = await ConfigGroupDAO.getCurrentVersionById(configGroupId, this.ctx)
|
|
802
|
+
let configdataRecord = await ConfigDataDAO.getByConfigGroupIdAndVersion(configGroupId, currentVersion, this.ctx)
|
|
803
|
+
//得到 zoo.cfg 中的 clientPort
|
|
804
|
+
let port = await this.ctx.service.config.getValueByFilekey(JSON.parse(configdataRecord.configData), 'zoo.cfg', 'clientPort')
|
|
805
|
+
return port
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
public async getSummary (zkServiceName) {
|
|
809
|
+
const properties = require('properties')
|
|
810
|
+
|
|
811
|
+
let serviceStatusRecord = await this.ctx.service.sql.select('service_status', {
|
|
812
|
+
where: {
|
|
813
|
+
idx_service_name: zkServiceName
|
|
814
|
+
},
|
|
815
|
+
columns: ['full_host_name']
|
|
816
|
+
})
|
|
817
|
+
|
|
818
|
+
let clientPort = '2181'
|
|
819
|
+
try {
|
|
820
|
+
clientPort = await this.getClientPort(zkServiceName)
|
|
821
|
+
} catch (err) {
|
|
822
|
+
clientPort = '2181'
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
//初始化值
|
|
826
|
+
this.ret['zkStatusList'] = []
|
|
827
|
+
this.ret['zxid'] = {
|
|
828
|
+
decimalZxid: 0,
|
|
829
|
+
hexadecimalZxid: '0x0'
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
let hostList = serviceStatusRecord.map(item => item.full_host_name)
|
|
833
|
+
|
|
834
|
+
if (hostList.length) {
|
|
835
|
+
let result = await HostDAO.fullHostNameListMapIPListWithOrder(hostList, this.ctx)
|
|
836
|
+
for (let zkHost in result) {
|
|
837
|
+
let ip = result[zkHost]
|
|
838
|
+
let status = {
|
|
839
|
+
zkHost,
|
|
840
|
+
ruok: 'unknown',
|
|
841
|
+
mode: 'unknown',
|
|
842
|
+
myid: 'unknown',
|
|
843
|
+
mntr: {}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
let ruok = await this.zkflwcmd('ruok', ip, clientPort)
|
|
847
|
+
if (ruok !== null && ruok.result && ruok.result.SUCCESS && ruok.result.SUCCESS === true) {
|
|
848
|
+
status.ruok = ruok.result.JOBRESULT // imok or other
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
let conf = await this.zkflwcmd('conf', ip, clientPort)
|
|
852
|
+
if (conf !== null && conf.result && conf.result.SUCCESS && conf.result.SUCCESS === true) {
|
|
853
|
+
let ret = properties.parse(conf.result.JOBRESULT)
|
|
854
|
+
status.myid = ret.serverId
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
let mntr = await this.zkflwcmd('mntr', ip, clientPort)
|
|
858
|
+
if (mntr !== null && mntr.result && mntr.result.SUCCESS && mntr.result.SUCCESS === true) {
|
|
859
|
+
let ret = properties.parse(mntr.result.JOBRESULT)
|
|
860
|
+
status.mntr = ret
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
let srvr = await this.zkflwcmd('srvr', ip, clientPort)
|
|
864
|
+
if (srvr !== null && srvr.result && srvr.result.SUCCESS && srvr.result.SUCCESS === true) {
|
|
865
|
+
let ret = properties.parse(srvr.result.JOBRESULT)
|
|
866
|
+
|
|
867
|
+
status.mode = ret.Mode ? ret.Mode : status.mode //leader or follower
|
|
868
|
+
|
|
869
|
+
if (ret.Zxid) { //zxid一次就获取到了
|
|
870
|
+
let decimalZxid = ret.Zxid ? ret.Zxid : -1 //10进制zxid (properties.parse解析会把16进制的zxid直接解析成10进制zxid)
|
|
871
|
+
let hexadecimalZxid = decimalZxid.toString(16) //16进制zxid
|
|
872
|
+
this.ret['zxid'] = {
|
|
873
|
+
decimalZxid: decimalZxid >>> 32, //关注zxid的低32位的值
|
|
874
|
+
hexadecimalZxid: '0x' + hexadecimalZxid
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
this.ret['zkStatusList'].push(status)
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
export class KEPLERNIMBUS extends ServiceSummary {
|
|
885
|
+
|
|
886
|
+
public async setTopologyOpsStatus (topologyId, opsStatus) {
|
|
887
|
+
let initParams = await this.service.kepler.getInitParams()
|
|
888
|
+
const options = {
|
|
889
|
+
method: 'POST',
|
|
890
|
+
timeout: 10000,
|
|
891
|
+
dataType: 'json',
|
|
892
|
+
contentType: 'json',
|
|
893
|
+
data: {
|
|
894
|
+
...initParams
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
let keplerUrl = await this.ctx.service.systemConfig.queryByKey('keplerUrl', 'SYSTEM_TEMPLATE')
|
|
898
|
+
let url = `${keplerUrl}/api/job/${topologyId}/ops/${opsStatus.toLowerCase()}`
|
|
899
|
+
let ret = await this.ctx.curl(url, options)
|
|
900
|
+
|
|
901
|
+
if (ret.status !== 200 || ret.data.success === false) { //返回失败 等待一秒 重试一次
|
|
902
|
+
await this.ctx.service.globalLock.sleep(1000)
|
|
903
|
+
ret = await this.ctx.curl(url, options)
|
|
904
|
+
|
|
905
|
+
if (ret.status !== 200 || ret.data.success === false) { //再次返回失败 抛出异常
|
|
906
|
+
this.ctx.logger.error('kepler接口调用失败', JSON.stringify(ret))
|
|
907
|
+
throwCustomError(ERROR.E_KEPLER_REST_ERROR)
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* kepler 作业批量操作
|
|
914
|
+
* jobIds: 要操作的作业id,以英文半角逗号分隔,如: "jobIds=123" "jobIds=123,456"
|
|
915
|
+
* targetVal: 对于一些需要指定参数的操作将参数作为targetVal传进来
|
|
916
|
+
* https://yuque.antfin-inc.com/docs/share/617a3cc9-b32b-4e48-ab3d-a5a7c31d2bf9
|
|
917
|
+
* @param {*} jobIds
|
|
918
|
+
* @param {*} targetVal
|
|
919
|
+
* @memberof KEPLERNIMBUS
|
|
920
|
+
*/
|
|
921
|
+
public async batchOpr (jobIds, oprType) {
|
|
922
|
+
const {ctx} = this
|
|
923
|
+
if (!jobIds || !oprType) {
|
|
924
|
+
throwCustomError(ERROR.E_KEPLER_REST_ERROR, {message: 'batchOpr parameter is null, jobIds:' + jobIds + ', oprType:' + oprType})
|
|
925
|
+
}
|
|
926
|
+
let initParams = await this.service.kepler.getInitParams()
|
|
927
|
+
let initParamsString = Object.keys(initParams).map(key => key + '=' + initParams[key]).join('&')
|
|
928
|
+
|
|
929
|
+
let queryParams = ''
|
|
930
|
+
queryParams += 'jobIds=' + jobIds + '&'
|
|
931
|
+
queryParams += 'oprType=' + oprType + '&'
|
|
932
|
+
|
|
933
|
+
const options = {
|
|
934
|
+
method: 'GET',
|
|
935
|
+
timeout: 10000,
|
|
936
|
+
dataType: 'json'
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
let keplerUrl = await ctx.service.systemConfig.queryByKey('keplerUrl', 'SYSTEM_TEMPLATE')
|
|
940
|
+
|
|
941
|
+
let ret
|
|
942
|
+
|
|
943
|
+
try {
|
|
944
|
+
let url = `${keplerUrl}/api/job/batchOpr?${queryParams}` + initParamsString
|
|
945
|
+
ret = await ctx.curl(url, options)
|
|
946
|
+
|
|
947
|
+
if (ret.status !== 200 || !ret.data || ret.data.success !== true) {
|
|
948
|
+
throwCustomError(ERROR.E_KEPLER_REST_ERROR, {message: 'kepler batchOpr ret:' + JSON.stringify(ret)})
|
|
949
|
+
}
|
|
950
|
+
} catch (err) {
|
|
951
|
+
ctx.logger.error('kepler batchOpr error:', JSON.stringify(err))
|
|
952
|
+
}
|
|
953
|
+
return ret.data.data
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* kepler作业状态批量查询
|
|
958
|
+
*
|
|
959
|
+
* @param {*} jobIds
|
|
960
|
+
* @memberof KEPLERNIMBUS
|
|
961
|
+
*/
|
|
962
|
+
public async statusByIds (jobIds) {
|
|
963
|
+
const {ctx} = this
|
|
964
|
+
if (!jobIds) {
|
|
965
|
+
throwCustomError(ERROR.E_KEPLER_REST_ERROR, {message: 'statusByIds parameter is null, jobIds:' + jobIds})
|
|
966
|
+
}
|
|
967
|
+
let initParams = await this.service.kepler.getInitParams()
|
|
968
|
+
let initParamsString = Object.keys(initParams).map(key => key + '=' + initParams[key]).join('&')
|
|
969
|
+
|
|
970
|
+
let queryParams = ''
|
|
971
|
+
queryParams += 'ids=' + jobIds + '&'
|
|
972
|
+
|
|
973
|
+
const options = {
|
|
974
|
+
method: 'GET',
|
|
975
|
+
timeout: 10000,
|
|
976
|
+
dataType: 'json'
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
let keplerUrl = await ctx.service.systemConfig.queryByKey('keplerUrl', 'SYSTEM_TEMPLATE')
|
|
980
|
+
|
|
981
|
+
let ret
|
|
982
|
+
|
|
983
|
+
try {
|
|
984
|
+
let url = `${keplerUrl}/api/job/statusByIds?${queryParams}` + initParamsString
|
|
985
|
+
|
|
986
|
+
ret = await ctx.curl(url, options)
|
|
987
|
+
if (ret.status !== 200 || !ret.data || ret.data.success !== true) {
|
|
988
|
+
throwCustomError(ERROR.E_KEPLER_REST_ERROR, {message: 'statusByIds fail, ret:' + JSON.stringify(ret)})
|
|
989
|
+
}
|
|
990
|
+
} catch (err) {
|
|
991
|
+
ctx.logger.error('statusByIds error:', JSON.stringify(err))
|
|
992
|
+
}
|
|
993
|
+
return ret.data.data
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* 作业资源使用信息 多维度查询
|
|
998
|
+
*
|
|
999
|
+
* @param {string} cluster
|
|
1000
|
+
* @param {string} [status='ACTIVE']
|
|
1001
|
+
* @param {*} [isMix=undefined]
|
|
1002
|
+
* @param {number} [level=2]
|
|
1003
|
+
* @param {*} [limit=undefined]
|
|
1004
|
+
* @returns
|
|
1005
|
+
* @memberof KEPLERNIMBUS
|
|
1006
|
+
*/
|
|
1007
|
+
public async getKeplerApps (cluster:string, status = 'ACTIVE', isMix = undefined, level = '1', limit = 5000) {
|
|
1008
|
+
let initParams = await this.service.kepler.getInitParams()
|
|
1009
|
+
let initParamsString = Object.keys(initParams).map(key => key + '=' + initParams[key]).join('&')
|
|
1010
|
+
let apps = []
|
|
1011
|
+
const options = {
|
|
1012
|
+
method: 'GET',
|
|
1013
|
+
timeout: 10000,
|
|
1014
|
+
dataType: 'json'
|
|
1015
|
+
}
|
|
1016
|
+
let queryParams = ''
|
|
1017
|
+
queryParams += cluster ? 'cluster=' + cluster + '&' : ''
|
|
1018
|
+
queryParams += status ? 'status=' + status + '&' : ''
|
|
1019
|
+
queryParams += isMix !== undefined ? 'isMix=' + isMix + '&' : ''
|
|
1020
|
+
queryParams += level ? 'level=' + level + '&' : ''
|
|
1021
|
+
queryParams += limit ? 'limit=' + limit + '&' : ''
|
|
1022
|
+
|
|
1023
|
+
let keplerUrl = await this.ctx.service.systemConfig.queryByKey('keplerUrl', 'SYSTEM_TEMPLATE')
|
|
1024
|
+
|
|
1025
|
+
try {
|
|
1026
|
+
let url = `${keplerUrl}/api/metrics/resource/jobs?${queryParams}` + initParamsString
|
|
1027
|
+
let ret = await this.ctx.curl(url, options)
|
|
1028
|
+
if (ret.status !== 200 || !ret.data || ret.data.success !== true) {
|
|
1029
|
+
throwCustomError(ERROR.E_KEPLER_REST_ERROR, {message: 'getKeplerApps fail, ret:' + JSON.stringify(ret)})
|
|
1030
|
+
}
|
|
1031
|
+
apps = ret.data.data
|
|
1032
|
+
} catch (err) {
|
|
1033
|
+
this.ctx.logger.error('getKeplerApps error:', JSON.stringify(err))
|
|
1034
|
+
}
|
|
1035
|
+
return apps
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
public async getSummary (serviceName) {
|
|
1039
|
+
const { ctx } = this
|
|
1040
|
+
let data = []
|
|
1041
|
+
let serviceRecord = await ServiceDAO.getClusterNameByServiceName(serviceName, ctx)
|
|
1042
|
+
let clusterName = serviceRecord.clusterName
|
|
1043
|
+
// clusterName = 'kepler_publicet15mixtest'
|
|
1044
|
+
/**
|
|
1045
|
+
* jobStatus枚举:ACTIVE, STOP, STARTING, STOPPING, RESTARTING, RESETTING
|
|
1046
|
+
*/
|
|
1047
|
+
|
|
1048
|
+
let activeApps = await this.getKeplerApps(clusterName, 'ACTIVE')
|
|
1049
|
+
let stopApps = await this.getKeplerApps(clusterName, 'STOP')
|
|
1050
|
+
let startingApps = await this.getKeplerApps(clusterName, 'STARTING')
|
|
1051
|
+
let stoppingApps = await this.getKeplerApps(clusterName, 'STOPPING')
|
|
1052
|
+
let restartingApps = await this.getKeplerApps(clusterName, 'RESTARTING')
|
|
1053
|
+
let resettingApps = await this.getKeplerApps(clusterName, 'RESETTING')
|
|
1054
|
+
data = data.concat(activeApps).concat(stopApps).concat(startingApps)
|
|
1055
|
+
.concat(stoppingApps).concat(restartingApps).concat(resettingApps)
|
|
1056
|
+
if (data.length) {
|
|
1057
|
+
this.ret['data'] = data
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|