aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java (renamed from prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java)49
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java9
2 files changed, 31 insertions, 27 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java
index c09cc945..7475814f 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,12 +24,14 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@@ -37,29 +39,28 @@ import reactor.core.publisher.Mono;
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/19/18
*/
@RestController
-@Api(value = "HeartbeatController", description = "Check liveness of PRH service")
-public class HeartbeatController {
+@Api(value = "AppInfoController", description = "Provides basic information about application")
+public class AppInfoController {
- private static final Logger LOGGER = LoggerFactory.getLogger(HeartbeatController.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(AppInfoController.class);
+ private final PrhAppConfig config;
- /**
- * Endpoint for checking that PRH is alive.
- *
- * @return HTTP Status Code
- */
- @RequestMapping(value = "heartbeat", method = RequestMethod.GET)
- @ApiOperation(value = "Returns liveness of PRH service")
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "PRH sevice is living"),
- @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
- @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
- @ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
- }
- )
+ public AppInfoController(PrhAppConfig config) {
+ this.config = config;
+ }
+
+ @GetMapping(value = "heartbeat", produces = MediaType.TEXT_PLAIN_VALUE)
+ @ApiOperation("Returns liveness of PRH service")
+ @ApiResponses(@ApiResponse(code = 200, message = "Service is alive"))
public Mono<ResponseEntity<String>> heartbeat() {
- LOGGER.trace("Receiving heartbeat request");
- return Mono.defer(() ->
- Mono.just(new ResponseEntity<>("alive", HttpStatus.OK))
+ LOGGER.trace("Heartbeat request received");
+ return Mono.defer(() -> Mono.just(new ResponseEntity<>("alive", HttpStatus.OK))
);
}
-} \ No newline at end of file
+
+ @GetMapping(value = "version", produces = MediaType.APPLICATION_JSON_VALUE)
+ @ApiOperation("Returns version information")
+ public Mono<Resource> version() {
+ return Mono.defer(() -> Mono.just(config.getGitInfo()));
+ }
+}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
index aa913654..a0aa17e3 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/ScheduleController.java
@@ -60,15 +60,18 @@ public class ScheduleController {
@ApiOperation(value = "Receiving stop scheduling worker request")
public Mono<ResponseEntity<String>> stopTask() {
LOGGER.trace("Receiving stop scheduling worker request");
- return scheduledTasksRunner.getResponseFromCancellationOfTasks();
+ return Mono.defer(() -> {
+ scheduledTasksRunner.cancelTasks();
+ return Mono.just(new ResponseEntity<>("PRH Service has been stopped!", HttpStatus.OK));
+ }
+ );
}
- @ApiOperation(value = "Sends success or error response on starting task execution")
private ResponseEntity<String> createStartTaskResponse(boolean wasScheduled) {
if (wasScheduled) {
return new ResponseEntity<>("PRH Service has been started!", HttpStatus.CREATED);
} else {
- return new ResponseEntity<>("PRH Service is still running!", HttpStatus.NOT_ACCEPTABLE);
+ return new ResponseEntity<>("PRH Service is already running!", HttpStatus.NOT_ACCEPTABLE);
}
}
}