diff --git a/components/ws-manager-bridge/src/cluster-service-server.ts b/components/ws-manager-bridge/src/cluster-service-server.ts index 0e71217c55a1bf..d08c40b68a8172 100644 --- a/components/ws-manager-bridge/src/cluster-service-server.ts +++ b/components/ws-manager-bridge/src/cluster-service-server.ts @@ -70,21 +70,24 @@ export class ClusterService implements IClusterServiceServer { try { // check if the name or URL are already registered/in use const req = call.request.toObject(); - await Promise.all([ - async () => { - const oldCluster = await this.clusterDB.findByName(req.name); - if (!oldCluster) { - throw new GRPCError(grpc.status.ALREADY_EXISTS, `a WorkspaceCluster with name ${req.name} already exists in the DB`); - } - }, - async () => { - const oldCluster = await this.clusterDB.findFiltered({ url: req.url }); - if (!oldCluster) { - throw new GRPCError(grpc.status.ALREADY_EXISTS, `a WorkspaceCluster with url ${req.url} already exists in the DB`); - } - } + + const clusterByNamePromise = this.clusterDB.findByName(req.name); + const clusterByUrlPromise = this.clusterDB.findFiltered({ url: req.url }) + + const [clusterByName, clusterByUrl] = await Promise.all([ + clusterByNamePromise, + clusterByUrlPromise ]); + if (!!clusterByName) { + throw new GRPCError(grpc.status.ALREADY_EXISTS, `a WorkspaceCluster with name ${req.name} already exists in the DB`); + } + if (!!clusterByUrl) { + if (clusterByUrl.length > 0) { + throw new GRPCError(grpc.status.ALREADY_EXISTS, `a WorkspaceCluster with url ${req.url} already exists in the DB`); + } + } + // store the ws-manager into the database let perfereability = Preferability.NONE; let govern = false; @@ -154,7 +157,7 @@ export class ClusterService implements IClusterServiceServer { const req = call.request.toObject(); const cluster = await this.clusterDB.findByName(req.name); if (!cluster) { - throw new GRPCError(grpc.status.ALREADY_EXISTS, `a WorkspaceCluster with name ${req.name} already exists in the DB!`); + throw new GRPCError(grpc.status.NOT_FOUND, `a WorkspaceCluster with name ${req.name} does not exist in the DB!`); } if (call.request.hasMaxScore()) { @@ -294,8 +297,10 @@ function convertToGRPC(ws: WorkspaceClusterWoTLS): ClusterStatus { break; case "has-user-level": constraint.setHasUserLevel(c.level); + break; case "has-more-resources": constraint.setHasMoreResources(true); + break; default: return; } diff --git a/dev/gpctl/.vscode/launch.json b/dev/gpctl/.vscode/launch.json new file mode 100644 index 00000000000000..32b38fadb04674 --- /dev/null +++ b/dev/gpctl/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "gpctl", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${fileWorkspaceFolder}", + "args": [ + "clusters", + "list", + ] + }, + ] +} \ No newline at end of file