Bugfix, RIC configs would disappear after one minute 46/3146/2
authorPatrikBuhr <patrik.buhr@est.tech>
Fri, 3 Apr 2020 13:54:09 +0000 (15:54 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 6 Apr 2020 07:00:37 +0000 (09:00 +0200)
Bugfix

Also fixed so that keepalive inerval <0 when registerring a servive
is rejected.

Change-Id: Ic9bec3d6e73237d34d9b9208682218c2df381d67
Issue-ID: NONRTRIC-183
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigTest.java

index 5d7d5d9..052a96c 100644 (file)
@@ -107,14 +107,13 @@ public class ApplicationConfig {
         Map<String, RicConfig> newRicConfigs = new HashMap<>();
         for (RicConfig newConfig : parserResult.ricConfigs()) {
             RicConfig oldConfig = this.ricConfigs.get(newConfig.name());
+            this.ricConfigs.remove(newConfig.name());
             if (oldConfig == null) {
                 newRicConfigs.put(newConfig.name(), newConfig);
                 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
-                this.ricConfigs.remove(newConfig.name());
             } else if (!newConfig.equals(oldConfig)) {
                 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
                 newRicConfigs.put(newConfig.name(), newConfig);
-                this.ricConfigs.remove(newConfig.name());
             } else {
                 newRicConfigs.put(oldConfig.name(), oldConfig);
             }
index 578e5c8..bf78742 100644 (file)
@@ -97,6 +97,9 @@ public class ServiceController {
         if (registrationInfo.serviceName.isEmpty()) {
             throw new ServiceException("Missing mandatory parameter 'serviceName'");
         }
+        if (registrationInfo.keepAliveIntervalSeconds < 0) {
+            throw new ServiceException("Keepalive interval shoul be greater or equal to 0");
+        }
     }
 
     @ApiOperation(value = "Register a service")
@@ -104,7 +107,7 @@ public class ServiceController {
         value = { //
             @ApiResponse(code = 200, message = "Service updated", response = String.class),
             @ApiResponse(code = 201, message = "Service created", response = String.class), //
-            @ApiResponse(code = 400, message = "Cannot parse the ServiceRegistrationInfo", response = String.class)})
+            @ApiResponse(code = 400, message = "The ServiceRegistrationInfo is not accepted", response = String.class)})
     @PutMapping("/service")
     public ResponseEntity<String> putService(//
         @RequestBody ServiceRegistrationInfo registrationInfo) {
index b7e9a4b..4f0dbb8 100644 (file)
@@ -554,9 +554,10 @@ public class ApplicationTest {
         // Keep alive, no registerred service
         testErrorCode(restClient().post("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND);
 
-        // PUT servive with crap payload
+        // PUT servive with bad payload
         testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
         testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
+        testErrorCode(restClient().put("/service", createServiceJson("name", -123)), HttpStatus.BAD_REQUEST);
 
         // GET non existing servive
         testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
index 27b9c87..96abd1c 100644 (file)
@@ -21,6 +21,7 @@
 package org.oransc.policyagent.configuration;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -78,6 +79,11 @@ public class ApplicationConfigTest {
 
         assertEquals(RIC_CONFIG_1, appConfigUnderTest.getRic(RIC_CONFIG_1.name()),
             "Not correct Ric retrieved from configurations.");
+
+        update = appConfigUnderTest.setConfiguration(configParserResult(RIC_CONFIG_1)).blockFirst();
+        assertNull(update, "Nothing should be updated");
+        assertTrue(appConfigUnderTest.getRicConfigs().contains(RIC_CONFIG_1), "Ric should remain.");
+
     }
 
     @Test