Added RIC state to RicInfo in the agent NBI

Change-Id: Ice8d3ee829c38e58d2f2808a8d0453024e250bbc
Issue-ID: NONRTRIC-164
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java
index 0991605..3240cdd 100644
--- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java
+++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java
@@ -268,7 +268,7 @@
     }
 
     private Mono<Object> assertRicStateIdle(Ric ric) {
-        if (ric.getState() == Ric.RicState.IDLE) {
+        if (ric.getState() == Ric.RicState.AVAILABLE) {
             return Mono.just("OK");
         } else {
             RejectionException e = new RejectionException(
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java
index 5a63571..c75270e 100644
--- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java
+++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/RicInfo.java
@@ -39,9 +39,13 @@
     @ApiModelProperty(value = "supported policy types")
     public final Collection<String> policyTypes;
 
-    RicInfo(String name, Collection<String> managedElementIds, Collection<String> policyTypes) {
+    @ApiModelProperty(value = "state info")
+    public final String state;
+
+    RicInfo(String name, Collection<String> managedElementIds, Collection<String> policyTypes, String state) {
         this.ricName = name;
         this.managedElementIds = managedElementIds;
         this.policyTypes = policyTypes;
+        this.state = state;
     }
 }
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 b7b1c30..1064c6f 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
@@ -97,7 +97,8 @@
         List<RicInfo> result = new ArrayList<>();
         for (Ric ric : rics.getRics()) {
             if (supportingPolicyType == null || ric.isSupportingType(supportingPolicyType)) {
-                result.add(new RicInfo(ric.name(), ric.getManagedElementIds(), ric.getSupportedPolicyTypeNames()));
+                result.add(new RicInfo(ric.name(), ric.getManagedElementIds(), ric.getSupportedPolicyTypeNames(),
+                    ric.getState().toString()));
             }
         }
 
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java
index 0242b90..77dc980 100644
--- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java
+++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java
@@ -38,7 +38,7 @@
 
     @Setter
     private RicConfig ricConfig;
-    private RicState state = RicState.UNDEFINED;
+    private RicState state = RicState.UNAVAILABLE;
     private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
     @Getter
     @Setter
@@ -144,11 +144,11 @@
         /**
          * The agent view of the Ric may be inconsistent.
          */
-        UNDEFINED,
+        UNAVAILABLE,
         /**
          * The normal state. Policies can be configured.
          */
-        IDLE,
+        AVAILABLE,
         /**
          * The agent is synchronizing the view of the Ric.
          */
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java
index ba050df..c2dd18e 100644
--- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java
+++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java
@@ -115,7 +115,7 @@
     }
 
     private Mono<RicData> checkRicState(RicData ric) {
-        if (ric.ric.getState() == RicState.UNDEFINED) {
+        if (ric.ric.getState() == RicState.UNAVAILABLE) {
             return startSynchronization(ric) //
                 .onErrorResume(t -> Mono.empty());
         } else if (ric.ric.getState() == RicState.SYNCHRONIZING) {
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 54b108e..ae91d4b 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
@@ -89,7 +89,7 @@
                 @Override
                 protected void hookOnError(Throwable throwable) {
                     logger.warn("Synchronization failure for ric: {}, reason: {}", ric.name(), throwable.getMessage());
-                    ric.setState(RicState.UNDEFINED);
+                    ric.setState(RicState.UNAVAILABLE);
                 }
 
                 @Override
@@ -126,7 +126,7 @@
 
     private void onSynchronizationComplete(Ric ric) {
         logger.debug("Synchronization completed for: {}", ric.name());
-        ric.setState(RicState.IDLE);
+        ric.setState(RicState.AVAILABLE);
         notifyAllServices("Synchronization completed for:" + ric.name());
     }
 
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 9b73892..19e0425 100644
--- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
+++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
@@ -184,7 +184,7 @@
             ric.getLock().lockBlocking(LockType.EXCLUSIVE);
             ric.getLock().unlockBlocking();
             assertThat(ric.getLock().getLockCounter()).isEqualTo(0);
-            assertThat(ric.getState()).isEqualTo(Ric.RicState.IDLE);
+            assertThat(ric.getState()).isEqualTo(Ric.RicState.AVAILABLE);
         }
     }
 
@@ -211,7 +211,7 @@
 
     @Test
     public void testSynchronization() throws Exception {
-        addRic("ric").setState(Ric.RicState.UNDEFINED);
+        addRic("ric").setState(Ric.RicState.UNAVAILABLE);
         String ricName = "ric";
         Policy policy2 = addPolicy("policyId2", "typeName", "service", ricName);
 
@@ -222,7 +222,7 @@
         Policy policy = addPolicy(policyId, "typeName", "service", ricName); // This should be created in the RIC
         supervision.checkAllRics(); // The created policy should be put in the RIC
         await().untilAsserted(() -> RicState.SYNCHRONIZING.equals(rics.getRic(ricName).getState()));
-        await().untilAsserted(() -> RicState.IDLE.equals(rics.getRic(ricName).getState()));
+        await().untilAsserted(() -> RicState.AVAILABLE.equals(rics.getRic(ricName).getState()));
 
         Policies ricPolicies = getA1Client(ricName).getPolicies();
         assertThat(ricPolicies.size()).isEqualTo(1);
@@ -266,7 +266,7 @@
 
         String url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
         final String policyBody = jsonString();
-        this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
+        this.rics.getRic(ricName).setState(Ric.RicState.AVAILABLE);
 
         restClient().put(url, policyBody).block();
 
@@ -290,7 +290,7 @@
         url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
         this.rics.getRic(ricName).setState(Ric.RicState.SYNCHRONIZING);
         testErrorCode(restClient().put(url, policyBody), HttpStatus.LOCKED);
-        this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
+        this.rics.getRic(ricName).setState(Ric.RicState.AVAILABLE);
     }
 
     @Test
@@ -718,7 +718,7 @@
             .controllerName("") //
             .build();
         Ric ric = new Ric(conf);
-        ric.setState(Ric.RicState.IDLE);
+        ric.setState(Ric.RicState.AVAILABLE);
         this.rics.put(ric);
         return ric;
     }
diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSupervisionTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSupervisionTest.java
index 3f8dd06..0a5b27b 100644
--- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSupervisionTest.java
+++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RicSupervisionTest.java
@@ -108,7 +108,7 @@
         types.clear();
         policies.clear();
         rics.clear();
-        RIC_1.setState(RicState.UNDEFINED);
+        RIC_1.setState(RicState.UNAVAILABLE);
         RIC_1.clearSupportedPolicyTypes();
     }
 
@@ -123,7 +123,7 @@
 
     @Test
     public void whenRicIdleAndNoChangedPoliciesOrPolicyTypes_thenNoSynchronization() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
         rics.put(RIC_1);
 
@@ -144,7 +144,7 @@
 
     @Test
     public void whenRicUndefined_thenSynchronization() {
-        RIC_1.setState(RicState.UNDEFINED);
+        RIC_1.setState(RicState.UNAVAILABLE);
         rics.put(RIC_1);
 
         RicSupervision supervisorUnderTest = spy(new RicSupervision(rics, policies, a1ClientFactory, types, null));
@@ -174,7 +174,7 @@
 
     @Test
     public void whenRicIdleAndErrorGettingPolicyIdentities_thenNoSynchronization() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
         rics.put(RIC_1);
 
@@ -189,7 +189,7 @@
 
     @Test
     public void whenRicIdleAndNotSameAmountOfPolicies_thenSynchronization() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         rics.put(RIC_1);
 
         policies.put(POLICY_1);
@@ -211,7 +211,7 @@
 
     @Test
     public void whenRicIdleAndSameAmountOfPoliciesButNotSamePolicies_thenSynchronization() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         rics.put(RIC_1);
 
         policies.put(POLICY_1);
@@ -233,7 +233,7 @@
 
     @Test
     public void whenRicIdleAndErrorGettingPolicyTypes_thenNoSynchronization() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
         rics.put(RIC_1);
 
@@ -249,7 +249,7 @@
 
     @Test
     public void whenRicIdleAndNotSameAmountOfPolicyTypes_thenSynchronization() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
         rics.put(RIC_1);
 
@@ -277,7 +277,7 @@
             .schema("") //
             .build();
 
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
         RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
         RIC_1.addSupportedPolicyType(policyType2);
         rics.put(RIC_1);
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 7360ff4..f6d2ade 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
@@ -108,7 +108,7 @@
         policyTypes = new PolicyTypes();
         policies = new Policies();
         services = new Services();
-        RIC_1.setState(RicState.UNDEFINED);
+        RIC_1.setState(RicState.UNAVAILABLE);
         RIC_1.clearSupportedPolicyTypes();
     }
 
@@ -135,7 +135,7 @@
 
     @Test
     public void ricIdlePolicyTypeInRepo_thenSynchronizationWithReuseOfTypeFromRepoAndCorrectServiceNotified() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
 
         policyTypes.put(POLICY_TYPE_1);
 
@@ -166,12 +166,12 @@
 
         assertThat(policyTypes.size()).isEqualTo(1);
         assertThat(policies.size()).isEqualTo(0);
-        assertThat(RIC_1.getState()).isEqualTo(RicState.IDLE);
+        assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
     }
 
     @Test
     public void ricIdlePolicyTypeNotInRepo_thenSynchronizationWithTypeFromRic() throws Exception {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
 
         setUpCreationOfA1Client();
         simulateRicWithOnePolicyType();
@@ -189,12 +189,12 @@
         assertThat(policyTypes.size()).isEqualTo(1);
         assertThat(policyTypes.getType(POLICY_TYPE_1_NAME).schema()).isEqualTo(typeSchema);
         assertThat(policies.size()).isEqualTo(0);
-        assertThat(RIC_1.getState()).isEqualTo(RicState.IDLE);
+        assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
     }
 
     @Test
     public void ricIdleAndHavePolicies_thenSynchronizationWithRecreationOfPolicies() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
 
         policies.put(POLICY_1);
 
@@ -215,12 +215,12 @@
 
         assertThat(policyTypes.size()).isEqualTo(0);
         assertThat(policies.size()).isEqualTo(1);
-        assertThat(RIC_1.getState()).isEqualTo(RicState.IDLE);
+        assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
     }
 
     @Test
     public void ricIdleAndErrorDeletingPoliciesFirstTime_thenSynchronizationWithDeletionOfPolicies() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
 
         policies.put(POLICY_1);
 
@@ -241,12 +241,12 @@
 
         assertThat(policyTypes.size()).isEqualTo(0);
         assertThat(policies.size()).isEqualTo(0);
-        assertThat(RIC_1.getState()).isEqualTo(RicState.IDLE);
+        assertThat(RIC_1.getState()).isEqualTo(RicState.AVAILABLE);
     }
 
     @Test
     public void ricIdleAndErrorDeletingPoliciesAllTheTime_thenSynchronizationWithFailedRecovery() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
 
         policies.put(POLICY_1);
 
@@ -272,12 +272,12 @@
 
         assertThat(policyTypes.size()).isEqualTo(0);
         assertThat(policies.size()).isEqualTo(0);
-        assertThat(RIC_1.getState()).isEqualTo(RicState.UNDEFINED);
+        assertThat(RIC_1.getState()).isEqualTo(RicState.UNAVAILABLE);
     }
 
     @Test
     public void ricIdlePolicyTypeInRepo_thenSynchronizationWithErrorOnServiceNotificationErrorLogged() {
-        RIC_1.setState(RicState.IDLE);
+        RIC_1.setState(RicState.AVAILABLE);
 
         policyTypes.put(POLICY_TYPE_1);