add agent serializer
This commit adds a serializer for the Agent. When the factory was originally designed to have the Member properities directly on the Agent class which was not set-up properly technically, but since we didn't really make use of the Agent endpoint.
This commit is contained in:
parent
b92ab047ff
commit
2efa6cc7e4
|
@ -39,10 +39,12 @@ export default class SystemService extends Service {
|
||||||
.authorizedRawRequest(`/${namespace}/agent/self`)
|
.authorizedRawRequest(`/${namespace}/agent/self`)
|
||||||
.then(jsonWithDefault({}))
|
.then(jsonWithDefault({}))
|
||||||
.then(agent => {
|
.then(agent => {
|
||||||
|
if (agent.config.Version) {
|
||||||
const { Version, VersionPrerelease, VersionMetadata } = agent.config.Version;
|
const { Version, VersionPrerelease, VersionMetadata } = agent.config.Version;
|
||||||
agent.version = Version;
|
agent.version = Version;
|
||||||
if (VersionPrerelease) agent.version += `-${VersionPrerelease}`;
|
if (VersionPrerelease) agent.version = `${agent.version}-${VersionPrerelease}`;
|
||||||
if (VersionMetadata) agent.version += `+${VersionMetadata}`;
|
if (VersionMetadata) agent.version = `${agent.version}+${VersionMetadata}`;
|
||||||
|
}
|
||||||
return agent;
|
return agent;
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -335,21 +335,12 @@ export default function() {
|
||||||
const firstRegion = regions.first();
|
const firstRegion = regions.first();
|
||||||
return {
|
return {
|
||||||
ServerRegion: firstRegion ? firstRegion.id : null,
|
ServerRegion: firstRegion ? firstRegion.id : null,
|
||||||
Members: this.serialize(agents.all()),
|
Members: this.serialize(agents.all()).map(({ member }) => ({ ...member })),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.get('/agent/self', function({ agents }) {
|
this.get('/agent/self', function({ agents }) {
|
||||||
return {
|
return agents.first();
|
||||||
member: this.serialize(agents.first()),
|
|
||||||
config: {
|
|
||||||
Version: {
|
|
||||||
Version: '1.1.0',
|
|
||||||
VersionMetadata: 'ent',
|
|
||||||
VersionPrerelease: 'dev',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.get('/agent/monitor', function({ agents, nodes }, { queryParams }) {
|
this.get('/agent/monitor', function({ agents, nodes }, { queryParams }) {
|
||||||
|
|
|
@ -8,32 +8,40 @@ const AGENT_STATUSES = ['alive', 'leaving', 'left', 'failed'];
|
||||||
|
|
||||||
export default Factory.extend({
|
export default Factory.extend({
|
||||||
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
|
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
|
||||||
name: () => `nomad@${faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6()}`,
|
|
||||||
|
|
||||||
status: () => faker.helpers.randomize(AGENT_STATUSES),
|
config: {
|
||||||
serfPort: () => faker.random.number({ min: 4000, max: 4999 }),
|
|
||||||
|
|
||||||
address() {
|
|
||||||
return this.name.split('@')[1];
|
|
||||||
},
|
|
||||||
|
|
||||||
config: makeConfig,
|
|
||||||
|
|
||||||
tags() {
|
|
||||||
const rpcPortCandidate = faker.random.number({ min: 4000, max: 4999 });
|
|
||||||
return {
|
|
||||||
port: rpcPortCandidate === this.serfPort ? rpcPortCandidate + 1 : rpcPortCandidate,
|
|
||||||
dc: faker.helpers.randomize(DATACENTERS),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
function makeConfig() {
|
|
||||||
return {
|
|
||||||
Version: {
|
Version: {
|
||||||
Version: '1.1.0',
|
Version: '1.1.0',
|
||||||
VersionMetadata: 'ent',
|
VersionMetadata: 'ent',
|
||||||
VersionPrerelease: 'dev',
|
VersionPrerelease: 'dev',
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
member: () => {
|
||||||
|
const name = generateName();
|
||||||
|
const serfPort = faker.random.number({ min: 4000, max: 4999 });
|
||||||
|
return {
|
||||||
|
Name: name,
|
||||||
|
Port: serfPort,
|
||||||
|
Status: faker.helpers.randomize(AGENT_STATUSES),
|
||||||
|
Address: generateAddress(name),
|
||||||
|
Tags: generateTags(serfPort),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function generateName() {
|
||||||
|
return `nomad@${faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateAddress(name) {
|
||||||
|
return name.split('@')[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateTags(serfPort) {
|
||||||
|
const rpcPortCandidate = faker.random.number({ min: 4000, max: 4999 });
|
||||||
|
return {
|
||||||
|
port: rpcPortCandidate === serfPort ? rpcPortCandidate + 1 : rpcPortCandidate,
|
||||||
|
dc: faker.helpers.randomize(DATACENTERS),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
10
ui/mirage/serializers/agent.js
Normal file
10
ui/mirage/serializers/agent.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import ApplicationSerializer from './application';
|
||||||
|
|
||||||
|
export default ApplicationSerializer.extend({
|
||||||
|
keyForAttribute(str) {
|
||||||
|
if (str === 'config' || str === 'member') {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return ApplicationSerializer.prototype.keyForAttribute.apply(this, arguments);
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in a new issue