aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-kserve
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-02 12:36:45 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-06-06 08:32:42 +0000
commitd58c0ca04ae993702b2c399afd52b01e503ec0fe (patch)
tree45ab9c6019c79ed3a0814258e06d98219787f03d /participant/participant-impl/participant-impl-kserve
parentebb4d0cf867d752ae148880dd0109fc3cf6d6025 (diff)
Add Failure handling support in all ACM-participants
In any transition (like deploy, undeploy,  lock, unlock, update, delete) a participant should respond with the final state of transition, a status indicator (stateChaneResult) indicating if error has occurred and a message. Issue-ID: POLICY-4706 Change-Id: I424bc6d620f476392baee8904e21d3a6c7aa8d6b Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-kserve')
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java61
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java51
2 files changed, 92 insertions, 20 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 6fdb16e53..4d556579d 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
@@ -24,6 +24,7 @@ import io.kubernetes.client.openapi.ApiException;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
@@ -45,7 +46,11 @@ 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.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
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.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -75,7 +80,6 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Getter(AccessLevel.PACKAGE)
private final Map<UUID, ConfigurationEntity> configRequestMap = new HashMap<>();
-
private static class ThreadConfig {
private int uninitializedToPassiveTimeout = 60;
@@ -93,7 +97,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
}
configRequestMap.remove(automationCompositionElementId);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed");
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Undeployed");
} catch (IOException | ApiException exception) {
LOGGER.warn("Deletion of Inference service failed", exception);
}
@@ -130,7 +135,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
if (isAllInferenceSvcDeployed) {
configRequestMap.put(element.getId(), configurationEntity);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
} else {
LOGGER.error("Inference Service deployment failed");
}
@@ -152,19 +157,55 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* Check the status of Inference Service.
*
* @param inferenceServiceName name of the inference service
- * @param namespace kubernetes namespace
- * @param timeout Inference service time check
- * @param statusCheckInterval Status check time interval
+ * @param namespace kubernetes namespace
+ * @param timeout Inference service time check
+ * @param statusCheckInterval Status check time interval
* @return status of the inference service
- * @throws ExecutionException Exception on execution
+ * @throws ExecutionException Exception on execution
* @throws InterruptedException Exception on inference service status check
*/
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, statusCheckInterval,
- kserveClient), "Done");
+ Future<String> result = executor.submit(new InferenceServiceValidator(inferenceServiceName, namespace, timeout,
+ statusCheckInterval, kserveClient), "Done");
return (!result.get().isEmpty()) && result.isDone();
}
+
+ @Override
+ public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Override
+ public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Override
+ public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null,
+ StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Override
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Override
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
+ throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Override
+ public void deprime(UUID compositionId) throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
}
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 63ad3ef14..38db1b8c1 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
@@ -31,6 +31,8 @@ import static org.mockito.Mockito.mock;
import io.kubernetes.client.openapi.ApiException;
import java.io.IOException;
+import java.util.List;
+import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@@ -83,8 +85,8 @@ class AcElementHandlerTest {
@BeforeEach
void startMocks() throws ExecutionException, InterruptedException, IOException, ApiException {
doReturn(true).when(kserveClient).deployInferenceService(any(), any());
- doReturn(true).when(automationCompositionElementHandler)
- .checkInferenceServiceStatus(any(), any(), anyInt(), anyInt());
+ doReturn(true).when(automationCompositionElementHandler).checkInferenceServiceStatus(any(), any(), anyInt(),
+ anyInt());
}
@Test
@@ -93,7 +95,6 @@ class AcElementHandlerTest {
var element = commonTestData.getAutomationCompositionElement();
var automationCompositionElementId = element.getId();
-
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
@@ -108,11 +109,9 @@ class AcElementHandlerTest {
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());
+ 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());
@@ -131,8 +130,40 @@ class AcElementHandlerTest {
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));
+ }
+
+ @Test
+ void testUpdate() throws PfModelException {
+ var automationCompositionId = commonTestData.getAutomationCompositionId();
+ var element = commonTestData.getAutomationCompositionElement();
assertDoesNotThrow(
- () -> automationCompositionElementHandler.checkInferenceServiceStatus("sklearn-iris", "kserve-test", 1,
- 1));
+ () -> automationCompositionElementHandler.update(automationCompositionId, element, Map.of()));
+ }
+
+ @Test
+ void testLock() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.lock(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testUnlock() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.unlock(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testDelete() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.delete(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testPrime() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.prime(UUID.randomUUID(), List.of()));
+ }
+
+ @Test
+ void testDeprime() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
}
}