Changed service keepAlive from POST to PUT 91/3191/1
authorPatrikBuhr <patrik.buhr@est.tech>
Tue, 7 Apr 2020 12:26:26 +0000 (14:26 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Tue, 7 Apr 2020 12:27:21 +0000 (14:27 +0200)
Fixed some very confusing log messages

Change-Id: I48679ba69252a09e610cdc239e2fb56554d665d9
Issue-ID: NONRTRIC-164
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
policy-agent/docs/api.yaml
policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientFactory.java
policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSynchronizationTask.java
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
policy-agent/src/test/java/org/oransc/policyagent/clients/A1ClientFactoryTest.java
policy-agent/src/test/java/org/oransc/policyagent/tasks/RefreshConfigTaskTest.java
policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSynchronizationTaskTest.java
policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1Client.java

index 3ea913d..306b15a 100644 (file)
@@ -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:
index 55abe2c..546979c 100644 (file)
@@ -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());
         }
index 83592ec..5110718 100644 (file)
@@ -101,6 +101,13 @@ public class AsyncRestClient {
         return retrieve(request);
     }
 
+    public Mono<ResponseEntity<String>> putForEntity(String uri) {
+        logger.debug("PUT uri = '{}{}''", baseUrl, uri);
+        RequestHeadersSpec<?> request = client.put() //
+            .uri(uri);
+        return retrieve(request);
+    }
+
     public Mono<String> put(String uri, String body) {
         return putForEntity(uri, body) //
             .flatMap(this::toBody);
index bf78742..4db3ade 100644 (file)
@@ -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<String> keepAliveService(//
         @RequestParam(name = "name", required = true) String serviceName) {
         try {
index e985fd3..54b108e 100644 (file)
@@ -146,7 +146,7 @@ public class RicSynchronizationTask {
     }
 
     private Flux<Object> 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<PolicyType> synchronizedTypes = this.a1ClientFactory.createA1Client(ric) //
index 4a7adf5..9b73892 100644 (file)
@@ -542,7 +542,7 @@ public class ApplicationTest {
 
         // Keep alive
         url = "/services/keepalive?name=name";
-        ResponseEntity<String> entity = restClient().postForEntity(url, null).block();
+        ResponseEntity<String> 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);
index 742734e..d696770 100644 (file)
@@ -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 {
index e8f0ec9..e24867b 100644 (file)
@@ -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;
index 1fae425..7360ff4 100644 (file)
@@ -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);
index 0fa5be4..fc0eba3 100644 (file)
@@ -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<String> 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 {