Added proxy and emetting data every 10 sec
diff --git a/xos-apps/auto-scale/gui/env/default.js b/xos-apps/auto-scale/gui/env/default.js
new file mode 100644
index 0000000..8d4546d
--- /dev/null
+++ b/xos-apps/auto-scale/gui/env/default.js
@@ -0,0 +1,3 @@
+module.exports = {
+ host: 'http://clnode015.clemson.cloudlab.us:9991'
+}
\ No newline at end of file
diff --git a/xos-apps/auto-scale/gui/gulp/server.js b/xos-apps/auto-scale/gui/gulp/server.js
index 53392b3..0626afd 100644
--- a/xos-apps/auto-scale/gui/gulp/server.js
+++ b/xos-apps/auto-scale/gui/gulp/server.js
@@ -8,6 +8,30 @@
var babel = require('gulp-babel');
var wiredep = require('wiredep').stream;
var del = require('del');
+var httpProxy = require('http-proxy');
+
+const environment = process.env.NODE_ENV;
+
+if (environment){
+ var conf = require(`../env/${environment}.js`);
+}
+else{
+ var conf = require('../env/default.js')
+}
+
+console.log(conf);
+
+var proxy = httpProxy.createProxyServer({
+ target: conf.host || 'http://0.0.0.0:9999'
+});
+
+proxy.on('error', function(error, req, res) {
+ res.writeHead(500, {
+ 'Content-Type': 'text/plain'
+ });
+
+ console.error('[Proxy]', error);
+});
module.exports = function(options){
@@ -25,10 +49,16 @@
},
server: {
baseDir: options.src,
- // routes: {
- // '/api': options.api,
- // '/xosHelpers/src': options.helpers
- // }
+ middleware: function(req, res, next){
+ if(
+ req.url.indexOf('autoscaledata') !== -1
+ ){
+ proxy.web(req, res);
+ }
+ else{
+ next();
+ }
+ }
}
});
@@ -54,7 +84,6 @@
// inject scripts
gulp.task('injectScript', function(){
- console.log(options.tmp);
runSequence(
'cleanTmp',
'babel',
diff --git a/xos-apps/auto-scale/gui/src/index.html b/xos-apps/auto-scale/gui/src/index.html
index fec8ec4..7b9c168 100644
--- a/xos-apps/auto-scale/gui/src/index.html
+++ b/xos-apps/auto-scale/gui/src/index.html
@@ -64,7 +64,8 @@
<!-- inject:js -->
<script src="/.tmp/main.js"></script>
- <script src="/.tmp/autoscaling_details.js"></script>
+ <script src="/.tmp/autoscaling_details.directive.js"></script>
+ <script src="/.tmp/autoscaling.service.js"></script>
<!-- endinject -->
</div>
diff --git a/xos-apps/auto-scale/gui/src/js/autoscaling.service.js b/xos-apps/auto-scale/gui/src/js/autoscaling.service.js
new file mode 100644
index 0000000..4146f19
--- /dev/null
+++ b/xos-apps/auto-scale/gui/src/js/autoscaling.service.js
@@ -0,0 +1,17 @@
+'use strict';
+
+angular.module('autoscaling')
+.service('Autoscaling', function($http, $interval, $rootScope){
+
+ const pollingFrequency = 1;
+ var pollinginterval;
+
+ this.getAutoscalingData = () => {
+ pollinginterval = $interval(() => {
+ $http.get('/autoscaledata')
+ .then((res) => {
+ $rootScope.$emit('autoscaling.update', res.data);
+ });
+ }, pollingFrequency * 1000)
+ };
+});
\ No newline at end of file
diff --git a/xos-apps/auto-scale/gui/src/js/autoscaling_details.js b/xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js
similarity index 65%
rename from xos-apps/auto-scale/gui/src/js/autoscaling_details.js
rename to xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js
index f6fb4d6..e4bd9ef 100644
--- a/xos-apps/auto-scale/gui/src/js/autoscaling_details.js
+++ b/xos-apps/auto-scale/gui/src/js/autoscaling_details.directive.js
@@ -6,8 +6,10 @@
bindToController: true,
controllerAs: 'vm',
templateUrl: 'templates/service-container.tpl.html',
- controller: () => {
-
+ controller: ($rootScope) => {
+ $rootScope.$on('autoscaling.update', (evt, data) => {
+ console.log(data);
+ });
}
};
});
diff --git a/xos-apps/auto-scale/gui/src/js/main.js b/xos-apps/auto-scale/gui/src/js/main.js
index 5976fd9..665aafe 100644
--- a/xos-apps/auto-scale/gui/src/js/main.js
+++ b/xos-apps/auto-scale/gui/src/js/main.js
@@ -6,8 +6,9 @@
'ngAnimate',
'chart.js'
])
-.run(() => {
- console.log('autoscaling is running');
+.run((Autoscaling) => {
+ // start polling data
+ Autoscaling.getAutoscalingData();
})
.config(($stateProvider, $urlRouterProvider) => {
$stateProvider
@@ -15,6 +16,6 @@
url: '/',
template: '<service-container></service-container>'
});
-
+
$urlRouterProvider.otherwise('/');
});