mirror of
https://github.com/yldio/copilot.git
synced 2024-11-14 23:30:05 +02:00
feat(cp-gql-mock-server): Implement transitional states
This commit is contained in:
parent
012a44c00a
commit
9730b5733a
@ -183,71 +183,98 @@ const scale = options => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const restartServices = options => {
|
|
||||||
const service = getServices({ id: options.ids[0] });
|
|
||||||
return service;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateInstancesStatus = (is, status) => {
|
const updateInstancesStatus = (is, status) => {
|
||||||
is.forEach(i => {
|
is.forEach(i => {
|
||||||
const instance = instances.filter(instance => instance.id === i.id)[0];
|
const instance = instances.filter(instance => instance.id === i.id)[0];
|
||||||
instance.status = status;
|
instance.status = status;
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateServiceStatus = (serviceId, status) => {
|
const updateServiceStatus = (ss, status) => {
|
||||||
return Promise.all([getServices({ id: serviceId }), getServices({ parentId: serviceId })])
|
ss.forEach(s => {
|
||||||
.then(services => services.reduce((services, service) =>
|
const service = services.filter(service => service.id === s.id)[0];
|
||||||
services.concat(service), []))
|
service.status = status;
|
||||||
.then(services => Promise.all(
|
});
|
||||||
services.reduce((instances, service) =>
|
return null;
|
||||||
service.instances ? instances.concat(service.instances()) : instances, [])))
|
}
|
||||||
.then(instances => updateInstancesStatus(instances.reduce((is, i) =>
|
|
||||||
is.concat(i), []), status))
|
const updateServiceAndInstancesStatus = (serviceId, serviceStatus, instancesStatus) => {
|
||||||
.then(() => Promise.all([
|
return Promise.all([
|
||||||
getServices({ id: serviceId }),
|
getServices({ id: serviceId }),
|
||||||
getServices({ parentId: serviceId })
|
getServices({ parentId: serviceId })
|
||||||
|
])
|
||||||
|
.then(services => services.reduce((services, service) =>
|
||||||
|
services.concat(service), []))
|
||||||
|
.then(services => {
|
||||||
|
updateServiceStatus(services, serviceStatus);
|
||||||
|
return Promise.all(
|
||||||
|
services.reduce((instances, service) =>
|
||||||
|
service.instances ? instances.concat(service.instances()) : instances, []))
|
||||||
|
.then(instances => updateInstancesStatus(instances.reduce((is, i) =>
|
||||||
|
is.concat(i), []), instancesStatus))
|
||||||
|
})
|
||||||
|
.then(() => Promise.all([
|
||||||
|
getUnfilteredServices({ id: serviceId }),
|
||||||
|
getUnfilteredServices({ parentId: serviceId })
|
||||||
]))
|
]))
|
||||||
.then(services => services.reduce((services, service) =>
|
.then(services => services.reduce((services, service) =>
|
||||||
services.concat(service), []));
|
services.concat(service), []));
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteServices = options => {
|
const handleStatusUpdateRequest = (serviceId,
|
||||||
const serviceId = options.ids[0];
|
transitionalServiceStatus, transitionalInstancesStatus,
|
||||||
const deleteService = getServices({ id: serviceId }).then(services => {
|
serviceStatus, instancesStatus) => {
|
||||||
const service = services.shift();
|
// this is what we need to delay
|
||||||
return service.instances().then(instances => {
|
const timeout = setTimeout(() => {
|
||||||
if (instances.length) {
|
updateServiceAndInstancesStatus(serviceId,
|
||||||
updateInstancesStatus(instances, 'DELETED');
|
serviceStatus, instancesStatus);
|
||||||
return [service];
|
}, 5000);
|
||||||
|
// this is what we'll need to return
|
||||||
|
return updateServiceAndInstancesStatus(serviceId,
|
||||||
|
transitionalServiceStatus, transitionalInstancesStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getUnfilteredServices({ parent: serviceId }).then(services => {
|
const deleteServices = options => {
|
||||||
return Promise.all(
|
// service transitional 'DELETING'
|
||||||
services.map(service => service.instances())
|
// instances transitional 'STOPPING'
|
||||||
).then(instances => {
|
// service 'DELETED'
|
||||||
const is = instances.reduce((is, i) => is.concat(i), []);
|
// instances 'DELETED'
|
||||||
updateInstancesStatus(is, 'DELETED');
|
const deleteService = handleStatusUpdateRequest(options.ids[0],
|
||||||
return [service];
|
'DELETING', 'STOPPING', 'DELETED', 'DELETED');
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return Promise.resolve(deleteService);
|
return Promise.resolve(deleteService);
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopServices = options => {
|
const stopServices = options => {
|
||||||
const stopService = updateServiceStatus(options.ids[0], 'STOPPED');
|
// service transitional 'STOPPING'
|
||||||
|
// instances transitional 'STOPPING'
|
||||||
|
// service 'STOPPED'
|
||||||
|
// instances 'STOPPED'
|
||||||
|
const stopService = handleStatusUpdateRequest(options.ids[0],
|
||||||
|
'STOPPING', 'STOPPING', 'STOPPED', 'STOPPED');
|
||||||
return Promise.resolve(stopService);
|
return Promise.resolve(stopService);
|
||||||
};
|
};
|
||||||
|
|
||||||
const startServices = options => {
|
const startServices = options => {
|
||||||
const startService = updateServiceStatus(options.ids[0], 'RUNNING');
|
// service transitional ...
|
||||||
|
// instances transitional ...
|
||||||
|
// service 'ACTIVE'
|
||||||
|
// instances 'RUNNING'
|
||||||
|
const startService = handleStatusUpdateRequest(options.ids[0],
|
||||||
|
'PROVISIONING', 'PROVISIONING', 'ACTIVE', 'RUNNING');
|
||||||
return Promise.resolve(startService);
|
return Promise.resolve(startService);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const restartServices = options => {
|
||||||
|
// service transitional 'RESTARTING'
|
||||||
|
// instances transitional 'STOPPING'
|
||||||
|
// service 'ACTIVE'
|
||||||
|
// instances 'RUNNING'
|
||||||
|
const restartService = handleStatusUpdateRequest(options.ids[0],
|
||||||
|
'RESTARTING', 'STOPPING', 'ACTIVE', 'RUNNING');
|
||||||
|
return Promise.resolve(restartService);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
portal: getPortal,
|
portal: getPortal,
|
||||||
deploymentGroups: getDeploymentGroups,
|
deploymentGroups: getDeploymentGroups,
|
||||||
|
Loading…
Reference in New Issue
Block a user