Skip to content

Commit

Permalink
initial version of working mongodb gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
woodsmc committed Mar 22, 2018
1 parent 4ba5feb commit 35e03bf
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/mongodb_gateway/gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
(c) Copyright 2018 Mind-Flip Limited
Based on the original from Intel (see license and details below).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
----------------------------------------------------------------------------
(c) Copyright 2013 Intel Performance Learning Solutions Ltd,
Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
In addition to the Apache License, Version 2.0, please note that:
This software is subject to the U.S. Export Administration Regulations
and other U.S. law, and may not be exported or re-exported to certain
countries (Cuba, Iran, North Korea, Sudan, and Syria) or to persons or
entities prohibited from receiving U.S. exports (including Denied Parties,
Specially Designated Nationals, and entities on the Bureau of Export
Administration Entity List or involved with missile technology or nuclear,
chemical or biological weapons).
**/

var io = require('socket.io').listen(server);
var ioclient = require('socket.io-client');
var ipaddresses = require('./getlocalip');
var importedSis = require('../../sis/sisyphus');
var $sis = importedSis.$sis;

var myIP = ipaddresses.getIPAddress();
console.log("my local ip is being used:" + myIP);

if ( process.argv.length == 3 ) {
console.log("Command line over rule for auto-detected IP address, using \"" + process.argv[2] + "\" instead.");
myIP = process.argv[2]; //"pint.dyndns.info";
}

$sis.configureAsGateway( { gateway : "node" }, "http://" + myIP + "/", [], io, ioclient );
71 changes: 71 additions & 0 deletions examples/mongodb_gateway/getlocalip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
(c) Copyright 2013 Intel Performance Learning Solutions Ltd, Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
In addition to the Apache License, Version 2.0, please note that:
This software is subject to the U.S. Export Administration Regulations
and other U.S. law, and may not be exported or re-exported to certain
countries (Cuba, Iran, North Korea, Sudan, and Syria) or to persons or
entities prohibited from receiving U.S. exports (including Denied Parties,
Specially Designated Nationals, and entities on the Bureau of Export
Administration Entity List or involved with missile technology or nuclear,
chemical or biological weapons).
**/


function getListOfIPAddresses() {
var retval = new Array();
var os = require('os');
var ifaces=os.networkInterfaces();
console.log("processing interfaces");

for(var dev in ifaces) {
var alias =0;
ifaces[dev].forEach(function(details){
if ( details.family=='IPv4') {
//console.log(dev+(alias?':'+alias:''),details.address);
retval.push(details.address);
alias++;
}
});
}

return retval;
}

function getFirstExternalIpAddress() {
var addresses = getListOfIPAddresses();
var retval = null;
for(var i =0 ; i < addresses.length; i++) {
if ( addresses[i] != '127.0.0.1' ) {
retval = addresses[i];
break;
}
}
return retval;
}


function getWorkableIPAddress() {
var address = getFirstExternalIpAddress();
if ( address == null ) {
addreess = '127.0.0.1';
}
return address;
}

if ( typeof(exports) != 'undefined' ) {
exports.getIPAddress = getWorkableIPAddress;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

function print {
echo -e "\e[36m$1\e[0m"
}

print "Install express"
sudo npm install express
print "Install socket.io"
sudo npm install socket.io
sudo npm install socket.io-client
print "Installing Q, for node"
sudo npm install q
print "Installing mongodb for node"
sudo npm install mongodb

56 changes: 56 additions & 0 deletions examples/mongodb_gateway/run_gateway.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

###############################################################################
# (c) Copyright 2018 Mind-Flip Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
################################################################################


function print {
echo -e "\e[36m$1\e[0m"
}

function print_green {
echo -e "\e[92m$1\e[0m"
}



function step {
LAST_STEP="$1"
print "$1"
}

function step_done {
print_green "$LAST_STEP finished."
}

function print_title {
print "Running Sisyphus Distributed Compute as Gateway"
print "=================================================="
print "Notes:"
print " * Running 'nodejs' (based on Ubuntu)."
print " * Runs web server (Express) on port 80 and"
print " therefore requires sudo."
print "Please ensure that the installation steps outlined"
print "in the readme.md file within the 'sis' directory "
print "have been followed. "
}

print_title

sudo nodejs ./gateway.js

0 comments on commit 35e03bf

Please sign in to comment.