diff --git a/ui/app/adapters/allocation.js b/ui/app/adapters/allocation.js index 8aa4b662f..dd26ef561 100644 --- a/ui/app/adapters/allocation.js +++ b/ui/app/adapters/allocation.js @@ -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); + }; +} diff --git a/ui/app/models/allocation.js b/ui/app/models/allocation.js index f93f19175..2a8239bcf 100644 --- a/ui/app/models/allocation.js +++ b/ui/app/models/allocation.js @@ -99,4 +99,12 @@ export default Model.extend({ ); } ), + + stop() { + return this.store.adapterFor('allocation').stop(this); + }, + + restart() { + return this.store.adapterFor('allocation').restart(this); + }, });