Skip to content

Commit

Permalink
Update InitWorkspaceServer.java
Browse files Browse the repository at this point in the history
  • Loading branch information
bio-boris authored Feb 12, 2025
1 parent c35a6e7 commit d80abad
Showing 1 changed file with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private static WorkspaceInitResults buildWorkspace(
rep.reportInfo("MongoDB initialized.");

rep.reportInfo("Setting up BlobStore...");
final BlobStore bs = setupBlobStore(db, cfg);
final BlobStore bs = setupBlobStore(db, cfg, rep);
rep.reportInfo("BlobStore setup complete.");

rep.reportInfo("Checking TypeDelegation...");
Expand Down Expand Up @@ -537,38 +537,66 @@ private static AuthToken getToken(
}
}

private static BlobStore setupBlobStore(
final MongoDatabase db,
final KBaseWorkspaceConfig cfg)
throws WorkspaceInitException {

if (cfg.getBackendType().equals(BackendType.GridFS)) {
return new GridFSBlobStore(db);
}
if (cfg.getBackendType().equals(BackendType.S3)) {
try {
final S3ClientWithPresign cli = new S3ClientWithPresign(
cfg.getBackendURL(),
cfg.getBackendUser(),
cfg.getBackendToken(),
cfg.getBackendRegion(),
cfg.getBackendTrustAllCerts());
return new S3BlobStore(
db.getCollection(COL_S3_OBJECTS),
cli,
cfg.getBackendContainer());
} catch (URISyntaxException e) {
throw new WorkspaceInitException("S3 url is not a valid URI: " +
e.getMessage(), e);
} catch (BlobStoreCommunicationException e) {
throw new WorkspaceInitException("Error communicating with the blob store: " +
e.getMessage(), e);
} catch (IllegalArgumentException e) {
throw new WorkspaceInitException("Illegal S3 bucket name: " + e.getMessage(), e);
}
}
throw new WorkspaceInitException("Unknown backend type: " + cfg.getBackendType().name());
}
private static BlobStore setupBlobStore(
final MongoDatabase db,
final KBaseWorkspaceConfig cfg,
final InitReporter rep) // Added rep to track progress
throws WorkspaceInitException {

rep.reportInfo("Entering setupBlobStore...");

// Check what backend type is being used
rep.reportInfo("Backend type: " + cfg.getBackendType().name());

if (cfg.getBackendType().equals(BackendType.GridFS)) {
rep.reportInfo("Initializing GridFSBlobStore...");
BlobStore store = new GridFSBlobStore(db);
rep.reportInfo("GridFSBlobStore initialized successfully.");
return store;
}

if (cfg.getBackendType().equals(BackendType.S3)) {
rep.reportInfo("Initializing S3BlobStore...");
try {
rep.reportInfo("Creating S3 client with the following parameters:");
rep.reportInfo("Backend URL: " + cfg.getBackendURL());
rep.reportInfo("Backend User: " + cfg.getBackendUser());
rep.reportInfo("Backend Region: " + cfg.getBackendRegion());
rep.reportInfo("Trust All Certs: " + cfg.getBackendTrustAllCerts());

final S3ClientWithPresign cli = new S3ClientWithPresign(
cfg.getBackendURL(),
cfg.getBackendUser(),
cfg.getBackendToken(),
cfg.getBackendRegion(),
cfg.getBackendTrustAllCerts());

rep.reportInfo("S3 client created successfully.");

rep.reportInfo("Fetching collection: " + COL_S3_OBJECTS);
BlobStore store = new S3BlobStore(
db.getCollection(COL_S3_OBJECTS),
cli,
cfg.getBackendContainer());

rep.reportInfo("S3BlobStore initialized successfully.");
return store;
} catch (URISyntaxException e) {
rep.reportInfo("Error: Invalid S3 URL: " + e.getMessage());
throw new WorkspaceInitException("S3 url is not a valid URI: " + e.getMessage(), e);
} catch (BlobStoreCommunicationException e) {
rep.reportInfo("Error: BlobStore communication issue: " + e.getMessage());
throw new WorkspaceInitException("Error communicating with the blob store: " + e.getMessage(), e);
} catch (IllegalArgumentException e) {
rep.reportInfo("Error: Illegal S3 bucket name: " + e.getMessage());
throw new WorkspaceInitException("Illegal S3 bucket name: " + e.getMessage(), e);
}
}

rep.reportInfo("Error: Unknown backend type: " + cfg.getBackendType().name());
throw new WorkspaceInitException("Unknown backend type: " + cfg.getBackendType().name());
}


private static TempFilesManager initTempFilesManager(
final String tempDir,
Expand Down

0 comments on commit d80abad

Please sign in to comment.