1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-10 11:00:13 +02:00
copilot/spikes/graphql/graphql-server/src/resolvers.js

147 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-05-03 17:56:02 +03:00
import { find, filter } from 'lodash';
import data from './mock-data';
import { normalMetricData, leakMetricData } from './mock-data/metrics';
2017-05-03 17:56:02 +03:00
2017-05-16 16:46:04 +03:00
const datacenters = data.datacenters.data;
const portal = { username: 'juditgreskovits', host: 'dockerhost', datacenter: datacenters[0]};
const deploymentGroups = data.projects.data.map(p => {
p.pathName = p.id;
return p;
});
const services = data.services.data.map(s => {
s.pathName = s.id;
return s;
});
2017-05-03 17:56:02 +03:00
const instances = data.instances.data;
const metricTypes = data.metrics.data.types;
const count = 10;
let index = 0;
const getInstanceMetricData = (dataset, type) => {
return dataset[type].slice(index, index + count);
}
const tick = setInterval(() => index++, 15*1000);
2017-05-03 17:56:02 +03:00
const resolveFunctions = {
Query: {
portal() {
return portal;
},
2017-05-03 19:36:38 +03:00
deploymentGroups() {
return deploymentGroups;
2017-05-03 17:56:02 +03:00
},
2017-05-16 16:46:04 +03:00
deploymentGroup(_, { uuid, pathName }) {
if(uuid) {
return find(deploymentGroups, { uuid: uuid });
}
2017-05-16 16:46:04 +03:00
if(pathName) {
return find(deploymentGroups, { pathName: pathName });
}
return null;
2017-05-03 17:56:02 +03:00
},
2017-05-16 16:46:04 +03:00
services(_, { deploymentGroupUuid=null, deploymentGroupPathName=null }) {
if(deploymentGroupUuid) {
return filter(services, { project: deploymentGroupUuid });
}
2017-05-16 16:46:04 +03:00
if(deploymentGroupPathName) {
const deploymentGroup = find(deploymentGroups, { pathName: deploymentGroupPathName });
if(deploymentGroup) {
return filter(services, { project: deploymentGroup.uuid });
}
return null;
}
2017-05-03 17:56:02 +03:00
return services;
},
2017-05-16 16:46:04 +03:00
service(_, { uuid, pathName }) {
if(uuid) {
return find(services, { uuid: uuid });
}
2017-05-16 16:46:04 +03:00
if(pathName) {
return find(services, { pathName: pathName });
}
return null;
2017-05-03 17:56:02 +03:00
},
2017-05-16 16:46:04 +03:00
instances(_, { serviceUuid=null, servicePathName=null }) {
if(serviceUuid) {
return filter(instances, { service: serviceUuid });
}
if(serviceId) {
2017-05-16 16:46:04 +03:00
const service = find(services, { pathName: servicePathName });
if(service) {
return filter(instances, { service: service.uuid });
}
return null;
}
2017-05-03 17:56:02 +03:00
return instances;
},
metricTypes() {
return metricTypes;
},
datacenters() {
return datacenters;
},
// tmp test
instanceMetric() {
return {
type: {
uuid: 'node_memory_rss_bytes',
id: 'node_memory_rss_bytes',
name: 'node_memory_rss_bytes',
},
data: getInstanceMetricData(leakMetricData, 'node_memory_rss_bytes')
};
}
2017-05-03 17:56:02 +03:00
},
2017-05-16 16:46:04 +03:00
Portal: {
deploymentGroups(portal) {
return deploymentGroups;
}
},
2017-05-03 19:36:38 +03:00
DeploymentGroup: {
services(deploymentGroup) {
2017-05-16 16:46:04 +03:00
return filter(services, { project: deploymentGroup.uuid });
},
2017-05-03 17:56:02 +03:00
},
Service: {
instances(service) {
2017-05-16 16:46:04 +03:00
return filter(instances, { service: service.uuid });
2017-05-03 17:56:02 +03:00
},
metrics(service) {
return service.metrics ?
service.metrics.map((metric) =>
2017-05-16 16:46:04 +03:00
find(metricTypes, { uuid: metric.type })) : [];
},
currentMetrics(service) {
// tmp
return [{
"name": "CPU",
"value": 50,
"measurement": "%",
}, {
"name": "Memory",
"value": 20,
"measurement": "%",
}, {
"name": "Network",
"value": 2.9,
"measurement": "Kb/sec",
}];
},
2017-05-03 17:56:02 +03:00
},
Instance: {
metrics(instance) {
return ([{
type: {
uuid: 'metric-type-uuid',
id: 'metric-type-id',
name: 'metric-type-name'
},
data: normalMetricData.node_memory_rss_bytes
2017-05-16 16:46:04 +03:00
}]);
}
}
2017-05-03 17:56:02 +03:00
};
export default resolveFunctions;