Commit 60faa20c authored by Ioannis Tsafaras's avatar Ioannis Tsafaras
Browse files

Disable lambda instance start/stop buttons, when they are clicked

parent a04cd591
......@@ -42,6 +42,7 @@ module.exports = function(environment) {
ENV.refresh_interval = 6000;
ENV.redirect_delay = 3000;
ENV.message_dismiss = 4000;
ENV.button_delay = 10000;
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
......
......@@ -12,13 +12,14 @@ export default Ember.Component.extend({
}
var _this = this;
//send request to start instance
instance.set('lambda_instance_id', this.get("instance-id"));
var lambda_instance_id = this.get('instance-id');
instance.set('lambda_instance_id', lambda_instance_id);
instance.set('action', "start");
instance.save().then(
function success() {
_this.set("request", true);
_this.set("message", "Your request to start the lambda-instance was successfully sent to the server.");
_this.sendAction('action');
_this.sendAction('action', 'start', lambda_instance_id);
}).catch(
function failure() {
_this.set("failure", true);
......@@ -30,6 +31,7 @@ export default Ember.Component.extend({
return false;
}
var _this = this;
var lambda_instance_id = this.get('instance-id');
if (this.get('check_apps'))
{
apps.forEach(function(item) {
......@@ -46,13 +48,13 @@ export default Ember.Component.extend({
//send request to stop instance
if (this.get("app_started")){
if (confirm("There is a deployed application currently running on this lambda-instance.\nAre you sure you want to stop this lambda instance?")) {
instance.set('lambda_instance_id', this.get("instance-id"));
instance.set('lambda_instance_id', lambda_instance_id);
instance.set('action', "stop");
instance.save().then(
function success() {
_this.set("request", true);
_this.set("message", "Your request to stop the lambda-instance was successfully sent to the server.");
_this.sendAction('action');
_this.sendAction('action', 'stop', lambda_instance_id);
}).catch(
function failure() {
_this.set("failure", true);
......@@ -60,13 +62,13 @@ export default Ember.Component.extend({
}
}
else {
instance.set('lambda_instance_id', this.get("instance-id"));
instance.set('lambda_instance_id', lambda_instance_id);
instance.set('action', "stop");
instance.save().then(
function success() {
_this.set("request", true);
_this.set("message", "Your request to stop the lambda-instance was successfully sent to the server.");
_this.sendAction('action');
_this.sendAction('action', 'stop', lambda_instance_id);
}).catch(
function failure() {
_this.set("failure", true);
......
......@@ -23,13 +23,28 @@ export default Ember.Controller.extend({
var alert = document.getElementById('app_alert');
alert.hidden=true;
},
start_stop: function()
start_stop: function (action)
{
var instance = this.get('model.instance');
if (action === 'start') {
instance.set('starting', true);
}
else if (action === 'stop') {
instance.set('stopping', true);
}
var _this = this;
Ember.run.later((function () {
_this.set('request', false);
_this.set('app_request', false);
}), ENV.message_dismiss);
Ember.run.later((function () {
if (action === 'start') {
instance.set('starting', false);
}
else if (action === 'stop') {
instance.set('stopping', false);
}
}), ENV.button_delay);
},
withdraw: function(application_id)
{
......
......@@ -37,12 +37,27 @@ export default Ember.ArrayController.extend({
actions: {
start_stop: function()
start_stop: function (action, instance_id)
{
var instance = this.get('model').findBy('id', instance_id);
if (action === 'start') {
instance.set('starting', true);
}
else if (action === 'stop') {
instance.set('stopping', true);
}
var _this = this;
Ember.run.later((function () {
_this.set('request', false);
}), ENV.message_dismiss);
Ember.run.later((function () {
if (action === 'start') {
instance.set('starting', false);
}
else if (action === 'stop') {
instance.set('stopping', false);
}
}), ENV.button_delay);
},
delete_instance: function(instance_id) {
......
......@@ -14,6 +14,9 @@ export default Ember.Helper.helper(function (params) {
result = params[i] && result;
}
break;
case 'not':
result = !result;
break;
}
return result;
});
......@@ -23,7 +23,12 @@ var LambdaInstance = DS.Model.extend({
running_app: DS.attr('boolean'), // is any app running on the lambda instance?
kafka_input_topics: DS.attr(), // kafka input topics of lambda instance
kafka_output_topics: DS.attr(), // kafka output topics of lambda instance
deleting: DS.attr('boolean') // has a delete request been sent?
deleting: DS.attr('boolean',
{ defaultValue: false }), // has a delete request been sent?
starting: DS.attr('boolean',
{ defaultValue: false }), // has a start request been sent?
stopping: DS.attr('boolean',
{ defaultValue: false }) // has a stop request been sent?
});
export default LambdaInstance;
......@@ -99,10 +99,16 @@
{{/tool-tip}}
{{/if}}
{{#tool-tip}}
{{#if (compare model.instance.status_code '==' '0')}}
{{#if (logical-op 'and'
(compare model.instance.status_code '==' '0')
(logical-op 'not' model.instance.stopping)
)}}
{{instance-action apps=model.apps check_apps=true stop=true instance=model.instance_action failure=failure instance-id=model.instance.id request=request message=message action="start_stop"}}
{{instance-action start=true disabled=true status_message=model.instance.status_message}}
{{else if (compare model.instance.status_code '==' '1')}}
{{else if (logical-op 'and'
(compare model.instance.status_code '==' '1')
(logical-op 'not' model.instance.starting)
)}}
{{instance-action stop=true disabled=true status_message=model.instance.status_message}}
{{instance-action start=true instance=model.instance_action instance-id=model.instance.id failure=failure request=request message=message action="start_stop"}}
{{else}}
......
......@@ -139,7 +139,10 @@
<a class="btn btn-info btn-xs" title="View Details" alt="View Details"><i class="fa fa-file-code-o"></i> Details</a>
{{/link-to}}
</td>
{{#if (compare lambda-instance.status_code '==' '0')}}
{{#if (logical-op 'and'
(compare lambda-instance.status_code '==' '0')
(logical-op 'not' lambda-instance.stopping)
)}}
<td style="padding-right: 5px;">
{{#tool-tip}}
{{instance-action start=true xs=true disabled=true status_message=lambda-instance.status_message}}
......@@ -157,7 +160,10 @@
</button>
{{/link-to}}
</td>
{{else if (compare lambda-instance.status_code '==' '1')}}
{{else if (logical-op 'and'
(compare lambda-instance.status_code '==' '1')
(logical-op 'not' lambda-instance.starting)
)}}
<td style="padding-right: 5px;">
{{instance-action start=true xs=true instance=instance_action instance-id=lambda-instance.id failure=failure request=request message=message action="start_stop"}}
</td>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment