2017-09-19 14:47:10 +00:00
|
|
|
import Ember from 'ember';
|
2017-10-10 18:23:10 +00:00
|
|
|
import Response from 'ember-cli-mirage/response';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { HOSTS } from './common';
|
2017-11-16 02:12:16 +00:00
|
|
|
import { logFrames, logEncode } from './data/logs';
|
2018-08-15 23:59:42 +00:00
|
|
|
import { generateDiff } from './factories/job-version';
|
2018-08-20 22:04:33 +00:00
|
|
|
import { generateTaskGroupFailures } from './factories/evaluation';
|
2019-03-26 04:55:06 +00:00
|
|
|
import { copy } from 'ember-copy';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export function findLeader(schema) {
|
|
|
|
const agent = schema.agents.first();
|
|
|
|
return `${agent.address}:${agent.tags.port}`;
|
|
|
|
}
|
|
|
|
|
2019-07-31 08:41:00 +00:00
|
|
|
export function filesForPath(allocFiles, filterPath) {
|
|
|
|
return allocFiles.where(
|
|
|
|
file =>
|
|
|
|
(!filterPath || file.path.startsWith(filterPath)) &&
|
|
|
|
file.path.length > filterPath.length &&
|
|
|
|
!file.path.substr(filterPath.length + 1).includes('/')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
export default function() {
|
2017-10-10 16:36:36 +00:00
|
|
|
this.timing = 0; // delay for each request, automatically set to 0 during testing
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-08-20 13:36:08 +00:00
|
|
|
this.logging = window.location.search.includes('mirage-logging=true');
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
this.namespace = 'v1';
|
2017-12-12 21:28:40 +00:00
|
|
|
this.trackRequests = Ember.testing;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-02-17 02:58:19 +00:00
|
|
|
const nomadIndices = {}; // used for tracking blocking queries
|
|
|
|
const server = this;
|
|
|
|
const withBlockingSupport = function(fn) {
|
|
|
|
return function(schema, request) {
|
|
|
|
// Get the original response
|
|
|
|
let { url } = request;
|
|
|
|
url = url.replace(/index=\d+[&;]?/, '');
|
|
|
|
const response = fn.apply(this, arguments);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-03-11 17:39:47 +00:00
|
|
|
// Get and increment the appropriate index
|
2018-03-21 20:28:56 +00:00
|
|
|
nomadIndices[url] || (nomadIndices[url] = 2);
|
2018-02-17 02:58:19 +00:00
|
|
|
const index = nomadIndices[url];
|
|
|
|
nomadIndices[url]++;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-02-17 02:58:19 +00:00
|
|
|
// Annotate the response with the index
|
|
|
|
if (response instanceof Response) {
|
|
|
|
response.headers['X-Nomad-Index'] = index;
|
|
|
|
return response;
|
|
|
|
}
|
2018-02-22 21:21:32 +00:00
|
|
|
return new Response(200, { 'x-nomad-index': index }, response);
|
2018-02-17 02:58:19 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
this.get(
|
|
|
|
'/jobs',
|
|
|
|
withBlockingSupport(function({ jobs }, { queryParams }) {
|
|
|
|
const json = this.serialize(jobs.all());
|
|
|
|
const namespace = queryParams.namespace || 'default';
|
|
|
|
return json
|
2019-04-02 01:30:44 +00:00
|
|
|
.filter(job =>
|
|
|
|
namespace === 'default'
|
|
|
|
? !job.NamespaceID || job.NamespaceID === namespace
|
|
|
|
: job.NamespaceID === namespace
|
2018-02-17 02:58:19 +00:00
|
|
|
)
|
|
|
|
.map(job => filterKeys(job, 'TaskGroups', 'NamespaceID'));
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2018-08-20 22:04:33 +00:00
|
|
|
this.post('/jobs', function(schema, req) {
|
2018-08-15 23:59:42 +00:00
|
|
|
const body = JSON.parse(req.requestBody);
|
|
|
|
|
|
|
|
if (!body.Job) return new Response(400, {}, 'Job is a required field on the request payload');
|
|
|
|
|
|
|
|
return okEmpty();
|
|
|
|
});
|
|
|
|
|
2018-08-20 22:04:33 +00:00
|
|
|
this.post('/jobs/parse', function(schema, req) {
|
2018-08-15 23:59:42 +00:00
|
|
|
const body = JSON.parse(req.requestBody);
|
|
|
|
|
|
|
|
if (!body.JobHCL)
|
|
|
|
return new Response(400, {}, 'JobHCL is a required field on the request payload');
|
|
|
|
if (!body.Canonicalize) return new Response(400, {}, 'Expected Canonicalize to be true');
|
|
|
|
|
2018-08-17 00:21:44 +00:00
|
|
|
// Parse the name out of the first real line of HCL to match IDs in the new job record
|
|
|
|
// Regex expectation:
|
|
|
|
// in: job "job-name" {
|
|
|
|
// out: job-name
|
|
|
|
const nameFromHCLBlock = /.+?"(.+?)"/;
|
|
|
|
const jobName = body.JobHCL.trim()
|
|
|
|
.split('\n')[0]
|
|
|
|
.match(nameFromHCLBlock)[1];
|
|
|
|
|
|
|
|
const job = server.create('job', { id: jobName });
|
|
|
|
return new Response(200, {}, this.serialize(job));
|
2018-08-15 23:59:42 +00:00
|
|
|
});
|
|
|
|
|
2018-08-20 22:04:33 +00:00
|
|
|
this.post('/job/:id/plan', function(schema, req) {
|
2018-08-15 23:59:42 +00:00
|
|
|
const body = JSON.parse(req.requestBody);
|
|
|
|
|
|
|
|
if (!body.Job) return new Response(400, {}, 'Job is a required field on the request payload');
|
|
|
|
if (!body.Diff) return new Response(400, {}, 'Expected Diff to be true');
|
|
|
|
|
2018-08-20 22:04:33 +00:00
|
|
|
const FailedTGAllocs = body.Job.Unschedulable && generateFailedTGAllocs(body.Job);
|
|
|
|
|
|
|
|
return new Response(
|
|
|
|
200,
|
|
|
|
{},
|
|
|
|
JSON.stringify({ FailedTGAllocs, Diff: generateDiff(req.params.id) })
|
|
|
|
);
|
2018-08-15 23:59:42 +00:00
|
|
|
});
|
|
|
|
|
2018-02-17 02:58:19 +00:00
|
|
|
this.get(
|
|
|
|
'/job/:id',
|
|
|
|
withBlockingSupport(function({ jobs }, { params, queryParams }) {
|
|
|
|
const job = jobs.all().models.find(job => {
|
|
|
|
const jobIsDefault = !job.namespaceId || job.namespaceId === 'default';
|
|
|
|
const qpIsDefault = !queryParams.namespace || queryParams.namespace === 'default';
|
|
|
|
return (
|
|
|
|
job.id === params.id &&
|
|
|
|
(job.namespaceId === queryParams.namespace || (jobIsDefault && qpIsDefault))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return job ? this.serialize(job) : new Response(404, {}, null);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2018-08-23 00:36:04 +00:00
|
|
|
this.post('/job/:id', function(schema, req) {
|
|
|
|
const body = JSON.parse(req.requestBody);
|
|
|
|
|
|
|
|
if (!body.Job) return new Response(400, {}, 'Job is a required field on the request payload');
|
|
|
|
|
|
|
|
return okEmpty();
|
|
|
|
});
|
|
|
|
|
2018-02-17 02:58:19 +00:00
|
|
|
this.get(
|
|
|
|
'/job/:id/summary',
|
|
|
|
withBlockingSupport(function({ jobSummaries }, { params }) {
|
|
|
|
return this.serialize(jobSummaries.findBy({ jobId: params.id }));
|
|
|
|
})
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
this.get('/job/:id/allocations', function({ allocations }, { params }) {
|
|
|
|
return this.serialize(allocations.where({ jobId: params.id }));
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/job/:id/versions', function({ jobVersions }, { params }) {
|
|
|
|
return this.serialize(jobVersions.where({ jobId: params.id }));
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/job/:id/deployments', function({ deployments }, { params }) {
|
|
|
|
return this.serialize(deployments.where({ jobId: params.id }));
|
|
|
|
});
|
|
|
|
|
2018-07-28 00:56:18 +00:00
|
|
|
this.get('/job/:id/deployment', function({ deployments }, { params }) {
|
2018-07-30 22:20:58 +00:00
|
|
|
const deployment = deployments.where({ jobId: params.id }).models[0];
|
|
|
|
return deployment ? this.serialize(deployment) : new Response(200, {}, 'null');
|
2018-07-28 00:56:18 +00:00
|
|
|
});
|
|
|
|
|
2018-02-02 02:54:23 +00:00
|
|
|
this.post('/job/:id/periodic/force', function(schema, { params }) {
|
|
|
|
// Create the child job
|
|
|
|
const parent = schema.jobs.find(params.id);
|
|
|
|
|
|
|
|
// Use the server instead of the schema to leverage the job factory
|
|
|
|
server.create('job', 'periodicChild', {
|
|
|
|
parentId: parent.id,
|
|
|
|
namespaceId: parent.namespaceId,
|
|
|
|
namespace: parent.namespace,
|
|
|
|
createAllocations: parent.createAllocations,
|
|
|
|
});
|
|
|
|
|
2018-08-15 23:59:42 +00:00
|
|
|
return okEmpty();
|
2018-02-02 02:54:23 +00:00
|
|
|
});
|
|
|
|
|
2018-04-19 18:13:23 +00:00
|
|
|
this.delete('/job/:id', function(schema, { params }) {
|
|
|
|
const job = schema.jobs.find(params.id);
|
|
|
|
job.update({ status: 'dead' });
|
|
|
|
return new Response(204, {}, '');
|
|
|
|
});
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
this.get('/deployment/:id');
|
2018-08-24 23:32:08 +00:00
|
|
|
this.post('/deployment/promote/:id', function() {
|
|
|
|
return new Response(204, {}, '');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-11-29 23:36:34 +00:00
|
|
|
this.get('/job/:id/evaluations', function({ evaluations }, { params }) {
|
|
|
|
return this.serialize(evaluations.where({ jobId: params.id }));
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/evaluation/:id');
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
this.get('/deployment/allocations/:id', function(schema, { params }) {
|
|
|
|
const job = schema.jobs.find(schema.deployments.find(params.id).jobId);
|
|
|
|
const allocations = schema.allocations.where({ jobId: job.id });
|
|
|
|
|
|
|
|
return this.serialize(allocations.slice(0, 3));
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/nodes', function({ nodes }) {
|
|
|
|
const json = this.serialize(nodes.all());
|
|
|
|
return json;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/node/:id');
|
|
|
|
|
|
|
|
this.get('/node/:id/allocations', function({ allocations }, { params }) {
|
|
|
|
return this.serialize(allocations.where({ nodeId: params.id }));
|
|
|
|
});
|
|
|
|
|
2018-04-21 01:11:32 +00:00
|
|
|
this.get('/allocations');
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
this.get('/allocation/:id');
|
|
|
|
|
2019-05-20 22:27:20 +00:00
|
|
|
this.post('/allocation/:id/stop', function() {
|
|
|
|
return new Response(204, {}, '');
|
|
|
|
});
|
|
|
|
|
2017-10-10 18:23:10 +00:00
|
|
|
this.get('/namespaces', function({ namespaces }) {
|
|
|
|
const records = namespaces.all();
|
|
|
|
|
|
|
|
if (records.length) {
|
|
|
|
return this.serialize(records);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Response(501, {}, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/namespace/:id', function({ namespaces }, { params }) {
|
|
|
|
if (namespaces.all().length) {
|
|
|
|
return this.serialize(namespaces.find(params.id));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Response(501, {}, null);
|
|
|
|
});
|
2017-10-07 01:27:36 +00:00
|
|
|
|
2018-08-10 02:57:21 +00:00
|
|
|
this.get('/agent/members', function({ agents, regions }) {
|
2018-08-10 18:20:44 +00:00
|
|
|
const firstRegion = regions.first();
|
2017-09-19 14:47:10 +00:00
|
|
|
return {
|
2018-08-10 18:20:44 +00:00
|
|
|
ServerRegion: firstRegion ? firstRegion.id : null,
|
2017-09-19 14:47:10 +00:00
|
|
|
Members: this.serialize(agents.all()),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/status/leader', function(schema) {
|
|
|
|
return JSON.stringify(findLeader(schema));
|
|
|
|
});
|
|
|
|
|
2017-10-14 19:42:14 +00:00
|
|
|
this.get('/acl/token/self', function({ tokens }, req) {
|
|
|
|
const secret = req.requestHeaders['X-Nomad-Token'];
|
|
|
|
const tokenForSecret = tokens.findBy({ secretId: secret });
|
|
|
|
|
|
|
|
// Return the token if it exists
|
|
|
|
if (tokenForSecret) {
|
|
|
|
return this.serialize(tokenForSecret);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client error if it doesn't
|
|
|
|
return new Response(400, {}, null);
|
|
|
|
});
|
|
|
|
|
2017-10-14 18:01:28 +00:00
|
|
|
this.get('/acl/token/:id', function({ tokens }, req) {
|
|
|
|
const token = tokens.find(req.params.id);
|
|
|
|
const secret = req.requestHeaders['X-Nomad-Token'];
|
|
|
|
const tokenForSecret = tokens.findBy({ secretId: secret });
|
|
|
|
|
|
|
|
// Return the token only if the request header matches the token
|
|
|
|
// or the token is of type management
|
|
|
|
if (token.secretId === secret || (tokenForSecret && tokenForSecret.type === 'management')) {
|
|
|
|
return this.serialize(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return not authorized otherwise
|
|
|
|
return new Response(403, {}, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/acl/policy/:id', function({ policies, tokens }, req) {
|
|
|
|
const policy = policies.find(req.params.id);
|
|
|
|
const secret = req.requestHeaders['X-Nomad-Token'];
|
|
|
|
const tokenForSecret = tokens.findBy({ secretId: secret });
|
|
|
|
|
|
|
|
// Return the policy only if the token that matches the request header
|
|
|
|
// includes the policy or if the token that matches the request header
|
|
|
|
// is of type management
|
|
|
|
if (
|
|
|
|
tokenForSecret &&
|
|
|
|
(tokenForSecret.policies.includes(policy) || tokenForSecret.type === 'management')
|
|
|
|
) {
|
|
|
|
return this.serialize(policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return not authorized otherwise
|
|
|
|
return new Response(403, {}, null);
|
|
|
|
});
|
|
|
|
|
2018-08-10 02:57:21 +00:00
|
|
|
this.get('/regions', function({ regions }) {
|
|
|
|
return this.serialize(regions.all());
|
2018-08-02 22:54:57 +00:00
|
|
|
});
|
|
|
|
|
2018-02-23 23:36:38 +00:00
|
|
|
const clientAllocationStatsHandler = function({ clientAllocationStats }, { params }) {
|
|
|
|
return this.serialize(clientAllocationStats.find(params.id));
|
|
|
|
};
|
|
|
|
|
|
|
|
const clientAllocationLog = function(server, { params, queryParams }) {
|
|
|
|
const allocation = server.allocations.find(params.allocation_id);
|
|
|
|
const tasks = allocation.taskStateIds.map(id => server.taskStates.find(id));
|
|
|
|
|
|
|
|
if (!tasks.mapBy('name').includes(queryParams.task)) {
|
|
|
|
return new Response(400, {}, 'must include task name');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (queryParams.plain) {
|
|
|
|
return logFrames.join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
return logEncode(logFrames, logFrames.length - 1);
|
|
|
|
};
|
|
|
|
|
2019-07-25 07:47:46 +00:00
|
|
|
const clientAllocationFSLsHandler = function({ allocFiles }, { queryParams }) {
|
|
|
|
// Ignore the task name at the beginning of the path
|
|
|
|
const filterPath = queryParams.path.substr(queryParams.path.indexOf('/') + 1);
|
2019-07-31 08:41:00 +00:00
|
|
|
const files = filesForPath(allocFiles, filterPath);
|
2019-07-25 07:47:46 +00:00
|
|
|
return this.serialize(files);
|
2019-07-02 21:42:38 +00:00
|
|
|
};
|
|
|
|
|
2019-07-25 07:47:46 +00:00
|
|
|
const clientAllocationFSStatHandler = function({ allocFiles }, { queryParams }) {
|
|
|
|
// Ignore the task name at the beginning of the path
|
|
|
|
const filterPath = queryParams.path.substr(queryParams.path.indexOf('/') + 1);
|
|
|
|
|
|
|
|
// Root path
|
|
|
|
if (!filterPath) {
|
|
|
|
return this.serialize({
|
|
|
|
IsDir: true,
|
|
|
|
ModTime: new Date(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either a file or a nested directory
|
|
|
|
const file = allocFiles.where({ path: filterPath }).models[0];
|
|
|
|
return this.serialize(file);
|
2019-07-02 21:42:38 +00:00
|
|
|
};
|
|
|
|
|
2019-07-25 08:12:44 +00:00
|
|
|
const clientAllocationCatHandler = function({ allocFiles }, { queryParams }) {
|
|
|
|
const [file, err] = fileOrError(allocFiles, queryParams.path);
|
|
|
|
|
|
|
|
if (err) return err;
|
|
|
|
return file.body;
|
|
|
|
};
|
|
|
|
|
|
|
|
const clientAllocationStreamHandler = function({ allocFiles }, { queryParams }) {
|
|
|
|
const [file, err] = fileOrError(allocFiles, queryParams.path);
|
|
|
|
|
|
|
|
if (err) return err;
|
|
|
|
|
|
|
|
// Pretender, and therefore Mirage, doesn't support streaming responses.
|
|
|
|
return file.body;
|
|
|
|
};
|
|
|
|
|
|
|
|
const clientAllocationReadAtHandler = function({ allocFiles }, { queryParams }) {
|
|
|
|
const [file, err] = fileOrError(allocFiles, queryParams.path);
|
|
|
|
|
|
|
|
if (err) return err;
|
|
|
|
return file.body.substr(queryParams.offset || 0, queryParams.limit);
|
|
|
|
};
|
|
|
|
|
|
|
|
const fileOrError = function(allocFiles, path, message = 'Operation not allowed on a directory') {
|
|
|
|
// Ignore the task name at the beginning of the path
|
|
|
|
const filterPath = path.substr(path.indexOf('/') + 1);
|
|
|
|
|
|
|
|
// Root path
|
|
|
|
if (!filterPath) {
|
|
|
|
return [null, new Response(400, {}, message)];
|
|
|
|
}
|
|
|
|
|
|
|
|
const file = allocFiles.where({ path: filterPath }).models[0];
|
|
|
|
if (file.isDir) {
|
|
|
|
return [null, new Response(400, {}, message)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [file, null];
|
|
|
|
};
|
|
|
|
|
2018-02-23 23:36:38 +00:00
|
|
|
// Client requests are available on the server and the client
|
2019-05-20 22:27:20 +00:00
|
|
|
this.put('/client/allocation/:id/restart', function() {
|
|
|
|
return new Response(204, {}, '');
|
|
|
|
});
|
|
|
|
|
2018-02-23 23:36:38 +00:00
|
|
|
this.get('/client/allocation/:id/stats', clientAllocationStatsHandler);
|
|
|
|
this.get('/client/fs/logs/:allocation_id', clientAllocationLog);
|
|
|
|
|
2019-07-02 21:42:38 +00:00
|
|
|
this.get('/client/fs/ls/:allocation_id', clientAllocationFSLsHandler);
|
|
|
|
this.get('/client/fs/stat/:allocation_id', clientAllocationFSStatHandler);
|
2019-07-25 08:12:44 +00:00
|
|
|
this.get('/client/fs/cat/:allocation_id', clientAllocationCatHandler);
|
|
|
|
this.get('/client/fs/stream/:allocation_id', clientAllocationStreamHandler);
|
|
|
|
this.get('/client/fs/readat/:allocation_id', clientAllocationReadAtHandler);
|
2019-07-02 21:42:38 +00:00
|
|
|
|
2018-08-31 21:37:13 +00:00
|
|
|
this.get('/client/stats', function({ clientStats }, { queryParams }) {
|
2018-11-02 05:11:56 +00:00
|
|
|
const seed = Math.random();
|
|
|
|
if (seed > 0.8) {
|
|
|
|
const stats = clientStats.find(queryParams.node_id);
|
|
|
|
stats.update({
|
|
|
|
timestamp: Date.now() * 1000000,
|
|
|
|
CPUTicksConsumed: stats.CPUTicksConsumed + (Math.random() * 20 - 10),
|
|
|
|
});
|
|
|
|
return this.serialize(stats);
|
|
|
|
} else {
|
|
|
|
return new Response(500, {}, null);
|
|
|
|
}
|
2018-02-23 23:36:38 +00:00
|
|
|
});
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
// TODO: in the future, this hack may be replaceable with dynamic host name
|
|
|
|
// support in pretender: https://github.com/pretenderjs/pretender/issues/210
|
|
|
|
HOSTS.forEach(host => {
|
2018-02-23 23:36:38 +00:00
|
|
|
this.get(`http://${host}/v1/client/allocation/:id/stats`, clientAllocationStatsHandler);
|
|
|
|
this.get(`http://${host}/v1/client/fs/logs/:allocation_id`, clientAllocationLog);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-07-02 21:42:38 +00:00
|
|
|
this.get(`http://${host}/v1/client/fs/ls/:allocation_id`, clientAllocationFSLsHandler);
|
|
|
|
this.get(`http://${host}/v1/client/stat/ls/:allocation_id`, clientAllocationFSStatHandler);
|
2019-08-08 00:34:41 +00:00
|
|
|
this.get(`http://${host}/v1/client/fs/cat/:allocation_id`, clientAllocationCatHandler);
|
|
|
|
this.get(`http://${host}/v1/client/fs/stream/:allocation_id`, clientAllocationStreamHandler);
|
|
|
|
this.get(`http://${host}/v1/client/fs/readat/:allocation_id`, clientAllocationReadAtHandler);
|
2019-07-02 21:42:38 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
this.get(`http://${host}/v1/client/stats`, function({ clientStats }) {
|
|
|
|
return this.serialize(clientStats.find(host));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function filterKeys(object, ...keys) {
|
|
|
|
const clone = copy(object, true);
|
|
|
|
|
|
|
|
keys.forEach(key => {
|
|
|
|
delete clone[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
2018-08-15 23:59:42 +00:00
|
|
|
|
|
|
|
// An empty response but not a 204 No Content. This is still a valid JSON
|
|
|
|
// response that represents a payload with no worthwhile data.
|
|
|
|
function okEmpty() {
|
|
|
|
return new Response(200, {}, '{}');
|
|
|
|
}
|
2018-08-20 22:04:33 +00:00
|
|
|
|
|
|
|
function generateFailedTGAllocs(job, taskGroups) {
|
|
|
|
const taskGroupsFromSpec = job.TaskGroups && job.TaskGroups.mapBy('Name');
|
|
|
|
|
|
|
|
let tgNames = ['tg-one', 'tg-two'];
|
|
|
|
if (taskGroupsFromSpec && taskGroupsFromSpec.length) tgNames = taskGroupsFromSpec;
|
|
|
|
if (taskGroups && taskGroups.length) tgNames = taskGroups;
|
|
|
|
|
|
|
|
return tgNames.reduce((hash, tgName) => {
|
|
|
|
hash[tgName] = generateTaskGroupFailures();
|
|
|
|
return hash;
|
|
|
|
}, {});
|
|
|
|
}
|