|
1 | 1 | package com.skyflow.vault.controller; |
2 | 2 |
|
3 | | -import java.util.ArrayList; |
4 | | -import java.util.Collections; |
5 | | -import java.util.List; |
6 | | -import java.util.concurrent.CompletableFuture; |
7 | | -import java.util.concurrent.ExecutionException; |
8 | | -import java.util.concurrent.ExecutorService; |
9 | | -import java.util.concurrent.Executors; |
10 | | - |
11 | 3 | import com.google.gson.Gson; |
12 | 4 | import com.google.gson.GsonBuilder; |
13 | 5 | import com.skyflow.VaultClient; |
|
25 | 17 | import com.skyflow.utils.Utils; |
26 | 18 | import com.skyflow.utils.logger.LogUtil; |
27 | 19 | import com.skyflow.utils.validations.Validations; |
28 | | -import com.skyflow.vault.data.DetokenizeRequest; |
29 | | -import com.skyflow.vault.data.DetokenizeResponse; |
30 | | -import com.skyflow.vault.data.DetokenizeResponseObject; |
31 | | -import com.skyflow.vault.data.ErrorRecord; |
32 | | -import com.skyflow.vault.data.InsertRecord; |
33 | | -import com.skyflow.vault.data.InsertRequest; |
34 | | -import com.skyflow.vault.data.Success; |
35 | | - |
| 20 | +import com.skyflow.vault.data.*; |
36 | 21 | import io.github.cdimascio.dotenv.Dotenv; |
| 22 | +import io.github.cdimascio.dotenv.DotenvException; |
| 23 | + |
| 24 | +import java.util.ArrayList; |
| 25 | +import java.util.Collections; |
| 26 | +import java.util.List; |
| 27 | +import java.util.concurrent.CompletableFuture; |
| 28 | +import java.util.concurrent.ExecutionException; |
| 29 | +import java.util.concurrent.ExecutorService; |
| 30 | +import java.util.concurrent.Executors; |
37 | 31 |
|
38 | 32 | public final class VaultController extends VaultClient { |
39 | 33 | private static final Gson gson = new GsonBuilder().serializeNulls().create(); |
@@ -307,18 +301,31 @@ private InsertResponse insertBatch(List<InsertRecordData> batch, String tableNam |
307 | 301 | .records(batch) |
308 | 302 | .upsert(upsert); |
309 | 303 | // .build(); |
310 | | - if(tableName != null && !tableName.isEmpty()){ |
| 304 | + if (tableName != null && !tableName.isEmpty()) { |
311 | 305 | req.tableName(tableName); |
312 | 306 | } |
313 | | - com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest request = req.build(); |
| 307 | + com.skyflow.generated.rest.resources.recordservice.requests.InsertRequest request = req.build(); |
314 | 308 | return this.getRecordsApi().insert(request); |
315 | 309 | } |
316 | 310 |
|
317 | 311 | private void configureInsertConcurrencyAndBatchSize(int totalRequests) { |
318 | 312 | try { |
319 | | - Dotenv dotenv = Dotenv.load(); |
320 | | - String userProvidedBatchSize = dotenv.get("INSERT_BATCH_SIZE"); |
321 | | - String userProvidedConcurrencyLimit = dotenv.get("INSERT_CONCURRENCY_LIMIT"); |
| 313 | + String userProvidedBatchSize = System.getenv("INSERT_BATCH_SIZE"); |
| 314 | + String userProvidedConcurrencyLimit = System.getenv("INSERT_CONCURRENCY_LIMIT"); |
| 315 | + |
| 316 | + Dotenv dotenv = null; |
| 317 | + try { |
| 318 | + dotenv = Dotenv.load(); |
| 319 | + } catch (DotenvException ignored) { |
| 320 | + // ignore the case if .env file is not found |
| 321 | + } |
| 322 | + |
| 323 | + if (userProvidedBatchSize == null && dotenv != null) { |
| 324 | + userProvidedBatchSize = dotenv.get("INSERT_BATCH_SIZE"); |
| 325 | + } |
| 326 | + if (userProvidedConcurrencyLimit == null && dotenv != null) { |
| 327 | + userProvidedConcurrencyLimit = dotenv.get("INSERT_CONCURRENCY_LIMIT"); |
| 328 | + } |
322 | 329 |
|
323 | 330 | if (userProvidedBatchSize != null) { |
324 | 331 | try { |
@@ -372,9 +379,22 @@ private void configureInsertConcurrencyAndBatchSize(int totalRequests) { |
372 | 379 |
|
373 | 380 | private void configureDetokenizeConcurrencyAndBatchSize(int totalRequests) { |
374 | 381 | try { |
375 | | - Dotenv dotenv = Dotenv.load(); |
376 | | - String userProvidedBatchSize = dotenv.get("DETOKENIZE_BATCH_SIZE"); |
377 | | - String userProvidedConcurrencyLimit = dotenv.get("DETOKENIZE_CONCURRENCY_LIMIT"); |
| 382 | + String userProvidedBatchSize = System.getenv("DETOKENIZE_BATCH_SIZE"); |
| 383 | + String userProvidedConcurrencyLimit = System.getenv("DETOKENIZE_CONCURRENCY_LIMIT"); |
| 384 | + |
| 385 | + Dotenv dotenv = null; |
| 386 | + try { |
| 387 | + dotenv = Dotenv.load(); |
| 388 | + } catch (DotenvException ignored) { |
| 389 | + // ignore the case if .env file is not found |
| 390 | + } |
| 391 | + |
| 392 | + if (userProvidedBatchSize == null && dotenv != null) { |
| 393 | + userProvidedBatchSize = dotenv.get("DETOKENIZE_BATCH_SIZE"); |
| 394 | + } |
| 395 | + if (userProvidedConcurrencyLimit == null && dotenv != null) { |
| 396 | + userProvidedConcurrencyLimit = dotenv.get("DETOKENIZE_CONCURRENCY_LIMIT"); |
| 397 | + } |
378 | 398 |
|
379 | 399 | if (userProvidedBatchSize != null) { |
380 | 400 | try { |
|
0 commit comments