summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/main')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java5
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java72
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java63
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java65
-rw-r--r--prh-app-server/src/main/resources/application.yaml8
-rw-r--r--prh-app-server/src/main/resources/logback-spring.xml2
6 files changed, 108 insertions, 107 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java
index 613e9a83..d26fbd81 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.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.
@@ -23,12 +23,15 @@ package org.onap.dcaegen2.services.prh.configuration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
+import org.springframework.core.io.Resource;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/25/18
*/
public interface Config {
+ Resource getGitInfo();
+
DmaapConsumerConfiguration getDmaapConsumerConfiguration();
AaiClientConfiguration getAaiClientConfiguration();
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
index 612fab48..85f7e983 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.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.
@@ -20,18 +20,8 @@
package org.onap.dcaegen2.services.prh.configuration;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSyntaxException;
-import com.google.gson.TypeAdapterFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.ServiceLoader;
-import javax.validation.constraints.NotNull;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.gson.*;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
@@ -42,6 +32,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
+import org.springframework.util.StreamUtils;
+
+import javax.annotation.PostConstruct;
+import javax.validation.constraints.NotNull;
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.ServiceLoader;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
@@ -50,6 +48,7 @@ import org.springframework.core.io.Resource;
@EnableConfigurationProperties
@ConfigurationProperties("app")
public abstract class PrhAppConfig implements Config {
+ private static final Logger LOGGER = LoggerFactory.getLogger(PrhAppConfig.class);
private static final String CONFIG = "configs";
private static final String AAI = "aai";
@@ -59,8 +58,6 @@ public abstract class PrhAppConfig implements Config {
private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
private static final String SECURITY = "security";
- private static final Logger LOGGER = LoggerFactory.getLogger(PrhAppConfig.class);
-
AaiClientConfiguration aaiClientConfiguration;
DmaapConsumerConfiguration dmaapConsumerConfiguration;
@@ -68,7 +65,20 @@ public abstract class PrhAppConfig implements Config {
DmaapPublisherConfiguration dmaapPublisherConfiguration;
@Value("classpath:prh_endpoints.json")
- private Resource resourceFile;
+ private Resource prhEndpoints;
+
+ @Value("classpath:git_info.json")
+ private Resource gitInfo;
+
+ @PostConstruct
+ private void printGitInfo() throws IOException {
+ LOGGER.debug("Git info={}", StreamUtils.copyToString(gitInfo.getInputStream(), Charset.defaultCharset()));
+ }
+
+ @Override
+ public Resource getGitInfo() {
+ return gitInfo;
+ }
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
@@ -87,21 +97,19 @@ public abstract class PrhAppConfig implements Config {
@Override
public void initFileStreamReader() {
-
GsonBuilder gsonBuilder = new GsonBuilder();
ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
JsonParser parser = new JsonParser();
- try (InputStream inputStream = resourceFile.getInputStream()) {
+ try (InputStream inputStream = prhEndpoints.getInputStream()) {
JsonElement rootElement = getJsonElement(parser, inputStream);
if (rootElement.isJsonObject()) {
deserializeAaiConfiguration(gsonBuilder, rootElement);
deserializeDmaapConsumerConfiguration(gsonBuilder, rootElement);
deserializeDmaapPublisherConfiguration(gsonBuilder, rootElement);
}
- }
- catch (IOException e) {
- LOGGER.warn("Problem with file loading, file ", e);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to load/parse file", e);
}
}
@@ -109,8 +117,8 @@ public abstract class PrhAppConfig implements Config {
dmaapPublisherConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP)
.getAsJsonObject(DMAAP_PRODUCER),
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- DmaapPublisherConfiguration.class);
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
+ DmaapPublisherConfiguration.class);
}
private void deserializeDmaapConsumerConfiguration(GsonBuilder gsonBuilder, JsonElement rootElement) {
@@ -118,7 +126,7 @@ public abstract class PrhAppConfig implements Config {
rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP)
.getAsJsonObject(DMAAP_CONSUMER),
rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- DmaapConsumerConfiguration.class);
+ DmaapConsumerConfiguration.class);
}
private void deserializeAaiConfiguration(GsonBuilder gsonBuilder, JsonElement rootElement) {
@@ -134,22 +142,22 @@ public abstract class PrhAppConfig implements Config {
private JsonObject concatenateJsonObjects(JsonObject target, JsonObject source) {
source.entrySet()
- .forEach(entry -> target.add(entry.getKey(), entry.getValue()));
+ .forEach(entry -> target.add(entry.getKey(), entry.getValue()));
return target;
}
private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
- @NotNull Class<T> type) {
+ @NotNull Class<T> type) {
try {
return gsonBuilder.create().fromJson(jsonObject, type);
- } catch (JsonSyntaxException e) {
- LOGGER.warn("Problem with Json deserialization", e);
+ } catch (JsonSyntaxException e) {
+ LOGGER.warn("Failed to parse JSON={}", jsonObject, e);
return null;
}
}
- void setResourceFile(Resource resourceFile) {
- this.resourceFile = resourceFile;
+ @VisibleForTesting
+ void setPrhEndpoints(Resource prhEndpoints) {
+ this.prhEndpoints = prhEndpoints;
}
-
-} \ No newline at end of file
+}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java
new file mode 100644
index 00000000..9a49dee5
--- /dev/null
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/AppInfoController.java
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.services.prh.controllers;
+
+import io.swagger.annotations.*;
+import org.onap.dcaegen2.services.prh.configuration.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.http.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+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 = "AppInfoController", description = "Provides basic information about application")
+public class AppInfoController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AppInfoController.class);
+ private final Resource gitInfo;
+
+ @Autowired
+ public AppInfoController(Config config) {
+ gitInfo = config.getGitInfo();
+ }
+
+ @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("Heartbeat request received");
+ return Mono.defer(() -> Mono.just(new ResponseEntity<>("alive", HttpStatus.OK))
+ );
+ }
+
+ @GetMapping(value = "version", produces = MediaType.APPLICATION_JSON_VALUE)
+ @ApiOperation("Returns version information")
+ public Mono<Resource> version() {
+ return Mono.defer(() -> Mono.just(gitInfo));
+ }
+}
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/HeartbeatController.java
deleted file mode 100644
index c09cc945..00000000
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dcaegen2.services.prh.controllers;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-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.RestController;
-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 {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(HeartbeatController.class);
-
- /**
- * 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 Mono<ResponseEntity<String>> heartbeat() {
- LOGGER.trace("Receiving heartbeat request");
- return Mono.defer(() ->
- Mono.just(new ResponseEntity<>("alive", HttpStatus.OK))
- );
- }
-} \ No newline at end of file
diff --git a/prh-app-server/src/main/resources/application.yaml b/prh-app-server/src/main/resources/application.yaml
index 88d1e401..a9a89421 100644
--- a/prh-app-server/src/main/resources/application.yaml
+++ b/prh-app-server/src/main/resources/application.yaml
@@ -9,11 +9,3 @@ server:
key-store: classpath:keystore-local
key-password: nokiapnf
keyAlias: tomcat-localhost
-logging:
- level:
- ROOT: ERROR
- org.onap.dcaegen2.services.prh: INFO
- reactor.ipc.netty.http.client: WARN
- org.springframework: ERROR
- org.springframework.data: ERROR
- org.springframework.web.reactive: WARN
diff --git a/prh-app-server/src/main/resources/logback-spring.xml b/prh-app-server/src/main/resources/logback-spring.xml
index 8f9bfd1c..70908b07 100644
--- a/prh-app-server/src/main/resources/logback-spring.xml
+++ b/prh-app-server/src/main/resources/logback-spring.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
+<configuration debug="false" scan="false">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="outputFilename" value="prh-app-server_output"/>
<property name="logPath" value="/var/log/ONAP/prh/prh-app-server"/>