2018-02-28 19:48:06 +00:00
|
|
|
import Watchable from './watchable';
|
2019-05-17 00:43:00 +00:00
|
|
|
import addToPath from 'nomad-ui/utils/add-to-path';
|
2018-02-28 19:48:06 +00:00
|
|
|
|
2019-05-17 00:43:00 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|