Skip to content

Commit ac8c89b

Browse files
authored
[TOOLS-4847] Broker all stop / start (#36)
* feature : stop / start all brokers api * feature : getautoaddvol implemented
1 parent 931e417 commit ac8c89b

33 files changed

+1038
-30
lines changed

WebCA Server API.postman_collection.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,20 @@
789789
},
790790
"response": []
791791
},
792+
{
793+
"name": "Get Auto Add Volume",
794+
"request": {
795+
"method": "GET",
796+
"header": [],
797+
"url": {
798+
"raw": "{{base_url}}/{{hostUid}}/database/auto-add-vol/{{dbname}}",
799+
"host": ["{{base_url}}"],
800+
"path": ["{{hostUid}}", "database", "auto-add-vol", "{{dbname}}"]
801+
},
802+
"description": "Get auto-add volume configuration for a database (CMS task: getautoaddvol). GET /:hostUid/database/auto-add-vol/:dbname. Success: data, data_ext_page, data_warn_outofspace, index, index_ext_page, index_warn_outofspace, note, execTime."
803+
},
804+
"response": []
805+
},
792806
{
793807
"name": "Set Auto Start",
794808
"request": {
@@ -1225,6 +1239,70 @@
12251239
{
12261240
"name": "Broker",
12271241
"item": [
1242+
{
1243+
"name": "Start All Brokers",
1244+
"request": {
1245+
"method": "POST",
1246+
"header": [],
1247+
"url": {
1248+
"raw": "{{base_url}}/{{hostUid}}/broker/start-all",
1249+
"host": ["{{base_url}}"],
1250+
"path": ["{{hostUid}}", "broker", "start-all"]
1251+
},
1252+
"description": "Start all brokers on the host (CMS task: startbroker). POST /:hostUid/broker/start-all. Auth: Bearer JWT."
1253+
},
1254+
"response": []
1255+
},
1256+
{
1257+
"name": "Stop All Brokers",
1258+
"request": {
1259+
"method": "POST",
1260+
"header": [],
1261+
"url": {
1262+
"raw": "{{base_url}}/{{hostUid}}/broker/stop-all",
1263+
"host": ["{{base_url}}"],
1264+
"path": ["{{hostUid}}", "broker", "stop-all"]
1265+
},
1266+
"description": "Stop all brokers on the host (CMS task: stopbroker). POST /:hostUid/broker/stop-all. Auth: Bearer JWT."
1267+
},
1268+
"response": []
1269+
},
1270+
{
1271+
"name": "Add DBMT User",
1272+
"request": {
1273+
"method": "POST",
1274+
"header": [{"key": "Content-Type", "value": "application/json"}],
1275+
"body": {
1276+
"mode": "raw",
1277+
"raw": "{\n \"targetid\": \"test_user_2\",\n \"password\": \"1234\",\n \"casauth\": \"none\",\n \"dbcreate\": \"none\",\n \"statusmonitorauth\": \"none\"\n}"
1278+
},
1279+
"url": {
1280+
"raw": "{{base_url}}/{{hostUid}}/broker/dbmt-user",
1281+
"host": ["{{base_url}}"],
1282+
"path": ["{{hostUid}}", "broker", "dbmt-user"]
1283+
},
1284+
"description": "Add a DBMT (CMS) user (CMS task: adddbmtuser). POST /:hostUid/broker/dbmt-user. Body: targetid, password, casauth, dbcreate, statusmonitorauth. Auth: Bearer JWT."
1285+
},
1286+
"response": []
1287+
},
1288+
{
1289+
"name": "Update DBMT User",
1290+
"request": {
1291+
"method": "PUT",
1292+
"header": [{"key": "Content-Type", "value": "application/json"}],
1293+
"body": {
1294+
"mode": "raw",
1295+
"raw": "{\n \"targetid\": \"test_user_2\",\n \"dbauth\": [],\n \"casauth\": \"none\",\n \"dbcreate\": \"none\",\n \"statusmonitorauth\": \"none\"\n}"
1296+
},
1297+
"url": {
1298+
"raw": "{{base_url}}/{{hostUid}}/broker/dbmt-user",
1299+
"host": ["{{base_url}}"],
1300+
"path": ["{{hostUid}}", "broker", "dbmt-user"]
1301+
},
1302+
"description": "Update a DBMT (CMS) user (CMS task: updatedbmtuser). PUT /:hostUid/broker/dbmt-user. Body: targetid, casauth, dbcreate, statusmonitorauth (dbauth optional). Auth: Bearer JWT."
1303+
},
1304+
"response": []
1305+
},
12281306
{
12291307
"name": "Get Broker List",
12301308
"request": {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,117 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { BrokerController } from './broker.controller';
3+
import { BrokerService } from './broker.service';
34

45
describe('BrokerController', () => {
56
let controller: BrokerController;
7+
let brokerService: jest.Mocked<BrokerService>;
68

79
beforeEach(async () => {
10+
const mockBrokerService = {
11+
getBrokers: jest.fn(),
12+
stopBroker: jest.fn(),
13+
startBroker: jest.fn(),
14+
restartBroker: jest.fn(),
15+
getBrokerStatus: jest.fn(),
16+
startAllBrokers: jest.fn(),
17+
stopAllBrokers: jest.fn(),
18+
addDbmtUser: jest.fn(),
19+
updateDbmtUser: jest.fn(),
20+
};
21+
822
const module: TestingModule = await Test.createTestingModule({
923
controllers: [BrokerController],
24+
providers: [
25+
{
26+
provide: BrokerService,
27+
useValue: mockBrokerService,
28+
},
29+
],
1030
}).compile();
1131

1232
controller = module.get<BrokerController>(BrokerController);
33+
brokerService = module.get(BrokerService);
1334
});
1435

1536
it('should be defined', () => {
1637
expect(controller).toBeDefined();
1738
});
39+
40+
describe('startAllBrokers', () => {
41+
it('should call brokerService.startAllBrokers and return { success: true }', async () => {
42+
const req = { user: { sub: 'user-123' } };
43+
brokerService.startAllBrokers.mockResolvedValue({ success: true });
44+
45+
const result = await controller.startAllBrokers(req, 'host-uid-1');
46+
47+
expect(brokerService.startAllBrokers).toHaveBeenCalledWith(
48+
'user-123',
49+
'host-uid-1'
50+
);
51+
expect(result).toEqual({ success: true });
52+
});
53+
});
54+
55+
describe('stopAllBrokers', () => {
56+
it('should call brokerService.stopAllBrokers and return { success: true }', async () => {
57+
const req = { user: { sub: 'user-123' } };
58+
brokerService.stopAllBrokers.mockResolvedValue({ success: true });
59+
60+
const result = await controller.stopAllBrokers(req, 'host-uid-1');
61+
62+
expect(brokerService.stopAllBrokers).toHaveBeenCalledWith(
63+
'user-123',
64+
'host-uid-1'
65+
);
66+
expect(result).toEqual({ success: true });
67+
});
68+
});
69+
70+
describe('addDbmtUser', () => {
71+
it('should call brokerService.addDbmtUser and return dblist and userlist', async () => {
72+
const req = { user: { sub: 'user-123' } };
73+
const body = {
74+
targetid: 'test_user_2',
75+
password: '1234',
76+
casauth: 'none',
77+
dbcreate: 'none',
78+
statusmonitorauth: 'none',
79+
};
80+
const mockResponse = { dblist: [], userlist: [] };
81+
brokerService.addDbmtUser.mockResolvedValue(mockResponse);
82+
83+
const result = await controller.addDbmtUser(req, 'host-uid-1', body);
84+
85+
expect(brokerService.addDbmtUser).toHaveBeenCalledWith(
86+
'user-123',
87+
'host-uid-1',
88+
body
89+
);
90+
expect(result).toEqual(mockResponse);
91+
});
92+
});
93+
94+
describe('updateDbmtUser', () => {
95+
it('should call brokerService.updateDbmtUser and return dblist and userlist', async () => {
96+
const req = { user: { sub: 'user-123' } };
97+
const body = {
98+
targetid: 'test_user_2',
99+
dbauth: [],
100+
casauth: 'none',
101+
dbcreate: 'none',
102+
statusmonitorauth: 'none',
103+
};
104+
const mockResponse = { dblist: [], userlist: [] };
105+
brokerService.updateDbmtUser.mockResolvedValue(mockResponse);
106+
107+
const result = await controller.updateDbmtUser(req, 'host-uid-1', body);
108+
109+
expect(brokerService.updateDbmtUser).toHaveBeenCalledWith(
110+
'user-123',
111+
'host-uid-1',
112+
body
113+
);
114+
expect(result).toEqual(mockResponse);
115+
});
116+
});
18117
});

apps/api-server/src/broker/broker.controller.ts

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import { Controller, Get, Logger, Param, Post, Request } from '@nestjs/common';
2-
import { BrokerListClientResponse, GetBrokerStatusClientResponse } from '@api-interfaces';
1+
import { Body, Controller, Get, Logger, Param, Post, Put, Request } from '@nestjs/common';
2+
import {
3+
AddDbmtUserClientResponse,
4+
AddDbmtUserRequest,
5+
BrokerListClientResponse,
6+
GetBrokerStatusClientResponse,
7+
StartAllBrokersClientResponse,
8+
StopAllBrokersClientResponse,
9+
UpdateDbmtUserClientResponse,
10+
UpdateDbmtUserRequest,
11+
} from '@api-interfaces';
12+
import { validateRequiredFields } from '@util';
313
import { BaseCmsResponse } from '@type';
414
import { BrokerService } from './broker.service';
515

@@ -23,6 +33,105 @@ export class BrokerController {
2333

2434
constructor(private readonly brokerService: BrokerService) {}
2535

36+
/**
37+
* Start all brokers on a host (CMS task: startbroker).
38+
*
39+
* @route POST /:hostUid/broker/start-all
40+
* @param req - Request object containing user information
41+
* @param hostUid - Host unique identifier from path parameter
42+
* @returns StartAllBrokersClientResponse { success: true } on success
43+
* @example
44+
* // POST /host-uid/broker/start-all
45+
*/
46+
@Post('start-all')
47+
async startAllBrokers(
48+
@Request() req,
49+
@Param('hostUid') hostUid: string
50+
): Promise<StartAllBrokersClientResponse> {
51+
const userId = req.user.sub;
52+
this.logger.log(`Starting all brokers on host: ${hostUid}`);
53+
return await this.brokerService.startAllBrokers(userId, hostUid);
54+
}
55+
56+
/**
57+
* Stop all brokers on a host (CMS task: stopbroker).
58+
*
59+
* @route POST /:hostUid/broker/stop-all
60+
* @param req - Request object containing user information
61+
* @param hostUid - Host unique identifier from path parameter
62+
* @returns StopAllBrokersClientResponse { success: true } on success
63+
* @example
64+
* // POST /host-uid/broker/stop-all
65+
*/
66+
@Post('stop-all')
67+
async stopAllBrokers(
68+
@Request() req,
69+
@Param('hostUid') hostUid: string
70+
): Promise<StopAllBrokersClientResponse> {
71+
const userId = req.user.sub;
72+
this.logger.log(`Stopping all brokers on host: ${hostUid}`);
73+
return await this.brokerService.stopAllBrokers(userId, hostUid);
74+
}
75+
76+
/**
77+
* Add a DBMT (CMS) user on the host (CMS task: adddbmtuser).
78+
*
79+
* @route POST /:hostUid/broker/dbmt-user
80+
* @param req - Request object containing user information
81+
* @param hostUid - Host unique identifier from path parameter
82+
* @param body - targetid, password, casauth, dbcreate, statusmonitorauth
83+
* @returns AddDbmtUserClientResponse dblist and userlist
84+
* @example
85+
* // POST /host-uid/broker/dbmt-user
86+
* // Body: { "targetid": "test_user_2", "password": "1234", "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
87+
*/
88+
@Post('dbmt-user')
89+
async addDbmtUser(
90+
@Request() req,
91+
@Param('hostUid') hostUid: string,
92+
@Body() body: AddDbmtUserRequest
93+
): Promise<AddDbmtUserClientResponse> {
94+
const userId = req.user.sub;
95+
validateRequiredFields(
96+
body,
97+
['targetid', 'password', 'casauth', 'dbcreate', 'statusmonitorauth'],
98+
'broker/dbmt-user',
99+
this.logger
100+
);
101+
this.logger.log(`Adding DBMT user: ${body.targetid} on host: ${hostUid}`);
102+
return await this.brokerService.addDbmtUser(userId, hostUid, body);
103+
}
104+
105+
/**
106+
* Update a DBMT (CMS) user on the host (CMS task: updatedbmtuser).
107+
*
108+
* @route PUT /:hostUid/broker/dbmt-user
109+
* @param req - Request object containing user information
110+
* @param hostUid - Host unique identifier from path parameter
111+
* @param body - targetid, casauth, dbcreate, statusmonitorauth (dbauth optional)
112+
* @returns UpdateDbmtUserClientResponse dblist and userlist
113+
* @example
114+
* // PUT /host-uid/broker/dbmt-user
115+
* // Body: { "targetid": "test_user_2", "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
116+
* // or with dbauth: { "targetid": "test_user_2", "dbauth": [], "casauth": "none", "dbcreate": "none", "statusmonitorauth": "none" }
117+
*/
118+
@Put('dbmt-user')
119+
async updateDbmtUser(
120+
@Request() req,
121+
@Param('hostUid') hostUid: string,
122+
@Body() body: UpdateDbmtUserRequest
123+
): Promise<UpdateDbmtUserClientResponse> {
124+
const userId = req.user.sub;
125+
validateRequiredFields(
126+
body,
127+
['targetid', 'casauth', 'dbcreate', 'statusmonitorauth'],
128+
'broker/dbmt-user',
129+
this.logger
130+
);
131+
this.logger.log(`Updating DBMT user: ${body.targetid} on host: ${hostUid}`);
132+
return await this.brokerService.updateDbmtUser(userId, hostUid, body);
133+
}
134+
26135
/**
27136
* Get list of brokers for a specific host.
28137
*
@@ -31,7 +140,7 @@ export class BrokerController {
31140
* @param hostUid - Host unique identifier from path parameter
32141
* @returns List of brokers
33142
* @example
34-
* // POST /host-uid/broker/list
143+
* // GET /host-uid/broker/list
35144
*/
36145
@Get('list')
37146
async getBrokers(
@@ -63,7 +172,7 @@ export class BrokerController {
63172
): Promise<BaseCmsResponse> {
64173
const userId = req.user.sub;
65174

66-
Logger.log(`Stopping broker: ${bname} on host: ${hostUid}`, 'BrokerController');
175+
this.logger.log(`Stopping broker: ${bname} on host: ${hostUid}`);
67176
const response = await this.brokerService.stopBroker(userId, hostUid, bname);
68177
return response;
69178
}
@@ -87,7 +196,7 @@ export class BrokerController {
87196
): Promise<BaseCmsResponse> {
88197
const userId = req.user.sub;
89198

90-
Logger.log(`Starting broker: ${bname} on host: ${hostUid}`, 'BrokerController');
199+
this.logger.log(`Starting broker: ${bname} on host: ${hostUid}`);
91200
const response = await this.brokerService.startBroker(userId, hostUid, bname);
92201
return response;
93202
}
@@ -111,7 +220,7 @@ export class BrokerController {
111220
): Promise<boolean> {
112221
const userId = req.user.sub;
113222

114-
Logger.log(`Restarting broker: ${bname} on host: ${hostUid}`, 'BrokerController');
223+
this.logger.log(`Restarting broker: ${bname} on host: ${hostUid}`);
115224
const response: boolean = await this.brokerService.restartBroker(userId, hostUid, bname);
116225
return response;
117226
}
@@ -135,7 +244,7 @@ export class BrokerController {
135244
): Promise<GetBrokerStatusClientResponse> {
136245
const userId = req.user.sub;
137246

138-
Logger.log(`Getting broker status: ${bname} on host: ${hostUid}`, 'BrokerController');
247+
this.logger.log(`Getting broker status: ${bname} on host: ${hostUid}`);
139248
const response = await this.brokerService.getBrokerStatus(userId, hostUid, bname);
140249
return response;
141250
}

0 commit comments

Comments
 (0)