mirror of
https://github.com/yldio/copilot.git
synced 2024-11-28 06:00:06 +02:00
fix(portal-api): don't return all services when no services
This commit is contained in:
parent
7f9c8b2847
commit
5a8eb965ff
@ -122,18 +122,6 @@ class Data extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// triton
|
|
||||||
|
|
||||||
_listMachines (deploymentGroupName, cb) {
|
|
||||||
this._triton.listMachines({
|
|
||||||
limit: 9999,
|
|
||||||
tag: {
|
|
||||||
[DEPLOYMENT_GROUP]: deploymentGroupName
|
|
||||||
}
|
|
||||||
}, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// portals
|
// portals
|
||||||
|
|
||||||
createPortal (clientPortal, cb) {
|
createPortal (clientPortal, cb) {
|
||||||
@ -261,31 +249,36 @@ class Data extends EventEmitter {
|
|||||||
// deployment_groups
|
// deployment_groups
|
||||||
|
|
||||||
createDeploymentGroup (clientDeploymentGroup, cb) {
|
createDeploymentGroup (clientDeploymentGroup, cb) {
|
||||||
const deploymentGroup = Transform.toDeploymentGroup(clientDeploymentGroup);
|
const dg = Transform.toDeploymentGroup(clientDeploymentGroup);
|
||||||
|
console.log(`-> creating DeploymentGroup: ${Util.inspect(dg)}`);
|
||||||
|
|
||||||
this._db.deployment_groups.query({
|
this._db.deployment_groups.query({
|
||||||
slug: deploymentGroup.slug
|
slug: dg.slug
|
||||||
}, (err, deploymentGroups) => {
|
}, (err, dgs) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deploymentGroups && deploymentGroups.length) {
|
if (dgs && dgs.length) {
|
||||||
return cb(new Error(`DeploymentGroup "${deploymentGroup.slug}" already exists (${deploymentGroups[0].id})`));
|
return cb(new Error(`DeploymentGroup "${dg.slug}" already exists (${dgs[0].id})`));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._db.deployment_groups.insert(deploymentGroup, (err, key) => {
|
this._db.deployment_groups.insert(dg, (err, key) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
deploymentGroup.id = key;
|
dg.id = key;
|
||||||
cb(null, Transform.fromDeploymentGroup(deploymentGroup));
|
cb(null, Transform.fromDeploymentGroup(dg));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDeploymentGroup (clientDeploymentGroup, cb) {
|
updateDeploymentGroup (clientDeploymentGroup, cb) {
|
||||||
this._db.deployment_groups.update([Transform.toDeploymentGroup(clientDeploymentGroup)], (err) => {
|
const dg = Transform.toDeploymentGroup(clientDeploymentGroup);
|
||||||
|
console.log(`-> updating DeploymentGroup: ${Util.inspect(dg)}`);
|
||||||
|
|
||||||
|
this._db.deployment_groups.update([dg], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
@ -300,11 +293,15 @@ class Data extends EventEmitter {
|
|||||||
args.ids = deploymentGroup.service_ids;
|
args.ids = deploymentGroup.service_ids;
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
return this.getServices(args, cb);
|
return args.ids && args.ids.length ?
|
||||||
|
this.getServices(args, cb) :
|
||||||
|
cb(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.getServices(args, internals.resolveCb(resolve, reject));
|
return args.ids && args.ids.length ?
|
||||||
|
this.getServices(args, internals.resolveCb(resolve, reject)) :
|
||||||
|
resolve([]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -330,11 +327,15 @@ class Data extends EventEmitter {
|
|||||||
args.version_ids = ForceArray(deploymentGroup.history_version_ids);
|
args.version_ids = ForceArray(deploymentGroup.history_version_ids);
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
return this.getHistory(args, cb);
|
return args.version_ids && args.version_ids.length ?
|
||||||
|
this.getHistory(args, cb) :
|
||||||
|
cb(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
return this.getHistory(args, internals.resolveCb(resolve, reject));
|
return args.version_ids && args.version_ids.length ?
|
||||||
|
this.getHistory(args, internals.resolveCb(resolve, reject)) :
|
||||||
|
resolve([]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -630,39 +631,36 @@ class Data extends EventEmitter {
|
|||||||
return fallback();
|
return fallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleMachinesList = (err, machines) => {
|
const machines = ForceArray(this._machines.getContainers())
|
||||||
if (err) {
|
.filter(({ tags = {} }) => {
|
||||||
return fallback(err);
|
return tags[DEPLOYMENT_GROUP] === deploymentGroupName;
|
||||||
}
|
|
||||||
|
|
||||||
const liveServices = ForceArray(machines).reduce((acc, { tags }) => {
|
|
||||||
return Object.assign(acc, {
|
|
||||||
[tags[SERVICE]]: 1
|
|
||||||
});
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
const allAndConfigServices = config.reduce((acc, { name }) => {
|
|
||||||
return Object.assign(acc, {
|
|
||||||
[name]: 1
|
|
||||||
});
|
|
||||||
}, liveServices);
|
|
||||||
|
|
||||||
const scale = Object.keys(allAndConfigServices).map((name) => {
|
|
||||||
const existingMachines = ForceArray(machines).filter((machine) => {
|
|
||||||
return machine.tags[SERVICE] === name;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: Uuid(),
|
|
||||||
serviceName: name,
|
|
||||||
replicas: existingMachines.length ? existingMachines.length : 1
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
cb(null, scale);
|
const liveServices = machines.reduce((acc, { tags }) => {
|
||||||
};
|
return Object.assign(acc, {
|
||||||
|
[tags[SERVICE]]: 1
|
||||||
|
});
|
||||||
|
}, {});
|
||||||
|
|
||||||
this._listMachines(deploymentGroupName, handleMachinesList);
|
const allAndConfigServices = config.reduce((acc, { name }) => {
|
||||||
|
return Object.assign(acc, {
|
||||||
|
[name]: 1
|
||||||
|
});
|
||||||
|
}, liveServices);
|
||||||
|
|
||||||
|
const scale = Object.keys(allAndConfigServices).map((name) => {
|
||||||
|
const existingMachines = machines.filter((machine) => {
|
||||||
|
return machine.tags[SERVICE] === name;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: Uuid(),
|
||||||
|
serviceName: name,
|
||||||
|
replicas: existingMachines.length ? existingMachines.length : 1
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
cb(null, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
scale ({ serviceId, replicas }, cb) {
|
scale ({ serviceId, replicas }, cb) {
|
||||||
@ -1455,7 +1453,7 @@ class Data extends EventEmitter {
|
|||||||
|
|
||||||
console.log(`-> Service ${Util.inspect(query)} found ${Util.inspect(service)}`);
|
console.log(`-> Service ${Util.inspect(query)} found ${Util.inspect(service)}`);
|
||||||
|
|
||||||
const branches = service.branches.map((branch) => {
|
const branches = ForceArray(service.branches).map((branch) => {
|
||||||
return Object.assign({}, branch, {
|
return Object.assign({}, branch, {
|
||||||
instances: this._instancesFilter(branch.instances)
|
instances: this._instancesFilter(branch.instances)
|
||||||
});
|
});
|
||||||
@ -1519,7 +1517,7 @@ class Data extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cb(null, services.map((service) => {
|
return cb(null, services.map((service) => {
|
||||||
const branches = service.branches.map((branch) => {
|
const branches = ForceArray(service.branches).map((branch) => {
|
||||||
return Object.assign({}, branch, {
|
return Object.assign({}, branch, {
|
||||||
instances: this._instancesFilter(branch.instances)
|
instances: this._instancesFilter(branch.instances)
|
||||||
});
|
});
|
||||||
|
@ -13,9 +13,9 @@ const {
|
|||||||
NAMESPACE
|
NAMESPACE
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const namespace = NAMESPACE
|
const namespace = NAMESPACE ?
|
||||||
? `/${NAMESPACE}`
|
`/${NAMESPACE}` :
|
||||||
: '';
|
'';
|
||||||
|
|
||||||
const internals = {};
|
const internals = {};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user