Merge "Added check in PUT policy"
authorHenrik Andersson <henrik.b.andersson@est.tech>
Thu, 9 Apr 2020 12:59:26 +0000 (12:59 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Thu, 9 Apr 2020 12:59:26 +0000 (12:59 +0000)
docs/policy-agent-api.rst
policy-agent/docs/api.yaml
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java

index a65e611..2a79b26 100644 (file)
@@ -965,7 +965,8 @@ GET
                 "policyTypes": [
                   "string"
                 ],
-                "ricName": "string"
+                "ricName": "string",
+                "state": "string"
               }
             ]
 
@@ -992,7 +993,8 @@ GET
               "Example_QoETarget_1.0.0",
               "ERIC_QoSNudging_0.2.0"
             ],
-            "ricName": "Ric 1"
+            "ricName": "Ric 1",
+            "state": "AVAILABLE"
           },
             .
             .
@@ -1004,7 +1006,8 @@ GET
             "policyTypes": [
               "STD_PolicyModelUnconstrained_0.2.0"
             ],
-            "ricName": "Ric X"
+            "ricName": "Ric X",
+            "state": "UNAVAILABLE"
           }
         ]
 
index 306b15a..f42c3e0 100644 (file)
@@ -581,6 +581,9 @@ definitions:
       ricName:
         type: string
         description: identity of the ric
+      state:
+        type: string
+        description: state info
     title: RicInfo
   ServiceRegistrationInfo:
     type: object
index 4db3ade..922ba3d 100644 (file)
@@ -28,6 +28,8 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
 
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -92,13 +94,17 @@ public class ServiceController {
             s.getCallbackUrl());
     }
 
-    private void validateRegistrationInfo(ServiceRegistrationInfo registrationInfo) throws ServiceException {
+    private void validateRegistrationInfo(ServiceRegistrationInfo registrationInfo)
+        throws ServiceException, MalformedURLException {
         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");
         }
+        if (!registrationInfo.callbackUrl.isEmpty()) {
+            new URL(registrationInfo.callbackUrl);
+        }
     }
 
     @ApiOperation(value = "Register a service")
index 7ad2dc8..4e3fd0f 100644 (file)
@@ -559,6 +559,8 @@ public class ApplicationTest {
         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);
+        testErrorCode(restClient().put("/service", createServiceJson("name", 0, "missing.portandprotocol.com")),
+            HttpStatus.BAD_REQUEST);
 
         // GET non existing servive
         testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
@@ -612,7 +614,11 @@ public class ApplicationTest {
     }
 
     private String createServiceJson(String name, long keepAliveIntervalSeconds) {
-        ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, "callbackUrl");
+        return createServiceJson(name, keepAliveIntervalSeconds, "https://examples.javacodegeeks.com/core-java/");
+    }
+
+    private String createServiceJson(String name, long keepAliveIntervalSeconds, String url) {
+        ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, url);
 
         String json = gson.toJson(service);
         return json;