Allocation methods for stopping and restarting

This commit is contained in:
Michael Lange
2019-05-16 17:43:00 -07:00
parent b33ff625db
commit 4038434603
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);
},
});