forked from CUBRID/cubrid-webmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbroker.controller.ts
More file actions
187 lines (173 loc) · 5.9 KB
/
broker.controller.ts
File metadata and controls
187 lines (173 loc) · 5.9 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
import { Controller, Get, Logger, Param, Post, Request } from '@nestjs/common';
import {
BrokerListClientResponse,
GetBrokerStatusClientResponse,
StartAllBrokersClientResponse,
StopAllBrokersClientResponse,
} from '@api-interfaces';
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);
}
/**
* 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;
}
}