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
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
// TMP / Util
|
2017-05-17 21:02:35 +03:00
|
|
|
const datacenter = {
|
|
|
|
uuid: 'datacenter-uuid',
|
|
|
|
region: 'us-east-1'
|
|
|
|
};
|
2017-05-24 20:09:10 +03:00
|
|
|
const user = {
|
|
|
|
uuid: 'unique-user-id',
|
|
|
|
firstName: 'Judit',
|
|
|
|
lastName: 'Greskovits',
|
|
|
|
email: 'name@email.com',
|
|
|
|
login: 'juditgreskovits'
|
|
|
|
}
|
|
|
|
const portal = { user, host: 'dockerhost', datacenter};
|
2017-05-16 16:46:04 +03:00
|
|
|
const deploymentGroups = data.projects.data.map(p => {
|
2017-05-17 19:10:18 +03:00
|
|
|
p.slug = p.id;
|
2017-05-16 16:46:04 +03:00
|
|
|
return p;
|
|
|
|
});
|
|
|
|
const services = data.services.data.map(s => {
|
2017-05-17 19:10:18 +03:00
|
|
|
s.slug = s.id;
|
2017-05-16 16:46:04 +03:00
|
|
|
return s;
|
|
|
|
});
|
2017-05-03 17:56:02 +03:00
|
|
|
const instances = data.instances.data;
|
|
|
|
const metricTypes = data.metrics.data.types;
|
|
|
|
|
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-22 20:13:24 +03:00
|
|
|
// GraphQL
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
const queries = {
|
|
|
|
portal() {
|
|
|
|
return portal;
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
deploymentGroups(_, { name, slug }) {
|
|
|
|
return deploymentGroups;
|
|
|
|
},
|
|
|
|
deploymentGroup(_, { uuid, name, slug }) {
|
|
|
|
if(uuid) {
|
|
|
|
return find(deploymentGroups, { uuid: uuid });
|
|
|
|
}
|
|
|
|
if(slug) {
|
|
|
|
return find(deploymentGroups, { slug: slug });
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
serviceScales(_, { serviceName, versionUuid }) { // : [ServiceScale]
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
serviceScale(_, { uuid }) { // : ServiceScale
|
|
|
|
return {};
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
convergenceActions(_, { type, service, versionUuid }) { // : [ConvergenceAction]
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
convergenceAction(uuid) { // : ConvergenceAction
|
|
|
|
return {};
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
stateConvergencePlans(_, { running, versionUuid }) { // : [StateConvergencePlan]
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
stateConvergencePlan(_, { uuid }) { // : StateConvergencePlan
|
|
|
|
return [];
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
versions(_, { manifestUuid, deploymentGroupUuid }) { // : [Version]
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
version(_, { uuid, manifestUuid }) { // : Version
|
|
|
|
return null;
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
manifests(_, { type, deploymentGroupUuid }) { // : [Manifest]
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
manifest(_, { uuid }) { // : Manifest
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
services(_, { name, slug, parentUuid, deploymentGroupUuid, deploymentGroupSlug }) { // }: [Service]
|
|
|
|
if(deploymentGroupUuid) {
|
|
|
|
return filter(services, { project: deploymentGroupUuid });
|
|
|
|
}
|
|
|
|
if(deploymentGroupSlug) {
|
|
|
|
const deploymentGroup = find(deploymentGroups, { slug: deploymentGroupSlug });
|
|
|
|
if(deploymentGroup) {
|
|
|
|
if(slug) {
|
|
|
|
return filter(services, { project: deploymentGroup.uuid, slug: slug });
|
2017-05-08 20:57:41 +03:00
|
|
|
}
|
2017-05-22 20:13:24 +03:00
|
|
|
return filter(services, { project: deploymentGroup.uuid });
|
2017-05-08 20:57:41 +03:00
|
|
|
}
|
|
|
|
return null;
|
2017-05-22 20:13:24 +03:00
|
|
|
}
|
|
|
|
return services;
|
|
|
|
},
|
|
|
|
service(_, { uuid, hash }) { // : Service
|
|
|
|
if(uuid) {
|
|
|
|
return find(services, { uuid: uuid });
|
|
|
|
}
|
|
|
|
if(hash) {
|
|
|
|
return find(services, { hash: hash });
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
packages(_, { name, type, memory, disk, swap, lwps, vcpus, version, group }) { // : [Package]
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
package(_, { uuid }) { // : Package
|
|
|
|
return {};
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
instances(_, { name, machineId, status, serviceUuid, serviceSlug, deploymentGroupUuid, deploymentGroupSlug }) { // : [Instance]
|
|
|
|
if(serviceUuid) {
|
|
|
|
return filter(instances, { service: serviceUuid });
|
|
|
|
}
|
|
|
|
if(serviceSlug) {
|
|
|
|
const service = find(services, { slug: serviceSlug });
|
|
|
|
if(service) {
|
|
|
|
return filter(instances, { service: service.uuid });
|
2017-05-17 19:10:18 +03:00
|
|
|
}
|
2017-05-22 20:13:24 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return instances;
|
|
|
|
},
|
|
|
|
instance(_, { uuid }) { // : Instance
|
|
|
|
if(uuid) {
|
|
|
|
return find(instances, { uuid: uuid });
|
|
|
|
}
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
datacenter() {
|
|
|
|
return datacenter;
|
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
|
2017-05-22 20:13:24 +03:00
|
|
|
/*metricTypes() {
|
|
|
|
return metricTypes;
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
2017-05-22 20:13:24 +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')
|
|
|
|
};
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
const resolveFunctions = {
|
|
|
|
Query: queries,
|
2017-05-16 16:46:04 +03:00
|
|
|
Portal: {
|
2017-05-22 20:13:24 +03:00
|
|
|
deploymentGroups(portal, args, context) {
|
2017-05-16 16:46:04 +03:00
|
|
|
return deploymentGroups;
|
|
|
|
}
|
|
|
|
},
|
2017-05-03 19:36:38 +03:00
|
|
|
DeploymentGroup: {
|
2017-05-22 20:13:24 +03:00
|
|
|
services(deploymentGroup, args, context) {
|
|
|
|
const a = Object.assign({}, args, {deploymentGroupSlug: deploymentGroup.slug})
|
|
|
|
return queries.services(null, a);
|
|
|
|
}
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
|
|
|
Service: {
|
2017-05-22 20:13:24 +03:00
|
|
|
instances(service, args, context) {
|
2017-05-16 16:46:04 +03:00
|
|
|
return filter(instances, { service: service.uuid });
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
/*metrics(service) {
|
2017-05-03 17:56:02 +03:00
|
|
|
return service.metrics ?
|
|
|
|
service.metrics.map((metric) =>
|
2017-05-16 16:46:04 +03:00
|
|
|
find(metricTypes, { uuid: metric.type })) : [];
|
2017-05-17 19:10:18 +03:00
|
|
|
},*/
|
|
|
|
/*currentMetrics(service) {
|
2017-05-16 16:46:04 +03:00
|
|
|
// tmp
|
|
|
|
return [{
|
|
|
|
"name": "CPU",
|
|
|
|
"value": 50,
|
|
|
|
"measurement": "%",
|
|
|
|
}, {
|
|
|
|
"name": "Memory",
|
|
|
|
"value": 20,
|
|
|
|
"measurement": "%",
|
|
|
|
}, {
|
|
|
|
"name": "Network",
|
|
|
|
"value": 2.9,
|
|
|
|
"measurement": "Kb/sec",
|
|
|
|
}];
|
2017-05-17 19:10:18 +03:00
|
|
|
},*/
|
2017-05-03 17:56:02 +03:00
|
|
|
},
|
2017-05-17 19:10:18 +03:00
|
|
|
/*Instance: {
|
2017-05-10 19:51:07 +03:00
|
|
|
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-10 19:51:07 +03:00
|
|
|
}
|
2017-05-17 19:10:18 +03:00
|
|
|
}*/
|
2017-05-03 17:56:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export default resolveFunctions;
|