aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-kserve
diff options
context:
space:
mode:
authorRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2024-06-17 13:35:35 +0000
committerGerrit Code Review <gerrit@onap.org>2024-06-17 13:35:35 +0000
commit94328f3eb1b573193eb3d201368efee0b9fbb0b6 (patch)
tree154f20a158682d53b2a0051a0ed5187b922fd11c /participant/participant-impl/participant-impl-kserve
parent8c76c17a2d589d4e94571f4b6dce40261c0bb62d (diff)
parentca2ee94054c580827fcfc7f07c9db641301d6b9a (diff)
Merge "Remove restarting implementation from participants"
Diffstat (limited to 'participant/participant-impl/participant-impl-kserve')
-rw-r--r--participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java147
-rw-r--r--participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java205
-rw-r--r--participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java22
-rw-r--r--participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/rest/ActuatorControllerTest.java30
-rw-r--r--participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonTestData.java32
5 files changed, 189 insertions, 247 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 d4b09c923..d9c932efd 100644
--- 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
@@ -26,28 +26,23 @@ import jakarta.validation.Validation;
import jakarta.validation.ValidationException;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.util.HashMap;
import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import lombok.AccessLevel;
-import lombok.Getter;
import org.apache.http.HttpStatus;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
import org.onap.policy.clamp.acm.participant.kserve.exception.KserveException;
import org.onap.policy.clamp.acm.participant.kserve.k8s.InferenceServiceValidator;
import org.onap.policy.clamp.acm.participant.kserve.k8s.KserveClient;
import org.onap.policy.clamp.acm.participant.kserve.models.ConfigurationEntity;
import org.onap.policy.clamp.acm.participant.kserve.models.KserveInferenceEntity;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
-import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
-import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -60,20 +55,17 @@ import org.springframework.stereotype.Component;
* This class handles implementation of automationCompositionElement updates.
*/
@Component
-public class AutomationCompositionElementHandler extends AcElementListenerV1 {
+public class AutomationCompositionElementHandler extends AcElementListenerV2 {
private static final Coder CODER = new StandardCoder();
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private ExecutorService executor = Context.taskWrapping(
+ private final ExecutorService executor = Context.taskWrapping(
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
private final KserveClient kserveClient;
- @Getter(AccessLevel.PACKAGE)
- private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>();
-
public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi, KserveClient kserveClient) {
super(intermediaryApi);
this.kserveClient = kserveClient;
@@ -86,20 +78,25 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
}
@Override
- public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) {
- var configurationEntity = configRequestMap.get(automationCompositionElementId);
+ public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+ throws PfModelException {
+ Map<String, Object> properties = new HashMap<>(compositionElement.inProperties());
+ properties.putAll(instanceElement.inProperties());
+ var configurationEntity = getConfigurationEntity(properties);
if (configurationEntity != null) {
try {
for (KserveInferenceEntity kserveInferenceEntity : configurationEntity.getKserveInferenceEntities()) {
kserveClient.undeployInferenceService(kserveInferenceEntity.getNamespace(),
kserveInferenceEntity.getName());
}
- configRequestMap.remove(automationCompositionElementId);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
- "Undeployed");
+ intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.UNDEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Undeployed");
} catch (IOException | ApiException exception) {
LOGGER.warn("Deletion of Inference service failed", exception);
+ intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.DEPLOYED, null,
+ StateChangeResult.FAILED, "Undeploy Failed");
}
}
}
@@ -107,49 +104,71 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
/**
* Callback method to handle an update on an automation composition element.
*
- * @param automationCompositionId the ID of the automation composition
- * @param element the information on the automation composition element
- * @param properties properties Map
+ * @param compositionElement the information of the Automation Composition Definition Element
+ * @param instanceElement the information of the Automation Composition Instance Element
+ * @throws PfModelException if error occurs
*/
@Override
- public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
+ public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
throws PfModelException {
+ Map<String, Object> properties = new HashMap<>(compositionElement.inProperties());
+ properties.putAll(instanceElement.inProperties());
try {
- var configurationEntity = CODER.convert(properties, ConfigurationEntity.class);
- var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity);
- if (violations.isEmpty()) {
- boolean isAllInferenceSvcDeployed = true;
- var config = CODER.convert(properties, ThreadConfig.class);
- for (KserveInferenceEntity kserveInferenceEntity : configurationEntity.getKserveInferenceEntities()) {
- kserveClient.deployInferenceService(kserveInferenceEntity.getNamespace(),
- kserveInferenceEntity.getPayload());
-
- if (!checkInferenceServiceStatus(kserveInferenceEntity.getName(),
- kserveInferenceEntity.getNamespace(), config.uninitializedToPassiveTimeout,
- config.statusCheckInterval)) {
- isAllInferenceSvcDeployed = false;
- break;
- }
- }
- if (isAllInferenceSvcDeployed) {
- configRequestMap.put(element.getId(), configurationEntity);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- } else {
- LOGGER.error("Inference Service deployment failed");
+ var configurationEntity = getConfigurationEntity(properties);
+ boolean isAllInferenceSvcDeployed = true;
+ var config = getThreadConfig(properties);
+ for (var kserveInferenceEntity : configurationEntity.getKserveInferenceEntities()) {
+ kserveClient.deployInferenceService(kserveInferenceEntity.getNamespace(),
+ kserveInferenceEntity.getPayload());
+
+ if (!checkInferenceServiceStatus(kserveInferenceEntity.getName(),
+ kserveInferenceEntity.getNamespace(), config.uninitializedToPassiveTimeout,
+ config.statusCheckInterval)) {
+ isAllInferenceSvcDeployed = false;
+ break;
}
+ }
+ if (isAllInferenceSvcDeployed) {
+ intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Deployed");
} else {
- LOGGER.error("Violations found in the config request parameters: {}", violations);
- throw new ValidationException("Constraint violations in the config request");
+ LOGGER.error("Inference Service deployment failed");
+ intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.UNDEPLOYED, null,
+ StateChangeResult.FAILED, "Deploy Failed");
}
- } catch (CoderException e) {
- throw new KserveException(HttpStatus.SC_BAD_REQUEST, "Invalid inference service configuration", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new KserveException("Interrupt in configuring the inference service", e);
} catch (IOException | ExecutionException | ApiException e) {
throw new KserveException("Failed to configure the inference service", e);
}
+
+ }
+
+ private ConfigurationEntity getConfigurationEntity(Map<String, Object> properties) throws KserveException {
+ try {
+ var configurationEntity = CODER.convert(properties, ConfigurationEntity.class);
+ try (var validatorFactory = Validation.buildDefaultValidatorFactory()) {
+ var violations = validatorFactory.getValidator().validate(configurationEntity);
+ if (!violations.isEmpty()) {
+ LOGGER.error("Violations found in the config request parameters: {}", violations);
+ throw new ValidationException("Constraint violations in the config request");
+ }
+ }
+ return configurationEntity;
+ } catch (CoderException e) {
+ throw new KserveException(HttpStatus.SC_BAD_REQUEST, "Invalid inference service configuration", e);
+ }
+ }
+
+ private ThreadConfig getThreadConfig(Map<String, Object> properties) throws KserveException {
+ try {
+ return CODER.convert(properties, ThreadConfig.class);
+ } catch (CoderException e) {
+ throw new KserveException(HttpStatus.SC_BAD_REQUEST, "Invalid inference service configuration", e);
+ }
}
/**
@@ -166,34 +185,8 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
public boolean checkInferenceServiceStatus(String inferenceServiceName, String namespace, int timeout,
int statusCheckInterval) throws ExecutionException, InterruptedException {
// Invoke runnable thread to check pod status
- Future<String> result = executor.submit(new InferenceServiceValidator(inferenceServiceName, namespace, timeout,
+ var result = executor.submit(new InferenceServiceValidator(inferenceServiceName, namespace, timeout,
statusCheckInterval, kserveClient), "Done");
return (!result.get().isEmpty()) && result.isDone();
}
-
- @Override
- public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element,
- Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException {
- if (DeployState.DEPLOYING.equals(deployState)) {
- deploy(automationCompositionId, element, properties);
- return;
- }
- if (DeployState.UNDEPLOYING.equals(deployState) || DeployState.DEPLOYED.equals(deployState)
- || DeployState.UPDATING.equals(deployState)) {
- try {
- var configurationEntity = CODER.convert(properties, ConfigurationEntity.class);
- configRequestMap.put(element.getId(), configurationEntity);
- } catch (CoderException e) {
- throw new KserveException(HttpStatus.SC_BAD_REQUEST, "Invalid inference service configuration", e);
- }
- }
- if (DeployState.UNDEPLOYING.equals(deployState)) {
- undeploy(automationCompositionId, element.getId());
- return;
- }
- deployState = AcmUtils.deployCompleted(deployState);
- lockState = AcmUtils.lockCompleted(deployState, lockState);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(), deployState,
- lockState, StateChangeResult.NO_ERROR, "Restarted");
- }
}
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());
}
/**