Skip to content
28 changes: 1 addition & 27 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ trigger:
branches:
include:
- develop
- release*
- release/*
paths:
exclude:
- README.md
Expand Down Expand Up @@ -70,32 +70,6 @@ jobs:
echo "npm test"
displayName: 'integration tests'

- script: |
npm pack
ls iofogcontroller-*.tgz
displayName: 'npm pack for release artefact'

- task: CopyFiles@2
inputs:
SourceFolder: $(System.DefaultWorkingDirectory)
TargetFolder: $(Build.ArtifactStagingDirectory)
Contents: |
standardjs.out
*.tgz
Dockerfile.dev
OverWrite: true
displayName: 'artefacts to publish'

- script: |
rm -fr iofogcontroller-*.tgz
git checkout package-lock.json
git config --global user.email "info@edgeworx.io"
git config --global user.name "Azure DevOps"

PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
npm --no-git-tag-version version $PACKAGE_VERSION-b$(Build.BuildId)
displayName: 'npm version'

- script: |
npm pack
displayName: 'npm pack with version containing build number'
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "iofogcontroller",
"version": "1.0.37",
"version": "1.0.38",
"description": "ioFog Controller project for Eclipse IoFog @ iofog.org \\nCopyright (c) 2018 Edgeworx, Inc.",
"main": "./src/main.js",
"author": "Saeid Baghbidi",
"contributors": [
"Kilton Hopkins <kilton@edgeworx.io>",
"Saeid Baghbidi",
"Alexandre de Wergifosse",
"Pavel Kazlou",
"Egor Krylovich",
"Iryna Laryionava",
Expand Down Expand Up @@ -86,7 +87,7 @@
"path": "0.12.7",
"portscanner": "2.2.0",
"qs": "6.6.0",
"request-promise": "^4.2.4",
"request-promise": "4.2.4",
"retry-as-promised": "3.1.0",
"semver": "5.6.0",
"sequelize": "4.42.0",
Expand All @@ -105,8 +106,8 @@
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"chai-http": "4.2.1",
"eslint": "^5.14.1",
"eslint-config-google": "^0.12.0",
"eslint": "5.14.1",
"eslint-config-google": "0.12.0",
"mocha": "5.2.0",
"nyc": "13.3.0",
"sinon": "7.2.3",
Expand Down
54 changes: 27 additions & 27 deletions scripts/cli-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const registryListFields = ['registries']

const tunnelListFields = ['tunnels']

function testControllerSection() {
function testControllerSection () {
console.log('\n=============================\nStarting controller section..')

responseHasFields(testCommand('controller status'), controllerStatusFields)
Expand All @@ -62,7 +62,7 @@ function testControllerSection() {
hasSomeResponse(testCommand('controller version'))
}

function testUserSection() {
function testUserSection () {
console.log('\n=============================\nStarting user section..')

responseHasFields(testCommand('user add -f John -l Doe -e user@domain.com -p \'#Bugs4Fun\''), userCreateFields)
Expand All @@ -75,7 +75,7 @@ function testUserSection() {
responseEquals(testCommand('user remove -e user@domain.com'), 'User removed successfully.')
}

function testConfigSection() {
function testConfigSection () {
console.log('\n=============================\nStarting config section..')

// TODO backup config before this command
Expand All @@ -86,7 +86,7 @@ function testConfigSection() {
responseEquals(testCommand('config email-activation -f'), 'Email activation state updated successfully.')
}

function testConnectorSection() {
function testConnectorSection () {
console.log('\n=============================\nStarting connector section..')

responseContains(testCommand('connector add -i 127.0.0.1 -n Connector1 -d iofog.test.org -c testCertPath' +
Expand All @@ -97,15 +97,15 @@ function testConnectorSection() {
responseIsArray(testCommand('connector list'))
}

function testTunnelSection() {
function testTunnelSection () {
console.log('\n=============================\nStarting tunnel section..')

responseContains(testCommand('tunnel update -i testIoFogUuid -u testUsername -p testPassword -s 127.0.0.1 ' +
'-k testRSAKeyPath -o 2048 -a open'), 'ENOENT: no such file or directory')
responseHasFields(testCommand('tunnel list'), tunnelListFields)
}

function testIoFogSection() {
function testIoFogSection () {
console.log('\n=============================\nStarting iofog section..')

const userCreateResponse = responseHasFields(executeCommand('user add -f John -l Doe -e fogUser@domain.com' +
Expand Down Expand Up @@ -135,7 +135,7 @@ function testIoFogSection() {
}
}

function testCatalogSection() {
function testCatalogSection () {
console.log('\n=============================\nStarting catalog section..')

const userCreateResponse = responseHasFields(executeCommand('user add -f John -l Doe -e catalogUser@domain.com' +
Expand All @@ -147,13 +147,13 @@ function testCatalogSection() {

try {
const catalogCreateResponse = responseHasFields(testCommand('catalog add -n testCatalogItem1 -d testDescription' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g '
+ registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat ' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g ' +
registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat ' +
'-X \'{}\' -u ' + userId), catalogCreateFields)
const catalogId = catalogCreateResponse.id
responseEquals(testCommand('catalog update -i ' + catalogId + ' -n testCatalogItem2 -d testDescription' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g '
+ registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat -X \'{}\''),
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g ' +
registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat -X \'{}\''),
'Catalog item has been updated successfully.')
responseHasFields(testCommand('catalog list'), catalogListFields)
responseHasFields(testCommand('catalog info -i ' + catalogId), catalogCreateFields)
Expand All @@ -166,7 +166,7 @@ function testCatalogSection() {
}
}

function testFlowSection() {
function testFlowSection () {
console.log('\n=============================\nStarting flow section..')

const userCreateResponse = responseHasFields(executeCommand('user add -f John -l Doe -e flowUser@domain.com' +
Expand All @@ -188,7 +188,7 @@ function testFlowSection() {
}
}

function testMicroserviceSection() {
function testMicroserviceSection () {
console.log('\n=============================\nStarting microservice section..')

const userCreateResponse = responseHasFields(executeCommand('user add -f John -l Doe -e microserviceUser@domain.com' +
Expand All @@ -200,8 +200,8 @@ function testMicroserviceSection() {
const registryId = registryCreateResponse.id

const catalogCreateResponse = responseHasFields(executeCommand('catalog add -n testCatalogItem1 -d testDescription' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g '
+ registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat ' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g ' +
registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat ' +
'-X \'{}\' -u ' + userId), catalogCreateFields)
const catalogId = catalogCreateResponse.id

Expand Down Expand Up @@ -254,7 +254,7 @@ function testMicroserviceSection() {
}
}

function testRegistrySection() {
function testRegistrySection () {
console.log('\n=============================\nStarting registry section..')

const userCreateResponse = responseHasFields(executeCommand('user add -f John -l Doe -e registryUser@domain.com' +
Expand All @@ -275,7 +275,7 @@ function testRegistrySection() {
}
}

function testDiagnosticsSection() {
function testDiagnosticsSection () {
console.log('\n=============================\nStarting diagnostics section..')

const userCreateResponse = responseHasFields(executeCommand('user add -f John -l Doe -e diagnosticsUser@domain.com' +
Expand All @@ -287,8 +287,8 @@ function testDiagnosticsSection() {
const registryId = registryCreateResponse.id

const catalogCreateResponse = responseHasFields(executeCommand('catalog add -n testCatalogItem1 -d testDescription' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g '
+ registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat ' +
' -c testCategory -x testIntelImage -a testArmImage -p testPublisher -s 15 -r 15 -t testPicture -g ' +
registryId + ' -I testInputType -F testInputFormat -O testOutputType -T testOutputFormat ' +
'-X \'{}\' -u ' + userId), catalogCreateFields)
const catalogId = catalogCreateResponse.id

Expand Down Expand Up @@ -333,27 +333,27 @@ function testDiagnosticsSection() {
}
}

function testCommand(command) {
function testCommand (command) {
console.log('\n Testing command \'' + command + '\'')
testsCounter++
return executeCommand(command)
}

function executeCommand(command) {
function executeCommand (command) {
let response = execSync('node ./src/main.js ' + command, options)
response = response.toString()
response = response.replace(/\r?\n?/g, '') // remove line breaks
return response
}

function hasSomeResponse(response) {
function hasSomeResponse (response) {
if (response === undefined || response === null) {
testsFailed++
console.log('\'hasSomeResponse\' test failed with response: ' + JSON.stringify(response))
}
}

function responseIsArray(jsonResponse) {
function responseIsArray (jsonResponse) {
try {
const response = JSON.parse(jsonResponse)
if (!Array.isArray(response)) {
Expand All @@ -366,7 +366,7 @@ function responseIsArray(jsonResponse) {
}
}

function responseHasFields(jsonResponse, fields) {
function responseHasFields (jsonResponse, fields) {
try {
const response = JSON.parse(jsonResponse)
for (const field of fields) {
Expand All @@ -383,21 +383,21 @@ function responseHasFields(jsonResponse, fields) {
}
}

function responseEquals(response, expectedResponse) {
function responseEquals (response, expectedResponse) {
if (response !== expectedResponse) {
testsFailed++
console.log('\'responseEquals\' test failed with response: ' + JSON.stringify(response))
}
}

function responseContains(response, expectedResponsePart) {
function responseContains (response, expectedResponsePart) {
if (!response.includes(expectedResponsePart)) {
testsFailed++
console.log('\'responseContains\' test failed with response: ' + JSON.stringify(response))
}
}

function cliTest() {
function cliTest () {
try {
backupDBs()
// create new DBs
Expand Down
6 changes: 6 additions & 0 deletions scripts/preuninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
*/

const execSync = require('child_process').execSync
const fs = require('fs')
const version = require('../package').version
const { backupDBs, backupConfigs, backupTrackingUuid, INSTALLATION_VARIABLES_FILE } = require('./util')
Expand All @@ -25,6 +26,11 @@ function preuninstall() {
backupDBs()
backupConfigs()
backupTrackingUuid()

const options = {
stdio: [process.stdin, process.stdout, process.stderr],
}
execSync('iofog-controller stop', options)
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ const _updateMicroserviceObject = function(obj) {
rootHostAccess: AppHelper.validateBooleanCliOptions(obj.rootEnable, obj.rootDisable),
logSize: obj.logSize,
rebuild: obj.rebuild,
arg: obj.cmd,
cmd: obj.cmd,
env,
}

Expand Down Expand Up @@ -524,7 +524,7 @@ const _createMicroserviceObject = function(obj) {
rootHostAccess: AppHelper.validateBooleanCliOptions(obj.rootEnable, obj.rootDisable),
logSize: obj.logSize,
routes: obj.routes,
arg: obj.cmd,
cmd: obj.cmd,
env,
}

Expand Down
34 changes: 19 additions & 15 deletions src/cli/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Start extends BaseCLIHandler {
if (pid === 0) {
this.initDB()
daemon.start()
checkDaemon(daemon, configuration)
await checkDaemon(daemon, configuration)
} else {
logger.cliRes(`iofog-controller already running. PID: ${pid}`)
}
Expand All @@ -49,24 +49,28 @@ class Start extends BaseCLIHandler {
}

function checkDaemon(daemon, configuration) {
let iterationsCount = 0
const check = () => {
iterationsCount++
const pid = daemon.status()
if (pid === 0) {
return logger.error('Error: port is probably allocated, or ssl_key or ssl_cert or intermediate_cert ' +
'is either missing or invalid.')
}
return new Promise((resolve, reject) => {
let iterationsCount = 0
const check = () => {
iterationsCount++
const pid = daemon.status()
if (pid === 0) {
logger.error('Error: port is probably allocated, or ssl_key or ssl_cert or intermediate_cert ' +
'is either missing or invalid.')
return reject(new Error('Error starting ioFog-Controller'))
}

if (iterationsCount === 5) {
checkServerProtocol(configuration)
return logger.cliRes(`ioFog-Controller has started at pid: ${pid}`)
if (iterationsCount === 5) {
checkServerProtocol(configuration)
logger.cliRes(`ioFog-Controller has started at pid: ${pid}`)
return resolve()
}

setTimeout(check, 1000)
}

setTimeout(check, 1000)
}

setTimeout(check, 1000)
})
}

function checkServerProtocol(configuration) {
Expand Down
Loading