Skip to content

Commit

Permalink
RPC control on board unavailable.
Browse files Browse the repository at this point in the history
  • Loading branch information
npeditto committed Jun 8, 2018
1 parent d7c1d23 commit d98dae9
Show file tree
Hide file tree
Showing 18 changed files with 461 additions and 246 deletions.
21 changes: 17 additions & 4 deletions docs/installation_ubuntu_14.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We tested this procedure on a Ubuntu 14.04 (within a LXD container also). Everyt

##### Install dependencies via apt-get
```
apt -y install python-dev python-setuptools libyaml-dev libpython2.7-dev mysql-server nmap apache2 unzip socat bridge-utils python-pip python-httplib2 libssl-dev libffi-dev
apt -y install build-essential python-dev python-setuptools libyaml-dev libpython2.7-dev mysql-server nmap apache2 unzip socat bridge-utils python-pip python-httplib2 libssl-dev libffi-dev
```

#### Install Crossbar.io router
Expand All @@ -21,17 +21,30 @@ pip install crossbar
```

##### Install latest NodeJS (and npm) distribution:
Execute the following procedures only if are not already installed:

- NodeJS installation:
```
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get install -y nodejs
node -v
```
- NPM installation:
```
npm install -g npm
npm config set python `which python2.7`
npm -v
```
- Check if the NODE_PATH variable is not already set:
```
echo $NODE_PATH
```

otherwise, locate the global "node_modules" folder in your system ()usually in "/usr/lib/node_modules" or "/usr/local/lib/node_modules")
and edit the path in the following command:
```
echo "NODE_PATH=/usr/lib/node_modules" | tee -a /etc/environment
source /etc/environment > /dev/null
. /etc/environment > /dev/null
echo $NODE_PATH
```

Expand Down
19 changes: 16 additions & 3 deletions docs/installation_ubuntu_16.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We tested this procedure on a Ubuntu 16.04 (within a LXD container also). Everyt

##### Install dependencies via apt-get
```
apt -y install python-dev python-setuptools libyaml-dev libpython2.7-dev mysql-server nmap apache2 unzip socat bridge-utils python-pip python-httplib2 libssl-dev libffi-dev
apt -y install build-essential python-dev python-setuptools libyaml-dev libpython2.7-dev mysql-server nmap apache2 unzip socat bridge-utils python-pip python-httplib2 libssl-dev libffi-dev
```

##### Install Crossbar.io router
Expand All @@ -15,17 +15,30 @@ pip install crossbar
```

##### Install latest LTS NodeJS (and npm) distribution:
Execute the following procedures only if are not already installed:

- NodeJS installation:
```
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get install -y nodejs
node -v
```
- NPM installation:
```
npm install -g npm
npm config set python `which python2.7`
npm -v
```
- Check if the NODE_PATH variable is not already set:
```
echo $NODE_PATH
```

otherwise, locate the global "node_modules" folder in your system ()usually in "/usr/lib/node_modules" or "/usr/local/lib/node_modules")
and edit the path in the following command:
```
echo "NODE_PATH=/usr/lib/node_modules" | tee -a /etc/environment
source /etc/environment > /dev/null
. /etc/environment > /dev/null
echo $NODE_PATH
```

Expand Down
2 changes: 1 addition & 1 deletion lib/init_iotronic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//###############################################################################
//##
//# Copyright (C) 2017 Nicola Peditto
//# Copyright (C) 2017-2018 Nicola Peditto
//##
//# Licensed under the Apache License, Version 2.0 (the "License");
//# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/iotronic_standalone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//############################################################################################
//##
//# Copyright (C) 2014-2017 Dario Bruneo, Francesco Longo, Andrea Rocco Lotronto,
//# Copyright (C) 2014-2018 Dario Bruneo, Francesco Longo, Andrea Rocco Lotronto,
//# Giovanni Merlino, Nicola Peditto
//##
//# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
15 changes: 2 additions & 13 deletions lib/management/mng_auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//###############################################################################
//##
//# Copyright (C) 2017 Nicola Peditto
//# Copyright (C) 2017-2018 Nicola Peditto
//##
//# Licensed under the Apache License, Version 2.0 (the "License");
//# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -219,9 +219,7 @@ var checkAuthorization = function (board_id, callback) {


callback(response);

//iotronic_session.call('s4t.' + board_id + '.board.checkRegistrationStatus', [response]);


}
else if (data.message[0].status == "C"){

Expand Down Expand Up @@ -265,15 +263,6 @@ var checkAuthorization = function (board_id, callback) {
});











}

}
Expand Down
73 changes: 49 additions & 24 deletions lib/management/mng_board.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//###############################################################################
//##
//# Copyright (C) 2016-2017 Nicola Peditto
//# Copyright (C) 2016-2018 Nicola Peditto
//##
//# Licensed under the Apache License, Version 2.0 (the "License");
//# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -725,12 +725,21 @@ board_utils = function (session, rest) {
logger.debug("[SYSTEM] - RPC call towards: 's4t." + board + "'.board.setBoardPosition \n with parameters: " + JSON.stringify(position));

session.call('s4t.' + board + '.board.setBoardPosition', [position]).then(

function (conf_result) {
response.message = db_result.message + " - " + conf_result;
response.result = "SUCCESS";
res.status(200).send(response);
},
session.log
function (rpc_error) {

response.message = "RPC UNAVAILABLE: " + rpc_error.error;
response.result = "WARNING";
logger.warn("[SYSTEM] - RPC UNAVAILABLE: " + rpc_error.error);
res.status(200).send(response);

}

);

} else {
Expand Down Expand Up @@ -1053,37 +1062,24 @@ board_utils = function (session, rest) {

logger.info("[API] - Board Operation - " + Object.keys( req.route.methods ) + " - " + req.route.path + " - " + req.IotronicUser);

checkBoardAvailable(board, res, function (available) {

if (available.result == "SUCCESS") {

var action = req.body.action; // reboot | etc..
var parameters = req.body.parameters; // OPTIONAL

var ApiRequired = {"action":action};
var action = req.body.action; // reboot | etc..
var parameters = req.body.parameters; // OPTIONAL

checkRequired(ApiRequired, function (check) {
var ApiRequired = {"action":action};

if (check.result == "ERROR") {
checkRequired(ApiRequired, function (check) {

res.status(500).send(check);
if (check.result == "ERROR") {

} else {
res.status(500).send(check);

var request_id = null;
execActionOnBoard(board, request_id, [action, parameters, res]);
} else {

}

});

var request_id = null;
execActionOnBoard(board, request_id, [action, parameters, res]);

}else if(available.result == "WARNING") {
logger.error("[API] --> " + available.message);
res.status(200).send(available);
}


});


Expand Down Expand Up @@ -1726,6 +1722,21 @@ var execActionOnBoard = function (board_id, request_id, args) {
}


},
function (rpc_error) {

response.message = "RPC UNAVAILABLE: " + rpc_error.error;
response.result = "WARNING";
if(res != false){
logger.warn("[SYSTEM] - RPC UNAVAILABLE: " + rpc_error.error);
res.status(200).send(response);
}
else{

request_utils.updateResult(request_id, board_id, response.result, response.message);

}

}

);
Expand Down Expand Up @@ -2087,9 +2098,23 @@ board_utils.prototype.injectConf = function (board_id, request_id, args){

}

},
function (rpc_error) {

response.message = "RPC UNAVAILABLE: " + rpc_error.error;
response.result = "WARNING";
if(res != false){
logger.warn("[SYSTEM] - RPC UNAVAILABLE: " + rpc_error.error);
res.status(200).send(response);
}
else{

request_utils.updateResult(request_id, board_id, response.result, response.message);

}

}

);

}
Expand Down
4 changes: 2 additions & 2 deletions lib/management/mng_request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//###############################################################################
//##
//# Copyright (C) 2017 Nicola Peditto
//# Copyright (C) 2018 Nicola Peditto
//##
//# Licensed under the Apache License, Version 2.0 (the "License");
//# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -184,7 +184,7 @@ request_utils = function (session, rest) {
} else {
response.message = data.message;
response.result = "SUCCESS";
logger.info("[REQUEST] --> Results of the request '"+request+"': " + JSON.stringify(response.message));
logger.debug("[REQUEST] --> Results of the request '"+request+"': " + JSON.stringify(response.message));
res.status(200).send(response);

}
Expand Down
Loading

0 comments on commit d98dae9

Please sign in to comment.