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';
|
2022-03-08 17:28:36 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2018-02-28 19:48:06 +00:00
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
@classic
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class AllocationAdapter extends Watchable {
|
|
|
|
stop = adapterAction('/stop');
|
2019-05-20 22:27:20 +00:00
|
|
|
|
|
|
|
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 },
|
|
|
|
});
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-06-01 13:15:59 +00:00
|
|
|
|
|
|
|
ls(model, path) {
|
|
|
|
return this.token
|
2021-12-28 16:08:12 +00:00
|
|
|
.authorizedRequest(
|
|
|
|
`/v1/client/fs/ls/${model.id}?path=${encodeURIComponent(path)}`
|
|
|
|
)
|
2020-06-01 13:15:59 +00:00
|
|
|
.then(handleFSResponse);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-06-01 13:15:59 +00:00
|
|
|
|
|
|
|
stat(model, path) {
|
|
|
|
return this.token
|
2021-12-28 16:08:12 +00:00
|
|
|
.authorizedRequest(
|
|
|
|
`/v1/client/fs/stat/${model.id}?path=${encodeURIComponent(path)}`
|
|
|
|
)
|
2020-06-01 13:15:59 +00:00
|
|
|
.then(handleFSResponse);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-17 00:43:00 +00:00
|
|
|
|
2020-06-01 13:15:59 +00:00
|
|
|
async function handleFSResponse(response) {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json();
|
|
|
|
} else {
|
|
|
|
const body = await response.text();
|
|
|
|
|
|
|
|
throw {
|
2021-11-17 16:15:07 +00:00
|
|
|
code: response.status,
|
2020-06-01 13:15:59 +00:00
|
|
|
toString: () => body,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-17 00:43:00 +00:00
|
|
|
function adapterAction(path, verb = 'POST') {
|
2021-12-28 14:45:20 +00:00
|
|
|
return function (allocation) {
|
2021-12-28 16:08:12 +00:00
|
|
|
const url = addToPath(
|
|
|
|
this.urlForFindRecord(allocation.id, 'allocation'),
|
|
|
|
path
|
|
|
|
);
|
2019-05-17 00:43:00 +00:00
|
|
|
return this.ajax(url, verb);
|
|
|
|
};
|
|
|
|
}
|