Changed service keepAlive from POST to PUT
Fixed some very confusing log messages
Change-Id: I48679ba69252a09e610cdc239e2fb56554d665d9
Issue-ID: NONRTRIC-164
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
diff --git a/policy-agent/docs/api.yaml b/policy-agent/docs/api.yaml
index 3ea913d..306b15a 100644
--- a/policy-agent/docs/api.yaml
+++ b/policy-agent/docs/api.yaml
@@ -135,7 +135,7 @@
schema:
type: string
'423':
- description: RIC is locked
+ description: RIC is not operational
schema:
type: string
deprecated: false
@@ -170,7 +170,7 @@
schema:
type: string
'423':
- description: RIC is locked
+ description: RIC is not operational
schema:
type: string
deprecated: false
@@ -342,7 +342,7 @@
- name: managedElementId
in: query
description: managedElementId
- required: false
+ required: true
type: string
responses:
'200':
@@ -415,7 +415,7 @@
schema:
type: string
'400':
- description: Cannot parse the ServiceRegistrationInfo
+ description: The ServiceRegistrationInfo is not accepted
schema:
type: string
'401':
@@ -487,11 +487,11 @@
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 55abe2c..546979c 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 @@
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 @@
.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 83592ec..5110718 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 @@
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);
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 bf78742..4db3ade 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.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 @@
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 {
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 e985fd3..54b108e 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 @@
}
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) //
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 4a7adf5..9b73892 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 @@
// 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 @@
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 742734e..d696770 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 @@
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 e8f0ec9..e24867b 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.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.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.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 1fae425..7360ff4 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 @@
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 0fa5be4..fc0eba3 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.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 @@
}
}
+ 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 {