Minor changes 63/3163/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 6 Apr 2020 14:53:31 +0000 (16:53 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 6 Apr 2020 14:57:49 +0000 (16:57 +0200)
Increased the TCP timeouts
Made managedElementId in GET rics mandatory (bugfix)

Change-Id: Ie2683d1fdd7e0abfc15877f4f4039e2f82f62eea
Issue-ID: NONRTRIC-164
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/RicRepositoryController.java

index 0289db9..83592ec 100644 (file)
 
 package org.oransc.policyagent.clients;
 
 
 package org.oransc.policyagent.clients;
 
+import io.netty.channel.ChannelOption;
+import io.netty.handler.timeout.ReadTimeoutHandler;
+import io.netty.handler.timeout.WriteTimeoutHandler;
+
 import java.lang.invoke.MethodHandles;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import java.lang.invoke.MethodHandles;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.reactive.ReactorClientHttpConnector;
 import org.springframework.lang.Nullable;
 import org.springframework.web.reactive.function.client.WebClient;
 import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
 import org.springframework.lang.Nullable;
 import org.springframework.web.reactive.function.client.WebClient;
 import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
+
 import reactor.core.publisher.Mono;
 import reactor.core.publisher.Mono;
+import reactor.netty.http.client.HttpClient;
+import reactor.netty.tcp.TcpClient;
 
 /**
  * Generic reactive REST client.
 
 /**
  * Generic reactive REST client.
@@ -40,7 +48,21 @@ public class AsyncRestClient {
     private final String baseUrl;
 
     public AsyncRestClient(String baseUrl) {
     private final String baseUrl;
 
     public AsyncRestClient(String baseUrl) {
-        this.client = WebClient.create(baseUrl);
+
+        TcpClient tcpClient = TcpClient.create() //
+            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) //
+            .doOnConnected(connection -> {
+                connection.addHandler(new ReadTimeoutHandler(10));
+                connection.addHandler(new WriteTimeoutHandler(30));
+            });
+        HttpClient httpClient = HttpClient.from(tcpClient);
+        ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
+
+        this.client = WebClient.builder() //
+            .clientConnector(connector) //
+            .baseUrl(baseUrl) //
+            .build();
+
         this.baseUrl = baseUrl;
     }
 
         this.baseUrl = baseUrl;
     }
 
index dcfbc64..dd35e5b 100644 (file)
@@ -215,7 +215,6 @@ public class ApplicationConfigParser {
         } catch (MalformedURLException e) {
             throw new ServiceException("Could not parse the URL", e);
         }
         } catch (MalformedURLException e) {
             throw new ServiceException("Could not parse the URL", e);
         }
-
     }
 
     private static @NotNull String getAsString(JsonObject obj, String memberName) throws ServiceException {
     }
 
     private static @NotNull String getAsString(JsonObject obj, String memberName) throws ServiceException {
index 465ee78..33a301c 100644 (file)
@@ -67,14 +67,14 @@ public class RicRepositoryController {
             @ApiResponse(code = 404, message = "RIC is not fond", response = String.class) //
         })
     public ResponseEntity<String> getRic(
             @ApiResponse(code = 404, message = "RIC is not fond", response = String.class) //
         })
     public ResponseEntity<String> getRic(
-        @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) {
+        @RequestParam(name = "managedElementId", required = true) String managedElementId) {
 
         Optional<Ric> ric = this.rics.lookupRicForManagedElement(managedElementId);
 
         if (ric.isPresent()) {
             return new ResponseEntity<>(ric.get().name(), HttpStatus.OK);
         } else {
 
         Optional<Ric> ric = this.rics.lookupRicForManagedElement(managedElementId);
 
         if (ric.isPresent()) {
             return new ResponseEntity<>(ric.get().name(), HttpStatus.OK);
         } else {
-            return new ResponseEntity<>("", HttpStatus.NOT_FOUND);
+            return new ResponseEntity<>("No RIC found", HttpStatus.NOT_FOUND);
         }
     }
 
         }
     }