From 35669400b685252cdf130659872f1f822f547cf0 Mon Sep 17 00:00:00 2001 From: Kyle Brennan Date: Thu, 17 Feb 2022 21:04:39 +0000 Subject: [PATCH 1/3] [gpctl] add debug config --- dev/gpctl/.vscode/launch.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 dev/gpctl/.vscode/launch.json 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 From 4b87fa1e37ab08936241fce1d1b7e62e34db89af Mon Sep 17 00:00:00 2001 From: Kyle Brennan Date: Sat, 19 Feb 2022 20:35:06 +0000 Subject: [PATCH 2/3] [ws-manager-bridge] include has-more-resources and has-user-level on cluster list --- components/ws-manager-bridge/src/cluster-service-server.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/ws-manager-bridge/src/cluster-service-server.ts b/components/ws-manager-bridge/src/cluster-service-server.ts index 0e71217c55a1bf..89d439559391d6 100644 --- a/components/ws-manager-bridge/src/cluster-service-server.ts +++ b/components/ws-manager-bridge/src/cluster-service-server.ts @@ -258,6 +258,8 @@ export class ClusterService implements IClusterServiceServer { response.addStatus(clusterStatus); } + log.info("response status for clusters.list", response.getStatusList()) + callback(null, response); } catch (err) { callback(mapToGRPCError(err), null); @@ -294,8 +296,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; } From 5031e01c4badf5ca26b65afcaf88447226a3bfc9 Mon Sep 17 00:00:00 2001 From: Kyle Brennan Date: Sat, 19 Feb 2022 21:10:10 +0000 Subject: [PATCH 3/3] [ws-manager-bridge] improve error handling for workspace cluster registration and update Prevent duplicate workspace cluster registration & improve error message for update when workspace cluster doesn't exist --- .../src/cluster-service-server.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/components/ws-manager-bridge/src/cluster-service-server.ts b/components/ws-manager-bridge/src/cluster-service-server.ts index 89d439559391d6..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()) { @@ -258,8 +261,6 @@ export class ClusterService implements IClusterServiceServer { response.addStatus(clusterStatus); } - log.info("response status for clusters.list", response.getStatusList()) - callback(null, response); } catch (err) { callback(mapToGRPCError(err), null);