Skip to content

Commit b0d3df0

Browse files
authored
Merge pull request #3048 from lcaouen/develop
Add swager-ui to Alarm Logger API
2 parents b9c5de4 + d66790b commit b0d3df0

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

services/alarm-logger/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@
141141
<scope>test</scope>
142142
</dependency>
143143

144+
<dependency>
145+
<groupId>org.springdoc</groupId>
146+
<artifactId>springdoc-openapi-ui</artifactId>
147+
<version>1.7.0</version>
148+
</dependency>
149+
150+
144151
</dependencies>
145152

146153
<profiles>

services/alarm-logger/src/main/java/org/phoebus/alarm/logging/rest/SearchController.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import co.elastic.clients.elasticsearch.ElasticsearchClient;
44
import co.elastic.clients.elasticsearch._types.ElasticsearchVersionInfo;
55
import co.elastic.clients.elasticsearch.core.InfoResponse;
6+
67
import com.fasterxml.jackson.core.JsonProcessingException;
78
import com.fasterxml.jackson.databind.ObjectMapper;
89
import org.phoebus.alarm.logging.AlarmLoggingService;
@@ -25,13 +26,20 @@
2526
import java.util.logging.Level;
2627
import java.util.logging.Logger;
2728

29+
import io.swagger.v3.oas.annotations.Operation;
30+
import io.swagger.v3.oas.annotations.tags.Tag;
31+
import io.swagger.v3.oas.annotations.media.Schema;
32+
import io.swagger.v3.oas.annotations.Parameter;
33+
import io.swagger.v3.oas.annotations.Parameters;
34+
2835
/**
2936
* A REST service for querying the alarm message history
3037
*
3138
* @author Kunal Shroff
3239
*/
3340
@RestController
3441
@SuppressWarnings("unused")
42+
@Tag(name = "Search controller")
3543
public class SearchController {
3644

3745
static final Logger logger = Logger.getLogger(SearchController.class.getName());
@@ -44,6 +52,7 @@ public class SearchController {
4452
/**
4553
* @return Information about the alarm logging service
4654
*/
55+
@Operation(summary = "Get Service Info")
4756
@GetMapping
4857
public String info() {
4958

@@ -74,22 +83,41 @@ public String info() {
7483
}
7584
}
7685

86+
@Operation(summary = "Search alarms")
87+
@Parameters({
88+
@Parameter(name = "pv", description = "PV name", schema = @Schema(type = "string"), required = false, example = "*"),
89+
@Parameter(name = "severity", description = "Alarm severity", schema = @Schema(type = "string"), required = false, example = "*"),
90+
@Parameter(name = "message", description = "Alarm message", schema = @Schema(type = "string"), required = false, example = "*"),
91+
@Parameter(name = "current_severity", description = "PV severity", schema = @Schema(type = "string"), required = false, example = "*"),
92+
@Parameter(name = "current_message", description = "PV message", schema = @Schema(type = "string"), required = false, example = "*"),
93+
@Parameter(name = "user", description = "User", schema = @Schema(type = "string"), required = false, example = "*"),
94+
@Parameter(name = "host", description = "Host", schema = @Schema(type = "string"), required = false, example = "*"),
95+
@Parameter(name = "command", description = "Command", schema = @Schema(type = "string"), required = false, example = "*"),
96+
@Parameter(name = "start", description = "Start time", schema = @Schema(type = "string"), required = false, example = "2024-06-12"),
97+
@Parameter(name = "end", description = "End time", schema = @Schema(type = "string"), required = false, example = "2024-06-14"),
98+
})
7799
@RequestMapping(value = "/search/alarm", method = RequestMethod.GET)
78-
public List<AlarmLogMessage> search(@RequestParam Map<String, String> allRequestParams) {
100+
public List<AlarmLogMessage> search(@Parameter(hidden = true) @RequestParam Map<String, String> allRequestParams) {
79101
List<AlarmLogMessage> result = AlarmLogSearchUtil.search(ElasticClientHelper.getInstance().getClient(), allRequestParams);
80102
return result;
81103
}
82104

105+
@Operation(summary = "Search alarms by PV name")
83106
@RequestMapping(value = "/search/alarm/pv/{pv}", method = RequestMethod.GET)
84-
public List<AlarmLogMessage> searchPv(@PathVariable String pv) {
107+
public List<AlarmLogMessage> searchPv(@Parameter(description = "PV name") @PathVariable String pv) {
85108
Map<String, String> searchParameters = new HashMap<>();
86109
searchParameters.put("pv", pv);
87110
List<AlarmLogMessage> result = AlarmLogSearchUtil.search(ElasticClientHelper.getInstance().getClient(), searchParameters);
88111
return result;
89112
}
90113

114+
@Operation(summary = "Search alarm config")
115+
@Schema(name = "config", example = "/Accelerator/compteur", required = true)
116+
@Parameters({
117+
@Parameter(name = "config", description = "Config path", schema = @Schema(type = "string"), required = false, example = "/Accelerator/pvname"),
118+
})
91119
@RequestMapping(value = "/search/alarm/config", method = RequestMethod.GET)
92-
public List<AlarmLogMessage> searchConfig(@RequestParam Map<String, String> allRequestParams) {
120+
public List<AlarmLogMessage> searchConfig(@Parameter(hidden = true) @RequestParam Map<String, String> allRequestParams) {
93121
if(allRequestParams == null ||
94122
allRequestParams.isEmpty() ||
95123
!allRequestParams.containsKey("config") ||

0 commit comments

Comments
 (0)