Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
wip!
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwhite committed May 27, 2021
1 parent 1a493a7 commit a3b5e80
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 8 deletions.
1 change: 1 addition & 0 deletions ui/app/helpers/icon-for-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function iconForComponent([component]: [string]): string {
case 'kubernetes':
return 'logo-kubernetes-color-alt';
case 'nomad':
case 'nomad-jobspec':
return 'logo-nomad-color';
case 'pack':
return 'logo-pack-color';
Expand Down
9 changes: 7 additions & 2 deletions ui/mirage/factories/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Factory, trait, association } from 'ember-cli-mirage';
import { fakeId } from '../utils';

export default Factory.extend({
id: () => fakeId(),
sequence: (i) => i + 1,

afterCreate(build, server) {
if (!build.workspace) {
let workspace =
Expand All @@ -11,8 +14,6 @@ export default Factory.extend({
},

random: trait({
id: () => fakeId(),
sequence: (i) => i + 1,
labels: () => ({
'common/vcs-ref': '0d56a9f8456b088dd0e4a7b689b842876fd47352',
'common/vcs-ref-path': 'https://github.com/hashicorp/waypoint/commit/',
Expand All @@ -21,6 +22,10 @@ export default Factory.extend({
status: association('random'),
}),

docker: trait({
component: association('builder', { name: 'docker' }),
}),

'seconds-old-success': trait({
status: association('random', 'success', 'seconds-old'),
}),
Expand Down
13 changes: 11 additions & 2 deletions ui/mirage/factories/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Factory, trait, association } from 'ember-cli-mirage';
import { fakeId } from '../utils';

export default Factory.extend({
id: () => fakeId(),

afterCreate(deployment, server) {
if (!deployment.workspace) {
let workspace =
Expand All @@ -11,9 +13,8 @@ export default Factory.extend({
},

random: trait({
id: () => fakeId(),
component: association('platform', 'with-random-name'),
sequence: (i) => i + 1,
component: association('platform', 'with-random-name'),
status: association('random'),
state: 'CREATED',
labels: () => ({
Expand All @@ -27,6 +28,14 @@ export default Factory.extend({
},
}),

nomad: trait({
component: association('platform', { name: 'nomad' }),
}),

'nomad-jobspec': trait({
component: association('platform', { name: 'nomad-jobspec' }),
}),

'seconds-old-success': trait({
status: association('random', 'success', 'seconds-old'),
}),
Expand Down
7 changes: 6 additions & 1 deletion ui/mirage/factories/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Factory, trait, association } from 'ember-cli-mirage';
import { fakeId, sequenceRandom } from '../utils';

export default Factory.extend({
id: () => fakeId(),

afterCreate(release, server) {
if (!release.workspace) {
let workspace =
Expand All @@ -11,7 +13,6 @@ export default Factory.extend({
},

random: trait({
id: () => fakeId(),
component: association('release-manager', 'with-random-name'),
sequence: () => sequenceRandom(),
status: association('random'),
Expand All @@ -23,6 +24,10 @@ export default Factory.extend({
url: 'https://wildly-intent-honeybee.waypoint.run',
}),

'nomad-jobspec': trait({
component: association('release-manager', { name: 'nomad-jobspec' }),
}),

'seconds-old-success': trait({
status: association('random', 'success', 'seconds-old'),
}),
Expand Down
6 changes: 3 additions & 3 deletions ui/mirage/models/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default Model.extend({
build: belongsTo(),
status: belongsTo({ inverse: 'owner' }),
component: belongsTo({ inverse: 'owner' }),
generation: belongsTo(),

toProtobuf(): Deployment {
let result = new Deployment();
Expand All @@ -18,8 +19,7 @@ export default Model.extend({
result.setArtifactId(this.artifactId);
result.setComponent(this.component?.toProtobuf());
// TODO: result.setDeployment
// TODO: result.setExtension
// TODO: result.setGeneration
result.setGeneration(this.generation?.toProtobuf());
result.setHasEntrypointConfig(this.hasEntrypointConfig);
result.setHasExecPlugin(this.hasExecPlugin);
result.setHasLogsPlugin(this.hasLogsPlugin);
Expand All @@ -30,7 +30,7 @@ export default Model.extend({
result.setState(PhysicalState[this.state as StateName]);
result.setStatus(this.status?.toProtobuf());
result.setTemplateData(this.templateData);
result.setWorkspace(this.workspace.toProtobufRef());
result.setWorkspace(this.workspace?.toProtobufRef());

for (let [key, value] of Object.entries<string>(this.labels ?? {})) {
result.getLabelsMap().set(key, value);
Expand Down
15 changes: 15 additions & 0 deletions ui/mirage/models/generation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Model, hasMany } from 'miragejs';
import { Generation } from 'waypoint-pb';

export default Model.extend({
deployment: hasMany(),

toProtobuf(): Generation {
let result = new Generation();

result.setId(this.id);
result.setInitialSequence(this.initialSequence);

return result;
},
});
109 changes: 109 additions & 0 deletions ui/mirage/scenarios/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,113 @@ import { Server } from 'ember-cli-mirage';

export default function (server: Server): void {
server.create('project', 'marketing-public');

let workspace = server.schema.workspaces.findBy({ name: 'default' });
let project = server.create('project', { name: 'mutable-project' });
let application = server.create('application', { name: 'mutable-application', project });
let builds = [
server.create('build', 'docker', 'days-old-success', {
application,
workspace,
sequence: 1,
}),
server.create('build', 'docker', 'days-old-success', {
application,
workspace,
sequence: 2,
}),
server.create('build', 'docker', 'hours-old-success', {
application,
workspace,
sequence: 3,
}),
server.create('build', 'docker', 'hours-old-success', {
application,
workspace,
sequence: 4,
}),
server.create('build', 'docker', 'minutes-old-success', {
application,
workspace,
sequence: 5,
}),
server.create('build', 'docker', 'minutes-old-success', {
application,
workspace,
sequence: 6,
}),
server.create('build', 'docker', 'seconds-old-success', {
application,
workspace,
sequence: 7,
}),
];
let generations = [
server.create('generation', {
id: 'job-v1',
initialSequence: 1,
}),
server.create('generation', {
id: 'job-v2',
initialSequence: 4,
}),
];
let deployments = [
server.create('deployment', 'random', 'nomad-jobspec', 'days-old-success', {
application,
workspace,
generation: generations[0],
build: builds[0],
sequence: 1,
}),
server.create('deployment', 'random', 'nomad-jobspec', 'days-old-success', {
application,
workspace,
generation: generations[0],
build: builds[1],
sequence: 2,
}),
server.create('deployment', 'random', 'nomad-jobspec', 'hours-old-success', {
application,
workspace,
generation: generations[0],
build: builds[2],
sequence: 3,
}),
server.create('deployment', 'random', 'nomad-jobspec', 'hours-old-success', {
application,
workspace,
generation: generations[1],
build: builds[2],
sequence: 4,
}),
server.create('deployment', 'random', 'nomad-jobspec', 'minutes-old-success', {
application,
workspace,
generation: generations[1],
build: builds[2],
sequence: 5,
}),
server.create('deployment', 'random', 'nomad-jobspec', 'minutes-old-success', {
application,
workspace,
generation: generations[1],
build: builds[2],
sequence: 6,
}),
server.create('deployment', 'random', 'nomad-jobspec', 'seconds-old-success', {
application,
workspace,
generation: generations[1],
build: builds[2],
sequence: 7,
}),
];

server.create('release', 'random', 'nomad-jobspec', 'seconds-old-success', {
sequence: 1,
deployment: deployments[0],
application,
workspace,
});
}
2 changes: 2 additions & 0 deletions ui/mirage/services/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function list(schema: any, { requestBody }: Request): Response {
let buildProtobufs = builds.models.map((b) => b.toProtobuf());
let resp = new ListBuildsResponse();

buildProtobufs.sort((a, b) => b.getSequence() - a.getSequence());

resp.setBuildsList(buildProtobufs);

return this.serialize(resp, 'application');
Expand Down
2 changes: 2 additions & 0 deletions ui/mirage/services/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function list(schema: any, { requestBody }: Request): Response {
let deploymentProtobufs = deployments.models.map((d) => d.toProtobuf());
let resp = new ListDeploymentsResponse();

deploymentProtobufs.sort((a, b) => b.getSequence() - a.getSequence());

resp.setDeploymentsList(deploymentProtobufs);

return this.serialize(resp, 'application');
Expand Down
2 changes: 2 additions & 0 deletions ui/mirage/services/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function list(schema: any, { requestBody }: Request): Response {
let releaseProtobufs = releases.models.map((d) => d.toProtobuf());
let resp = new ListReleasesResponse();

releaseProtobufs.sort((a, b) => b.getSequence() - a.getSequence());

resp.setReleasesList(releaseProtobufs);

return this.serialize(resp, 'application');
Expand Down

0 comments on commit a3b5e80

Please sign in to comment.