-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbroker.controller.ts
More file actions
251 lines (235 loc) · 8.37 KB
/
broker.controller.ts
File metadata and controls
251 lines (235 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import { Body, Controller, Get, Logger, Param, Patch, Post, Request } from '@nestjs/common';
import {
AddDbmtUserClientResponse,
AddDbmtUserRequest,
BrokerListClientResponse,
GetBrokerStatusClientResponse,
StartAllBrokersClientResponse,
StopAllBrokersClientResponse,
UpdateDbmtUserClientResponse,
UpdateDbmtUserRequest,
} from '@api-interfaces';
import { validateRequiredFields } from '@util';
import { BaseCmsResponse } from '@type';
import { BrokerService } from './broker.service';
/**
* Controller for handling broker-related operations.
* Provides REST API endpoints for broker management operations including:
* - Get broker list for a specific host
* - Stop a broker
* - Start a broker
* - Restart a broker
* - Get broker status
* - All endpoints receive `hostUid` as a path parameter
* - Follows RESTful pattern: /:hostUid/broker/{action}/{identifier}
*
* @category Controllers
* @since 1.0.0
*/
@Controller(':hostUid/broker')
export class BrokerController {
private readonly logger = new Logger(BrokerController.name);
constructor(private readonly brokerService: BrokerService) {}
/**
* Start all brokers on a host (CMS task: startbroker).
*
* @route POST /:hostUid/broker/start-all
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @returns StartAllBrokersClientResponse { success: true } on success
* @example
* // POST /host-uid/broker/start-all
*/
@Post('start-all')
async startAllBrokers(
@Request() req,
@Param('hostUid') hostUid: string
): Promise<StartAllBrokersClientResponse> {
const userId = req.user.sub;
this.logger.log(`Starting all brokers on host: ${hostUid}`);
return await this.brokerService.startAllBrokers(userId, hostUid);
}
/**
* Stop all brokers on a host (CMS task: stopbroker).
*
* @route POST /:hostUid/broker/stop-all
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @returns StopAllBrokersClientResponse { success: true } on success
* @example
* // POST /host-uid/broker/stop-all
*/
@Post('stop-all')
async stopAllBrokers(
@Request() req,
@Param('hostUid') hostUid: string
): Promise<StopAllBrokersClientResponse> {
const userId = req.user.sub;
this.logger.log(`Stopping all brokers on host: ${hostUid}`);
return await this.brokerService.stopAllBrokers(userId, hostUid);
}
/**
* Add a DBMT (CMS) user on the host (CMS task: adddbmtuser).
*
* @route POST /:hostUid/broker/dbmt-user
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @param body - targetid, password, casauth, dbcreate, statusmonitorauth
* @returns AddDbmtUserClientResponse dblist and userlist
* @example
* // POST /host-uid/broker/dbmt-user
* // Body: { "targetid": "test_user_2", "password": "1234", "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
*/
@Post('dbmt-user')
async addDbmtUser(
@Request() req,
@Param('hostUid') hostUid: string,
@Body() body: AddDbmtUserRequest
): Promise<AddDbmtUserClientResponse> {
const userId = req.user.sub;
validateRequiredFields(
body,
['targetid', 'password', 'casauth', 'dbcreate', 'statusmonitorauth'],
'broker/dbmt-user',
this.logger
);
this.logger.log(`Adding DBMT user: ${body.targetid} on host: ${hostUid}`);
return await this.brokerService.addDbmtUser(userId, hostUid, body);
}
/**
* Update a DBMT (CMS) user on the host (CMS task: updatedbmtuser).
*
* @route PATCH /:hostUid/broker/dbmt-user
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @param body - targetid, casauth, dbcreate, statusmonitorauth (dbauth optional)
* @returns UpdateDbmtUserClientResponse dblist and userlist
* @example
* // PATCH /host-uid/broker/dbmt-user
* // Body: { "targetid": "test_user_2", "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
* // or with dbauth: { "targetid": "test_user_2", "dbauth": [], "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
*/
@Patch('dbmt-user')
async updateDbmtUser(
@Request() req,
@Param('hostUid') hostUid: string,
@Body() body: UpdateDbmtUserRequest
): Promise<UpdateDbmtUserClientResponse> {
const userId = req.user.sub;
validateRequiredFields(
body,
['targetid', 'casauth', 'dbcreate', 'statusmonitorauth'],
'broker/dbmt-user',
this.logger
);
this.logger.log(`Updating DBMT user: ${body.targetid} on host: ${hostUid}`);
return await this.brokerService.updateDbmtUser(userId, hostUid, body);
}
/**
* Get list of brokers for a specific host.
*
* @route GET /:hostUid/broker/list
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @returns List of brokers
* @example
* // GET /host-uid/broker/list
*/
@Get('list')
async getBrokers(
@Request() req,
@Param('hostUid') hostUid: string
): Promise<BrokerListClientResponse> {
const userId = req.user.sub;
const response = await this.brokerService.getBrokers(userId, hostUid);
return response;
}
/**
* Stop a broker.
*
* @route POST /:hostUid/broker/stop/:bname
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @param bname - Broker name from path parameter
* @returns Response indicating success or failure
* @example
* // POST /host-uid/broker/stop/query_editor
*/
@Post('stop/:bname')
async stopBroker(
@Request() req,
@Param('hostUid') hostUid: string,
@Param('bname') bname: string
): Promise<BaseCmsResponse> {
const userId = req.user.sub;
this.logger.log(`Stopping broker: ${bname} on host: ${hostUid}`);
const response = await this.brokerService.stopBroker(userId, hostUid, bname);
return response;
}
/**
* Start a broker.
*
* @route POST /:hostUid/broker/start/:bname
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @param bname - Broker name from path parameter
* @returns Response indicating success or failure
* @example
* // POST /host-uid/broker/start/query_editor
*/
@Post('start/:bname')
async startBroker(
@Request() req,
@Param('hostUid') hostUid: string,
@Param('bname') bname: string
): Promise<BaseCmsResponse> {
const userId = req.user.sub;
this.logger.log(`Starting broker: ${bname} on host: ${hostUid}`);
const response = await this.brokerService.startBroker(userId, hostUid, bname);
return response;
}
/**
* Restart a broker.
*
* @route POST /:hostUid/broker/restart/:bname
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @param bname - Broker name from path parameter
* @returns Boolean indicating success
* @example
* // POST /host-uid/broker/restart/query_editor
*/
@Post('restart/:bname')
async restartBroker(
@Request() req,
@Param('hostUid') hostUid: string,
@Param('bname') bname: string
): Promise<boolean> {
const userId = req.user.sub;
this.logger.log(`Restarting broker: ${bname} on host: ${hostUid}`);
const response: boolean = await this.brokerService.restartBroker(userId, hostUid, bname);
return response;
}
/**
* Get broker status including application server information.
*
* @route GET /:hostUid/broker/status/:bname
* @param req - Request object containing user information
* @param hostUid - Host unique identifier from path parameter
* @param bname - Broker name from path parameter
* @returns Broker status data without BaseCmsResponse fields
* @example
* // POST /host-uid/broker/status/query_editor
*/
@Get('status/:bname')
async getBrokerStatus(
@Request() req,
@Param('hostUid') hostUid: string,
@Param('bname') bname: string
): Promise<GetBrokerStatusClientResponse> {
const userId = req.user.sub;
this.logger.log(`Getting broker status: ${bname} on host: ${hostUid}`);
const response = await this.brokerService.getBrokerStatus(userId, hostUid, bname);
return response;
}
}