Allocation methods for stopping and restarting

This commit is contained in:
Michael Lange 2019-05-16 17:43:00 -07:00
parent d3e919a2c8
commit a00bc8befc
2 changed files with 28 additions and 1 deletions

View file

@ -1,3 +1,22 @@
import Watchable from './watchable';
import addToPath from 'nomad-ui/utils/add-to-path';
export default Watchable.extend();
export default Watchable.extend({
stop: adapterAction('/stop'),
restart: adapterAction((adapter, allocation) => {
const prefix = `${adapter.host || '/'}${adapter.urlPrefix()}`;
return `${prefix}/client/allocation/${allocation.id}/restart`;
}, 'PUT'),
});
function adapterAction(path, verb = 'POST') {
return function(allocation) {
let url;
if (typeof path === 'function') {
url = path(this, allocation);
} else {
url = addToPath(this.urlForFindRecord(allocation.id, 'allocation'), path);
}
return this.ajax(url, verb);
};
}

View file

@ -99,4 +99,12 @@ export default Model.extend({
);
}
),
stop() {
return this.store.adapterFor('allocation').stop(this);
},
restart() {
return this.store.adapterFor('allocation').restart(this);
},
});