From 80111fe3c4c1e2e145485c2f2a833bdaabb3a680 Mon Sep 17 00:00:00 2001 From: "aravind.est" Date: Mon, 6 Mar 2023 16:29:58 +0000 Subject: Add log message when kserve setup is unavailable and improve coverage Add log message when kserve setup is unavailable. Improve code coverage. Issue-ID: POLICY-4525 Signed-off-by: aravind.est Change-Id: If92fc38ceb8e3427e4b2c6045d2fd3ffcc106198 --- .../AutomationCompositionElementHandler.java | 5 +++-- .../kserve/k8s/InferenceServiceValidator.java | 11 ++++++++--- .../kserve/handler/AcElementHandlerTest.java | 21 +++++++++++++++++++-- .../kserve/k8s/InferenceServiceValidatorTest.java | 2 +- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java index 07fbce80c..a6e1c9cbc 100755 --- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java +++ b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java @@ -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 configRequestMap = new HashMap<>(); + @Getter(AccessLevel.PACKAGE) + private final Map configRequestMap = new HashMap<>(); private static class ThreadConfig { diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidator.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidator.java index 5cffa48f8..bbf00b4cd 100755 --- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidator.java +++ b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidator.java @@ -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"); + } } } } diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java index d8a896ef8..63ad3ef14 100755 --- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java @@ -20,14 +20,18 @@ 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 diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java index 3ef89a7c1..6f1b8c433 100755 --- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java +++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java @@ -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 -- cgit 1.2.3-korg