summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2020-10-12 09:59:34 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2020-10-12 10:00:10 +0200
commit4e948fe8cfed4cb6a9d48f3588962aab9bbb4e3d (patch)
tree0ef3c27307f4dd5fe98806a0b32c385f1d199c8d /a1-policy-management/src
parent672d820b5807e6b2f9378359e8de817622d0d31c (diff)
Improvent of usage of AsynchRestClient
Change-Id: I34ce159abacde85cfe7631402491e457d30c7097 Issue-ID: CCSDK-2502 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java7
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java7
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java5
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java33
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java4
5 files changed, 29 insertions, 27 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
index 0fee08cf..e4d7d8d7 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
@@ -39,6 +39,7 @@ import lombok.AccessLevel;
import lombok.Getter;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig.RicConfigUpdate;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
@@ -92,6 +93,7 @@ public class RefreshConfigTask {
private final Policies policies;
private final Services services;
private final PolicyTypes policyTypes;
+ private final AsyncRestClientFactory restClientFactory;
@Autowired
public RefreshConfigTask(ApplicationConfig appConfig, Rics rics, Policies policies, Services services,
@@ -102,6 +104,7 @@ public class RefreshConfigTask {
this.services = services;
this.policyTypes = policyTypes;
this.a1ClientFactory = a1ClientFactory;
+ this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig());
}
public void start() {
@@ -199,7 +202,7 @@ public class RefreshConfigTask {
private void removePoliciciesInRic(@Nullable Ric ric) {
if (ric != null) {
RicSynchronizationTask synch =
- new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, appConfig);
+ new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory);
synch.run(ric);
}
}
@@ -234,7 +237,7 @@ public class RefreshConfigTask {
void runRicSynchronization(Ric ric) {
RicSynchronizationTask synchronizationTask =
- new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, appConfig);
+ new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory);
synchronizationTask.run(ric);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java
index 5ff6d191..cae257cd 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervision.java
@@ -24,6 +24,7 @@ import java.util.Collection;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock.LockType;
@@ -59,7 +60,7 @@ public class RicSupervision {
private final PolicyTypes policyTypes;
private final A1ClientFactory a1ClientFactory;
private final Services services;
- private final ApplicationConfig config;
+ private final AsyncRestClientFactory restClientFactory;
private static class SynchStartedException extends ServiceException {
private static final long serialVersionUID = 1L;
@@ -91,7 +92,7 @@ public class RicSupervision {
this.a1ClientFactory = a1ClientFactory;
this.policyTypes = policyTypes;
this.services = services;
- this.config = config;
+ this.restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
}
/**
@@ -210,6 +211,6 @@ public class RicSupervision {
}
RicSynchronizationTask createSynchronizationTask() {
- return new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, config);
+ return new RicSynchronizationTask(a1ClientFactory, policyTypes, policies, services, restClientFactory);
}
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java
index df0771cb..cf7ca74e 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java
@@ -26,7 +26,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicyType;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock.LockType;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
@@ -69,12 +68,12 @@ public class RicSynchronizationTask {
private final AsyncRestClientFactory restClientFactory;
public RicSynchronizationTask(A1ClientFactory a1ClientFactory, PolicyTypes policyTypes, Policies policies,
- Services services, ApplicationConfig config) {
+ Services services, AsyncRestClientFactory restClientFactory) {
this.a1ClientFactory = a1ClientFactory;
this.policyTypes = policyTypes;
this.policies = policies;
this.services = services;
- this.restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
+ this.restClientFactory = restClientFactory;
}
public void run(Ric ric) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
index 90292d30..ca5a6192 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
@@ -43,6 +43,7 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicyType;
@@ -137,8 +138,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_1_ID)));
setUpGetPolicyTypeIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_TYPE_1_NAME)));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
supervisorUnderTest.checkAllRics();
@@ -152,8 +152,7 @@ class RicSupervisionTest {
RIC_1.setState(RicState.UNAVAILABLE);
rics.put(RIC_1);
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -171,8 +170,7 @@ class RicSupervisionTest {
RIC_1.setState(RicState.SYNCHRONIZING);
rics.put(RIC_1);
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
supervisorUnderTest.checkAllRics();
@@ -189,8 +187,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new Exception("Failed"));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
@@ -209,8 +206,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_1_ID)));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -233,8 +229,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_1_ID, "Another_policy")));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -256,8 +251,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(Collections.emptyList());
setUpGetPolicyTypeIdentitiesToReturn(new Exception("Failed"));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
supervisorUnderTest.checkAllRics();
verify(supervisorUnderTest).checkAllRics();
@@ -276,8 +270,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(Collections.emptyList());
setUpGetPolicyTypeIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_TYPE_1_NAME, "another_policy_type")));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -305,8 +298,7 @@ class RicSupervisionTest {
setUpGetPolicyIdentitiesToReturn(Collections.emptyList());
setUpGetPolicyTypeIdentitiesToReturn(new ArrayList<>(Arrays.asList(POLICY_TYPE_1_NAME, "another_policy_type")));
- RicSupervision supervisorUnderTest =
- spy(new RicSupervision(rics, policies, a1ClientFactory, types, null, null));
+ RicSupervision supervisorUnderTest = spy(createRicSupervision());
doReturn(synchronizationTaskMock).when(supervisorUnderTest).createSynchronizationTask();
@@ -335,4 +327,9 @@ class RicSupervisionTest {
when(a1ClientMock.getPolicyTypeIdentities()).thenReturn(Mono.error((Exception) returnValue));
}
}
+
+ private RicSupervision createRicSupervision() {
+ ApplicationConfig config = new ApplicationConfig();
+ return new RicSupervision(rics, policies, a1ClientFactory, types, null, config);
+ }
}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java
index 0a7fc850..0ac8fdb0 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java
@@ -49,6 +49,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ImmutableRicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicy;
@@ -121,7 +122,8 @@ class RicSynchronizationTaskTest {
private RicSynchronizationTask createTask() {
ApplicationConfig config = new ApplicationConfig();
- return new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services, config);
+ AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
+ return new RicSynchronizationTask(a1ClientFactoryMock, policyTypes, policies, services, restClientFactory);
};
@Test