-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nomad Services: job routes, model, and serializer updates (#14226)
* Added to subnav and basic table implemented * Existing services become service fragments, and services tab aggregated beneath job route * Index page within jobs/job/services * Watchable services * Lintfixes * Links to clients and individual services set up * Child service route * Keyboard shortcuts on service page * Model that shows consul services as well, plus level and provider cols * lintfix * Level as query param * Watch job for service name changes too * Lintfix * Testfixes * Placeholder mirage route
- Loading branch information
1 parent
e23b47e
commit 59e250a
Showing
37 changed files
with
478 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Watchable from './watchable'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
@classic | ||
export default class ServiceAdapter extends Watchable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class JobServiceRowComponent extends Component { | ||
@service router; | ||
|
||
@action | ||
gotoService(service) { | ||
if (service.provider === 'nomad') { | ||
this.router.transitionTo('jobs.job.services.service', service.name, { | ||
queryParams: { level: service.level }, | ||
instances: service.instances, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Controller from '@ember/controller'; | ||
|
||
export default class JobsJobServicesController extends Controller {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Controller from '@ember/controller'; | ||
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting'; | ||
import { alias } from '@ember/object/computed'; | ||
import { computed } from '@ember/object'; | ||
import { union } from '@ember/object/computed'; | ||
|
||
export default class JobsJobServicesIndexController extends Controller.extend( | ||
WithNamespaceResetting | ||
) { | ||
@alias('model') job; | ||
@alias('job.taskGroups') taskGroups; | ||
|
||
@computed('[email protected]') | ||
get tasks() { | ||
return this.taskGroups.map((group) => group.tasks.toArray()).flat(); | ||
} | ||
|
||
@computed('[email protected]') | ||
get taskServices() { | ||
return this.tasks | ||
.map((t) => (t.services || []).toArray()) | ||
.flat() | ||
.compact() | ||
.map((service) => { | ||
service.level = 'task'; | ||
return service; | ||
}); | ||
} | ||
|
||
@computed('[email protected]', 'taskGroups') | ||
get groupServices() { | ||
return this.taskGroups | ||
.map((g) => (g.services || []).toArray()) | ||
.flat() | ||
.compact() | ||
.map((service) => { | ||
service.level = 'group'; | ||
return service; | ||
}); | ||
} | ||
|
||
@union('taskServices', 'groupServices') serviceFragments; | ||
|
||
// Services, grouped by name, with aggregatable allocations. | ||
@computed( | ||
'job.services.@each.{name,allocation}', | ||
'job.services.length', | ||
'serviceFragments' | ||
) | ||
get services() { | ||
return this.serviceFragments.map((fragment) => { | ||
fragment.instances = this.job.services.filter( | ||
(s) => s.name === fragment.name && s.derivedLevel === fragment.level | ||
); | ||
return fragment; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class JobsJobServicesServiceController extends Controller { | ||
@service router; | ||
queryParams = ['level']; | ||
|
||
@action | ||
gotoAllocation(allocation) { | ||
this.router.transitionTo('allocations.allocation', allocation.get('id')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { attr } from '@ember-data/model'; | ||
import Fragment from 'ember-data-model-fragments/fragment'; | ||
import { fragment } from 'ember-data-model-fragments/attributes'; | ||
|
||
export default class Service extends Fragment { | ||
@attr('string') name; | ||
@attr('string') portLabel; | ||
@attr() tags; | ||
@attr('string') onUpdate; | ||
@attr('string') provider; | ||
@fragment('consul-connect') connect; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
import { attr } from '@ember-data/model'; | ||
import Fragment from 'ember-data-model-fragments/fragment'; | ||
import { fragment } from 'ember-data-model-fragments/attributes'; | ||
// @ts-check | ||
import { attr, belongsTo } from '@ember-data/model'; | ||
import Model from '@ember-data/model'; | ||
import { alias } from '@ember/object/computed'; | ||
|
||
export default class Service extends Fragment { | ||
@attr('string') name; | ||
@attr('string') portLabel; | ||
export default class Service extends Model { | ||
@belongsTo('allocation') allocation; | ||
@belongsTo('job') job; | ||
@belongsTo('node') node; | ||
|
||
@attr('string') address; | ||
@attr('number') createIndex; | ||
@attr('string') datacenter; | ||
@attr('number') modifyIndex; | ||
@attr('string') namespace; | ||
@attr('number') port; | ||
@attr('string') serviceName; | ||
@attr() tags; | ||
@attr('string') onUpdate; | ||
@fragment('consul-connect') connect; | ||
|
||
@alias('serviceName') name; | ||
|
||
// Services can exist at either Group or Task level. | ||
// While our endpoints to get them do not explicitly tell us this, | ||
// we can infer it from the service's ID: | ||
get derivedLevel() { | ||
const idWithoutServiceName = this.id.replace(this.serviceName, ''); | ||
if (idWithoutServiceName.includes('group-')) { | ||
return 'group'; | ||
} else { | ||
return 'task'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Route from '@ember/routing/route'; | ||
import WithWatchers from 'nomad-ui/mixins/with-watchers'; | ||
import { collect } from '@ember/object/computed'; | ||
import { | ||
watchRecord, | ||
watchRelationship, | ||
} from 'nomad-ui/utils/properties/watch'; | ||
|
||
export default class JobsJobServicesRoute extends Route.extend(WithWatchers) { | ||
model() { | ||
const job = this.modelFor('jobs.job'); | ||
return job && job.get('services').then(() => job); | ||
} | ||
|
||
startWatchers(controller, model) { | ||
if (model) { | ||
controller.set('watchServices', this.watchServices.perform(model)); | ||
controller.set('watchJob', this.watchJob.perform(model)); | ||
} | ||
} | ||
|
||
@watchRelationship('services', true) watchServices; | ||
@watchRecord('job') watchJob; | ||
|
||
@collect('watchServices', 'watchJob') watchers; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class JobsJobServicesIndexRoute extends Route {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
export default class JobsJobServicesServiceRoute extends Route { | ||
model({ name = '', level = '' }) { | ||
const services = this.modelFor('jobs.job') | ||
.get('services') | ||
.filter( | ||
(service) => service.name === name && service.derivedLevel === level | ||
); | ||
return { name, instances: services || [] }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import ApplicationSerializer from './application'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
@classic | ||
export default class ServiceFragmentSerializer extends ApplicationSerializer { | ||
attrs = { | ||
connect: 'Connect', | ||
}; | ||
|
||
arrayNullOverrides = ['Tags']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import ApplicationSerializer from './application'; | ||
import classic from 'ember-classic-decorator'; | ||
import ApplicationSerializer from './application'; | ||
|
||
@classic | ||
export default class ServiceSerializer extends ApplicationSerializer { | ||
attrs = { | ||
connect: 'Connect', | ||
}; | ||
|
||
arrayNullOverrides = ['Tags']; | ||
normalize(typeHash, hash) { | ||
hash.AllocationID = hash.AllocID; // TODO: keyForRelationship maybe? | ||
hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]); | ||
return super.normalize(typeHash, hash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.service-list { | ||
.title { | ||
.back-link { | ||
text-decoration: none; | ||
color: #363636; | ||
position: relative; | ||
top: 4px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<tr {{on "click" (fn this.gotoService @service)}} class={{if (eq @service.provider "nomad") "is-interactive"}} data-test-service={{@service.id}}> | ||
<td> | ||
{{#if (eq @service.provider "nomad")}} | ||
<FlightIcon @name="nomad-color" /> | ||
{{else if (eq @service.provider "consul")}} | ||
<FlightIcon @name="consul-color" /> | ||
{{/if}} | ||
</td> | ||
<td | ||
{{keyboard-shortcut | ||
enumerated=true | ||
action=(action "gotoService" @service) | ||
}} | ||
> | ||
{{#if (eq @service.provider "nomad")}} | ||
<LinkTo class="is-primary" @route="jobs.job.services.service" @model={{@service}} @query={{hash level=@service.level}}>{{@service.name}}</LinkTo> | ||
{{else}} | ||
{{@service.name}} | ||
{{/if}} | ||
</td> | ||
<td> | ||
{{@service.level}} | ||
</td> | ||
<td> | ||
<LinkTo @route="clients.client" @model={{@service.instances.0.node.id}}>{{@service.instances.0.node.name}}</LinkTo> | ||
</td> | ||
<td> | ||
{{#each @service.tags as |tag|}} | ||
<span class="tag">{{tag}}</span> | ||
{{/each}} | ||
</td> | ||
<td> | ||
{{#if (eq @service.provider "nomad")}} | ||
{{@service.instances.length}} {{pluralize "allocation" @service.instances.length}} | ||
{{else}} | ||
-- | ||
{{/if}} | ||
</td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{page-title "Job " @model.name " services"}} | ||
<JobSubnav @job={{@model}} /> | ||
{{outlet}} |
Oops, something went wrong.