2017-05-03 17:56:02 +03:00
|
|
|
import { find, filter } from 'lodash';
|
|
|
|
import data from './mock-data';
|
2017-05-10 19:51:07 +03:00
|
|
|
import { normalMetricData, leakMetricData } from './mock-data/metrics';
|
2017-05-03 17:56:02 +03:00
|
|
|
|
|
|
|
const portal = { username: 'juditgreskovits', host: 'dockerhost'};
|
2017-05-03 19:36:38 +03:00
|
|
|
const deploymentGroups = data.projects.data;
|
2017-05-03 17:56:02 +03:00
|
|
|
const services = data.services.data;
|
|
|
|
const instances = data.instances.data;
|
|
|
|
const metricTypes = data.metrics.data.types;
|
|
|
|
const datacenters = data.datacenters.data;
|
|
|
|
|
2017-05-10 19:51:07 +03:00
|
|
|
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-08 20:57:41 +03:00
|
|
|
deploymentGroup(_, { uuid, id }) {
|
|
|
|
if(uuid) {
|
|
|
|
return find(deploymentGroups, { uuid: uuid });
|
|
|
|
}
|
|
|
|
if(id) {
|
|
|
|
return find(deploymentGroups, { id: id });
|
|
|
|
}
|
|
|
|
return null;
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
2017-05-08 20:57:41 +03:00
|
|
|
services(_, { deploymentGroupUuid=null, deploymentGroupId=null }) {
|
2017-05-04 20:27:25 +03:00
|
|
|
if(deploymentGroupUuid) {
|
2017-05-08 20:57:41 +03:00
|
|
|
return filter(services, { project: deploymentGroupUuid });
|
|
|
|
}
|
|
|
|
if(deploymentGroupId) {
|
|
|
|
const deploymentGroup = find(deploymentGroups, { id: deploymentGroupId });
|
|
|
|
if(deploymentGroup) {
|
|
|
|
return filter(services, { project: deploymentGroup.uuid });
|
|
|
|
}
|
|
|
|
return null;
|
2017-05-04 20:27:25 +03:00
|
|
|
}
|
2017-05-03 17:56:02 +03:00
|
|
|
return services;
|
|
|
|
},
|
2017-05-08 20:57:41 +03:00
|
|
|
service(_, { uuid, id }) {
|
|
|
|
if(uuid) {
|
|
|
|
return find(services, { uuid: uuid });
|
|
|
|
}
|
|
|
|
if(id) {
|
|
|
|
return find(services, { id: id });
|
|
|
|
}
|
|
|
|
return null;
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
2017-05-08 20:57:41 +03:00
|
|
|
instances(_, { serviceUuid=null, serviceId=null }) {
|
|
|
|
if(serviceUuid) {
|
|
|
|
return filter(instances, { service: serviceUuid });
|
|
|
|
}
|
|
|
|
if(serviceId) {
|
|
|
|
const service = find(services, { id: serviceId });
|
|
|
|
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;
|
|
|
|
},
|
2017-05-10 19:51:07 +03:00
|
|
|
// 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-03 19:36:38 +03:00
|
|
|
DeploymentGroup: {
|
|
|
|
services(deploymentGroup) {
|
|
|
|
return filter(services, { project: deploymentGroup.uuid })
|
2017-05-08 20:57:41 +03:00
|
|
|
},
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
|
|
|
Service: {
|
|
|
|
instances(service) {
|
|
|
|
return filter(instances, { service: service.uuid })
|
|
|
|
},
|
|
|
|
metrics(service) {
|
|
|
|
return service.metrics ?
|
|
|
|
service.metrics.map((metric) =>
|
|
|
|
find(metricTypes, { uuid: metric.type })) : []
|
2017-05-08 20:57:41 +03:00
|
|
|
},
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
2017-05-10 19:51:07 +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-03 17:56:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default resolveFunctions;
|