aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java105
-rw-r--r--participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java209
-rw-r--r--participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java32
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java17
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java79
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java29
-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
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java78
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java79
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java24
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java53
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java18
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java60
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java53
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java64
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java74
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/rest/ActuatorControllerTest.java29
21 files changed, 367 insertions, 1072 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
index 75f3edb0a..47870ea39 100644
--- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
@@ -23,26 +23,21 @@ package org.onap.policy.clamp.acm.participant.a1pms.handler;
import jakarta.validation.Validation;
import jakarta.validation.ValidationException;
import java.lang.invoke.MethodHandles;
+import java.util.HashMap;
import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import lombok.AccessLevel;
-import lombok.Getter;
import org.apache.http.HttpStatus;
import org.onap.policy.clamp.acm.participant.a1pms.exception.A1PolicyServiceException;
import org.onap.policy.clamp.acm.participant.a1pms.models.ConfigurationEntity;
import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient;
+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.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
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;
-import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -51,7 +46,7 @@ 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();
@@ -59,10 +54,6 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
private final AcA1PmsClient acA1PmsClient;
- // Map of acElement Id and A1PMS services
- @Getter(AccessLevel.PACKAGE)
- private final Map<UUID, ConfigurationEntity> configRequestMap = new ConcurrentHashMap<>();
-
public AutomationCompositionElementHandler(ParticipantIntermediaryApi intermediaryApi,
AcA1PmsClient acA1PmsClient) {
super(intermediaryApi);
@@ -72,20 +63,21 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
/**
* Handle a automation composition element state change.
*
- * @param automationCompositionId the ID of the automation composition
- * @param automationCompositionElementId the ID of the automation composition element
+ * @param compositionElement the information of the Automation Composition Definition Element
+ * @param instanceElement the information of the Automation Composition Instance Element
* @throws A1PolicyServiceException in case of a model exception
*/
@Override
- public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId)
+ public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
throws A1PolicyServiceException {
- var configurationEntity = configRequestMap.get(automationCompositionElementId);
+ Map<String, Object> properties = new HashMap<>(compositionElement.inProperties());
+ properties.putAll(instanceElement.inProperties());
+ var configurationEntity = getConfigurationEntity(properties);
if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) {
acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities());
- 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");
} else {
LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity);
throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Unable to connect with A1PMS");
@@ -95,60 +87,45 @@ 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 A1PolicyServiceException in case of a model exception
*/
@Override
- public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
+ public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
throws A1PolicyServiceException {
+ 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()) {
- if (acA1PmsClient.isPmsHealthy()) {
- acA1PmsClient.createService(configurationEntity.getPolicyServiceEntities());
- configRequestMap.put(element.getId(), configurationEntity);
+ var configurationEntity = getConfigurationEntity(properties);
+ if (acA1PmsClient.isPmsHealthy()) {
+ acA1PmsClient.createService(configurationEntity.getPolicyServiceEntities());
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- } else {
- LOGGER.error("Failed to connect with A1PMS");
- throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE,
- "Unable to connect with A1PMS");
- }
+ 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("Failed to connect with A1PMS");
+ throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Unable to connect with A1PMS");
}
- } catch (ValidationException | CoderException | A1PolicyServiceException e) {
+ } catch (ValidationException | A1PolicyServiceException e) {
throw new A1PolicyServiceException(HttpStatus.SC_BAD_REQUEST, "Invalid Configuration", e);
}
}
- @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 (ValidationException | CoderException e) {
- throw new A1PolicyServiceException(HttpStatus.SC_BAD_REQUEST, "Invalid Configuration", e);
+ private ConfigurationEntity getConfigurationEntity(Map<String, Object> properties) throws A1PolicyServiceException {
+ 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 A1PolicyServiceException(HttpStatus.SC_BAD_REQUEST, "Invalid 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-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
index 1d3a262d6..37b102d48 100644
--- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
@@ -27,9 +27,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.List;
import java.util.Map;
-import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,11 +36,8 @@ import org.onap.policy.clamp.acm.participant.a1pms.utils.CommonTestData;
import org.onap.policy.clamp.acm.participant.a1pms.utils.ToscaUtils;
import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-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.clamp.models.acm.concepts.StateChangeResult;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class AcElementHandlerTest {
@@ -72,23 +67,22 @@ class AcElementHandlerTest {
var automationCompositionElementHandler =
new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
- var automationCompositionId = commonTestData.getAutomationCompositionId();
- var element = commonTestData.getAutomationCompositionElement();
- var automationCompositionElementId = element.getId();
-
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
+ var compositionElement = commonTestData.getCompositionElement(
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
+ var element = commonTestData.getAutomationCompositionElement();
+
+ automationCompositionElementHandler.deploy(compositionElement, element);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(element.instanceId(),
+ element.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- automationCompositionElementHandler.undeploy(automationCompositionId, automationCompositionElementId);
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+ automationCompositionElementHandler.undeploy(compositionElement, element);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(element.instanceId(),
+ element.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
- assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
- .undeploy(automationCompositionId, automationCompositionElementId));
+ assertThrows(A1PolicyServiceException.class,
+ () -> automationCompositionElementHandler.undeploy(compositionElement, element));
}
@Test
@@ -97,12 +91,14 @@ class AcElementHandlerTest {
var automationCompositionElementHandler =
new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
- var element = commonTestData.getAutomationCompositionElement();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
+ var compositionElement = commonTestData.getCompositionElement(
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ var element = commonTestData.getAutomationCompositionElement();
+
+ automationCompositionElementHandler.deploy(compositionElement, element);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(
- commonTestData.getAutomationCompositionId(), element.getId(), DeployState.DEPLOYED, null,
+ element.instanceId(), element.elementId(), DeployState.DEPLOYED, null,
StateChangeResult.NO_ERROR, "Deployed");
}
@@ -112,13 +108,14 @@ class AcElementHandlerTest {
var automationCompositionElementHandler =
new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ var compositionElement = commonTestData.getCompositionElement(
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
var element = commonTestData.getAutomationCompositionElement();
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
- var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ () -> automationCompositionElementHandler.deploy(compositionElement, element));
}
@Test
@@ -127,167 +124,9 @@ class AcElementHandlerTest {
var automationCompositionElementHandler =
new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
+ var compositionElement = commonTestData.getCompositionElement(Map.of());
var element = commonTestData.getAutomationCompositionElement();
- assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
- .deploy(commonTestData.getAutomationCompositionId(), element, Map.of()));
- }
-
- @Test
- void testLock() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- automationCompositionElementHandler.lock(automationCompositionId, elementId);
-
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
- null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
- }
-
- @Test
- void testUnlock() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- automationCompositionElementHandler.unlock(automationCompositionId, elementId);
-
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
- null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
- }
-
- @Test
- void testUpdate() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var element = commonTestData.getAutomationCompositionElement();
- automationCompositionElementHandler.update(automationCompositionId, element, Map.of());
-
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
- element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
- }
-
- @Test
- void testDelete() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- automationCompositionElementHandler.delete(automationCompositionId, elementId);
-
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
- }
-
- @Test
- void testPrime() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var compositionId = UUID.randomUUID();
- automationCompositionElementHandler.prime(compositionId, List.of());
-
- verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
- StateChangeResult.NO_ERROR, "Primed");
- }
-
- @Test
- void testDeprime() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var compositionId = UUID.randomUUID();
- automationCompositionElementHandler.deprime(compositionId);
-
- verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
- StateChangeResult.NO_ERROR, "Deprimed");
- }
-
- @Test
- void testHandleRestartComposition() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var compositionId = UUID.randomUUID();
- automationCompositionElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED);
-
- verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
- StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @Test
- void testHandleRestartInstanceDeploying() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var element = commonTestData.getAutomationCompositionElement();
- var automationCompositionElementId = element.getId();
- var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.handleRestartInstance(automationCompositionId, element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYING,
- LockState.NONE);
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- }
-
- @Test
- void testHandleRestartInstanceDeployed() throws PfModelException {
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(intermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var element = commonTestData.getAutomationCompositionElement();
- var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.handleRestartInstance(automationCompositionId, element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYED,
- LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @Test
- void testHandleRestartInstanceUndeployed() throws PfModelException {
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(intermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var element = commonTestData.getAutomationCompositionElement();
- var automationCompositionElementId = element.getId();
- var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.handleRestartInstance(automationCompositionId, element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.UNDEPLOYING,
- LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
- }
-
- @Test
- void testMigrate() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, acA1PmsClient);
-
- var automationCompositionId = UUID.randomUUID();
- var element = commonTestData.getAutomationCompositionElement();
- automationCompositionElementHandler.migrate(automationCompositionId, element, UUID.randomUUID(), Map.of());
-
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
- element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
+ assertThrows(A1PolicyServiceException.class,
+ () -> automationCompositionElementHandler.deploy(compositionElement, element));
}
}
diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java
index d31e81fe8..89e834390 100644
--- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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,10 +22,11 @@
package org.onap.policy.clamp.acm.participant.a1pms.utils;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import org.onap.policy.clamp.acm.participant.a1pms.models.A1PolicyServiceEntity;
-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());
}
/**
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
index 752b8d938..161cf9278 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
@@ -36,7 +36,6 @@ 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;
-import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
@@ -76,11 +75,9 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
* @param automationCompositionId the automationComposition Id
* @param element the information on the automation composition element
* @param properties properties Map
- * @throws PfModelException in case of a exception
*/
@Override
- public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
- throws PfModelException {
+ public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) {
try {
var configRequest = getConfigRequest(properties);
var restResponseMap = acHttpClient.run(configRequest);
@@ -104,11 +101,13 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
private ConfigRequest getConfigRequest(Map<String, Object> properties) throws AutomationCompositionException {
try {
var configRequest = CODER.convert(properties, ConfigRequest.class);
- var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest);
- if (!violations.isEmpty()) {
- LOGGER.error("Violations found in the config request parameters: {}", violations);
- throw new AutomationCompositionException(Status.BAD_REQUEST,
- "Constraint violations in the config request");
+ try (var validatorFactory = Validation.buildDefaultValidatorFactory()) {
+ var violations = validatorFactory.getValidator().validate(configRequest);
+ if (!violations.isEmpty()) {
+ LOGGER.error("Violations found in the config request parameters: {}", violations);
+ throw new AutomationCompositionException(Status.BAD_REQUEST,
+ "Constraint violations in the config request");
+ }
}
return configRequest;
} catch (CoderException e) {
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
index 634e78880..9c0b9aecd 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.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.
@@ -23,11 +23,13 @@ package org.onap.policy.clamp.acm.participant.http.handler;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler;
import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
@@ -40,6 +42,8 @@ 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.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.http.HttpStatus;
class AcElementHandlerTest {
@@ -63,7 +67,7 @@ class AcElementHandlerTest {
}
@Test
- void testDeployConstraintViolations() throws PfModelException {
+ void testDeployConstraintViolations() {
var instanceId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -78,7 +82,7 @@ class AcElementHandlerTest {
}
@Test
- void testDeployError() throws PfModelException {
+ void testDeployError() {
var instanceId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -95,7 +99,30 @@ class AcElementHandlerTest {
}
@Test
- void testDeploy() throws Exception {
+ void testDeployFailed() {
+ var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ var element = commonTestData.getAutomationCompositionElement();
+ map.putAll(element.getProperties());
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var acHttpClient = mock(AcHttpClient.class);
+ when(acHttpClient.run(any())).thenReturn(Map.of(new ToscaConceptIdentifier(),
+ Pair.of(HttpStatus.BAD_REQUEST.value(), "")));
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+
+ var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(participantIntermediaryApi, acHttpClient);
+
+ automationCompositionElementHandler.deploy(instanceId, element, map);
+ verify(acHttpClient).run(any(ConfigRequest.class));
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+ "Error on Invoking the http request: [(400,)]");
+ }
+
+ @Test
+ void testDeploy() {
var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
@@ -198,50 +225,6 @@ class AcElementHandlerTest {
}
@Test
- void testHandleRestartComposition() throws PfModelException {
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class));
-
- var compositionId = UUID.randomUUID();
- automationCompositionElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED);
- verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
- StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @Test
- void testHandleRestartInstanceDeploying() throws PfModelException {
- var serviceTemplate = ToscaUtils.readAutomationCompositionFromTosca();
- var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
- var element = commonTestData.getAutomationCompositionElement();
- map.putAll(element.getProperties());
- var instanceId = commonTestData.getAutomationCompositionId();
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class));
-
- automationCompositionElementHandler.handleRestartInstance(instanceId, element, map, DeployState.DEPLOYING,
- LockState.NONE);
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- }
-
- @Test
- void testHandleRestartInstanceDeployed() throws PfModelException {
- var element = commonTestData.getAutomationCompositionElement();
- var instanceId = commonTestData.getAutomationCompositionId();
- var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(participantIntermediaryApi, mock(AcHttpClient.class));
-
- automationCompositionElementHandler.handleRestartInstance(instanceId, element, element.getProperties(),
- DeployState.DEPLOYED, LockState.LOCKED);
- verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @Test
void testMigrate() throws PfModelException {
var instanceId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java
index f6c0c5a8a..149d8d910 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/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.
@@ -53,39 +53,42 @@ 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/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());
}
/**
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
index ae8e47461..1c40c7281 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
@@ -25,7 +25,6 @@ import jakarta.ws.rs.core.Response.Status;
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.ConcurrentHashMap;
@@ -39,12 +38,8 @@ import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo;
import org.onap.policy.clamp.acm.participant.kubernetes.service.ChartService;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
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.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;
@@ -177,77 +172,4 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
}
-
- @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");
- }
-
- @Override
- public void handleRestartComposition(UUID compositionId,
- List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state)
- throws PfModelException {
- var finalState = AcTypeState.PRIMED.equals(state) || AcTypeState.PRIMING.equals(state) ? AcTypeState.PRIMED
- : AcTypeState.COMMISSIONED;
- intermediaryApi.updateCompositionState(compositionId, finalState, StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @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 chartInfo = getChartInfo(properties);
- chartMap.put(element.getId(), chartInfo);
- } catch (AutomationCompositionException e) {
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, e.getMessage());
- }
- }
- 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-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
index 14b505f66..26dcb05ff 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
@@ -36,9 +36,6 @@ 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;
-import java.util.concurrent.Future;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -53,9 +50,6 @@ import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartList;
import org.onap.policy.clamp.acm.participant.kubernetes.parameters.CommonTestData;
import org.onap.policy.clamp.acm.participant.kubernetes.service.ChartService;
import org.onap.policy.clamp.acm.participant.kubernetes.utils.TestUtils;
-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.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -84,11 +78,6 @@ class AutomationCompositionElementHandlerTest {
@Mock
private ChartService chartService;
- @Mock
- private ExecutorService executor;
- @Mock
- private Future<String> result;
-
@BeforeAll
static void init() throws CoderException {
charts = CODER.decode(new File(CHART_INFO_YAML), ChartList.class).getCharts();
@@ -116,7 +105,7 @@ class AutomationCompositionElementHandlerTest {
@Test
void test_AutomationCompositionElementUpdate()
- throws PfModelException, IOException, ServiceException, ExecutionException, InterruptedException {
+ throws PfModelException, IOException, ServiceException, InterruptedException {
doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
var element = CommonTestData.createAcElementDeploy();
var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
@@ -143,7 +132,7 @@ class AutomationCompositionElementHandlerTest {
}
@Test
- void test_checkPodStatus() throws ExecutionException, InterruptedException {
+ void test_checkPodStatus() {
var chartInfo = charts.get(0);
var automationCompositionId = UUID.randomUUID();
assertThrows(ServiceException.class, () -> automationCompositionElementHandler
@@ -151,7 +140,7 @@ class AutomationCompositionElementHandlerTest {
}
@Test
- void testUpdate() throws PfModelException {
+ void testUpdate() {
var element = CommonTestData.createAcElementDeploy();
var automationCompositionId = commonTestData.getAutomationCompositionId();
assertDoesNotThrow(
@@ -159,82 +148,32 @@ class AutomationCompositionElementHandlerTest {
}
@Test
- void testLock() throws PfModelException {
+ void testLock() {
assertDoesNotThrow(() -> automationCompositionElementHandler.lock(UUID.randomUUID(), UUID.randomUUID()));
}
@Test
- void testUnlock() throws PfModelException {
+ void testUnlock() {
assertDoesNotThrow(() -> automationCompositionElementHandler.unlock(UUID.randomUUID(), UUID.randomUUID()));
}
@Test
- void testDelete() throws PfModelException {
+ void testDelete() {
assertDoesNotThrow(() -> automationCompositionElementHandler.delete(UUID.randomUUID(), UUID.randomUUID()));
}
@Test
- void testPrime() throws PfModelException {
+ void testPrime() {
assertDoesNotThrow(() -> automationCompositionElementHandler.prime(UUID.randomUUID(), List.of()));
}
@Test
- void testDeprime() throws PfModelException {
+ void testDeprime() {
assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
}
@Test
- void testHandleRestartComposition() throws PfModelException {
- assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartComposition(UUID.randomUUID(),
- List.of(), AcTypeState.PRIMED));
- }
-
- @Test
- void testHandleRestartInstanceDeploying()
- throws PfModelException, InterruptedException, ServiceException, IOException {
- doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
- var element = CommonTestData.createAcElementDeploy();
- var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
-
- doReturn(true).when(chartService).installChart(any());
- assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYING,
- LockState.NONE));
-
- assertThat(automationCompositionElementHandler.getChartMap()).containsKey(element.getId());
- }
-
- @Test
- void testHandleRestartInstanceDeployed()
- throws PfModelException, InterruptedException, ServiceException, IOException {
- doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
- var element = CommonTestData.createAcElementDeploy();
- var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.DEPLOYED,
- LockState.LOCKED));
-
- assertThat(automationCompositionElementHandler.getChartMap()).containsKey(element.getId());
- }
-
- @Test
- void testHandleRestartInstanceUndeploying()
- throws PfModelException, InterruptedException, ServiceException, IOException {
- doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
- var element = CommonTestData.createAcElementDeploy();
- var nodeTemplatesMap = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.handleRestartInstance(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties(), DeployState.UNDEPLOYING,
- LockState.LOCKED));
- }
-
- @Test
- void testMigrate() throws PfModelException {
+ void testMigrate() {
var element = CommonTestData.createAcElementDeploy();
var automationCompositionId = commonTestData.getAutomationCompositionId();
assertDoesNotThrow(() -> automationCompositionElementHandler.migrate(automationCompositionId, element,
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index d66ab3154..ae906e1ef 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -35,9 +35,7 @@ import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
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.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -221,26 +219,4 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
return policyList;
}
-
- @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)) {
- var automationCompositionDefinition = element.getToscaServiceTemplateFragment();
- serviceTemplateMap.put(element.getId(), automationCompositionDefinition);
- }
- 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-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index af6a401f2..013cb3432 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.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.
@@ -136,7 +136,7 @@ class AutomationCompositionElementHandlerTest {
}
@Test
- void testDeployPapException() throws PfModelException {
+ void testDeployPapException() {
var api = mock(PolicyApiHttpClient.class);
doReturn(Response.ok().build()).when(api).createPolicyType(any());
doReturn(Response.ok().build()).when(api).createPolicy(any());
@@ -220,55 +220,6 @@ class AutomationCompositionElementHandlerTest {
}
@Test
- void testHandleRestartComposition() throws PfModelException {
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var automationCompositionElementHandler =
- new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
- mock(PolicyPapHttpClient.class), intermediaryApi);
-
- var compositionId = UUID.randomUUID();
- automationCompositionElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED);
-
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
- StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @Test
- void testHandleRestartInstanceDeploying() throws PfModelException {
- // Mock success scenario for policy creation and deployment
- var api = mock(PolicyApiHttpClient.class);
- doReturn(Response.ok().build()).when(api).createPolicyType(any());
- doReturn(Response.ok().build()).when(api).createPolicy(any());
-
- var pap = mock(PolicyPapHttpClient.class);
- doReturn(Response.accepted().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
-
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
- var element = getTestingAcElement();
-
- handler.handleRestartInstance(AC_ID, element, Map.of(), DeployState.DEPLOYING, LockState.NONE);
- verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
-
- handler.handleRestartInstance(AC_ID, element, Map.of(), DeployState.UNDEPLOYING, LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
- }
-
- @Test
- void testHandleRestartInstanceDeployed() throws PfModelException {
- var api = mock(PolicyApiHttpClient.class);
- var pap = mock(PolicyPapHttpClient.class);
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
- var element = getTestingAcElement();
- handler.handleRestartInstance(AC_ID, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
- }
-
- @Test
void testMigrate() throws Exception {
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java
index b3fe2d3a5..3672e5903 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/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.
@@ -22,7 +22,6 @@ package org.onap.policy.clamp.acm.participant.policy.main.rest;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -71,21 +70,24 @@ class ActuatorControllerTest extends CommonActuatorController {
@Test
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() {
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() {
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-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
index f503987a2..03a0517e0 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
@@ -28,10 +28,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementList
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.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,63 +101,6 @@ public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 {
}
@Override
- public void handleRestartComposition(UUID compositionId,
- List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state)
- throws PfModelException {
- LOGGER.debug("restart composition definition call compositionId: {}, elementDefinitionList: {}, state: {}",
- compositionId, elementDefinitionList, state);
-
- switch (state) {
- case PRIMING:
- prime(compositionId, elementDefinitionList);
- break;
-
- case DEPRIMING:
- deprime(compositionId);
- break;
-
- default:
- intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.NO_ERROR, "Restarted");
- }
- }
-
- @Override
- public void handleRestartInstance(UUID instanceId, AcElementDeploy element,
- Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException {
- LOGGER.debug("restart instance call instanceId: {}, element: {}, properties: {},"
- + "deployState: {}, lockState: {}", instanceId, element, properties, deployState, lockState);
-
- if (!AcmUtils.isInTransitionalState(deployState, lockState)) {
- intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(),
- deployState, lockState, StateChangeResult.NO_ERROR, "Restarted");
- return;
- }
- if (DeployState.DEPLOYING.equals(deployState)) {
- deploy(instanceId, element, properties);
- return;
- }
- if (DeployState.UNDEPLOYING.equals(deployState)) {
- undeploy(instanceId, element.getId());
- return;
- }
- if (DeployState.UPDATING.equals(deployState)) {
- update(instanceId, element, properties);
- return;
- }
- if (DeployState.DELETING.equals(deployState)) {
- delete(instanceId, element.getId());
- return;
- }
- if (LockState.LOCKING.equals(lockState)) {
- lock(instanceId, element.getId());
- return;
- }
- if (LockState.UNLOCKING.equals(lockState)) {
- unlock(instanceId, element.getId());
- }
- }
-
- @Override
public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId,
Map<String, Object> properties) throws PfModelException {
LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
index e836c9874..28bade22f 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
@@ -123,59 +123,6 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
}
@Override
- public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException {
- LOGGER.debug("restart composition definition call");
- switch (state) {
- case PRIMING:
- prime(composition);
- break;
-
- case DEPRIMING:
- deprime(composition);
- break;
-
- default:
- intermediaryApi.updateCompositionState(composition.compositionId(), state,
- StateChangeResult.NO_ERROR, "Restarted");
- }
- }
-
- @Override
- public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
- DeployState deployState, LockState lockState) throws PfModelException {
- LOGGER.debug("restart instance call");
- if (!AcmUtils.isInTransitionalState(deployState, lockState)) {
- intermediaryApi.updateAutomationCompositionElementState(
- instanceElement.instanceId(), instanceElement.elementId(), deployState, lockState,
- StateChangeResult.NO_ERROR, "Restarted");
- return;
- }
- if (DeployState.DEPLOYING.equals(deployState)) {
- deploy(compositionElement, instanceElement);
- return;
- }
- if (DeployState.UNDEPLOYING.equals(deployState)) {
- undeploy(compositionElement, instanceElement);
- return;
- }
- if (DeployState.UPDATING.equals(deployState)) {
- update(compositionElement, instanceElement, instanceElement);
- return;
- }
- if (DeployState.DELETING.equals(deployState)) {
- delete(compositionElement, instanceElement);
- return;
- }
- if (LockState.LOCKING.equals(lockState)) {
- lock(compositionElement, instanceElement);
- return;
- }
- if (LockState.UNLOCKING.equals(lockState)) {
- unlock(compositionElement, instanceElement);
- }
- }
-
- @Override
public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
throws PfModelException {
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
index 1061b3ba1..300caa52c 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java
@@ -199,70 +199,6 @@ class AutomationCompositionElementHandlerV1Test {
}
@Test
- void testHandleRestartComposition() throws PfModelException {
- var config = new SimConfig();
- config.setPrimeTimerMs(1);
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var simulatorService = new SimulatorService(intermediaryApi);
- var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
- simulatorService.setConfig(config);
- var compositionId = UUID.randomUUID();
- acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMING);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
- "Primed");
-
- acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.PRIMED);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
- "Restarted");
-
- acElementHandler.handleRestartComposition(compositionId, List.of(), AcTypeState.DEPRIMING);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
- StateChangeResult.NO_ERROR, "Deprimed");
- }
-
- @Test
- void testHandleRestartInstance() throws PfModelException {
- var config = new SimConfig();
- config.setDeployTimerMs(1);
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var simulatorService = new SimulatorService(intermediaryApi);
- var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService);
- simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var element = new AcElementDeploy();
- element.setId(UUID.randomUUID());
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYING, LockState.NONE);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
-
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
-
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.UPDATING, LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
-
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.UNDEPLOYING,
- LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
-
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DELETING, LockState.NONE);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
-
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED, LockState.LOCKING);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), null,
- LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
-
- acElementHandler.handleRestartInstance(instanceId, element, Map.of(), DeployState.DEPLOYED,
- LockState.UNLOCKING);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(), null,
- LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
- }
-
- @Test
void testMigrate() throws PfModelException {
var config = new SimConfig();
config.setUpdateTimerMs(1);
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
index c521d3755..51e39067f 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
@@ -223,80 +223,6 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testHandleRestartComposition() throws PfModelException {
- var config = new SimConfig();
- config.setPrimeTimerMs(1);
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var simulatorService = new SimulatorService(intermediaryApi);
- var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
- simulatorService.setConfig(config);
- var compositionId = UUID.randomUUID();
- var composition = new CompositionDto(compositionId, Map.of(), Map.of());
- acElementHandler.handleRestartComposition(composition, AcTypeState.PRIMING);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
- "Primed");
-
- acElementHandler.handleRestartComposition(composition, AcTypeState.PRIMED);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
- "Restarted");
-
- acElementHandler.handleRestartComposition(composition, AcTypeState.DEPRIMING);
- verify(intermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
- StateChangeResult.NO_ERROR, "Deprimed");
- }
-
- @Test
- void testHandleRestartInstance() throws PfModelException {
- var config = new SimConfig();
- config.setDeployTimerMs(1);
- var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var simulatorService = new SimulatorService(intermediaryApi);
- var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
- simulatorService.setConfig(config);
- var instanceId = UUID.randomUUID();
- var elementId = UUID.randomUUID();
- var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
- var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
- Map.of(), Map.of());
- acElementHandler.handleRestartInstance(compositionElement, instanceElement,
- DeployState.DEPLOYING, LockState.NONE);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
-
- acElementHandler.handleRestartInstance(compositionElement, instanceElement,
- DeployState.DEPLOYED, LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DEPLOYED, LockState.LOCKED, StateChangeResult.NO_ERROR, "Restarted");
-
- acElementHandler.handleRestartInstance(compositionElement, instanceElement,
- DeployState.UPDATING, LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
-
- acElementHandler.handleRestartInstance(compositionElement, instanceElement, DeployState.UNDEPLOYING,
- LockState.LOCKED);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
-
- acElementHandler.handleRestartInstance(compositionElement, instanceElement,
- DeployState.DELETING, LockState.NONE);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
-
- acElementHandler.handleRestartInstance(compositionElement, instanceElement,
- DeployState.DEPLOYED, LockState.LOCKING);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null,
- LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
-
- acElementHandler.handleRestartInstance(compositionElement, instanceElement, DeployState.DEPLOYED,
- LockState.UNLOCKING);
- verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, null,
- LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
- }
-
-
-
- @Test
void testMigrate() throws PfModelException {
var config = new SimConfig();
config.setUpdateTimerMs(1);
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/rest/ActuatorControllerTest.java
index 08557f56d..ac24dea72 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/rest/ActuatorControllerTest.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/rest/ActuatorControllerTest.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.
@@ -53,39 +53,42 @@ 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());
+ }
}
}