Skip to content

Commit

Permalink
refactoring job client status
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Aug 24, 2021
1 parent c4584e7 commit 38f764f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ui/app/controllers/jobs/job/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import Controller from '@ember/controller';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
import { action } from '@ember/object';
import classic from 'ember-classic-decorator';
import jobClientStatus from 'nomad-ui/utils/properties/job-client-status';

@classic
export default class IndexController extends Controller.extend(WithNamespaceResetting) {
@service system;
@service store;

@jobClientStatus('nodes', 'job.status', 'job.allocations') jobClientStatus;

@computed('job')
get uniqueNodes() {
// add datacenter filter
Expand All @@ -34,6 +37,10 @@ export default class IndexController extends Controller.extend(WithNamespaceRese
return this.store.peekAll('node').toArray().length;
}

get nodes() {
return this.store.peekAll('node');
}

queryParams = [
{
currentPage: 'page',
Expand Down
4 changes: 2 additions & 2 deletions ui/app/templates/components/job-page/parts/summary.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<em class="is-faded">No Children</em>
{{/if}}
{{else}}
<ClientStatusBar @nodes={{this.nodes}} @allocationContainer={{a.item}} @isNarrow={{true}} />
<ClientStatusBar @jobClientStatus={{this.jobClientStatus}} @nodes={{this.nodes}} @allocationContainer={{a.item}} @isNarrow={{true}} />
{{/if}}
</div>
</div>
Expand All @@ -38,6 +38,7 @@
job=a.item.summary
nodes=this.nodes
totalNodes=this.totalNodes
jobClientStatus=this.jobClientStatus
class="split-view" as |chart|}}
<ol data-test-legend class="legend">
{{#each chart.data as |datum index|}}
Expand Down Expand Up @@ -109,4 +110,3 @@
{{/component}}
</a.body>
</ListAccordion>

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}} @totalNodes={{this.totalNodes}} @nodes={{this.nodes}} />
<JobPage::Parts::Summary @job={{this.job}} @totalNodes={{this.totalNodes}} @nodes={{this.nodes}} @jobClientStatus={{this.jobClientStatus}} />

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

Expand Down
1 change: 1 addition & 0 deletions ui/app/templates/jobs/job/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
job=this.model
nodes=this.uniqueNodes
totalNodes=this.totalNodes
jobClientStatus=this.jobClientStatus
sortProperty=this.sortProperty
sortDescending=this.sortDescending
currentPage=this.currentPage
Expand Down
23 changes: 23 additions & 0 deletions ui/app/utils/properties/job-client-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { computed } from '@ember/object';

// An Ember.Computed property that persists set values in localStorage
// and will attempt to get its initial value from localStorage before
// falling back to a default.
//
// ex. showTutorial: localStorageProperty('nomadTutorial', true),
export default function jobClientStatus(nodesKey, jobStatusKey, jobAllocsKey) {
return computed(nodesKey, jobStatusKey, jobAllocsKey, function() {
const allocs = this.get(jobAllocsKey);
const jobStatus = this.get(jobStatusKey);
const nodes = this.get(nodesKey);

return {
byNode: {
'123': 'running',
},
byStatus: {
running: ['123'],
},
};
});
}
2 changes: 1 addition & 1 deletion ui/mirage/factories/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DATACENTERS } from '../common';

const REF_TIME = new Date();
const JOB_PREFIXES = provide(5, faker.hacker.abbreviation);
const JOB_TYPES = ['service', 'batch', 'system'];
const JOB_TYPES = ['service', 'batch', 'system', 'sysbatch'];
const JOB_STATUSES = ['pending', 'running', 'dead'];

export default Factory.extend({
Expand Down
2 changes: 2 additions & 0 deletions ui/mirage/scenarios/default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from 'nomad-ui/config/environment';
import * as topoScenarios from './topo';
import * as sysbatchScenarios from './sysbatch';
import { pickOne } from '../utils';

const withNamespaces = getConfigValue('mirageWithNamespaces', false);
Expand All @@ -16,6 +17,7 @@ const allScenarios = {
everyFeature,
emptyCluster,
...topoScenarios,
...sysbatchScenarios,
};

const scenario = getScenarioQueryParameter() || getConfigValue('mirageScenario', 'emptyCluster');
Expand Down
18 changes: 18 additions & 0 deletions ui/mirage/scenarios/sysbatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function sysbatchSmall(server) {
server.createList('agent', 3);
server.createList('node', 12, {
datacenter: 'dc1',
status: 'ready',
});

const jobConstraints = [[], [], [], [], [], []];

jobConstraints.forEach(spec => {
server.create('job', {
status: 'running',
datacenters: ['dc1'],
type: 'sysbatch',
createAllocations: true,
});
});
}
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
]
},
"dependencies": {
"lodash": "^4.17.21",
"lru_map": "^0.3.3",
"no-case": "^3.0.4",
"title-case": "^3.0.3"
Expand Down
2 changes: 1 addition & 1 deletion ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11746,7 +11746,7 @@ lodash.values@^4.3.0:
resolved "https://registry.yarnpkg.com/lodash.values/-/lodash.values-4.3.0.tgz#a3a6c2b0ebecc5c2cba1c17e6e620fe81b53d347"
integrity sha1-o6bCsOvsxcLLocF+bmIP6BtT00c=

lodash@^4.0.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.5.1:
lodash@^4.0.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.5.1:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down

0 comments on commit 38f764f

Please sign in to comment.