aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-05-19 13:29:44 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2021-05-19 13:30:05 +0200
commit8b965c4b287a42e6504853f3d85f3a9c82c399b1 (patch)
treeb099b0ce3b435c02b18beb37100cc0e95e0d2b04 /a1-policy-management/src/main
parent9a8965fa835da0639719245e44625e15f165d7d5 (diff)
PMS Bugfix - A1 Istanbul
Bugfix, rejecting putting and getting configuratioon via REST if the consul is used (then the configuration file has no effect).. Issue-ID: CCSDK-3256 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: Ia3b4a387f450b137b576a9d82ba2f7093a5839ef
Diffstat (limited to 'a1-policy-management/src/main')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java19
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java11
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/ServiceException.java15
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java3
4 files changed, 44 insertions, 4 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
index e6b938a0..b677a405 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
@@ -36,6 +36,8 @@ import java.util.Optional;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ConfigurationFile;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
+import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
+import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -58,6 +60,9 @@ public class ConfigurationController {
@Autowired
ConfigurationFile configurationFile;
+ @Autowired
+ RefreshConfigTask refreshConfigTask;
+
private static Gson gson = new GsonBuilder() //
.create(); //
@@ -77,6 +82,7 @@ public class ConfigurationController {
})
public ResponseEntity<Object> putConfiguration(@RequestBody Object configuration) {
try {
+ validateConfigFileIsUsed();
String configAsString = gson.toJson(configuration);
JsonObject configJson = JsonParser.parseString(configAsString).getAsJsonObject();
ApplicationConfigParser configParser = new ApplicationConfigParser();
@@ -86,11 +92,10 @@ public class ConfigurationController {
return new ResponseEntity<>(HttpStatus.OK);
} catch (IOException ioe) {
logger.warn("Configuration file not written, {}.", ioe.getMessage());
- return ErrorResponse.create("Internal error when writing the configuration. Try again.",
+ return ErrorResponse.create("Internal error when writing the configuration.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
- return ErrorResponse.create(String.format("Faulty configuration. %s", e.getMessage()),
- HttpStatus.BAD_REQUEST);
+ return ErrorResponse.create(e, HttpStatus.BAD_REQUEST);
}
}
@@ -108,6 +113,7 @@ public class ConfigurationController {
})
public ResponseEntity<Object> getConfiguration() {
try {
+ validateConfigFileIsUsed();
Optional<JsonObject> rootObject = configurationFile.readFile();
if (rootObject.isPresent()) {
return new ResponseEntity<>(rootObject.get().toString(), HttpStatus.OK);
@@ -119,4 +125,11 @@ public class ConfigurationController {
}
}
+ private void validateConfigFileIsUsed() throws ServiceException {
+ if (this.refreshConfigTask.isConsulUsed()) {
+ throw new ServiceException("Config file not used (Consul is used)", HttpStatus.FORBIDDEN);
+ }
+
+ }
+
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java
index c3ee1952..78ba6b69 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java
@@ -26,6 +26,7 @@ import com.google.gson.annotations.SerializedName;
import io.swagger.v3.oas.annotations.media.Schema;
+import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -96,7 +97,15 @@ public class ErrorResponse {
return new ResponseEntity<>(json, headers, code);
}
- public static ResponseEntity<Object> create(Exception e, HttpStatus code) {
+ public static ResponseEntity<Object> create(Throwable e, HttpStatus code) {
+ if (e instanceof RuntimeException) {
+ code = HttpStatus.INTERNAL_SERVER_ERROR;
+ } else if (e instanceof ServiceException) {
+ ServiceException se = (ServiceException) e;
+ if (se.getHttpStatus() != null) {
+ code = se.getHttpStatus();
+ }
+ }
return create(e.toString(), code);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/ServiceException.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/ServiceException.java
index 17e651aa..8f5956ce 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/ServiceException.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/exceptions/ServiceException.java
@@ -20,15 +20,30 @@
package org.onap.ccsdk.oran.a1policymanagementservice.exceptions;
+import lombok.Getter;
+
+import org.springframework.http.HttpStatus;
+
public class ServiceException extends Exception {
private static final long serialVersionUID = 1L;
+ @Getter
+ private final HttpStatus httpStatus;
+
public ServiceException(String message) {
super(message);
+ httpStatus = null;
}
public ServiceException(String message, Exception originalException) {
super(message, originalException);
+ httpStatus = null;
}
+
+ public ServiceException(String message, HttpStatus httpStatus) {
+ super(message);
+ this.httpStatus = httpStatus;
+ }
+
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
index e84c9838..30279815 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
@@ -80,8 +80,11 @@ public class RefreshConfigTask {
final ConfigurationFile configurationFile;
final ApplicationConfig appConfig;
+
@Getter(AccessLevel.PROTECTED)
private Disposable refreshTask = null;
+
+ @Getter
private boolean isConsulUsed = false;
private final Rics rics;