Add log message when kserve setup is unavailable and improve coverage 55/133555/1
authoraravind.est <aravindhan.a@est.tech>
Mon, 6 Mar 2023 16:29:58 +0000 (16:29 +0000)
committeraravind.est <aravindhan.a@est.tech>
Mon, 6 Mar 2023 17:00:45 +0000 (17:00 +0000)
Add log message when kserve setup is unavailable.
Improve code coverage.

Issue-ID: POLICY-4525
Signed-off-by: aravind.est <aravindhan.a@est.tech>
Change-Id: If92fc38ceb8e3427e4b2c6045d2fd3ffcc106198

participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidator.java
participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java

index 07fbce8..a6e1c9c 100755 (executable)
@@ -32,6 +32,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import javax.validation.Validation;
 import javax.validation.ValidationException;
+import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.Setter;
@@ -72,8 +73,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
 
     private final KserveClient kserveClient;
 
-    @Getter
-    private static final Map<UUID, ConfigurationEntity> configRequestMap = new HashMap<>();
+    @Getter(AccessLevel.PACKAGE)
+    private final Map<UUID, ConfigurationEntity> configRequestMap = new HashMap<>();
 
 
     private static class ThreadConfig {
index 5cffa48..bbf00b4 100755 (executable)
@@ -81,11 +81,12 @@ public class InferenceServiceValidator implements Runnable {
     private void verifyInferenceServiceStatus()
             throws KserveException, IOException, InterruptedException, ApiException {
         var isVerified = false;
+        String isvcStatus = null;
         long endTime = System.currentTimeMillis() + (timeout * 1000L);
 
         while (!isVerified && System.currentTimeMillis() < endTime) {
-            var output = kserveClient.getInferenceServiceStatus(namespace, inferenceServiceName);
-            isVerified = output.equalsIgnoreCase(Boolean.TRUE.toString());
+            isvcStatus = kserveClient.getInferenceServiceStatus(namespace, inferenceServiceName);
+            isVerified = isvcStatus.equalsIgnoreCase(Boolean.TRUE.toString());
             if (!isVerified) {
                 logger.info("Waiting for the inference service {} to be active ", inferenceServiceName);
                 // Recheck status of pods in specific intervals.
@@ -95,7 +96,11 @@ public class InferenceServiceValidator implements Runnable {
             }
         }
         if (!isVerified) {
-            throw new KserveException("Time out Exception verifying the status of the inference service");
+            if (isvcStatus != null && isvcStatus.isEmpty()) {
+                throw new KserveException("Kserve setup is unavailable for inference service to be deployed");
+            } else {
+                throw new KserveException("Time out Exception verifying the status of the inference service");
+            }
         }
     }
 }
index d8a896e..63ad3ef 100755 (executable)
 
 package org.onap.policy.clamp.acm.participant.kserve.handler;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 
 import io.kubernetes.client.openapi.ApiException;
 import java.io.IOException;
+import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
@@ -77,7 +81,7 @@ class AcElementHandlerTest {
     }
 
     @BeforeEach
-    void startMocks() throws KserveException, ExecutionException, InterruptedException, IOException, ApiException {
+    void startMocks() throws ExecutionException, InterruptedException, IOException, ApiException {
         doReturn(true).when(kserveClient).deployInferenceService(any(), any());
         doReturn(true).when(automationCompositionElementHandler)
                 .checkInferenceServiceStatus(any(), any(), anyInt(), anyInt());
@@ -100,13 +104,26 @@ class AcElementHandlerTest {
     }
 
     @Test
-    void test_AutomationCompositionElementUpdate() {
+    void test_AutomationCompositionElementUpdate() throws IOException, ApiException {
         var element = commonTestData.getAutomationCompositionElement();
 
         var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
         assertDoesNotThrow(
                 () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
                         nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+        assertThat(automationCompositionElementHandler.getConfigRequestMap()).hasSize(1)
+                .containsKey(element.getId());
+
+        doThrow(new ApiException("Error installing the inference service")).when(kserveClient)
+                .deployInferenceService(any(), any());
+
+        var elementId2 = UUID.randomUUID();
+        element.setId(elementId2);
+        assertThrows(KserveException.class,
+                () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
+                        nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+
+        assertThat(automationCompositionElementHandler.getConfigRequestMap().containsKey(elementId2)).isFalse();
     }
 
     @Test
index 3ef89a7..6f1b8c4 100755 (executable)
@@ -62,7 +62,7 @@ class InferenceServiceValidatorTest {
                 new InferenceServiceValidator("", namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
                         kserveClient);
         assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
-                .hasMessage("Error verifying the status of the inference service. Exiting");
+                .cause().hasMessage("Kserve setup is unavailable for inference service to be deployed");
     }
 
     @Test