Skip to content

Commit 629f37a

Browse files
mchepelevalexandershpak
authored andcommitted
todo in iofog-service was done (#363)
1 parent 06f1db0 commit 629f37a

File tree

2 files changed

+63
-86
lines changed

2 files changed

+63
-86
lines changed

src/services/connector-service.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ async function _makeRequest(connector, options, data) {
143143
})
144144
}
145145

146-
//TODO refactor this
147146
async function openPortsOnConnector(connector, isPublicAccess, transaction) {
148147
let data = isPublicAccess
149148
? await qs.stringify({

src/services/iofog-service.js

Lines changed: 63 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -63,45 +63,12 @@ async function _createFog(fogData, user, isCli, transaction) {
6363

6464
await ChangeTrackingService.create(fog.uuid, transaction);
6565

66-
//TODO: proccess watchdog flag
67-
68-
//TODO refactor. call MicroserviceService.createMicroservice
69-
//TODO: refactor. to function
7066
if (fogData.abstractedHardwareEnabled) {
71-
const halItem = await CatalogService.getHalCatalogItem(transaction);
72-
73-
const halMicroserviceData = {
74-
uuid: AppHelper.generateRandomString(32),
75-
name: `HAL for Fog ${fog.uuid}`,
76-
config: '{}',
77-
catalogItemId: halItem.id,
78-
iofogUuid: fog.uuid,
79-
rootHostAccess: true,
80-
logSize: 50,
81-
userId: user.id,
82-
configLastUpdated: Date.now()
83-
};
84-
85-
await MicroserviceManager.create(halMicroserviceData, transaction);
67+
await _createHalMicroserviceForFog(fog, null, user, transaction);
8668
}
8769

88-
//TODO: refactor. to function
8970
if (fogData.bluetoothEnabled) {
90-
const bluetoothItem = await CatalogService.getBluetoothCatalogItem(transaction);
91-
92-
const bluetoothMicroserviceData = {
93-
uuid: AppHelper.generateRandomString(32),
94-
name: `Bluetooth for Fog ${fog.uuid}`,
95-
config: '{}',
96-
catalogItemId: bluetoothItem.id,
97-
iofogUuid: fog.uuid,
98-
rootHostAccess: true,
99-
logSize: 50,
100-
userId: user.id,
101-
configLastUpdated: Date.now()
102-
};
103-
104-
await MicroserviceManager.create(bluetoothMicroserviceData, transaction);
71+
await _createBluetoothMicroserviceForFog(fog, null, user, transaction);
10572
}
10673

10774
await ChangeTrackingService.update(fogData.uuid, ChangeTrackingService.events.microserviceCommon, transaction)
@@ -150,67 +117,22 @@ async function _updateFog(fogData, user, isCli, transaction) {
150117
await ChangeTrackingService.update(fogData.uuid, ChangeTrackingService.events.config, transaction);
151118

152119
let msChanged = false;
153-
//TODO: refactor. to function
154-
if (oldFog.bluetoothEnabled === true && fogData.bluetoothEnabled === false) {
155-
const bluetoothItem = await CatalogService.getBluetoothCatalogItem(transaction);
156-
const deleteBluetoothMicroserviceData = {
157-
iofogUuid: fogData.uuid,
158-
catalogItemId: bluetoothItem.id
159-
};
160120

161-
await MicroserviceManager.delete(deleteBluetoothMicroserviceData, transaction)
121+
if (oldFog.bluetoothEnabled === true && fogData.bluetoothEnabled === false) {
122+
await _deleteBluetoothMicroserviceByFog(fogData, transaction);
162123
msChanged = true;
163124
}
164-
165-
//TODO: refactor. to function
166125
if (oldFog.bluetoothEnabled === false && fogData.bluetoothEnabled === true) {
167-
const bluetoothItem = await CatalogService.getBluetoothCatalogItem(transaction);
168-
169-
const bluetoothMicroserviceData = {
170-
uuid: AppHelper.generateRandomString(32),
171-
name: `Bluetooth for Fog ${fogData.uuid}`,
172-
config: '{}',
173-
catalogItemId: bluetoothItem.id,
174-
iofogUuid: fogData.uuid,
175-
rootHostAccess: true,
176-
logSize: 50,
177-
userId: isCli ? oldFog.userId : user.id,
178-
configLastUpdated: Date.now()
179-
};
180-
181-
await MicroserviceManager.create(bluetoothMicroserviceData, transaction);
126+
await _createBluetoothMicroserviceForFog(fogData, oldFog, user, transaction);
182127
msChanged = true;
183128
}
184129

185-
//TODO: refactor. to function
186130
if (oldFog.abstractedHardwareEnabled === true && fogData.abstractedHardwareEnabled === false) {
187-
const halItem = await CatalogService.getHalCatalogItem(transaction);
188-
const deleteHalMicroserviceData = {
189-
iofogUuid: fogData.uuid,
190-
catalogItemId: halItem.id
191-
};
192-
193-
await MicroserviceManager.delete(deleteHalMicroserviceData, transaction)
131+
await _deleteHalMicroseviceByFog(fogData, transaction);
194132
msChanged = true;
195133
}
196-
197-
//TODO: refactor. to function
198134
if (oldFog.abstractedHardwareEnabled === false && fogData.abstractedHardwareEnabled === true) {
199-
const halItem = await CatalogService.getHalCatalogItem(transaction);
200-
201-
const halMicroserviceData = {
202-
uuid: AppHelper.generateRandomString(32),
203-
name: `Hal for Fog ${fogData.uuid}`,
204-
config: '{}',
205-
catalogItemId: halItem.id,
206-
iofogUuid: fogData.uuid,
207-
rootHostAccess: true,
208-
logSize: 50,
209-
userId: isCli ? oldFog.userId : user.id,
210-
configLastUpdated: Date.now()
211-
};
212-
213-
await MicroserviceManager.create(halMicroserviceData, transaction);
135+
await _createHalMicroserviceForFog(fogData, oldFog, user, transaction);
214136
msChanged = true;
215137
}
216138

@@ -454,6 +376,62 @@ async function _processDeleteCommand(fog, transaction) {
454376
}
455377
}
456378

379+
async function _createHalMicroserviceForFog(fogData, oldFog, user, transaction) {
380+
const halItem = await CatalogService.getHalCatalogItem(transaction);
381+
382+
const halMicroserviceData = {
383+
uuid: AppHelper.generateRandomString(32),
384+
name: `Hal for Fog ${fogData.uuid}`,
385+
config: '{}',
386+
catalogItemId: halItem.id,
387+
iofogUuid: fogData.uuid,
388+
rootHostAccess: true,
389+
logSize: 50,
390+
userId: oldFog ? oldFog.userId : user.id,
391+
configLastUpdated: Date.now()
392+
};
393+
394+
await MicroserviceManager.create(halMicroserviceData, transaction);
395+
}
396+
397+
async function _deleteHalMicroseviceByFog(fogData, transaction) {
398+
const halItem = await CatalogService.getHalCatalogItem(transaction);
399+
const deleteHalMicroserviceData = {
400+
iofogUuid: fogData.uuid,
401+
catalogItemId: halItem.id
402+
};
403+
404+
await MicroserviceManager.delete(deleteHalMicroserviceData, transaction)
405+
}
406+
407+
async function _createBluetoothMicroserviceForFog(fogData, oldFog, user, transaction) {
408+
const bluetoothItem = await CatalogService.getBluetoothCatalogItem(transaction);
409+
410+
const bluetoothMicroserviceData = {
411+
uuid: AppHelper.generateRandomString(32),
412+
name: `Bluetooth for Fog ${fogData.uuid}`,
413+
config: '{}',
414+
catalogItemId: bluetoothItem.id,
415+
iofogUuid: fogData.uuid,
416+
rootHostAccess: true,
417+
logSize: 50,
418+
userId: oldFog ? oldFog.userId : user.id,
419+
configLastUpdated: Date.now()
420+
};
421+
422+
await MicroserviceManager.create(bluetoothMicroserviceData, transaction);
423+
}
424+
425+
async function _deleteBluetoothMicroserviceByFog(fogData, transaction) {
426+
const bluetoothItem = await CatalogService.getBluetoothCatalogItem(transaction);
427+
const deleteBluetoothMicroserviceData = {
428+
iofogUuid: fogData.uuid,
429+
catalogItemId: bluetoothItem.id
430+
};
431+
432+
await MicroserviceManager.delete(deleteBluetoothMicroserviceData, transaction)
433+
}
434+
457435
module.exports = {
458436
createFog: TransactionDecorator.generateTransaction(_createFog),
459437
updateFog: TransactionDecorator.generateTransaction(_updateFog),

0 commit comments

Comments
 (0)