diff options
author | 2024-06-14 14:10:58 +0100 | |
---|---|---|
committer | 2024-06-17 09:04:18 +0000 | |
commit | ca2ee94054c580827fcfc7f07c9db641301d6b9a (patch) | |
tree | 837edef253934aa10a09ecafa5819035b9ca0097 /participant/participant-impl/participant-impl-kserve/src/test | |
parent | b52e095b34ee7c576f7ee83df05e2a09366a8c8a (diff) |
Remove restarting implementation from participants
Remove restarting implementation from participants and
Remove local Map from a1pms and kserve participants.
Issue-ID: POLICY-5046
Change-Id: I9cc2a33d603751c60007475414b45ca54f0aac25
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-kserve/src/test')
4 files changed, 119 insertions, 170 deletions
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 07dc021b1..ccdb31f82 100644 --- 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ 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; @@ -28,51 +27,26 @@ 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 static org.mockito.Mockito.spy; import io.kubernetes.client.openapi.ApiException; +import jakarta.validation.ValidationException; import java.io.IOException; -import java.util.List; +import java.util.HashMap; import java.util.Map; -import java.util.UUID; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException; import org.onap.policy.clamp.acm.participant.kserve.k8s.KserveClient; import org.onap.policy.clamp.acm.participant.kserve.utils.CommonTestData; import org.onap.policy.clamp.acm.participant.kserve.utils.ToscaUtils; -import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -import org.onap.policy.clamp.models.acm.concepts.DeployState; -import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(SpringExtension.class) class AcElementHandlerTest { - private final KserveClient kserveClient = mock(KserveClient.class); - - private ParticipantIntermediaryApi participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); - - @InjectMocks - @Spy - private AutomationCompositionElementHandler automationCompositionElementHandler = - new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient); - - @Mock - private ExecutorService executor; - @Mock - private Future<String> result; - private final CommonTestData commonTestData = new CommonTestData(); private static ToscaServiceTemplate serviceTemplate; @@ -84,137 +58,104 @@ class AcElementHandlerTest { serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca(); } - @BeforeEach - void startMocks() throws ExecutionException, InterruptedException, IOException, ApiException { - doReturn(true).when(kserveClient).deployInferenceService(any(), any()); - doReturn(true).when(automationCompositionElementHandler).checkInferenceServiceStatus(any(), any(), anyInt(), - anyInt()); - } - @Test - void test_automationCompositionElementStateChange() throws PfModelException { - var automationCompositionId = commonTestData.getAutomationCompositionId(); - var element = commonTestData.getAutomationCompositionElement(); - var automationCompositionElementId = element.getId(); - + void test_automationCompositionElementStateChange() + throws ExecutionException, InterruptedException, IOException, ApiException { var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element, + var compositionElement = commonTestData.getCompositionElement( nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); - - assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(automationCompositionId, - automationCompositionElementId)); - - } - - @Test - 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())); + var kserveClient = mock(KserveClient.class); + doReturn(true).when(kserveClient).deployInferenceService(any(), any()); + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + spy(new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient)); + doReturn(true).when(automationCompositionElementHandler) + .checkInferenceServiceStatus(any(), any(), anyInt(), anyInt()); - assertThat(automationCompositionElementHandler.getConfigRequestMap().containsKey(elementId2)).isFalse(); + assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(compositionElement, element)); + assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(compositionElement, element)); } @Test - void test_checkInferenceServiceStatus() throws ExecutionException, InterruptedException { - doReturn(result).when(executor).submit(any(Runnable.class), any()); - doReturn("Done").when(result).get(); - doReturn(true).when(result).isDone(); - assertDoesNotThrow(() -> automationCompositionElementHandler.checkInferenceServiceStatus("sklearn-iris", - "kserve-test", 1, 1)); - } + void test_automationCompositionElementFailed() + throws ExecutionException, InterruptedException, IOException, ApiException { + var kserveClient = mock(KserveClient.class); + doReturn(false).when(kserveClient).deployInferenceService(any(), any()); + doReturn(false).when(kserveClient).undeployInferenceService(any(), any()); + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + spy(new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient)); + doReturn(false).when(automationCompositionElementHandler) + .checkInferenceServiceStatus(any(), any(), anyInt(), anyInt()); - @Test - void testUpdate() throws PfModelException { - var automationCompositionId = commonTestData.getAutomationCompositionId(); + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + var compositionElement = commonTestData.getCompositionElement( + nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); var element = commonTestData.getAutomationCompositionElement(); - assertDoesNotThrow( - () -> automationCompositionElementHandler.update(automationCompositionId, element, Map.of())); + assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(compositionElement, element)); + assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(compositionElement, element)); } @Test - void testLock() throws PfModelException { - assertDoesNotThrow(() -> automationCompositionElementHandler.lock(UUID.randomUUID(), UUID.randomUUID())); - } + void test_automationCompositionElementWrongData() { + var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); + var element = commonTestData.getAutomationCompositionElement(); - @Test - void testUnlock() throws PfModelException { - assertDoesNotThrow(() -> automationCompositionElementHandler.unlock(UUID.randomUUID(), UUID.randomUUID())); - } + var kserveClient = mock(KserveClient.class); + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient); - @Test - void testDelete() throws PfModelException { - assertDoesNotThrow(() -> automationCompositionElementHandler.delete(UUID.randomUUID(), UUID.randomUUID())); - } + var compositionElementEmpty = commonTestData.getCompositionElement(Map.of()); + assertThrows(ValidationException.class, + () -> automationCompositionElementHandler.deploy(compositionElementEmpty, element)); - @Test - void testPrime() throws PfModelException { - assertDoesNotThrow(() -> automationCompositionElementHandler.prime(UUID.randomUUID(), List.of())); - } + var compositionElementWrong = commonTestData.getCompositionElement(Map.of("kserveInferenceEntities", "1")); + assertThrows(KserveException.class, + () -> automationCompositionElementHandler.deploy(compositionElementWrong, element)); - @Test - void testDeprime() throws PfModelException { - assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID())); + var map = new HashMap<>(nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); + map.put("uninitializedToPassiveTimeout", " "); + var compositionElementWrong2 = commonTestData.getCompositionElement(map); + assertThrows(KserveException.class, + () -> automationCompositionElementHandler.deploy(compositionElementWrong2, element)); } @Test - void testHandleRestartComposition() throws PfModelException { - assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartComposition(UUID.randomUUID(), - List.of(), AcTypeState.PRIMED)); - } + void test_AutomationCompositionElementUpdate() + throws IOException, ApiException, ExecutionException, InterruptedException { + var kserveClient = mock(KserveClient.class); + doReturn(true).when(kserveClient).deployInferenceService(any(), any()); - @Test - void testHandleRestartInstanceDeploying() throws PfModelException { - var element = commonTestData.getAutomationCompositionElement(); + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + spy(new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient)); + doReturn(true).when(automationCompositionElementHandler) + .checkInferenceServiceStatus(any(), any(), anyInt(), anyInt()); + doThrow(new ApiException("Error installing the inference service")).when(kserveClient) + .deployInferenceService(any(), any()); var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance( - commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYING, - LockState.NONE)); - assertThat(automationCompositionElementHandler.getConfigRequestMap()).containsKey(element.getId()); - } - - @Test - void testHandleRestartInstanceDeployed() throws PfModelException { + var compositionElement = commonTestData.getCompositionElement( + nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()); var element = commonTestData.getAutomationCompositionElement(); + assertThrows(KserveException.class, + () -> automationCompositionElementHandler.deploy(compositionElement, element)); - var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance( - commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYED, - LockState.LOCKED)); - assertThat(automationCompositionElementHandler.getConfigRequestMap()).containsKey(element.getId()); } @Test - void testHandleRestartInstanceUndeployed() throws PfModelException { - var element = commonTestData.getAutomationCompositionElement(); - - var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates(); - assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance( - commonTestData.getAutomationCompositionId(), element, - nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.UNDEPLOYING, - LockState.LOCKED)); - } + void test_checkInferenceServiceStatus() throws IOException, ApiException { + var kserveClient = mock(KserveClient.class); + doReturn("True").when(kserveClient).getInferenceServiceStatus(any(), any()); + doReturn(true).when(kserveClient).deployInferenceService(any(), any()); + var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class); + var automationCompositionElementHandler = + new AutomationCompositionElementHandler(participantIntermediaryApi, kserveClient); - @Test - void testMigrate() throws PfModelException { - var automationCompositionId = commonTestData.getAutomationCompositionId(); - var element = commonTestData.getAutomationCompositionElement(); - assertDoesNotThrow(() -> automationCompositionElementHandler.migrate(automationCompositionId, element, - UUID.randomUUID(), Map.of())); + assertDoesNotThrow(() -> automationCompositionElementHandler.checkInferenceServiceStatus("sklearn-iris", + "kserve-test", 1, 1)); } } 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 6f1b8c433..5bf7bf13b 100644 --- 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,30 +24,24 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import io.kubernetes.client.openapi.ApiException; import java.io.IOException; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) class InferenceServiceValidatorTest { - private static int TIMEOUT = 2; - private static int STATUS_CHECK_INTERVAL = 1; - - @MockBean - private KserveClient kserveClient; + private static final int TIMEOUT = 2; + private static final int STATUS_CHECK_INTERVAL = 1; - String inferenceSvcName = "inference-test"; - String namespace = "test"; + private static final String inferenceSvcName = "inference-test"; + private static final String namespace = "test"; @Test void test_runningPodState() throws IOException, ApiException { + var kserveClient = mock(KserveClient.class); doReturn("True").when(kserveClient).getInferenceServiceStatus(any(), any()); var inferenceServiceValidator = new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL, @@ -57,6 +51,7 @@ class InferenceServiceValidatorTest { @Test void test_EmptyPodState() throws IOException, ApiException { + var kserveClient = mock(KserveClient.class); doReturn("").when(kserveClient).getInferenceServiceStatus(any(), any()); var inferenceServiceValidator = new InferenceServiceValidator("", namespace, TIMEOUT, STATUS_CHECK_INTERVAL, @@ -67,6 +62,7 @@ class InferenceServiceValidatorTest { @Test void test_PodFailureState() throws IOException, ApiException { + var kserveClient = mock(KserveClient.class); doReturn("False").when(kserveClient).getInferenceServiceStatus(any(), any()); var inferenceServiceValidator = new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL, diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/rest/ActuatorControllerTest.java index b7cc7b843..dbdefd25a 100644 --- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/rest/ActuatorControllerTest.java +++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/rest/ActuatorControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,39 +58,41 @@ class ActuatorControllerTest extends CommonActuatorController { } @Test - void testGetHealth_Unauthorized() throws Exception { + void testGetHealth_Unauthorized() { assertUnauthorizedActGet(HEALTH_ENDPOINT); } @Test - void testGetMetrics_Unauthorized() throws Exception { + void testGetMetrics_Unauthorized() { assertUnauthorizedActGet(METRICS_ENDPOINT); } @Test - void testGetPrometheus_Unauthorized() throws Exception { + void testGetPrometheus_Unauthorized() { assertUnauthorizedActGet(PROMETHEUS_ENDPOINT); } @Test - void testGetHealth() throws Exception { + void testGetHealth() { var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test - void testGetMetrics() throws Exception { + void testGetMetrics() { var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test - void testGePrometheus() throws Exception { + void testGePrometheus() { var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } - } diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonTestData.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonTestData.java index 440018d3f..18f314c62 100644 --- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonTestData.java +++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonTestData.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * Modifications Copyright (C) 2022 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,9 +22,10 @@ package org.onap.policy.clamp.acm.participant.kserve.utils; import java.util.List; +import java.util.Map; import java.util.UUID; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; public class CommonTestData { @@ -34,16 +35,25 @@ public class CommonTestData { private static final List<UUID> AC_ID_LIST = List.of(UUID.randomUUID(), UUID.randomUUID()); /** - * Get a automationComposition Element. + * Get a new InstanceElement. * - * @return automationCompositionElement object + * @return InstanceElementDto object */ - public AcElementDeploy getAutomationCompositionElement() { - var element = new AcElementDeploy(); - element.setId(UUID.randomUUID()); - element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1")); - element.setOrderedState(DeployOrder.DEPLOY); - return element; + public InstanceElementDto getAutomationCompositionElement() { + return new InstanceElementDto( + getAutomationCompositionId(), UUID.randomUUID(), null, Map.of(), Map.of()); + } + + /** + * Get a new CompositionElement. + * + * @param properties common properties from service template + * @return CompositionElementDto object + */ + public CompositionElementDto getCompositionElement(Map<String, Object> properties) { + return new CompositionElementDto(UUID.randomUUID(), + new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1"), + properties, Map.of()); } /** |