Skip to content

Commit cdb0c08

Browse files
committed
renaming
Signed-off-by: Thang PHAM <[email protected]>
1 parent 5e0dd7b commit cdb0c08

File tree

7 files changed

+69
-66
lines changed

7 files changed

+69
-66
lines changed

src/main/java/org/gridsuite/computation/s3/S3Service.java renamed to src/main/java/org/gridsuite/computation/s3/ComputationS3Service.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
2424
*/
25-
public class S3Service {
25+
public class ComputationS3Service {
2626

2727
public static final String S3_DELIMITER = "/";
2828
public static final String S3_SERVICE_NOT_AVAILABLE_MESSAGE = "S3 service not available";
@@ -33,7 +33,7 @@ public class S3Service {
3333

3434
private final String bucketName;
3535

36-
public S3Service(S3Client s3Client, String bucketName) {
36+
public ComputationS3Service(S3Client s3Client, String bucketName) {
3737
this.s3Client = s3Client;
3838
this.bucketName = bucketName;
3939
}

src/main/java/org/gridsuite/computation/s3/S3AutoConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
2020
*/
2121
@AutoConfiguration
22-
@ConditionalOnProperty(name = "spring.cloud.aws.s3.enabled", havingValue = "true")
22+
@ConditionalOnProperty(name = "computation.s3.enabled", havingValue = "true")
2323
public class S3AutoConfiguration {
2424
private static final Logger LOGGER = LoggerFactory.getLogger(S3AutoConfiguration.class);
25-
@Value("${spring.cloud.aws.bucket:my-bucket}")
25+
@Value("${spring.cloud.aws.bucket:ws-bucket}")
2626
private String bucketName;
2727

2828
@Bean
29-
public S3Service s3Service(S3Client s3Client) {
30-
LOGGER.info("Configuring S3Service with bucket: {}", bucketName);
31-
return new S3Service(s3Client, bucketName);
29+
public ComputationS3Service s3Service(S3Client s3Client) {
30+
LOGGER.info("Configuring ComputationS3Service with bucket: {}", bucketName);
31+
return new ComputationS3Service(s3Client, bucketName);
3232
}
3333
}

src/main/java/org/gridsuite/computation/service/AbstractComputationService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import com.fasterxml.jackson.databind.ObjectMapper;
1010
import com.powsybl.commons.PowsyblException;
1111
import lombok.Getter;
12+
import org.gridsuite.computation.s3.ComputationS3Service;
1213
import org.gridsuite.computation.s3.S3InputStreamInfos;
13-
import org.gridsuite.computation.s3.S3Service;
1414
import org.springframework.core.io.InputStreamResource;
1515
import org.springframework.core.io.Resource;
1616
import org.springframework.http.ContentDisposition;
@@ -25,7 +25,7 @@
2525
import java.util.Objects;
2626
import java.util.UUID;
2727

28-
import static org.gridsuite.computation.s3.S3Service.S3_SERVICE_NOT_AVAILABLE_MESSAGE;
28+
import static org.gridsuite.computation.s3.ComputationS3Service.S3_SERVICE_NOT_AVAILABLE_MESSAGE;
2929

3030
/**
3131
* @author Mathieu Deharbe <mathieu.deharbe at rte-france.com>
@@ -39,7 +39,7 @@ public abstract class AbstractComputationService<C extends AbstractComputationRu
3939
protected NotificationService notificationService;
4040
protected UuidGeneratorService uuidGeneratorService;
4141
protected T resultService;
42-
protected S3Service s3Service;
42+
protected ComputationS3Service computationS3Service;
4343
@Getter
4444
private final String defaultProvider;
4545

@@ -53,7 +53,7 @@ protected AbstractComputationService(NotificationService notificationService,
5353

5454
protected AbstractComputationService(NotificationService notificationService,
5555
T resultService,
56-
S3Service s3Service,
56+
ComputationS3Service computationS3Service,
5757
ObjectMapper objectMapper,
5858
UuidGeneratorService uuidGeneratorService,
5959
String defaultProvider) {
@@ -62,7 +62,7 @@ protected AbstractComputationService(NotificationService notificationService,
6262
this.uuidGeneratorService = Objects.requireNonNull(uuidGeneratorService);
6363
this.defaultProvider = defaultProvider;
6464
this.resultService = Objects.requireNonNull(resultService);
65-
this.s3Service = s3Service;
65+
this.computationS3Service = computationS3Service;
6666
}
6767

6868
public void stop(UUID resultUuid, String receiver) {
@@ -102,7 +102,7 @@ public S getStatus(UUID resultUuid) {
102102
}
103103

104104
public ResponseEntity<Resource> downloadDebugFile(UUID resultUuid) {
105-
if (s3Service == null) {
105+
if (computationS3Service == null) {
106106
throw new PowsyblException(S3_SERVICE_NOT_AVAILABLE_MESSAGE);
107107
}
108108

@@ -112,7 +112,7 @@ public ResponseEntity<Resource> downloadDebugFile(UUID resultUuid) {
112112
}
113113

114114
try {
115-
S3InputStreamInfos s3InputStreamInfos = s3Service.downloadFile(s3Key);
115+
S3InputStreamInfos s3InputStreamInfos = computationS3Service.downloadFile(s3Key);
116116
InputStream inputStream = s3InputStreamInfos.getInputStream();
117117
String fileName = s3InputStreamInfos.getFileName();
118118
Long fileLength = s3InputStreamInfos.getFileLength();

src/main/java/org/gridsuite/computation/service/AbstractWorkerService.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import com.powsybl.network.store.client.NetworkStoreService;
1616
import com.powsybl.network.store.client.PreloadingStrategy;
1717
import com.powsybl.ws.commons.ZipUtils;
18-
import org.gridsuite.computation.s3.S3Service;
1918
import org.apache.commons.lang3.StringUtils;
2019
import org.gridsuite.computation.ComputationException;
20+
import org.gridsuite.computation.s3.ComputationS3Service;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.springframework.beans.factory.annotation.Value;
@@ -33,15 +33,18 @@
3333
import java.util.HashMap;
3434
import java.util.Map;
3535
import java.util.UUID;
36-
import java.util.concurrent.*;
36+
import java.util.concurrent.CancellationException;
37+
import java.util.concurrent.CompletableFuture;
38+
import java.util.concurrent.ConcurrentHashMap;
39+
import java.util.concurrent.TimeUnit;
3740
import java.util.concurrent.atomic.AtomicReference;
3841
import java.util.concurrent.locks.Lock;
3942
import java.util.concurrent.locks.ReentrantLock;
4043
import java.util.function.Consumer;
4144

42-
import static com.powsybl.ws.commons.computation.service.NotificationService.HEADER_ERROR_MESSAGE;
43-
import static com.powsybl.ws.commons.s3.S3Service.S3_DELIMITER;
44-
import static com.powsybl.ws.commons.s3.S3Service.S3_SERVICE_NOT_AVAILABLE_MESSAGE;
45+
import static org.gridsuite.computation.s3.ComputationS3Service.S3_DELIMITER;
46+
import static org.gridsuite.computation.s3.ComputationS3Service.S3_SERVICE_NOT_AVAILABLE_MESSAGE;
47+
import static org.gridsuite.computation.service.NotificationService.HEADER_ERROR_MESSAGE;
4548

4649
/**
4750
* @author Mathieu Deharbe <mathieu.deharbe at rte-france.com>
@@ -53,8 +56,8 @@
5356
public abstract class AbstractWorkerService<R, C extends AbstractComputationRunContext<P>, P, S extends AbstractComputationResultService<?>> {
5457
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractWorkerService.class);
5558

56-
@Value("${debug-subpath:debug}")
57-
private String s3DebugSubpath;
59+
@Value("${powsybl-ws.s3.subpath.prefix:}${debug-subpath:debug}")
60+
private String debugRootPath;
5861

5962
protected final Lock lockRunAndCancel = new ReentrantLock();
6063
protected final ObjectMapper objectMapper;
@@ -67,7 +70,7 @@ public abstract class AbstractWorkerService<R, C extends AbstractComputationRunC
6770
protected final Map<UUID, CancelContext> cancelComputationRequests = new ConcurrentHashMap<>();
6871
protected final S resultService;
6972

70-
protected final S3Service s3Service;
73+
protected final ComputationS3Service computationS3Service;
7174

7275
protected AbstractWorkerService(NetworkStoreService networkStoreService,
7376
NotificationService notificationService,
@@ -83,15 +86,15 @@ protected AbstractWorkerService(NetworkStoreService networkStoreService,
8386
NotificationService notificationService,
8487
ReportService reportService,
8588
S resultService,
86-
S3Service s3Service,
89+
ComputationS3Service computationS3Service,
8790
ExecutionService executionService,
8891
AbstractComputationObserver<R, P> observer,
8992
ObjectMapper objectMapper) {
9093
this.networkStoreService = networkStoreService;
9194
this.notificationService = notificationService;
9295
this.reportService = reportService;
9396
this.resultService = resultService;
94-
this.s3Service = s3Service;
97+
this.computationS3Service = computationS3Service;
9598
this.executionService = executionService;
9699
this.observer = observer;
97100
this.objectMapper = objectMapper;
@@ -197,7 +200,7 @@ protected void clean(AbstractResultContext<C> resultContext) {
197200

198201
// run in debug mode, clean debug dir
199202
C runContext = resultContext.getRunContext();
200-
if (Boolean.TRUE.equals(runContext.getDebug()) && s3Service != null) {
203+
if (Boolean.TRUE.equals(runContext.getDebug()) && computationS3Service != null) {
201204
removeDirectory(runContext.getDebugDir());
202205
}
203206
}
@@ -207,7 +210,7 @@ protected void clean(AbstractResultContext<C> resultContext) {
207210
* @param resultContext The context of the computation
208211
*/
209212
protected void processDebug(AbstractResultContext<C> resultContext) {
210-
if (s3Service == null) {
213+
if (computationS3Service == null) {
211214
sendDebugMessage(resultContext, S3_SERVICE_NOT_AVAILABLE_MESSAGE);
212215
return;
213216
}
@@ -221,13 +224,13 @@ protected void processDebug(AbstractResultContext<C> resultContext) {
221224
try {
222225
// zip the working directory
223226
ZipUtils.zip(debugDir, debugFilePath);
224-
String s3Key = s3DebugSubpath + S3_DELIMITER + fileName;
227+
String s3Key = debugRootPath + S3_DELIMITER + fileName;
225228

226229
// insert debug file path into db
227230
resultService.saveDebugFileLocation(resultContext.getResultUuid(), s3Key);
228231

229232
// upload zip file to s3 storage
230-
s3Service.uploadFile(debugFilePath, s3Key, fileName, 30);
233+
computationS3Service.uploadFile(debugFilePath, s3Key, fileName, 30);
231234

232235
// notify to study-server
233236
sendDebugMessage(resultContext, null);
@@ -287,7 +290,7 @@ protected void preRun(C runContext) {
287290
LOGGER.info("Run {} computation...", getComputationType());
288291

289292
// run in debug mode, create debug dir
290-
if (Boolean.TRUE.equals(runContext.getDebug()) && s3Service != null) {
293+
if (Boolean.TRUE.equals(runContext.getDebug()) && computationS3Service != null) {
291294
runContext.setDebugDir(createDebugDir());
292295
}
293296
}

src/test/java/org/gridsuite/computation/ComputationTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import lombok.extern.slf4j.Slf4j;
2727
import org.assertj.core.api.WithAssertions;
2828
import org.gridsuite.computation.dto.ReportInfos;
29+
import org.gridsuite.computation.s3.ComputationS3Service;
2930
import org.gridsuite.computation.s3.S3InputStreamInfos;
30-
import org.gridsuite.computation.s3.S3Service;
3131
import org.gridsuite.computation.service.*;
3232
import org.junit.jupiter.api.AfterEach;
3333
import org.junit.jupiter.api.BeforeEach;
@@ -60,8 +60,8 @@
6060
import java.util.concurrent.CompletableFuture;
6161
import java.util.concurrent.ForkJoinPool;
6262

63-
import static org.gridsuite.computation.s3.S3Service.S3_DELIMITER;
64-
import static org.gridsuite.computation.s3.S3Service.S3_SERVICE_NOT_AVAILABLE_MESSAGE;
63+
import static org.gridsuite.computation.s3.ComputationS3Service.S3_DELIMITER;
64+
import static org.gridsuite.computation.s3.ComputationS3Service.S3_SERVICE_NOT_AVAILABLE_MESSAGE;
6565
import static org.gridsuite.computation.service.NotificationService.*;
6666
import static org.junit.jupiter.api.Assertions.*;
6767
import static org.mockito.ArgumentMatchers.*;
@@ -97,7 +97,7 @@ class ComputationTest implements WithAssertions {
9797
@Mock
9898
private Network network;
9999
@Mock
100-
private S3Service s3Service;
100+
private ComputationS3Service computationS3Service;
101101

102102
private enum MockComputationStatus {
103103
NOT_DONE,
@@ -164,8 +164,8 @@ protected MockComputationResultContext(UUID resultUuid, MockComputationRunContex
164164
}
165165

166166
private static class MockComputationService extends AbstractComputationService<MockComputationRunContext, MockComputationResultService, MockComputationStatus> {
167-
protected MockComputationService(NotificationService notificationService, MockComputationResultService resultService, S3Service s3Service, ObjectMapper objectMapper, UuidGeneratorService uuidGeneratorService, String defaultProvider) {
168-
super(notificationService, resultService, s3Service, objectMapper, uuidGeneratorService, defaultProvider);
167+
protected MockComputationService(NotificationService notificationService, MockComputationResultService resultService, ComputationS3Service computationS3Service, ObjectMapper objectMapper, UuidGeneratorService uuidGeneratorService, String defaultProvider) {
168+
super(notificationService, resultService, computationS3Service, objectMapper, uuidGeneratorService, defaultProvider);
169169
}
170170

171171
@Override
@@ -187,8 +187,8 @@ private enum ComputationResultWanted {
187187
}
188188

189189
private static class MockComputationWorkerService extends AbstractWorkerService<Object, MockComputationRunContext, Object, MockComputationResultService> {
190-
protected MockComputationWorkerService(NetworkStoreService networkStoreService, NotificationService notificationService, ReportService reportService, MockComputationResultService resultService, S3Service s3Service, ExecutionService executionService, AbstractComputationObserver<Object, Object> observer, ObjectMapper objectMapper) {
191-
super(networkStoreService, notificationService, reportService, resultService, s3Service, executionService, observer, objectMapper);
190+
protected MockComputationWorkerService(NetworkStoreService networkStoreService, NotificationService notificationService, ReportService reportService, MockComputationResultService resultService, ComputationS3Service computationS3Service, ExecutionService executionService, AbstractComputationObserver<Object, Object> observer, ObjectMapper objectMapper) {
191+
super(networkStoreService, notificationService, reportService, resultService, computationS3Service, executionService, observer, objectMapper);
192192
}
193193

194194
@Override
@@ -257,12 +257,12 @@ void init() throws IOException {
257257
notificationService,
258258
reportService,
259259
resultService,
260-
s3Service,
260+
computationS3Service,
261261
executionService,
262262
new MockComputationObserver(ObservationRegistry.create(), new SimpleMeterRegistry()),
263263
objectMapper
264264
);
265-
computationService = new MockComputationService(notificationService, resultService, s3Service, objectMapper, uuidGeneratorService, provider);
265+
computationService = new MockComputationService(notificationService, resultService, computationS3Service, objectMapper, uuidGeneratorService, provider);
266266

267267
MessageBuilder<String> builder = MessageBuilder
268268
.withPayload("")
@@ -392,7 +392,7 @@ void testProcessDebugWithS3Service() throws IOException {
392392

393393
// Verify interactions
394394
verify(resultService).saveDebugFileLocation(eq(RESULT_UUID), anyString());
395-
verify(s3Service).uploadFile(any(Path.class), anyString(), anyString(), eq(30));
395+
verify(computationS3Service).uploadFile(any(Path.class), anyString(), anyString(), eq(30));
396396
verify(notificationService.getPublisher(), times(1 /* for result message */))
397397
.send(eq("publishResult-out-0"), isA(Message.class));
398398
verify(notificationService.getPublisher(), times(1 /* for debug message */))
@@ -411,7 +411,7 @@ void testConsumeRunWithoutDebug() {
411411
workerService.consumeRun().accept(message);
412412

413413
// Verify interactions
414-
verifyNoInteractions(s3Service, resultService);
414+
verifyNoInteractions(computationS3Service, resultService);
415415
verify(notificationService.getPublisher(), times(1 /* only result */))
416416
.send(eq("publishResult-out-0"), isA(Message.class));
417417
verify(notificationService.getPublisher(), times(0 /* no debug */))
@@ -420,7 +420,7 @@ void testConsumeRunWithoutDebug() {
420420

421421
@Test
422422
void testProcessDebugWithoutS3Service() {
423-
// Setup worker service without S3Service
423+
// Setup worker service without ComputationS3Service
424424
workerService = new MockComputationWorkerService(
425425
networkStoreService,
426426
notificationService,
@@ -441,7 +441,7 @@ void testProcessDebugWithoutS3Service() {
441441
// Verify
442442
verify(notificationService.getPublisher()).send(eq("publishDebug-out-0"), argThat((Message<String> msg) ->
443443
msg.getHeaders().get(HEADER_ERROR_MESSAGE).equals(S3_SERVICE_NOT_AVAILABLE_MESSAGE)));
444-
verifyNoInteractions(s3Service, resultService);
444+
verifyNoInteractions(computationS3Service, resultService);
445445
}
446446

447447
@Test
@@ -459,7 +459,7 @@ void testProcessDebugWithIOException() throws IOException {
459459
workerService.consumeRun().accept(message);
460460

461461
// Verify interactions
462-
verify(s3Service, never()).uploadFile(any(), any(), any(), anyInt());
462+
verify(computationS3Service, never()).uploadFile(any(), any(), any(), anyInt());
463463
verify(resultService, never()).saveDebugFileLocation(any(), any());
464464
verify(notificationService.getPublisher()).send(eq("publishDebug-out-0"), argThat((Message<String> msg) ->
465465
msg.getHeaders().get(HEADER_ERROR_MESSAGE).equals("Zip error")));
@@ -478,7 +478,7 @@ void testDownloadDebugFileSuccess() throws IOException {
478478
.fileLength(fileLength)
479479
.build();
480480
when(resultService.findDebugFileLocation(RESULT_UUID)).thenReturn(S3_KEY);
481-
when(s3Service.downloadFile(S3_KEY)).thenReturn(s3InputStreamInfos);
481+
when(computationS3Service.downloadFile(S3_KEY)).thenReturn(s3InputStreamInfos);
482482

483483
// Execute
484484
ResponseEntity<?> response = computationService.downloadDebugFile(RESULT_UUID);
@@ -489,7 +489,7 @@ void testDownloadDebugFileSuccess() throws IOException {
489489
assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_OCTET_STREAM);
490490
assertThat(response.getHeaders().getContentLength()).isEqualTo(fileLength);
491491
assertThat(response.getHeaders().get(HttpHeaders.CONTENT_DISPOSITION)).contains("attachment; filename=\"" + fileName + "\"");
492-
verify(s3Service).downloadFile(S3_KEY);
492+
verify(computationS3Service).downloadFile(S3_KEY);
493493
}
494494

495495
@Test
@@ -499,7 +499,7 @@ void testDownloadDebugFileS3NotAvailable() throws IOException {
499499

500500
// Execute & Check
501501
assertThrows(PowsyblException.class, () -> computationService.downloadDebugFile(RESULT_UUID), "S3 service not available");
502-
verify(s3Service, never()).downloadFile(any());
502+
verify(computationS3Service, never()).downloadFile(any());
503503
}
504504

505505
@Test
@@ -512,21 +512,21 @@ void testDownloadDebugFileNotFound() throws IOException {
512512

513513
// Check
514514
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
515-
verify(s3Service, never()).downloadFile(any());
515+
verify(computationS3Service, never()).downloadFile(any());
516516
}
517517

518518
@Test
519519
void testDownloadDebugFileIOException() throws IOException {
520520
// Setup
521521
when(resultService.findDebugFileLocation(RESULT_UUID)).thenReturn(S3_KEY);
522-
when(s3Service.downloadFile(S3_KEY)).thenThrow(new IOException("S3 error"));
522+
when(computationS3Service.downloadFile(S3_KEY)).thenThrow(new IOException("S3 error"));
523523

524524
// Act
525525
ResponseEntity<?> response = computationService.downloadDebugFile(RESULT_UUID);
526526

527527
// Assert
528528
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
529-
verify(s3Service).downloadFile(S3_KEY);
529+
verify(computationS3Service).downloadFile(S3_KEY);
530530
}
531531

532532
}

0 commit comments

Comments
 (0)