mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Now that tasks that have finished running can be restarted, the UI needs to use the actual task state to determine which CSS class to use when rendering the task lifecycle chart element.
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import Watchable from './watchable';
|
|
import addToPath from 'nomad-ui/utils/add-to-path';
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
@classic
|
|
export default class AllocationAdapter extends Watchable {
|
|
stop = adapterAction('/stop');
|
|
|
|
restart(allocation, taskName) {
|
|
const prefix = `${this.host || '/'}${this.urlPrefix()}`;
|
|
const url = `${prefix}/client/allocation/${allocation.id}/restart`;
|
|
return this.ajax(url, 'PUT', {
|
|
data: taskName && { TaskName: taskName },
|
|
});
|
|
}
|
|
|
|
restartAll(allocation) {
|
|
const prefix = `${this.host || '/'}${this.urlPrefix()}`;
|
|
const url = `${prefix}/client/allocation/${allocation.id}/restart`;
|
|
return this.ajax(url, 'PUT', { data: { AllTasks: true } });
|
|
}
|
|
|
|
ls(model, path) {
|
|
return this.token
|
|
.authorizedRequest(
|
|
`/v1/client/fs/ls/${model.id}?path=${encodeURIComponent(path)}`
|
|
)
|
|
.then(handleFSResponse);
|
|
}
|
|
|
|
stat(model, path) {
|
|
return this.token
|
|
.authorizedRequest(
|
|
`/v1/client/fs/stat/${model.id}?path=${encodeURIComponent(path)}`
|
|
)
|
|
.then(handleFSResponse);
|
|
}
|
|
}
|
|
|
|
async function handleFSResponse(response) {
|
|
if (response.ok) {
|
|
return response.json();
|
|
} else {
|
|
const body = await response.text();
|
|
|
|
throw {
|
|
code: response.status,
|
|
toString: () => body,
|
|
};
|
|
}
|
|
}
|
|
|
|
function adapterAction(path, verb = 'POST') {
|
|
return function (allocation) {
|
|
const url = addToPath(
|
|
this.urlForFindRecord(allocation.id, 'allocation'),
|
|
path
|
|
);
|
|
return this.ajax(url, verb);
|
|
};
|
|
}
|