Skip to content

Commit

Permalink
local run dbReader from GCS
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMunin committed Dec 13, 2024
1 parent 5a11d49 commit e23fb55
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import com.maxmind.geoip2.DatabaseReader;
Expand All @@ -11,8 +10,6 @@

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
Expand Down Expand Up @@ -49,16 +46,6 @@ public void initialize(Promise<Void> initializePromise) {
}

databaseReaderRef.set(new DatabaseReader.Builder(databasePath.toFile()).build());

System.out.println(
"DatabaseReaderFactory/initialize: \n" +
" gcsBucketName: " + gcsBucketName + "\n" +
" geoLiteCountryPath: " + geoLiteCountryPath + "\n" +
" blob: " + blob + "\n" +
" databasePath: " + databasePath + "\n" +
" gcsBucketName: " + gcsBucketName
);

} catch (IOException e) {
throw new PreBidException("Failed to initialize DatabaseReader from URL", e);
}
Expand All @@ -67,9 +54,9 @@ public void initialize(Promise<Void> initializePromise) {
.onComplete(initializePromise);
}

private Blob getBlob(String blobName) {
private Blob getBlob(String geoLiteCountryPath) {
return Optional.ofNullable(storage.get(gcsBucketName))
.map(bucket -> bucket.get(blobName))
.map(bucket -> bucket.get(geoLiteCountryPath))
.orElseThrow(() -> new PreBidException("Bucket not found: " + gcsBucketName));
}

Expand Down

0 comments on commit e23fb55

Please sign in to comment.