1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 06:00:06 +02:00

feat(portal-api): support deleteDeploymentGroup

This commit is contained in:
Sérgio Ramos 2017-07-17 15:19:31 +01:00 committed by Judit Greskovits
parent 3ddc156c18
commit 9296d51075
4 changed files with 108 additions and 5 deletions

View File

@ -391,6 +391,92 @@ class Data extends EventEmitter {
});
}
deleteDeploymentGroup ({ id }, cb) {
// dg, services, instances, versions, manifests
const remove = (err, result) => {
if (err) {
return cb(err);
}
const res = ForceArray(result.successes).reduce((acc, res) => {
return Object.assign(acc, res);
}, {});
VAsync.parallel({
funcs: [
(cb) => {
this._db.deployment_groups.remove({ id }, cb);
},
(cb) => {
VAsync.forEachParallel({
inputs: res.services,
func: ({ id }, next) => {
this._db.services.remove({ id }, next);
}
});
},
(cb) => {
VAsync.forEachParallel({
inputs: res.instances,
func: ({ id }, next) => {
this._db.instances.remove({ id }, next);
}
});
},
(cb) => {
VAsync.forEachParallel({
inputs: res.versions,
func: ({ id }, next) => {
this._db.versions.remove({ id }, next);
}
});
},
(cb) => {
VAsync.forEachParallel({
inputs: res.manifests,
func: ({ id }, next) => {
this._db.manifests.remove({ id }, next);
}
});
}
]
}, (err) => {
cb(err, res.cb);
});
};
VAsync.parallel({
funcs: [
(cb) => {
this.getDeploymentGroup({ id }, (err, dg) => {
cb(err, { dg });
});
},
(cb) => {
this.getServices({ deploymentGroupId: id }, (err, services) => {
cb(err, { services });
});
},
(cb) => {
this.getInstances({ deploymentGroupId: id }, (err, instances) => {
cb(err, { instances });
});
},
(cb) => {
this.getVersions({ deploymentGroupId: id }, (err, versions) => {
cb(err, { versions });
});
},
(cb) => {
this.getManifests({ deploymentGroupId: id }, (err, manifests) => {
cb(err, { manifests });
});
}
]
}, remove);
}
// versions
_versionFns (version) {
@ -1235,7 +1321,9 @@ class Data extends EventEmitter {
ctx.config = config;
this.createManifest(clientManifest, handleNewManifest);
this.createManifest(Object.assign(clientManifest, {
deploymentGroupId: ctx.currentDeploymentGroup.id
}), handleNewManifest);
};
// 1. check if deployment group exists
@ -2201,7 +2289,9 @@ class Data extends EventEmitter {
VAsync.forEachParallel({
inputs: service.instances,
func: (instance, next) => {
return this.createInstance(instance, next);
return this.createInstance(Object.assign(instance, {
deploymentGroupId
}), next);
}
}, (err, results) => {
if (err) {

View File

@ -80,7 +80,6 @@ exports.fromService = function ({ service, instances, packages }) {
};
exports.toService = function (clientService) {
// wat??
return clean({
id: clientService.id,
version_hash: clientService.hash,
@ -106,6 +105,7 @@ exports.toVersion = function (clientVersion) {
id: clientVersion.id,
created: clientVersion.created || Date.now(),
manifest_id: (clientVersion.manifest || {}).id,
deployment_group_id: clientVersion.deploymentGroupId,
service_scales: clientVersion.scale ? clientVersion.scale : undefined,
plan: clientVersion.plan ? clientVersion.plan : undefined,
error: clientVersion.version
@ -116,6 +116,7 @@ exports.fromVersion = function (version) {
return {
id: version.id,
created: version.created,
deploymentGroupId: version.deployment_group_id,
manifest: version.manifest,
scale: version.service_scales,
plan: version.plan,
@ -171,6 +172,8 @@ exports.fromInstance = function (instance) {
id: instance.id,
name: instance.name,
machineId: instance.machine_id,
serviceId: instance.service_id,
deploymentGroupId: instance.deployment_group_id,
status: instance.status,
healthy: instance.healthy,
watchers: instance.watchers,
@ -184,6 +187,8 @@ exports.toInstance = function (clientInstance) {
id: clientInstance.id,
name: clientInstance.name,
machine_id: clientInstance.machineId,
deployment_group_id: clientInstance.deploymentGroupId,
service_id: clientInstance.serviceId,
status: clientInstance.status,
healthy: clientInstance.healthy,
watchers: clientInstance.watchers,

View File

@ -33,6 +33,7 @@ module.exports = (data) => {
const mutations = [
'createDeploymentGroup',
'updateDeploymentGroup',
'deleteDeploymentGroup',
'provisionManifest',
'scale',
'stopServices',

View File

@ -155,7 +155,7 @@ module.exports = class MachineWatcher {
});
}
createInstance ({ machine, instances, service }, cb) {
createInstance ({ deploymentGroup, machine, instances, service }, cb) {
console.error(`-> detected that machine ${machine.name} was created`);
const status = (machine.state || '').toUpperCase();
@ -167,6 +167,7 @@ module.exports = class MachineWatcher {
const instance = {
name: machine.name,
status,
deploymentGroupId: deploymentGroup.id,
machineId: machine.id
};
@ -523,7 +524,13 @@ module.exports = class MachineWatcher {
this.createInstance :
this.updateInstance;
createOrUpdateInstance.call(this, { machine, instances, instance, service }, handleCreateOrUpdatedInstance);
createOrUpdateInstance.call(this, {
deploymentGroup,
machine,
instances,
instance,
service
}, handleCreateOrUpdatedInstance);
}
onChange (machine) {