feat(portal-api): support deleteDeploymentGroup
This commit is contained in:
parent
3ddc156c18
commit
9296d51075
@ -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
|
// versions
|
||||||
|
|
||||||
_versionFns (version) {
|
_versionFns (version) {
|
||||||
@ -1235,7 +1321,9 @@ class Data extends EventEmitter {
|
|||||||
|
|
||||||
ctx.config = config;
|
ctx.config = config;
|
||||||
|
|
||||||
this.createManifest(clientManifest, handleNewManifest);
|
this.createManifest(Object.assign(clientManifest, {
|
||||||
|
deploymentGroupId: ctx.currentDeploymentGroup.id
|
||||||
|
}), handleNewManifest);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. check if deployment group exists
|
// 1. check if deployment group exists
|
||||||
@ -2201,7 +2289,9 @@ class Data extends EventEmitter {
|
|||||||
VAsync.forEachParallel({
|
VAsync.forEachParallel({
|
||||||
inputs: service.instances,
|
inputs: service.instances,
|
||||||
func: (instance, next) => {
|
func: (instance, next) => {
|
||||||
return this.createInstance(instance, next);
|
return this.createInstance(Object.assign(instance, {
|
||||||
|
deploymentGroupId
|
||||||
|
}), next);
|
||||||
}
|
}
|
||||||
}, (err, results) => {
|
}, (err, results) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -80,7 +80,6 @@ exports.fromService = function ({ service, instances, packages }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.toService = function (clientService) {
|
exports.toService = function (clientService) {
|
||||||
// wat??
|
|
||||||
return clean({
|
return clean({
|
||||||
id: clientService.id,
|
id: clientService.id,
|
||||||
version_hash: clientService.hash,
|
version_hash: clientService.hash,
|
||||||
@ -106,6 +105,7 @@ exports.toVersion = function (clientVersion) {
|
|||||||
id: clientVersion.id,
|
id: clientVersion.id,
|
||||||
created: clientVersion.created || Date.now(),
|
created: clientVersion.created || Date.now(),
|
||||||
manifest_id: (clientVersion.manifest || {}).id,
|
manifest_id: (clientVersion.manifest || {}).id,
|
||||||
|
deployment_group_id: clientVersion.deploymentGroupId,
|
||||||
service_scales: clientVersion.scale ? clientVersion.scale : undefined,
|
service_scales: clientVersion.scale ? clientVersion.scale : undefined,
|
||||||
plan: clientVersion.plan ? clientVersion.plan : undefined,
|
plan: clientVersion.plan ? clientVersion.plan : undefined,
|
||||||
error: clientVersion.version
|
error: clientVersion.version
|
||||||
@ -116,6 +116,7 @@ exports.fromVersion = function (version) {
|
|||||||
return {
|
return {
|
||||||
id: version.id,
|
id: version.id,
|
||||||
created: version.created,
|
created: version.created,
|
||||||
|
deploymentGroupId: version.deployment_group_id,
|
||||||
manifest: version.manifest,
|
manifest: version.manifest,
|
||||||
scale: version.service_scales,
|
scale: version.service_scales,
|
||||||
plan: version.plan,
|
plan: version.plan,
|
||||||
@ -171,6 +172,8 @@ exports.fromInstance = function (instance) {
|
|||||||
id: instance.id,
|
id: instance.id,
|
||||||
name: instance.name,
|
name: instance.name,
|
||||||
machineId: instance.machine_id,
|
machineId: instance.machine_id,
|
||||||
|
serviceId: instance.service_id,
|
||||||
|
deploymentGroupId: instance.deployment_group_id,
|
||||||
status: instance.status,
|
status: instance.status,
|
||||||
healthy: instance.healthy,
|
healthy: instance.healthy,
|
||||||
watchers: instance.watchers,
|
watchers: instance.watchers,
|
||||||
@ -184,6 +187,8 @@ exports.toInstance = function (clientInstance) {
|
|||||||
id: clientInstance.id,
|
id: clientInstance.id,
|
||||||
name: clientInstance.name,
|
name: clientInstance.name,
|
||||||
machine_id: clientInstance.machineId,
|
machine_id: clientInstance.machineId,
|
||||||
|
deployment_group_id: clientInstance.deploymentGroupId,
|
||||||
|
service_id: clientInstance.serviceId,
|
||||||
status: clientInstance.status,
|
status: clientInstance.status,
|
||||||
healthy: clientInstance.healthy,
|
healthy: clientInstance.healthy,
|
||||||
watchers: clientInstance.watchers,
|
watchers: clientInstance.watchers,
|
||||||
|
@ -33,6 +33,7 @@ module.exports = (data) => {
|
|||||||
const mutations = [
|
const mutations = [
|
||||||
'createDeploymentGroup',
|
'createDeploymentGroup',
|
||||||
'updateDeploymentGroup',
|
'updateDeploymentGroup',
|
||||||
|
'deleteDeploymentGroup',
|
||||||
'provisionManifest',
|
'provisionManifest',
|
||||||
'scale',
|
'scale',
|
||||||
'stopServices',
|
'stopServices',
|
||||||
|
@ -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`);
|
console.error(`-> detected that machine ${machine.name} was created`);
|
||||||
|
|
||||||
const status = (machine.state || '').toUpperCase();
|
const status = (machine.state || '').toUpperCase();
|
||||||
@ -167,6 +167,7 @@ module.exports = class MachineWatcher {
|
|||||||
const instance = {
|
const instance = {
|
||||||
name: machine.name,
|
name: machine.name,
|
||||||
status,
|
status,
|
||||||
|
deploymentGroupId: deploymentGroup.id,
|
||||||
machineId: machine.id
|
machineId: machine.id
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -523,7 +524,13 @@ module.exports = class MachineWatcher {
|
|||||||
this.createInstance :
|
this.createInstance :
|
||||||
this.updateInstance;
|
this.updateInstance;
|
||||||
|
|
||||||
createOrUpdateInstance.call(this, { machine, instances, instance, service }, handleCreateOrUpdatedInstance);
|
createOrUpdateInstance.call(this, {
|
||||||
|
deploymentGroup,
|
||||||
|
machine,
|
||||||
|
instances,
|
||||||
|
instance,
|
||||||
|
service
|
||||||
|
}, handleCreateOrUpdatedInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange (machine) {
|
onChange (machine) {
|
||||||
|
Loading…
Reference in New Issue
Block a user