Skip to content

Commit 2d262e9

Browse files
authored
Merge branch 'develop' into master
2 parents 893259d + 858e29f commit 2d262e9

File tree

10 files changed

+110
-69
lines changed

10 files changed

+110
-69
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ Also see the **[release page](https://github.com/ioFog/Controller/releases)**.
55
<br>
66

77
## [1.0.22](https://github.com/ioFog/Controller/releases/tag/1.0.22) (2018-11-26)
8+
## [1.0.20](https://github.com/ioFog/Controller/releases/tag/1.0.20) (2018-11-24)
9+
10+
11+
<br>
12+
13+
## [1.0.19](https://github.com/ioFog/Controller/releases/tag/1.0.19) (2018-11-22)
14+
15+
16+
<br>
17+
18+
## [1.0.0](https://github.com/ioFog/Controller/releases/tag/1.0.0) (2018-10-30)
819

920

1021
<br>

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
"start-dev": "NODE_ENV=development node ./src/main.js start",
3939
"build": "export NODE_ENV=production && cd src/sequelize && ../../node_modules/.bin/sequelize db:migrate && ../../node_modules/.bin/sequelize db:seed:all",
4040
"preuninstall": "bash scripts/preuninstall.sh",
41-
"postinstall": "bash scripts/postinstall.sh",
41+
"postinstall": "bash scripts/postinstall.sh && NODE_ENV=production node ./src/main.js init",
4242
"lint": "./node_modules/.bin/eslint \"**/*.js\"",
43-
"automatic-release": "automatic-release"
43+
"automatic-release": "automatic-release",
44+
"test": ""
4445
},
4546
"preferGlobal": true,
4647
"bin": {

src/cli/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Cli extends BaseCLIHandler {
3636
this.commands = {
3737
[constants.CMD_START]: 'Start iofog-controller service.',
3838
[constants.CMD_STOP]: 'Stop iofog-controller service.',
39+
//init db is hidden command
40+
// [constants.CMD_INIT_DB]: 'Init sqlite db for iofog-controller.',
3941
[constants.CMD_CONTROLLER]: 'Display iofog-controller service information.',
4042
[constants.CMD_HELP]: 'Display usage information.',
4143
[constants.CMD_USER]: 'User operations.',
@@ -60,6 +62,8 @@ class Cli extends BaseCLIHandler {
6062
return Start.run({ daemon });
6163
case constants.CMD_STOP:
6264
return daemon.stop();
65+
case constants.CMD_INIT_DB:
66+
return Start.initDB();
6367
case constants.CMD_CONTROLLER:
6468
return Controller.run({ argv });
6569
case constants.CMD_USER:

src/cli/start.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,23 @@ class Start extends BaseCLIHandler {
2929
const pid = daemon.status();
3030

3131
if (pid === 0) {
32-
try {
33-
await db.migrate();
34-
await db.seed();
35-
} catch (err) {
36-
logger.silly('Unable to initialize the database.', err);
37-
process.exit(1)
38-
}
32+
this.initDB();
3933
daemon.start();
4034
checkDaemon(daemon, configuration)
4135
} else {
4236
logger.silly(`iofog-controller already running. PID: ${pid}`)
4337
}
4438
}
39+
40+
async initDB() {
41+
try {
42+
await db.migrate();
43+
await db.seed();
44+
} catch (err) {
45+
logger.silly('Unable to initialize the database.', err);
46+
process.exit(1)
47+
}
48+
}
4549
}
4650

4751
function checkDaemon(daemon, configuration) {

src/daemon.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* *******************************************************************************
3+
* * Copyright (c) 2018 Edgeworx, Inc.
4+
* *
5+
* * This program and the accompanying materials are made available under the
6+
* * terms of the Eclipse Public License v. 2.0 which is available at
7+
* * http://www.eclipse.org/legal/epl-2.0
8+
* *
9+
* * SPDX-License-Identifier: EPL-2.0
10+
* *******************************************************************************
11+
*
12+
*/
13+
14+
const daemonize = require('daemonize2');
15+
const logger = require('./logger');
16+
17+
const daemon = daemonize.setup({
18+
main: 'server.js',
19+
name: 'iofog-controller',
20+
pidfile: 'iofog-controller.pid',
21+
silent: true,
22+
});
23+
24+
daemon
25+
.on('starting', async () => {
26+
logger.silly('Starting iofog-controller...');
27+
})
28+
.on('stopping', () => {
29+
logger.silly('Stopping iofog-controller...')
30+
})
31+
.on('stopped', (pid) => {
32+
logger.silly('iofog-controller stopped.')
33+
})
34+
.on('running', (pid) => {
35+
logger.silly('iofog-controller already running. PID: ' + pid)
36+
})
37+
.on('notrunning', () => {
38+
logger.silly('iofog-controller is not running')
39+
})
40+
.on('error', (err) => {
41+
logger.silly('iofog-controller failed to start: ' + err.message)
42+
});
43+
44+
45+
module.exports = daemon;

src/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
CMD_HELP: 'help',
2626
CMD_START: 'start',
2727
CMD_STOP: 'stop',
28+
CMD_INIT_DB: 'init',
2829
CMD_STATUS: 'status',
2930
CMD_VERSION: 'version',
3031
CMD_USER: 'user',

src/main.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,13 @@ if (!process.env.NODE_ENV) {
1717
process.env.NODE_ENV = 'production'
1818
}
1919

20-
const daemonize = require('daemonize2');
2120
const Cli = require('./cli');
2221
const logger = require('./logger');
22+
const daemon = require('./daemon');
2323

2424
function main() {
25-
const daemon = daemonize.setup({
26-
main: 'server.js',
27-
name: 'iofog-controller',
28-
pidfile: 'iofog-controller.pid',
29-
silent: true,
30-
});
31-
3225
const cli = new Cli();
3326

34-
daemon
35-
.on('starting', async () => {
36-
logger.silly('Starting iofog-controller...');
37-
})
38-
.on('stopping', () => {
39-
logger.silly('Stopping iofog-controller...')
40-
})
41-
.on('stopped', (pid) => {
42-
logger.silly('iofog-controller stopped.')
43-
})
44-
.on('running', (pid) => {
45-
logger.silly('iofog-controller already running. PID: ' + pid)
46-
})
47-
.on('notrunning', () => {
48-
logger.silly('iofog-controller is not running')
49-
})
50-
.on('error', (err) => {
51-
logger.silly('iofog-controller failed to start: ' + err.message)
52-
});
53-
5427
cli.run(daemon)
5528
}
5629

src/sequelize/managers/microservice-manager.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ const Routing = models.Routing;
2626
const Registry = models.Registry;
2727
const MicroserviceStatus = models.MicroserviceStatus;
2828

29+
const microserviceExcludedFields = [
30+
'configLastUpdated',
31+
'created_at',
32+
'updated_at',
33+
'updatedBy',
34+
'registryId',
35+
'isNetwork',
36+
'rebuild',
37+
'deleteWithCleanUp',
38+
'imageSnapshot',
39+
'catalog_item_id',
40+
'iofog_uuid'
41+
];
42+
2943
class MicroserviceManager extends BaseManager {
3044
getEntity() {
3145
return Microservice
@@ -247,41 +261,20 @@ class MicroserviceManager extends BaseManager {
247261
return Microservice.findOne({
248262
where: where,
249263
attributes: {
250-
exclude: [
251-
'configLastUpdated',
252-
'created_at',
253-
'updated_at',
254-
'updatedBy',
255-
'registryId',
256-
'isNetwork',
257-
'rebuild',
258-
'deleteWithCleanUp',
259-
'imageSnapshot',
260-
'catalog_item_id',
261-
'iofog_uuid'
262-
]}}, {transaction: transaction})
264+
exclude: microserviceExcludedFields
265+
}}, {
266+
transaction: transaction
267+
});
263268
}
264269

265270
async findAllExcludeFields(where, transaction) {
266271
return Microservice.findAll({
267272
where: where,
268273
attributes: {
269-
exclude: [
270-
'configLastUpdated',
271-
'created_at',
272-
'updated_at',
273-
'updatedBy',
274-
'flowId',
275-
'registryId',
276-
'isNetwork',
277-
'rebuild',
278-
'deleteWithCleanUp',
279-
'imageSnapshot',
280-
'catalog_item_id',
281-
'iofog_uuid',
282-
'iofogUuid',
283-
'catalogItemId'
284-
]}}, {transaction: transaction})
274+
exclude: microserviceExcludedFields
275+
}}, {
276+
transaction: transaction
277+
});
285278
}
286279
}
287280

src/services/controller-service.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ const emailActivation = async function (isCLI) {
4242
};
4343

4444
const statusController = async function (isCLI) {
45+
const daemon = require('../daemon');
46+
47+
let pid = daemon.status();
48+
if (pid === 0) {
49+
status = 'offline'
50+
} else {
51+
status = 'online'
52+
}
53+
4554
return {
46-
"status": "ok",
55+
"status": status,
4756
"timestamp": Date.now(),
4857
}
4958
};

src/services/microservices-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const _createVolumeMappings = async function (volumeMappings, microserviceUuid,
136136

137137
const _createRoutes = async function (routes, microserviceUuid, user, transaction) {
138138
for (let route of routes) {
139-
await _createRoute(microserviceUuid, route, user, transaction)
139+
await _createRoute(microserviceUuid, route, user, false, transaction)
140140
}
141141
};
142142

@@ -470,7 +470,7 @@ async function _createNetworkMicroserviceForMaster(masterMicroservice, sourceNet
470470
iofogUuid: masterMicroservice.iofogUuid,
471471
rootHostAccess: false,
472472
logSize: 50,
473-
userId: user.id,
473+
userId: masterMicroservice.userId,
474474
configLastUpdated: Date.now()
475475
};
476476

0 commit comments

Comments
 (0)