18
18
import java .util .UUID ;
19
19
20
20
import org .gridsuite .study .server .dto .ComputationType ;
21
- import org .springframework .beans .factory .annotation .Value ;
21
+ import org .gridsuite .study .server .elasticsearch .EquipmentInfosService ;
22
+ import org .springframework .data .elasticsearch .client .ClientConfiguration ;
22
23
import org .springframework .http .MediaType ;
23
24
import org .springframework .http .ResponseEntity ;
24
25
import org .springframework .web .bind .annotation .*;
31
32
@ Tag (name = "Study server - Supervision" )
32
33
public class SupervisionController {
33
34
34
- // Simple solution to get index name (with the prefix by environment).
35
- // Maybe use the Spring boot actuator or other solution ?
36
- // Keep indexName in sync with the annotation @Document in EquipmentInfos and TombstonedEquipmentInfos
37
- @ Value ("#{@environment.getProperty('powsybl-ws.elasticsearch.index.prefix')}equipments" )
38
- public String indexNameEquipments ;
39
- @ Value ("#{@environment.getProperty('powsybl-ws.elasticsearch.index.prefix')}tombstoned-equipments" )
40
- public String indexNameTombstonedEquipments ;
41
-
42
- @ Value ("#{@environment.getProperty('spring.data.elasticsearch.host')}" + ":" + "#{@environment.getProperty('spring.data.elasticsearch.port')}" )
43
- public String elasticSerachHost ;
44
-
45
35
private final SupervisionService supervisionService ;
46
36
47
37
private final StudyService studyService ;
48
38
49
- public SupervisionController (SupervisionService supervisionService , StudyService studyService ) {
39
+ private final EquipmentInfosService equipmentInfosService ;
40
+
41
+ private final ClientConfiguration elasticsearchClientConfiguration ;
42
+
43
+ public SupervisionController (SupervisionService supervisionService , StudyService studyService , EquipmentInfosService equipmentInfosService , ClientConfiguration elasticsearchClientConfiguration ) {
50
44
this .supervisionService = supervisionService ;
51
45
this .studyService = studyService ;
46
+ this .equipmentInfosService = equipmentInfosService ;
47
+ this .elasticsearchClientConfiguration = elasticsearchClientConfiguration ;
52
48
}
53
49
54
50
@ DeleteMapping (value = "/computation/results" )
@@ -63,42 +59,45 @@ public ResponseEntity<Integer> deleteComputationResults(@Parameter(description =
63
59
@ Operation (summary = "get the elasticsearch address" )
64
60
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "the elasticsearch address" )})
65
61
public ResponseEntity <String > getElasticsearchHost () {
66
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (elasticSerachHost );
62
+ String host = elasticsearchClientConfiguration .getEndpoints ().get (0 ).getHostName ()
63
+ + ":"
64
+ + elasticsearchClientConfiguration .getEndpoints ().get (0 ).getPort ();
65
+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (host );
67
66
}
68
67
69
- @ GetMapping (value = "/indexed- equipments- index-name" )
68
+ @ GetMapping (value = "/equipments/ index-name" )
70
69
@ Operation (summary = "get the indexed equipments index name" )
71
70
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Indexed equipments index name" )})
72
71
public ResponseEntity <String > getIndexedEquipmentsIndexName () {
73
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (indexNameEquipments );
72
+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (equipmentInfosService . getEquipmentsIndexName () );
74
73
}
75
74
76
- @ GetMapping (value = "/indexed- tombstoned-equipments- index-name" )
75
+ @ GetMapping (value = "/tombstoned-equipments/ index-name" )
77
76
@ Operation (summary = "get the indexed tombstoned equipments index name" )
78
77
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Indexed tombstoned equipments index name" )})
79
78
public ResponseEntity <String > getIndexedTombstonedEquipmentsIndexName () {
80
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (indexNameTombstonedEquipments );
79
+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (equipmentInfosService . getTombstonedEquipmentsIndexName () );
81
80
}
82
81
83
- @ GetMapping (value = "/indexed- equipments-count" )
82
+ @ GetMapping (value = "/equipments/indexation -count" )
84
83
@ Operation (summary = "get indexed equipments count for all studies" )
85
84
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Indexed equipments count" )})
86
- public ResponseEntity <Long > getIndexedEquipmentsCount () {
87
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (supervisionService .getIndexedEquipmentsCount ());
85
+ public ResponseEntity <String > getIndexedEquipmentsCount () {
86
+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (Long . toString ( supervisionService .getIndexedEquipmentsCount () ));
88
87
}
89
88
90
- @ GetMapping (value = "/indexed- tombstoned-equipments-count" )
89
+ @ GetMapping (value = "/tombstoned-equipments/indexation -count" )
91
90
@ Operation (summary = "get indexed tombstoned equipments count for all studies" )
92
91
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "Tombstoned equipments count" )})
93
- public ResponseEntity <Long > getIndexedTombstonedEquipmentsCount () {
94
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (supervisionService .getIndexedTombstonedEquipmentsCount ());
92
+ public ResponseEntity <String > getIndexedTombstonedEquipmentsCount () {
93
+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (Long . toString ( supervisionService .getIndexedTombstonedEquipmentsCount () ));
95
94
}
96
95
97
- @ DeleteMapping (value = "/studies/{studyUuid}/indexed- equipments" )
96
+ @ DeleteMapping (value = "/studies/{studyUuid}/equipments/indexation " )
98
97
@ Operation (summary = "delete indexed equipments and tombstoned equipments for the given study" )
99
98
@ ApiResponses (value = {@ ApiResponse (responseCode = "200" , description = "all indexed equipments and tombstoned equipments for the given study have been deleted" )})
100
- public ResponseEntity <Long > deleteStudyIndexedEquipmentsAndTombstoned (@ PathVariable ("studyUuid" ) UUID studyUuid ) {
101
- return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON ).body (supervisionService .deleteStudyIndexedEquipmentsAndTombstoned (studyUuid ));
99
+ public ResponseEntity <String > deleteStudyIndexedEquipmentsAndTombstoned (@ PathVariable ("studyUuid" ) UUID studyUuid ) {
100
+ return ResponseEntity .ok ().contentType (MediaType .TEXT_PLAIN ).body (Long . toString ( supervisionService .deleteStudyIndexedEquipmentsAndTombstoned (studyUuid ) ));
102
101
}
103
102
104
103
@ GetMapping (value = "/orphan_indexed_network_uuids" )
0 commit comments