From: PatrikBuhr Date: Mon, 6 Apr 2020 14:53:31 +0000 (+0200) Subject: Minor changes X-Git-Tag: 2.0.0~92^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=776c8156aae66f505ab234063923e66e7e610a01;hp=--cc;p=nonrtric.git Minor changes Increased the TCP timeouts Made managedElementId in GET rics mandatory (bugfix) Change-Id: Ie2683d1fdd7e0abfc15877f4f4039e2f82f62eea Issue-ID: NONRTRIC-164 Signed-off-by: PatrikBuhr --- 776c8156aae66f505ab234063923e66e7e610a01 diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java index 0289db98..83592ecf 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java @@ -20,16 +20,24 @@ 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 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 reactor.core.publisher.Mono; +import reactor.netty.http.client.HttpClient; +import reactor.netty.tcp.TcpClient; /** * Generic reactive REST client. @@ -40,7 +48,21 @@ public class AsyncRestClient { 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; } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java index dcfbc646..dd35e5b3 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java @@ -215,7 +215,6 @@ public class ApplicationConfigParser { } catch (MalformedURLException e) { throw new ServiceException("Could not parse the URL", e); } - } private static @NotNull String getAsString(JsonObject obj, String memberName) throws ServiceException { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicRepositoryController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicRepositoryController.java index 465ee78c..33a301c2 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicRepositoryController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicRepositoryController.java @@ -67,14 +67,14 @@ public class RicRepositoryController { @ApiResponse(code = 404, message = "RIC is not fond", response = String.class) // }) public ResponseEntity getRic( - @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) { + @RequestParam(name = "managedElementId", required = true) String managedElementId) { Optional 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); } }