github.com/aminovpavel/nomad@v0.11.8/ui/app/adapters/allocation.js (about) 1 import Watchable from './watchable'; 2 import addToPath from 'nomad-ui/utils/add-to-path'; 3 4 export default Watchable.extend({ 5 stop: adapterAction('/stop'), 6 7 restart(allocation, taskName) { 8 const prefix = `${this.host || '/'}${this.urlPrefix()}`; 9 const url = `${prefix}/client/allocation/${allocation.id}/restart`; 10 return this.ajax(url, 'PUT', { 11 data: taskName && { TaskName: taskName }, 12 }); 13 }, 14 15 ls(model, path) { 16 return this.token 17 .authorizedRequest(`/v1/client/fs/ls/${model.id}?path=${encodeURIComponent(path)}`) 18 .then(handleFSResponse); 19 }, 20 21 stat(model, path) { 22 return this.token 23 .authorizedRequest( 24 `/v1/client/fs/stat/${model.id}?path=${encodeURIComponent(path)}` 25 ) 26 .then(handleFSResponse); 27 }, 28 }); 29 30 async function handleFSResponse(response) { 31 if (response.ok) { 32 return response.json(); 33 } else { 34 const body = await response.text(); 35 36 // TODO update this if/when endpoint returns 404 as expected 37 const statusIs500 = response.status === 500; 38 const bodyIncludes404Text = body.includes('no such file or directory'); 39 40 const translatedCode = statusIs500 && bodyIncludes404Text ? 404 : response.status; 41 42 throw { 43 code: translatedCode, 44 toString: () => body, 45 }; 46 } 47 } 48 49 function adapterAction(path, verb = 'POST') { 50 return function(allocation) { 51 const url = addToPath(this.urlForFindRecord(allocation.id, 'allocation'), path); 52 return this.ajax(url, verb); 53 }; 54 }