Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ $ iofog-controller config <*options*>
-a, --email-address string (Email address to send activations from) <br>
-w, --email-password string (Email password to send activations from) <br>
-s, --email-service string (Email service to send activations) <br>
-d, --log-dir string (Log files directory) <br>
-d, --log-dir string (Path to log files directory) <br>
-z, --log-size number (Log files size (MB)) <br>

*list*<br>
Expand Down Expand Up @@ -135,7 +135,7 @@ $ iofog-controller connector <*command*> <*options*>
-n, --name string (Connector name) <br>
-d, --domain string (Connector domain name) <br>
-i, --public-ip string (Connector public IP address) <br>
-c, --cert string (Certificate) <br>
-c, --cert string (Path to certificate file) <br>
-S, --self-signed-on (Switch on self-signed enabled) <br>
-s, --self-signed-off (Switch off self-signed disabled) <br>
-H, --dev-mode-on (Switch on dev mode) <br>
Expand Down Expand Up @@ -173,7 +173,7 @@ $ iofog-controller tunnel <*command*> <*options*>
-u, --username string (Tunnel username) <br>
-p, --password string (Tunnel password) <br>
-s, --host string (Tunnel host address) <br>
-k, --rsa-key string (Tunnel RSA key) <br>
-k, --rsa-key string (Path to tunnel RSA key) <br>
-o, --port number (Tunnel port) <br>
-f, --iofogUuid string (Fog UUID) <br>

Expand Down Expand Up @@ -215,11 +215,11 @@ tunnel list
-d, --description string (ioFog node description) <br>
-D, --docker-url string (ioFog node docker url) <br>
-M, --disk-limit number (ioFog node disk usage limit (MB)) <br>
-T, --disk-directory string (ioFog node disk directory) <br>
-T, --disk-directory string (Path to ioFog node disk directory) <br>
-m, --memory-limit number (ioFog node memory usage limit (MB)) <br>
-c, --cpu-limit number (ioFog node CPU usage limit (%)) <br>
-G, --log-limit number (ioFog node log size limit (MB)) <br>
-Y, --log-directory string (ioFog node log files directory) <br>
-Y, --log-directory string (Path to ioFog node log files directory) <br>
-C, --log-file-count number (ioFog node log files count) <br>
-s, --status-frequency number (ioFog node status check frequency (seconds)) <br>
-F, --change-frequency number (ioFog node configuration change check frequency (seconds)) <br>
Expand Down Expand Up @@ -702,7 +702,7 @@ $ iofog-controller catalog <*command*> <*options*> <br>

*strace-info -i* <*microservice-id*><br>

-f, --format string (Format of strace data to receive)<br>
-f, --format string (Format of strace data to receive. Possible values: string, file)<br>

*strace-ftp-post -i* <*microservice-id*><br>

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iofogcontroller",
"version": "1.0.26",
"version": "1.0.27",
"description": "ioFog Controller project for Eclipse IoFog @ iofog.org \\nCopyright (c) 2018 Edgeworx, Inc.",
"main": "./src/main.js",
"author": "Saeid Baghbidi",
Expand Down Expand Up @@ -79,7 +79,8 @@
"xss-clean": "^0.1.1",
"qs": "^6.5.2",
"child_process": "^1.0.2",
"os": "^0.1.1"
"os": "^0.1.1",
"semver": "^5.6.0"
},
"devDependencies": {
"automatic-release": "^1.1.1",
Expand Down
56 changes: 48 additions & 8 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
*
*/


const os = require('os');
const execSync = require('child_process').execSync;
const fs = require('fs');
const semver = require('semver');
const currentVersion = require('../package').version;

const rootDir = `${__dirname}/../`;
let installation_variables_file_name = 'iofogcontroller_install_variables';
let installation_variables_file;
let installationVariablesFileName = 'iofogcontroller_install_variables';
let installationVariablesFile;
let tempDir;

if (os.type() === 'Linux') {
Expand All @@ -31,17 +32,56 @@ if (os.type() === 'Linux') {
throw new Error("Unsupported OS found: " + os.type());
}

installation_variables_file = tempDir + installation_variables_file_name;

installationVariablesFile = tempDir + installationVariablesFileName;

const devDbBackup = `${tempDir}dev_database.sqlite`;
const devDb = `${rootDir}/src/sequelize/dev_database.sqlite`;
if (fs.existsSync(devDbBackup)) {
fs.renameSync(devDbBackup, `${rootDir}/src/sequelize/dev_database.sqlite`)
fs.renameSync(devDbBackup, devDb);
}

const prodDbBackup = `${tempDir}prod_database.sqlite`;
const prodDb = `${rootDir}/src/sequelize/prod_database.sqlite`;
if (fs.existsSync(prodDbBackup)) {
fs.renameSync(prodDbBackup, `${rootDir}/src/sequelize/prod_database.sqlite`)
fs.renameSync(prodDbBackup, prodDb);
}

//TODO: add version migrations
try {
const instalationVarsStr = fs.readFileSync(installationVariablesFile);
const instalationVars = JSON.parse(instalationVarsStr);
const prevVersion = instalationVars.prevVer;

console.log(`previous version - ${prevVersion}`);
console.log(`new version - ${currentVersion}`);

if (semver.satisfies(prevVersion, '<=1.0.0')) {
console.log('upgrading from version <=1.0.0 :');
console.log(' inserting seeds meta info in db');
const options = {
env: {
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};

execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928110125-insert-registry.js');"`, options);
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928111532-insert-catalog-item.js');"`, options);
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928112152-insert-iofog-type.js');"`, options);
execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928121334-insert-catalog-item-image.js');"`, options);
}

fs.unlinkSync(installationVariablesFile);
} catch (e) {
console.log('no previous version')
}

//init db
const options = {
env: {
'NODE_ENV': 'production',
"PATH": process.env.PATH
},
stdio: [process.stdin, process.stdout, process.stderr]
};

execSync('node ./src/main.js init', options);
77 changes: 0 additions & 77 deletions scripts/postinstall.sh

This file was deleted.

12 changes: 8 additions & 4 deletions scripts/preuninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const fs = require('fs');
const version = require('../package').version;

const rootDir = `${__dirname}/../`;
let installation_variables_file_name = 'iofogcontroller_install_variables';
let installation_variables_file;
let installationVariablesFileName = 'iofogcontroller_install_variables';
let installationVariablesFile;
let tempDir;

if (os.type() === 'Linux') {
Expand All @@ -31,9 +31,13 @@ if (os.type() === 'Linux') {
throw new Error("Unsupported OS found: " + os.type());
}

installation_variables_file = tempDir + installation_variables_file_name;
installationVariablesFile = tempDir + installationVariablesFileName;

fs.writeFileSync(installation_variables_file, `prev_ver: ${version}`);
const instalationVars = {
prevVer: version
};

fs.writeFileSync(installationVariablesFile, JSON.stringify(instalationVars));

const devDb = `${rootDir}/src/sequelize/dev_database.sqlite`;
if (fs.existsSync(devDb)) {
Expand Down
16 changes: 12 additions & 4 deletions src/cli/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,25 @@ const _createCatalogItemObject = function (catalogItem) {
picture: catalogItem.picture,
isPublic: AppHelper.validateBooleanCliOptions(catalogItem.public, catalogItem.private),
registryId: catalogItem.registryId,
images: [
images: []
};

if (catalogItem.x86Image) {
catalogItemObj.images.push(
{
containerImage: catalogItem.x86Image,
fogTypeId: 1
},
}
);
}
if (catalogItem.armImage) {
catalogItemObj.images.push(
{
containerImage: catalogItem.armImage,
fogTypeId: 2
}
]
};
);
}

if (catalogItem.inputType) {
catalogItemObj.inputType = {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Config extends BaseCLIHandler {
group: constants.CMD_ADD
},
{
name: 'log-dir', alias: 'd', type: String, description: 'Log files directory',
name: 'log-dir', alias: 'd', type: String, description: 'Path to log files directory',
group: constants.CMD_ADD
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/cli/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Connector extends BaseCLIHandler {
},
{
name: 'cert', alias: 'c', type: String,
description: 'Certificate',
description: 'Path to certificate file',
group: [constants.CMD_ADD, constants.CMD_UPDATE]
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/cli/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Diagnostics extends BaseCLIHandler {
constants.CMD_IMAGE_SNAPSHOT_CREATE, constants.CMD_IMAGE_SNAPSHOT_GET]
},
{
name: 'format', alias: 'f', type: String, description: 'Format of strace data to receive',
name: 'format', alias: 'f', type: String, description: 'Format of strace data to receive. Possible values: string, file',
group: [constants.CMD_STRACE_INFO]
},
{
Expand Down Expand Up @@ -128,7 +128,7 @@ const _executeCase = async function (diagnosticCommand, commandName, f, isUserRe
const _changeMicroserviceStraceState = async function (obj) {
logger.info(JSON.stringify(obj));

const enable = AppHelper.validateBooleanCliOptions(obj.disable, obj.enable);
const enable = AppHelper.validateBooleanCliOptions(obj.enable, obj.disable);
await DiagnosticService.changeMicroserviceStraceState(obj.microserviceId, {enable: enable}, {}, true);
const msg = enable ? 'Microservice strace has been enabled' : 'Microservice strace has been disabled';
logger.info(msg);
Expand Down
4 changes: 2 additions & 2 deletions src/cli/iofog.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class IOFog extends BaseCLIHandler {
},
{
name: 'disk-directory', alias: 'T', type: String,
description: 'ioFog node disk directory',
description: 'Path to ioFog node disk directory',
group: [constants.CMD_UPDATE, constants.CMD_ADD]
},
{
Expand All @@ -119,7 +119,7 @@ class IOFog extends BaseCLIHandler {
},
{
name: 'log-directory', alias: 'Y', type: String,
description: 'ioFog node log files directory',
description: 'Path to ioFog node log files directory',
group: [constants.CMD_UPDATE, constants.CMD_ADD]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/cli/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const _removePortMapping = async function (obj, user) {
await MicroserviceService.deletePortMapping(obj.microserviceId, internalPort, user, true);
logger.info('Port mapping has been deleted successfully.');
} catch (e) {
logger.error(ErrorMessages.CLI.INVALID_INTERNAL_PORT);
logger.error(e.message);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/cli/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Tunnel extends BaseCLIHandler {
},
{
name: 'rsa-key', alias: 'k', type: String,
description: 'Tunnel RSA key',
description: 'Path to tunnel RSA key',
group: [constants.CMD_UPDATE]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/transaction-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function transaction(f) {

const fArgs = Array.prototype.slice.call(arguments);
//TODO [when transactions concurrency issue fixed]: Remove 'fArgs[fArgs.length - 1].fakeTransaction'
if (fArgs.length > 0 && (fArgs[fArgs.length - 1] instanceof Transaction || fArgs[fArgs.length - 1].fakeTransaction)) {
if (fArgs.length > 0 && fArgs[fArgs.length - 1] && (fArgs[fArgs.length - 1] instanceof Transaction || fArgs[fArgs.length - 1].fakeTransaction)) {
return await f.apply(this, fArgs);
} else {
//return f.apply(this, fArgs)
Expand Down
7 changes: 6 additions & 1 deletion src/helpers/app-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ async function checkPortAvailability(port) {
}

const findAvailablePort = async function (hostname) {
let portBounds = Config.get("Tunnel:PortRange").split("-").map(i => parseInt(i));
let portRange = Config.get("Tunnel:PortRange");
if (!portRange) {
logger.warn('Port range was\'n specified in config. Default range (2000-10000) will be used');
portRange = '2000-10000';
}
let portBounds = portRange.split("-").map(i => parseInt(i));
return await portscanner.findAPortNotInUse(portBounds[0], portBounds[1], hostname);
}

Expand Down
1 change: 1 addition & 0 deletions src/schemas/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const catalogItemCreate = {
"configExample": {"type": "string"},
"images": {
"type": "array",
"minItems": 1,
"maxItems": 2,
"items": {"$ref": "/image"}
},
Expand Down
Loading