Skip to content

Commit

Permalink
initial logic for computing client status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaiWithJai committed Aug 24, 2021
1 parent 2bb0317 commit 978f087
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 2 deletions.
24 changes: 24 additions & 0 deletions ui/app/controllers/jobs/job/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import Controller from '@ember/controller';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
import { action } from '@ember/object';
Expand All @@ -8,6 +9,29 @@ import classic from 'ember-classic-decorator';
@classic
export default class IndexController extends Controller.extend(WithNamespaceResetting) {
@service system;
@service store;

@computed('job')
get uniqueNodes() {
// add datacenter filter
const allocs = this.job.allocations;
const nodes = allocs.mapBy('node');
const uniqueNodes = nodes.uniqBy('id').toArray();
return 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),
};
});
}

@computed('node')
get totalNodes() {
return this.store.peekAll('node').toArray().length;
}

queryParams = [
{
Expand Down
9 changes: 9 additions & 0 deletions ui/app/routes/jobs/job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { watchRecord, watchRelationship, watchAll } from 'nomad-ui/utils/propert
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default class IndexRoute extends Route.extend(WithWatchers) {
async model() {
// Optimizing future node look ups by preemptively loading everything
await this.store.findAll('node');
return this.modelFor('jobs.job');
}

startWatchers(controller, model) {
if (!model) {
return;
Expand All @@ -16,6 +22,7 @@ export default class IndexRoute extends Route.extend(WithWatchers) {
latestDeployment:
model.get('supportsDeployments') && this.watchLatestDeployment.perform(model),
list: model.get('hasChildren') && this.watchAll.perform(),
nodes: /*model.type === 'sysbatch' && */ this.watchNodes.perform(),
});
}

Expand All @@ -33,6 +40,7 @@ export default class IndexRoute extends Route.extend(WithWatchers) {

@watchRecord('job') watch;
@watchAll('job') watchAll;
@watchAll('node') watchNodes;
@watchRecord('job-summary') watchSummary;
@watchRelationship('allocations') watchAllocations;
@watchRelationship('evaluations') watchEvaluations;
Expand All @@ -41,6 +49,7 @@ export default class IndexRoute extends Route.extend(WithWatchers) {
@collect(
'watch',
'watchAll',
'watchNodes',
'watchSummary',
'watchAllocations',
'watchEvaluations',
Expand Down
18 changes: 18 additions & 0 deletions ui/app/styles/charts/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ $running: $primary;
$complete: $nomad-green-dark;
$failed: $danger;
$lost: $dark;
$not-scheduled: $grey-darker;
$degraded: $warning;

.chart {
.queued {
Expand Down Expand Up @@ -37,6 +39,14 @@ $lost: $dark;
.lost {
fill: $lost;
}

.not-scheduled {
fill: $not-scheduled;
}

.degraded {
fill: $degraded;
}
}

.color-swatch {
Expand Down Expand Up @@ -102,6 +112,14 @@ $lost: $dark;
background: $lost;
}

&.not-scheduled {
fill: $not-scheduled;
}

&.degraded {
fill: $degraded;
}

@each $name, $pair in $colors {
$color: nth($pair, 1);

Expand Down
58 changes: 58 additions & 0 deletions ui/app/templates/components/job-page/parts/summary.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,62 @@
<ListAccordion data-test-job-summary @source={{array this.job}} @key="id" @startExpanded={{this.isExpanded}} @onToggle={{action this.persist}} as |a|>
<a.head @buttonLabel={{if a.isOpen "collapse" "expand"}}>
<div class="columns">
<div class="column is-minimum nowrap">
{{#if a.item.hasChildren}}
Children Status
<span class="badge {{if a.isOpen "is-white" "is-light"}}">
{{a.item.summary.totalChildren}}
</span>
{{else}}
Client Status
<span class="badge {{if a.isOpen "is-white" "is-light"}}">
{{a.item.summary.totalAllocs}}
</span>
{{/if}}
</div>

{{#unless a.isOpen}}
<div class="column">
<div class="inline-chart bumper-left">
{{#if a.item.hasChildren}}
{{#if (gt a.item.totalChildren 0)}}
<ChildrenStatusBar @job={{a.item}} @isNarrow={{true}} />
{{else}}
<em class="is-faded">No Children</em>
{{/if}}
{{else}}
<ClientStatusBar @nodes={{this.nodes}} @allocationContainer={{a.item}} @isNarrow={{true}} />
{{/if}}
</div>
</div>
{{/unless}}
</div>
</a.head>
<a.body>
{{#component (if a.item.hasChildren "children-status-bar" "client-status-bar")
allocationContainer=a.item.summary
job=a.item.summary
nodes=this.nodes
totalNodes=this.totalNodes
class="split-view" as |chart|}}
<ol data-test-legend class="legend">
{{#each chart.data as |datum index|}}
<li class="{{datum.className}} {{if (eq datum.label chart.activeDatum.label) "is-active"}} {{if (eq datum.value 0) "is-empty"}}">
<span class="color-swatch {{if datum.className datum.className (concat "swatch-" index)}}" />
<span class="value" data-test-legend-value="{{datum.className}}">{{datum.value}}</span>
<span class="label">
{{datum.label}}
</span>
</li>
{{/each}}
</ol>
{{/component}}
</a.body>
</ListAccordion>

<br/>

<ListAccordion data-test-job-summary @source={{array this.job}} @key="id" @startExpanded={{false}} @onToggle={{action this.persist}} as |a|>
<a.head @buttonLabel={{if a.isOpen "collapse" "expand"}}>
<div class="columns">
<div class="column is-minimum nowrap">
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-page/service.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{/each}}
{{/if}}

<JobPage::Parts::Summary @job={{this.job}} />
<JobPage::Parts::Summary @job={{this.job}} @totalNodes={{this.totalNodes}} @nodes={{this.nodes}} />

<JobPage::Parts::PlacementFailures @job={{this.job}} />

Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-page/system.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{/each}}
{{/if}}

<JobPage::Parts::Summary @job={{this.job}} />
<JobPage::Parts::Summary @job={{this.job}} @nodes={{this.nodes}} />

<JobPage::Parts::PlacementFailures @job={{this.job}} />

Expand Down
2 changes: 2 additions & 0 deletions ui/app/templates/jobs/job/index.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{page-title "Job " this.model.name}}
{{component (concat "job-page/" this.model.templateType)
job=this.model
nodes=this.uniqueNodes
totalNodes=this.totalNodes
sortProperty=this.sortProperty
sortDescending=this.sortDescending
currentPage=this.currentPage
Expand Down

0 comments on commit 978f087

Please sign in to comment.