Skip to content

Commit

Permalink
Add the possibility to force the borker to always assign the same vm
Browse files Browse the repository at this point in the history
to a user.

This option is available only in the config file.
  • Loading branch information
corentindrouet committed Sep 30, 2016
1 parent f8f838d commit 3f10646
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ to avoid commiting those changes
- machinesName (Defaults to 'Nanocloud Exec Server') default name for machines
- plazaURI (Defaults to https://s3-eu-west-1.amazonaws.com/nanocloud/plaza/1.0.0/windows/amd64/plaza.exe) URL to download plaza from
- plazaPort (Defaults to 9090) port to communicate with plaza
- neverTerminateMachine (Defaults to false) if set to true, machines are
never destroyed, users have always the same machine all times.

## SMTP configuration

Expand Down
42 changes: 34 additions & 8 deletions api/services/MachineService.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,24 @@ function getMachineForUser(user) {
});
});
} else {
return Promise.resolve(res);
return ConfigService.get('neverTerminateMachine')
.then((config) => {
if (config.neverTerminateMachine) {
if (res.status === 'stopped') {
startMachine(res)
.then(() => {
increaseUsersMachineEndDate(user);
});
return Promise.reject('Your machine is starting. Please retry in one minute.');
} else if (res.status === 'running') {
return Promise.resolve(res);
} else {
return Promise.reject(`Your machine is ${res.status}. Please retry in one minute.`);
}
} else {
return Promise.resolve(res);
}
});
}
});
});
Expand Down Expand Up @@ -475,17 +492,26 @@ function _updateMachinesPool() {
* @return {null}
*/
function _shouldTerminateMachine(machine) {
machine.isSessionActive()
.then((isActive) => {
Promise.props({
isActive: machine.isSessionActive(),
config: ConfigService.get('neverTerminateMachine')
})
.then((props) => {
var isActive = props.isActive;
var config = props.config;
if (!isActive) {
const now = new Date();
if (machine.endDate < now) {
machine.user = null;
if (config.neverTerminateMachine) {
stopMachine(machine);
} else {
machine.user = null;

Machine.update(machine.id, machine)
.then(() => {
_terminateMachine(machine);
});
Machine.update(machine.id, machine)
.then(() => {
_terminateMachine(machine);
});
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions assets/app/configuration/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default Ember.Service.extend({
'iaas',
'teamEnabled',
'machinesName',
'neverTerminateMachine',
],
keyToBeRetrievedAsString: Ember.computed('keyToBeRetrieved', function() {
let params = this.get('keyToBeRetrieved');
Expand Down
6 changes: 6 additions & 0 deletions assets/app/machine/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ export default DS.Model.extend({
return this.get('name') || 'No name';
}),
user: DS.belongsTo('user'),
isStopped: Ember.computed('status', function() {
return (this.get('status') === 'stopping' || this.get('status') === 'stopped');
}),
isStarting: Ember.computed('status', function() {
return (this.get('status') === 'starting');
}),
});
5 changes: 5 additions & 0 deletions assets/app/protected/machines/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import Ember from 'ember';

export default Ember.Controller.extend({
configController: Ember.inject.controller('protected.configs'),
store: Ember.inject.service('store'),
modelIsEmpty: Ember.computed.empty('items'),
sortableTableConfig: {
Expand All @@ -49,6 +50,7 @@ export default Ember.Controller.extend({

setData: function() {
var ret = Ember.A([]);
var neverTerminateMachine = this.get('configController.neverTerminateMachine');
this.get('items').forEach(function(item) {
let now = new Date();
let endDate = window.moment(item.get('endDate'));
Expand All @@ -65,6 +67,9 @@ export default Ember.Controller.extend({
status: item.get('status'),
user: item.get('user'),
endDate: item.get('endDate'),
stopped: item.get('isStopped'),
starting: item.get('isStarting'),
neverTerminateMachine: neverTerminateMachine,
}));
});
this.set('data', ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
{{#if record.expiration}}
{{live-countdown class='color-primary' value=record.expiration isTime=true}}
{{else}}
This machine will be terminated soon.
{{#if record.neverTerminateMachine}}
This machine will be stopped soon.
{{else}}
This machine will be terminated soon.
{{/if}}
{{/if}}
{{else if record.user}}
<span class='color-success'>Currently in use</span>
{{#if record.stopped}}
-
{{else if record.starting}}
-
{{else}}
<span class='color-success'>Currently in use</span>
{{/if}}
{{else}}
-
{{/if}}
9 changes: 7 additions & 2 deletions assets/app/styles/light-bulb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
box-shadow: 0px 0px 1px #a0a0a0;
}

&.running {
&.running, &.inUse {
background-color: #5eca20;
box-shadow: 0px 0px 1px #5eca20;
}
Expand All @@ -34,7 +34,7 @@
@extend .booting;
}

&.booting, &.rebooting {
&.booting, &.rebooting, &.starting {
background-color: #F4B835;
box-shadow: 0px 0px 1px #F4B835;
@extend .transition-enabled;
Expand All @@ -56,6 +56,11 @@
background-color: #8EDAFB;
box-shadow: 0px 0px 1px #8EDAFB;
}

&.stopped {
background-color: red;
box-shadow: 0px 0px 1px red;
}
}

}
1 change: 1 addition & 0 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = {
iaas: 'manual',
machinePoolSize: 1,

neverTerminateMachine: false,
sessionDuration: 600, // 10 minutes
machinesName: 'Nanocloud Exec Server',
plazaURI: 'https://s3-eu-west-1.amazonaws.com/nanocloud/plaza/1.0.0/windows/amd64/plaza.exe',
Expand Down
Loading

0 comments on commit 3f10646

Please # to comment.