Skip to content

Commit e3484f7

Browse files
committed
[GRD-3891] organize monitor-server services
1 parent 2e3181e commit e3484f7

18 files changed

Lines changed: 86 additions & 68 deletions

monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/MonitorController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.gridsuite.monitor.commons.SecurityAnalysisConfig;
1717
import org.gridsuite.monitor.server.dto.ProcessExecution;
1818
import org.gridsuite.monitor.server.dto.ReportPage;
19-
import org.gridsuite.monitor.server.services.MonitorService;
19+
import org.gridsuite.monitor.server.services.internal.MonitorService;
2020
import org.springframework.http.ResponseEntity;
2121
import org.springframework.web.bind.annotation.*;
2222

monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisResultProvider.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/external/adapter/SecurityAnalysisResultProvider.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.external.adapter;
88

99
import org.gridsuite.monitor.commons.ResultType;
10+
import org.gridsuite.monitor.server.services.internal.ResultProvider;
11+
import org.gridsuite.monitor.server.services.external.client.SecurityAnalysisRestClient;
1012
import org.springframework.stereotype.Service;
1113

1214
import java.util.UUID;
@@ -16,10 +18,10 @@
1618
*/
1719
@Service
1820
public class SecurityAnalysisResultProvider implements ResultProvider {
19-
private final SecurityAnalysisService securityAnalysisService;
21+
private final SecurityAnalysisRestClient securityAnalysisRestClient;
2022

21-
public SecurityAnalysisResultProvider(SecurityAnalysisService securityAnalysisService) {
22-
this.securityAnalysisService = securityAnalysisService;
23+
public SecurityAnalysisResultProvider(SecurityAnalysisRestClient securityAnalysisRestClient) {
24+
this.securityAnalysisRestClient = securityAnalysisRestClient;
2325
}
2426

2527
@Override
@@ -29,11 +31,11 @@ public ResultType getType() {
2931

3032
@Override
3133
public String getResult(UUID resultId) {
32-
return securityAnalysisService.getResult(resultId);
34+
return securityAnalysisRestClient.getResult(resultId);
3335
}
3436

3537
@Override
3638
public void deleteResult(UUID resultId) {
37-
securityAnalysisService.deleteResult(resultId);
39+
securityAnalysisRestClient.deleteResult(resultId);
3840
}
3941
}

monitor-server/src/main/java/org/gridsuite/monitor/server/services/ReportService.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/external/client/ReportRestClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.external.client;
88

99
import org.gridsuite.monitor.server.dto.ReportPage;
1010
import org.springframework.beans.factory.annotation.Value;
@@ -24,7 +24,7 @@
2424
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
2525
*/
2626
@Service
27-
public class ReportService {
27+
public class ReportRestClient {
2828
private static final String REPORT_API_VERSION = "v1";
2929

3030
private static final String DELIMITER = "/";
@@ -33,8 +33,8 @@ public class ReportService {
3333

3434
private final RestTemplate restTemplate;
3535

36-
public ReportService(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri,
37-
RestTemplateBuilder restTemplateBuilder) {
36+
public ReportRestClient(@Value("${gridsuite.services.report-server.base-uri:http://report-server/}") String reportServerBaseUri,
37+
RestTemplateBuilder restTemplateBuilder) {
3838
this.reportServerBaseUri = reportServerBaseUri;
3939
this.restTemplate = restTemplateBuilder.build();
4040
}

monitor-server/src/main/java/org/gridsuite/monitor/server/services/SecurityAnalysisService.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/external/client/SecurityAnalysisRestClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.external.client;
88

99
import lombok.Setter;
1010
import org.slf4j.Logger;
@@ -23,8 +23,8 @@
2323
* @author Kevin Le Saulnier <kevin.le-saulnier at rte-france.com>
2424
*/
2525
@Service
26-
public class SecurityAnalysisService {
27-
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAnalysisService.class);
26+
public class SecurityAnalysisRestClient {
27+
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAnalysisRestClient.class);
2828
static final String SA_API_VERSION = "v1";
2929
private static final String DELIMITER = "/";
3030

@@ -37,7 +37,7 @@ private String getSecurityAnalysisServerBaseUri() {
3737
return this.securityAnalysisServerBaseUri + DELIMITER + SA_API_VERSION + DELIMITER;
3838
}
3939

40-
public SecurityAnalysisService(
40+
public SecurityAnalysisRestClient(
4141
RestTemplateBuilder restTemplateBuilder,
4242
@Value("${gridsuite.services.security-analysis-server.base-uri:http://security-analysis-server/}") String securityAnalysisServerBaseUri) {
4343
this.securityAnalysisServerBaseUri = securityAnalysisServerBaseUri;

monitor-server/src/main/java/org/gridsuite/monitor/server/services/MonitorService.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/internal/MonitorService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.internal;
88

99
import org.gridsuite.monitor.commons.ProcessConfig;
1010
import org.gridsuite.monitor.commons.ProcessExecutionStep;
@@ -18,6 +18,8 @@
1818
import org.gridsuite.monitor.server.mapper.ProcessExecutionMapper;
1919
import org.gridsuite.monitor.server.mapper.ProcessExecutionStepMapper;
2020
import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository;
21+
import org.gridsuite.monitor.server.services.messaging.NotificationService;
22+
import org.gridsuite.monitor.server.services.external.client.ReportRestClient;
2123
import org.springframework.stereotype.Service;
2224
import org.springframework.transaction.annotation.Transactional;
2325

@@ -35,16 +37,16 @@ public class MonitorService {
3537

3638
private final ProcessExecutionRepository executionRepository;
3739
private final NotificationService notificationService;
38-
private final ReportService reportService;
40+
private final ReportRestClient reportRestClient;
3941
private final ResultService resultService;
4042

4143
public MonitorService(ProcessExecutionRepository executionRepository,
4244
NotificationService notificationService,
43-
ReportService reportService,
45+
ReportRestClient reportRestClient,
4446
ResultService resultService) {
4547
this.executionRepository = executionRepository;
4648
this.notificationService = notificationService;
47-
this.reportService = reportService;
49+
this.reportRestClient = reportRestClient;
4850
this.resultService = resultService;
4951
}
5052

@@ -142,7 +144,7 @@ private ProcessExecutionStepEntity toStepEntity(ProcessExecutionStep processExec
142144
public List<ReportPage> getReports(UUID executionId) {
143145
List<UUID> reportIds = getReportIds(executionId);
144146
return reportIds.stream()
145-
.map(reportService::getReport)
147+
.map(reportRestClient::getReport)
146148
.toList();
147149
}
148150

@@ -206,7 +208,7 @@ public boolean deleteExecution(UUID executionId) {
206208
}
207209
});
208210
resultIds.forEach(resultService::deleteResult);
209-
reportIds.forEach(reportService::deleteReport);
211+
reportIds.forEach(reportRestClient::deleteReport);
210212

211213
executionRepository.deleteById(executionId);
212214

monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultProvider.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/internal/ResultProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.internal;
88

99
import org.gridsuite.monitor.commons.ResultType;
1010

monitor-server/src/main/java/org/gridsuite/monitor/server/services/ResultService.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/internal/ResultService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.internal;
88

99
import org.gridsuite.monitor.commons.ResultInfos;
1010
import org.gridsuite.monitor.commons.ResultType;

monitor-server/src/main/java/org/gridsuite/monitor/server/services/ConsumerService.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/messaging/ConsumerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.messaging;
88

99
import com.fasterxml.jackson.core.JsonProcessingException;
1010
import com.fasterxml.jackson.core.type.TypeReference;
1111
import com.fasterxml.jackson.databind.ObjectMapper;
1212
import org.gridsuite.monitor.commons.MessageType;
1313
import org.gridsuite.monitor.commons.ProcessExecutionStatusUpdate;
1414
import org.gridsuite.monitor.commons.ProcessExecutionStep;
15+
import org.gridsuite.monitor.server.services.internal.MonitorService;
1516
import org.slf4j.Logger;
1617
import org.slf4j.LoggerFactory;
1718
import org.springframework.beans.factory.annotation.Autowired;

monitor-server/src/main/java/org/gridsuite/monitor/server/services/NotificationService.java renamed to monitor-server/src/main/java/org/gridsuite/monitor/server/services/messaging/NotificationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package org.gridsuite.monitor.server.services;
7+
package org.gridsuite.monitor.server.services.messaging;
88

99
import lombok.RequiredArgsConstructor;
1010
import org.gridsuite.monitor.commons.ProcessConfig;

monitor-server/src/test/java/org/gridsuite/monitor/server/MonitorIntegrationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import org.gridsuite.monitor.server.entities.ProcessExecutionEntity;
1515
import org.gridsuite.monitor.server.repositories.ProcessConfigRepository;
1616
import org.gridsuite.monitor.server.repositories.ProcessExecutionRepository;
17-
import org.gridsuite.monitor.server.services.ConsumerService;
17+
import org.gridsuite.monitor.server.services.messaging.ConsumerService;
1818
import org.gridsuite.monitor.server.services.ProcessConfigService;
19-
import org.gridsuite.monitor.server.services.ReportService;
20-
import org.gridsuite.monitor.server.services.MonitorService;
21-
import org.gridsuite.monitor.server.services.ResultService;
19+
import org.gridsuite.monitor.server.services.external.client.ReportRestClient;
20+
import org.gridsuite.monitor.server.services.internal.MonitorService;
21+
import org.gridsuite.monitor.server.services.internal.ResultService;
2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.beans.factory.annotation.Autowired;
@@ -78,7 +78,7 @@ class MonitorIntegrationTest {
7878
private MockMvc mockMvc;
7979

8080
@MockitoBean
81-
private ReportService reportService;
81+
private ReportRestClient reportRestClient;
8282

8383
@MockitoBean
8484
private ResultService resultService;
@@ -183,8 +183,8 @@ void securityAnalysisProcessIT() throws Exception {
183183
new ReportLog("message2", Severity.WARN, 2, UUID.randomUUID())), 100, 10);
184184
ReportPage reportPage1 = new ReportPage(2, List.of(new ReportLog("message3", Severity.ERROR, 3, UUID.randomUUID())), 200, 20);
185185

186-
when(reportService.getReport(reportId0)).thenReturn(reportPage0);
187-
when(reportService.getReport(reportId1)).thenReturn(reportPage1);
186+
when(reportRestClient.getReport(reportId0)).thenReturn(reportPage0);
187+
when(reportRestClient.getReport(reportId1)).thenReturn(reportPage1);
188188

189189
// Test the reports endpoint fetches correctly from database
190190
mockMvc.perform(get("/v1/executions/{executionId}/reports", executionId))

0 commit comments

Comments
 (0)