Skip to content

Commit 906ca1a

Browse files
mchepelevRailag
authored andcommitted
fix(microservice): add ports volumeMappings and routes in info response (ENG-250)
1 parent acf0e0e commit 906ca1a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/services/microservices-service.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,22 @@ async function listMicroservices(flowId, user, isCLI, transaction) {
4242
const where = isCLI ? {delete: false} : {flowId: flowId, delete: false};
4343

4444
const microservices = await MicroserviceManager.findAllExcludeFields(where, transaction);
45+
46+
const res = await Promise.all(microservices.map(async (microservice) => {
47+
const microserviceUuid = microservice.uuid;
48+
const portMappings = await MicroservicePortManager.findAll({microserviceUuid: microserviceUuid}, transaction);
49+
const volumeMappings = await VolumeMappingManager.findAll({microserviceUuid: microserviceUuid}, transaction);
50+
const routes = await RoutingManager.findAll({sourceMicroserviceUuid: microserviceUuid}, transaction);
51+
52+
const fullMs = Object.assign({}, microservice.dataValues);
53+
fullMs.ports = portMappings.map((pm) => {return {internal: pm.portInternal, external: pm.portExternal, publicMode: pm.isPublic}});
54+
fullMs.volumeMappings = volumeMappings.map(vm => vm.dataValues);
55+
fullMs.routes = routes.map(r => r.destMicroserviceUuid);
56+
57+
return fullMs;
58+
}));
4559
return {
46-
microservices: microservices
60+
microservices: res
4761
}
4862
}
4963

@@ -59,7 +73,16 @@ async function getMicroservice(microserviceUuid, user, isCLI, transaction) {
5973
if (!microservice) {
6074
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_MICROSERVICE_UUID, microserviceUuid));
6175
}
62-
return microservice;
76+
77+
const portMappings = await MicroservicePortManager.findAll({microserviceUuid: microserviceUuid}, transaction);
78+
const volumeMappings = await VolumeMappingManager.findAll({microserviceUuid: microserviceUuid}, transaction);
79+
const routes = await RoutingManager.findAll({sourceMicroserviceUuid: microserviceUuid}, transaction);
80+
81+
const res = Object.assign({}, microservice.dataValues);
82+
res.ports = portMappings.map((pm) => {return {internal: pm.portInternal, external: pm.portExternal, publicMode: pm.isPublic}});
83+
res.volumeMappings = volumeMappings.map(vm => vm.dataValues);
84+
res.routes = routes.map(r => r.destMicroserviceUuid);
85+
return res;
6386
}
6487

6588
async function createMicroservice(microserviceData, user, isCLI, transaction) {

test/src/services/microservices-service.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ describe('Microservices Service', () => {
4141

4242
def('subject', () => $subject.listMicroservices(flowId, user, isCLI, transaction));
4343
def('findMicroservicesResponse', () => Promise.resolve(response));
44+
def('findPortMappingsResponse', () => Promise.resolve([]));
45+
def('findVolumeMappingsResponse', () => Promise.resolve([]));
46+
def('findRoutesResponse', () => Promise.resolve([]));
4447

4548
beforeEach(() => {
4649
$sandbox.stub(MicroserviceManager, 'findAllExcludeFields').returns($findMicroservicesResponse);
50+
$sandbox.stub(MicroservicePortManager, 'findAll').returns($findPortMappingsResponse);
51+
$sandbox.stub(VolumeMappingManager, 'findAll').returns($findVolumeMappingsResponse);
52+
$sandbox.stub(RoutingManager, 'findAll').returns($findRoutesResponse);
4753
});
4854

4955
it('calls MicroserviceManager#findAllExcludeFields() with correct args', async () => {
@@ -79,14 +85,22 @@ describe('Microservices Service', () => {
7985
const microserviceUuid = 'testMicroserviceUuid';
8086

8187
const response = {
82-
uuid: 'testUuid'
88+
dataValues: {
89+
uuid: 'testUuid'
90+
}
8391
};
8492

8593
def('subject', () => $subject.getMicroservice(microserviceUuid, user, isCLI, transaction));
8694
def('findMicroserviceResponse', () => Promise.resolve(response));
95+
def('findPortMappingsResponse', () => Promise.resolve([]));
96+
def('findVolumeMappingsResponse', () => Promise.resolve([]));
97+
def('findRoutesResponse', () => Promise.resolve([]));
8798

8899
beforeEach(() => {
89100
$sandbox.stub(MicroserviceManager, 'findOneExcludeFields').returns($findMicroserviceResponse);
101+
$sandbox.stub(MicroservicePortManager, 'findAll').returns($findPortMappingsResponse);
102+
$sandbox.stub(VolumeMappingManager, 'findAll').returns($findVolumeMappingsResponse);
103+
$sandbox.stub(RoutingManager, 'findAll').returns($findRoutesResponse);
90104
});
91105

92106
it('calls MicroserviceManager#findOneExcludeFields() with correct args', async () => {

0 commit comments

Comments
 (0)