Skip to content

Commit

Permalink
edit the schema of uniqueNodes returned by the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiWithJai committed Aug 24, 2021
1 parent 1f95a67 commit c4584e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
57 changes: 29 additions & 28 deletions ui/app/components/client-status-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,40 @@ export default class ClientStatusBar extends DistributionBar {
failed: 0,
lost: 0,
};
for (const node of this.nodes) {
const concatenatedAllocationStatuses = [].concat(...Object.values(node));
console.log(concatenatedAllocationStatuses);
// there is a bug that counts nodes multiple times in this part of the loop
for (const status of concatenatedAllocationStatuses) {
const val = str => str;
const statusCount = countBy(concatenatedAllocationStatuses, val);
if (Object.keys(statusCount).length === 1) {
if (statusCount.running > 0) {
statuses.running++;
}
if (statusCount.failed > 0) {
statuses.failed++;
}
if (statusCount.lost > 0) {
statuses.lost++;
}
if (statusCount.complete > 0) {
statuses.complete++;
}
} else if (Object.keys(statusCount).length !== 1 && !!statusCount.running) {
if (!!statusCount.failed || !!statusCount.lost) {
statuses.degraded++;
}
} else if (Object.keys(statusCount).length !== 1 && !!statusCount.pending) {
const formattedNodes = this.nodes.map(node => {
const [[_, allocs]] = Object.entries(node);
return allocs.map(alloc => alloc.clientStatus);
});
for (const node of formattedNodes) {
const statusCount = countBy(node, status => status);
const hasOnly1Status = Object.keys(statusCount).length === 1;

if (hasOnly1Status) {
if (statusCount.running > 0) {
statuses.running++;
}
if (statusCount.failed > 0) {
statuses.failed++;
}
if (statusCount.lost > 0) {
statuses.lost++;
}
if (statusCount.complete > 0) {
statuses.complete++;
}
} else if (!hasOnly1Status && !!statusCount.running) {
if (!!statusCount.failed || !!statusCount.lost) {
statuses.degraded++;
} else if (statusCount.pending) {
statuses.starting++;
} else {
statuses.queued++;
}
} else {
// if no allocations then queued -- job registered, hasn't been assigned clients to run -- no allocations
// may only have this state for a few milliseconds
statuses.queued++;
}
}

console.log('statuses\n\n', statuses);
return [
{ label: 'Not Scheduled', value: statuses['not scheduled'], className: 'not-scheduled' },
{ label: 'Queued', value: statuses.queued, className: 'queued' },
Expand Down
7 changes: 4 additions & 3 deletions ui/app/controllers/jobs/job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ export default class IndexController extends Controller.extend(WithNamespaceRese
const allocs = this.job.allocations;
const nodes = allocs.mapBy('node');
const uniqueNodes = nodes.uniqBy('id').toArray();
return uniqueNodes.map(nodeId => {
const result = uniqueNodes.map(nodeId => {
return {
[nodeId.get('id')]: allocs
.toArray()
.filter(alloc => nodeId.get('id') === alloc.get('node.id'))
.map(alloc => alloc.getProperties('clientStatus'))
.map(alloc => alloc.clientStatus),
.map(alloc => alloc.getProperties('clientStatus', 'name', 'createTime', 'modifyTime')),
};
});
console.log('result\n\n', result);
return result;
}

@computed('node')
Expand Down

0 comments on commit c4584e7

Please sign in to comment.