fix(portal-api): update import logic to assign dg.services

This commit is contained in:
Sérgio Ramos 2017-08-03 13:41:14 +01:00
parent 0ec4acce1e
commit 2b552360e0

View File

@ -2038,7 +2038,7 @@ class Data extends EventEmitter {
this._triton.stopMachine(instance.machine_id, next); this._triton.stopMachine(instance.machine_id, next);
}, },
inputs: instances inputs: instances
}, (err, results) => { }, (err) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
@ -2113,7 +2113,7 @@ class Data extends EventEmitter {
this._triton.rebootMachine(instance.machine_id, next); this._triton.rebootMachine(instance.machine_id, next);
}, },
inputs: instances inputs: instances
}, (err, results) => { }, (err) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
@ -2338,34 +2338,78 @@ class Data extends EventEmitter {
}); });
}, {}); }, {});
const handleNewInstances = ({ id }, next) => {
return (err, result) => {
if (err) {
return next(err);
}
this._server.log(['debug'], `-> created Instances ${Util.inspect(result.successes)}`);
this.updateService({
id,
instances: result.successes
}, next);
};
};
const handleNewService = ({ instances, deploymentGroupId }, next) => {
return (err, service) => {
if (err) {
return next(err);
}
VAsync.forEachParallel({
inputs: instances,
func: (instance, next) => {
return this.createInstance(Object.assign(instance, {
deploymentGroupId,
serviceId: service.id
}), next);
}
}, handleNewInstances(service, next));
};
};
const createService = (deploymentGroupId) => { const createService = (deploymentGroupId) => {
return (serviceId, next) => { return (serviceIndex, next) => {
const service = services[serviceId]; const service = services[serviceIndex];
this._server.log(['debug'], `-> creating Service ${Util.inspect(service)}`); this._server.log(['debug'], `-> creating Service ${Util.inspect(service)}`);
VAsync.forEachParallel({ this.createService(Object.assign(service, {
inputs: service.instances,
func: (instance, next) => {
return this.createInstance(Object.assign(instance, {
deploymentGroupId deploymentGroupId
}), next); }), handleNewService({
} instances: service.instances,
}, (err, results) => { deploymentGroupId
}, next));
};
};
const handleNewServices = (deploymentGroupId) => {
return (err, result) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
this._server.log(['debug'], `-> created Instances ${Util.inspect(results.successes)}`); this.updateDeploymentGroup({
id: deploymentGroupId,
this.createService(Object.assign(service, { services: result.successes
instances: results.successes, }, cb);
deploymentGroupId
}), next);
});
}; };
}; };
const handleNewDeploymentGroup = (err, dg) => {
if (err) {
return cb(err);
}
VAsync.forEachParallel({
inputs: Object.keys(services),
func: createService(dg.id)
}, handleNewServices(dg.id));
};
const deploymentGroup = { const deploymentGroup = {
name: tags[DEPLOYMENT_GROUP], name: tags[DEPLOYMENT_GROUP],
slug: ParamCase(tags[DEPLOYMENT_GROUP]), slug: ParamCase(tags[DEPLOYMENT_GROUP]),
@ -2375,18 +2419,7 @@ class Data extends EventEmitter {
this._server.log(['debug'], `-> creating DeploymentGroup ${Util.inspect(deploymentGroup)}`); this._server.log(['debug'], `-> creating DeploymentGroup ${Util.inspect(deploymentGroup)}`);
this.createDeploymentGroup(deploymentGroup, (err, dg) => { this.createDeploymentGroup(deploymentGroup, handleNewDeploymentGroup);
if (err) {
return cb(err);
}
VAsync.forEachParallel({
inputs: Object.keys(services),
func: createService(dg.id)
}, (err) => {
return cb(err, dg);
});
});
} }
} }