2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-02-16 19:02:43 +00:00
|
|
|
import Watchable from './watchable';
|
2019-10-25 00:52:34 +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';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2022-03-08 17:28:36 +00:00
|
|
|
@classic
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class NodeAdapter extends Watchable {
|
2019-10-25 00:52:34 +00:00
|
|
|
setEligible(node) {
|
|
|
|
return this.setEligibility(node, true);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 00:52:34 +00:00
|
|
|
|
|
|
|
setIneligible(node) {
|
|
|
|
return this.setEligibility(node, false);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 00:52:34 +00:00
|
|
|
|
|
|
|
setEligibility(node, isEligible) {
|
2021-12-28 16:08:12 +00:00
|
|
|
const url = addToPath(
|
|
|
|
this.urlForFindRecord(node.id, 'node'),
|
|
|
|
'/eligibility'
|
|
|
|
);
|
2019-10-25 00:52:34 +00:00
|
|
|
return this.ajax(url, 'POST', {
|
|
|
|
data: {
|
|
|
|
NodeID: node.id,
|
|
|
|
Eligibility: isEligible ? 'eligible' : 'ineligible',
|
|
|
|
},
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 02:58:18 +00:00
|
|
|
|
|
|
|
// Force: -1s deadline
|
|
|
|
// No Deadline: 0 deadline
|
|
|
|
drain(node, drainSpec) {
|
|
|
|
const url = addToPath(this.urlForFindRecord(node.id, 'node'), '/drain');
|
|
|
|
return this.ajax(url, 'POST', {
|
2019-10-30 18:24:09 +00:00
|
|
|
data: {
|
|
|
|
NodeID: node.id,
|
|
|
|
DrainSpec: Object.assign(
|
|
|
|
{
|
|
|
|
Deadline: 0,
|
|
|
|
IgnoreSystemJobs: true,
|
|
|
|
},
|
|
|
|
drainSpec
|
|
|
|
),
|
|
|
|
},
|
2019-10-25 02:58:18 +00:00
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 02:58:18 +00:00
|
|
|
|
|
|
|
forceDrain(node, drainSpec) {
|
|
|
|
return this.drain(
|
|
|
|
node,
|
|
|
|
Object.assign({}, drainSpec, {
|
2019-12-07 07:45:00 +00:00
|
|
|
Deadline: -1,
|
2019-10-25 02:58:18 +00:00
|
|
|
})
|
|
|
|
);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-30 18:24:09 +00:00
|
|
|
|
|
|
|
cancelDrain(node) {
|
|
|
|
const url = addToPath(this.urlForFindRecord(node.id, 'node'), '/drain');
|
|
|
|
return this.ajax(url, 'POST', {
|
|
|
|
data: {
|
|
|
|
NodeID: node.id,
|
|
|
|
DrainSpec: null,
|
|
|
|
},
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2023-02-07 22:42:25 +00:00
|
|
|
|
|
|
|
addMeta(node, newMeta) {
|
|
|
|
const url = `/v1/client/metadata?node_id=${node.id}`;
|
|
|
|
return this.ajax(url, 'POST', {
|
|
|
|
data: { Meta: newMeta },
|
|
|
|
});
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|