Skip to content

[ws-manager-bridge] fix error handling for register & update, show all admission-constraints for list #8330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions components/ws-manager-bridge/src/cluster-service-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 19 additions & 0 deletions dev/gpctl/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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",
]
},
]
}