From 2bfc144d136e8895aa5462cc331841a5d8107683 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Tue, 7 Apr 2020 14:26:26 +0200 Subject: [PATCH] Changed service keepAlive from POST to PUT Fixed some very confusing log messages Change-Id: I48679ba69252a09e610cdc239e2fb56554d665d9 Issue-ID: NONRTRIC-164 Signed-off-by: PatrikBuhr --- policy-agent/docs/api.yaml | 12 ++++++------ .../java/org/oransc/policyagent/clients/A1ClientFactory.java | 6 ++++-- .../java/org/oransc/policyagent/clients/AsyncRestClient.java | 7 +++++++ .../oransc/policyagent/controllers/ServiceController.java | 3 +-- .../org/oransc/policyagent/tasks/RicSynchronizationTask.java | 2 +- .../test/java/org/oransc/policyagent/ApplicationTest.java | 4 ++-- .../org/oransc/policyagent/clients/A1ClientFactoryTest.java | 4 ++-- .../org/oransc/policyagent/tasks/RefreshConfigTaskTest.java | 3 +++ .../oransc/policyagent/tasks/RicSynchronizationTaskTest.java | 2 +- .../test/java/org/oransc/policyagent/utils/MockA1Client.java | 10 ++++++++++ 10 files changed, 37 insertions(+), 16 deletions(-) diff --git a/policy-agent/docs/api.yaml b/policy-agent/docs/api.yaml index 3ea913d5..306b15a8 100644 --- a/policy-agent/docs/api.yaml +++ b/policy-agent/docs/api.yaml @@ -135,7 +135,7 @@ paths: schema: type: string '423': - description: RIC is locked + description: RIC is not operational schema: type: string deprecated: false @@ -170,7 +170,7 @@ paths: schema: type: string '423': - description: RIC is locked + description: RIC is not operational schema: type: string deprecated: false @@ -342,7 +342,7 @@ paths: - name: managedElementId in: query description: managedElementId - required: false + required: true type: string responses: '200': @@ -415,7 +415,7 @@ paths: schema: type: string '400': - description: Cannot parse the ServiceRegistrationInfo + description: The ServiceRegistrationInfo is not accepted schema: type: string '401': @@ -487,11 +487,11 @@ paths: type: string deprecated: false /services/keepalive: - post: + put: tags: - Service registry and supervision summary: Heartbeat from a serice - operationId: keepAliveServiceUsingPOST + operationId: keepAliveServiceUsingPUT consumes: - application/json produces: diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java index 55abe2c6..546979ce 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java @@ -86,7 +86,7 @@ public class A1ClientFactory { private ControllerConfig getControllerConfig(Ric ric) throws ServiceException { String controllerName = ric.getConfig().controllerName(); if (controllerName.isEmpty()) { - throw new ServiceException("NO controller configured for RIC: " + ric.name()); + throw new ServiceException("No controller configured for RIC: " + ric.name()); } return this.appConfig.getControllerConfig(controllerName); } @@ -114,7 +114,9 @@ public class A1ClientFactory { .onErrorResume(notUsed -> fetchVersion(ric, A1ProtocolType.SDNC_ONAP)) // .doOnNext(ric::setProtocolVersion) .doOnNext(version -> logger.debug("Established protocol version:{} for Ric: {}", version, ric.name())) // - .doOnError(notUsed -> logger.warn("Could not get protocol version from RIC: {}", ric.name())); // + .doOnError(notUsed -> logger.warn("Could not get protocol version from RIC: {}", ric.name())) // + .onErrorResume( + notUsed -> Mono.error(new ServiceException("Protocol negotiation failed for " + ric.name()))); } else { return Mono.just(ric.getProtocolVersion()); } 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 83592ecf..5110718d 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 @@ -101,6 +101,13 @@ public class AsyncRestClient { return retrieve(request); } + public Mono> putForEntity(String uri) { + logger.debug("PUT uri = '{}{}''", baseUrl, uri); + RequestHeadersSpec request = client.put() // + .uri(uri); + return retrieve(request); + } + public Mono put(String uri, String body) { return putForEntity(uri, body) // .flatMap(this::toBody); diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java index bf787427..4db3ade5 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java @@ -42,7 +42,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -145,7 +144,7 @@ public class ServiceController { value = { // @ApiResponse(code = 200, message = "Service supervision timer refreshed, OK"), @ApiResponse(code = 404, message = "The service is not found, needs re-registration")}) - @PostMapping("/services/keepalive") + @PutMapping("/services/keepalive") public ResponseEntity keepAliveService(// @RequestParam(name = "name", required = true) String serviceName) { try { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java index e985fd39..54b108e7 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java @@ -146,7 +146,7 @@ public class RicSynchronizationTask { } private Flux deleteAllPolicyInstances(Ric ric, Throwable t) { - logger.warn("Recreation of policies failed for ric: {}, reason: {}", ric.name(), t.getMessage()); + logger.debug("Recreation of policies failed for ric: {}, reason: {}", ric.name(), t.getMessage()); deleteAllPoliciesInRepository(ric); Flux synchronizedTypes = this.a1ClientFactory.createA1Client(ric) // diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index 4a7adf50..9b73892b 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -542,7 +542,7 @@ public class ApplicationTest { // Keep alive url = "/services/keepalive?name=name"; - ResponseEntity entity = restClient().postForEntity(url, null).block(); + ResponseEntity entity = restClient().putForEntity(url).block(); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); // DELETE service @@ -552,7 +552,7 @@ public class ApplicationTest { assertThat(services.size()).isEqualTo(0); // Keep alive, no registerred service - testErrorCode(restClient().post("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND); + testErrorCode(restClient().put("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND); // PUT servive with bad payload testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientFactoryTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientFactoryTest.java index 742734e5..d696770e 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientFactoryTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientFactoryTest.java @@ -115,10 +115,10 @@ public class A1ClientFactoryTest { StepVerifier.create(factoryUnderTest.createA1Client(ric)) // .expectSubscription() // - .expectErrorMatches(throwable -> throwable.getMessage().equals(EXCEPTION_MESSAGE)) // + .expectError() // .verify(); - assertEquals(A1ProtocolType.UNKNOWN, ric.getProtocolVersion(), "Not correct protocol"); + assertEquals(A1ProtocolType.UNKNOWN, ric.getProtocolVersion(), "Protocol negotiation failed for " + ric.name()); } private A1Client createClient(A1ProtocolType version) throws ServiceException { diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java index e8f0ec94..e24867b7 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java @@ -40,6 +40,7 @@ import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -52,6 +53,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Properties; import java.util.Vector; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -77,6 +79,7 @@ import org.oransc.policyagent.repository.Ric; import org.oransc.policyagent.repository.Rics; import org.oransc.policyagent.repository.Services; import org.oransc.policyagent.utils.LoggingUtils; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSynchronizationTaskTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSynchronizationTaskTest.java index 1fae425a..7360ff48 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSynchronizationTaskTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSynchronizationTaskTest.java @@ -265,7 +265,7 @@ public class RicSynchronizationTaskTest { synchronizerUnderTest.run(RIC_1); verifyCorrectLogMessage(0, logAppender, - "Recreation of policies failed for ric: " + RIC_1_NAME + ", reason: " + originalErrorMessage); + "Synchronization failure for ric: " + RIC_1_NAME + ", reason: " + originalErrorMessage); verify(a1ClientMock, times(2)).deleteAllPolicies(); verifyNoMoreInteractions(a1ClientMock); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1Client.java b/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1Client.java index 0fa5be4f..fc0eba35 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1Client.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1Client.java @@ -20,6 +20,7 @@ package org.oransc.policyagent.utils; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.List; import java.util.Vector; @@ -29,6 +30,8 @@ import org.oransc.policyagent.repository.Policies; import org.oransc.policyagent.repository.Policy; import org.oransc.policyagent.repository.PolicyType; import org.oransc.policyagent.repository.PolicyTypes; +import org.springframework.http.HttpStatus; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -114,6 +117,13 @@ public class MockA1Client implements A1Client { } } + Mono monoError(String responseBody, HttpStatus status) { + byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8); + WebClientResponseException a1Exception = new WebClientResponseException(status.value(), + status.getReasonPhrase(), null, responseBodyBytes, StandardCharsets.UTF_8, null); + return Mono.error(a1Exception); + } + @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests. private void sleep() { try { -- 2.16.6