@@ -70,21 +70,24 @@ export class ClusterService implements IClusterServiceServer {
70
70
try {
71
71
// check if the name or URL are already registered/in use
72
72
const req = call . request . toObject ( ) ;
73
- await Promise . all ( [
74
- async ( ) => {
75
- const oldCluster = await this . clusterDB . findByName ( req . name ) ;
76
- if ( ! oldCluster ) {
77
- throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with name ${ req . name } already exists in the DB` ) ;
78
- }
79
- } ,
80
- async ( ) => {
81
- const oldCluster = await this . clusterDB . findFiltered ( { url : req . url } ) ;
82
- if ( ! oldCluster ) {
83
- throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with url ${ req . url } already exists in the DB` ) ;
84
- }
85
- }
73
+
74
+ const clusterByNamePromise = this . clusterDB . findByName ( req . name ) ;
75
+ const clusterByUrlPromise = this . clusterDB . findFiltered ( { url : req . url } )
76
+
77
+ const [ clusterByName , clusterByUrl ] = await Promise . all ( [
78
+ clusterByNamePromise ,
79
+ clusterByUrlPromise
86
80
] ) ;
87
81
82
+ if ( ! ! clusterByName ) {
83
+ throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with name ${ req . name } already exists in the DB` ) ;
84
+ }
85
+ if ( ! ! clusterByUrl ) {
86
+ if ( clusterByUrl . length > 0 ) {
87
+ throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with url ${ req . url } already exists in the DB` ) ;
88
+ }
89
+ }
90
+
88
91
// store the ws-manager into the database
89
92
let perfereability = Preferability . NONE ;
90
93
let govern = false ;
@@ -154,7 +157,7 @@ export class ClusterService implements IClusterServiceServer {
154
157
const req = call . request . toObject ( ) ;
155
158
const cluster = await this . clusterDB . findByName ( req . name ) ;
156
159
if ( ! cluster ) {
157
- throw new GRPCError ( grpc . status . ALREADY_EXISTS , `a WorkspaceCluster with name ${ req . name } already exists in the DB!` ) ;
160
+ throw new GRPCError ( grpc . status . NOT_FOUND , `a WorkspaceCluster with name ${ req . name } does not exist in the DB!` ) ;
158
161
}
159
162
160
163
if ( call . request . hasMaxScore ( ) ) {
@@ -258,8 +261,6 @@ export class ClusterService implements IClusterServiceServer {
258
261
response . addStatus ( clusterStatus ) ;
259
262
}
260
263
261
- log . info ( "response status for clusters.list" , response . getStatusList ( ) )
262
-
263
264
callback ( null , response ) ;
264
265
} catch ( err ) {
265
266
callback ( mapToGRPCError ( err ) , null ) ;
0 commit comments