summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java17
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java112
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java20
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java11
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java5
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java16
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java45
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java74
-rw-r--r--models/src/test/resources/providers/TestAutomationCompositionsDeregister.json55
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java65
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java42
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonTestData.java12
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java45
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java25
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonTestData.java12
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java72
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/models/InstallationInfo.java2
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java33
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java79
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java35
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java16
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java17
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java17
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java278
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java3
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java16
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java98
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java26
-rw-r--r--pom.xml4
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/ParticipantControllerStub.java70
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java4
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java6
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java10
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java93
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java1
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java113
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java43
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java70
-rw-r--r--runtime-acm/src/main/resources/application-stub.yaml6
-rw-r--r--runtime-acm/src/main/resources/openapi/examples/getMultipleParticipantResponse.json88
-rw-r--r--runtime-acm/src/main/resources/openapi/examples/getSingleParticipantResponse.json43
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java83
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java59
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java1
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java58
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java103
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java16
50 files changed, 1249 insertions, 897 deletions
diff --git a/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml b/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml
index 9d8a37519..4587e31e8 100644
--- a/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml
+++ b/examples/src/main/resources/clamp/acm/pmsh/funtional-pmsh-usecase.yaml
@@ -342,7 +342,7 @@ node_types:
type: onap.datatypes.ToscaConceptIdentifier
description: Specifies a list of automation composition element definitions that make up this automation composition definition
org.onap.policy.clamp.acm.PolicyAutomationCompositionElement:
- version: 1.0.1
+ version: 1.0.0
derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement
properties:
policy_type_id:
@@ -359,7 +359,7 @@ node_types:
type: onap.datatypes.ToscaConceptIdentifier
required: true
org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement:
- version: 1.0.1
+ version: 1.0.0
derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement
properties:
chart:
@@ -379,7 +379,7 @@ node_types:
type: string
required: true
org.onap.policy.clamp.acm.HttpAutomationCompositionElement:
- version: 1.0.1
+ version: 1.0.0
derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement
properties:
baseUrl:
@@ -419,7 +419,7 @@ topology_template:
org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement:
version: 1.2.3
type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement
- type_version: 1.0.1
+ type_version: 1.0.0
description: Automation composition element for the operational policy for Performance Management Subscription Handling
properties:
provider: Ericsson
@@ -441,7 +441,7 @@ topology_template:
# Chart from new repository
version: 1.2.3
type: org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement
- type_version: 1.0.1
+ type_version: 1.0.0
description: Automation composition element for the K8S microservice for PMSH
properties:
provider: ONAP
@@ -470,7 +470,7 @@ topology_template:
# Http config for PMSH.
version: 1.2.3
type: org.onap.policy.clamp.acm.HttpAutomationCompositionElement
- type_version: 1.0.1
+ type_version: 1.0.0
description: Automation composition element for the http requests of PMSH microservice
properties:
provider: ONAP
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
index afbd61bd1..8f8a54f39 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
@@ -32,9 +32,6 @@ import lombok.ToString;
public class AcElementDeployAck {
// State of the AutomationCompositionElement
- private AutomationCompositionState state;
-
- // State of the AutomationCompositionElement
private DeployState deployState;
// State of the AutomationCompositionElement
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
index 65b72c436..25d72cb06 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
@@ -29,6 +29,8 @@ import javax.ws.rs.core.Response.Status;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
+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.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
@@ -180,4 +182,19 @@ public class ParticipantProvider {
return ProviderUtils.asEntityList(nodeTemplateStateRepository
.findByParticipantId(participantId.toString()));
}
+
+ /**
+ * Reset the Deploy and Lock states of all the ac elements associated with a participant.
+ *
+ * @param participantId the participant id associated with the automation composition elements
+ */
+ public void resetParticipantAcElementState(@NonNull final UUID participantId) {
+ var participantAcElementList = automationCompositionElementRepository
+ .findByParticipantId(participantId.toString());
+ participantAcElementList.forEach(e -> {
+ e.setDeployState(DeployState.UNDEPLOYED);
+ e.setLockState(LockState.NONE);
+ });
+ automationCompositionElementRepository.saveAll(participantAcElementList);
+ }
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
index af29deb3f..35482b9bb 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
@@ -37,13 +37,13 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
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.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
@@ -67,38 +67,6 @@ public final class AcmUtils {
public static final String ENTRY = "entry ";
/**
- * Prepare participant updates map.
- *
- * @param acElement automation composition element
- * @param participantUpdates list of participantUpdates
- */
- public static void prepareParticipantUpdate(AutomationCompositionElement acElement,
- List<ParticipantDeploy> participantUpdates) {
- if (participantUpdates.isEmpty()) {
- participantUpdates.add(getAutomationCompositionElementList(acElement));
- return;
- }
-
- var participantExists = false;
- for (ParticipantDeploy participantUpdate : participantUpdates) {
- if (participantUpdate.getParticipantId().equals(acElement.getParticipantId())) {
- participantUpdate.getAutomationCompositionElementList().add(acElement);
- participantExists = true;
- }
- }
- if (!participantExists) {
- participantUpdates.add(getAutomationCompositionElementList(acElement));
- }
- }
-
- private static ParticipantDeploy getAutomationCompositionElementList(AutomationCompositionElement acElement) {
- var participantUpdate = new ParticipantDeploy();
- participantUpdate.setParticipantId(acElement.getParticipantId());
- participantUpdate.getAutomationCompositionElementList().add(acElement);
- return participantUpdate;
- }
-
- /**
* Get the Policy information in the service template for the deploy message to participants.
*
* @param toscaServiceTemplate ToscaServiceTemplate
@@ -196,7 +164,7 @@ public final class AcmUtils {
public static List<Entry<String, ToscaNodeTemplate>> extractAcElementsFromServiceTemplate(
ToscaServiceTemplate serviceTemplate) {
return serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet().stream().filter(
- nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(),
+ nodeTemplateEntry -> checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplateEntry.getValue(),
serviceTemplate))
.collect(Collectors.toList());
}
@@ -309,7 +277,6 @@ public final class AcmUtils {
// @formatter:on
}
-
/**
* Return true if DeployState and LockState are in a Transitional State.
*
@@ -321,6 +288,79 @@ public final class AcmUtils {
}
/**
+ * Get DeployOrder from transitional DeployState.
+ *
+ * @param deployState the Deploy State
+ * @return the DeployOrder
+ */
+ public static DeployOrder stateDeployToOrder(DeployState deployState) {
+ if (DeployState.DEPLOYING.equals(deployState)) {
+ return DeployOrder.DEPLOY;
+ } else if (DeployState.UNDEPLOYING.equals(deployState)) {
+ return DeployOrder.UNDEPLOY;
+ }
+ return DeployOrder.NONE;
+ }
+
+ /**
+ * Get LockOrder from transitional LockState.
+ *
+ * @param lockState the Lock State
+ * @return the LockOrder
+ */
+ public static LockOrder stateLockToOrder(LockState lockState) {
+ if (LockState.LOCKING.equals(lockState)) {
+ return LockOrder.LOCK;
+ } else if (LockState.UNLOCKING.equals(lockState)) {
+ return LockOrder.UNLOCK;
+ }
+ return LockOrder.NONE;
+ }
+
+ /**
+ * Get final DeployState from transitional DeployState.
+ *
+ * @param deployState the DeployState
+ * @return the DeployState
+ */
+ public static DeployState deployCompleted(DeployState deployState) {
+ if (DeployState.DEPLOYING.equals(deployState)) {
+ return DeployState.DEPLOYED;
+ } else if (DeployState.UNDEPLOYING.equals(deployState)) {
+ return DeployState.UNDEPLOYED;
+ }
+ return deployState;
+ }
+
+ /**
+ * Get final LockState from transitional LockState.
+ *
+ * @param lockState the LockState
+ * @return the LockState
+ */
+ public static LockState lockCompleted(DeployState deployState, LockState lockState) {
+ if (LockState.LOCKING.equals(lockState) || DeployState.DEPLOYING.equals(deployState)) {
+ return LockState.LOCKED;
+ } else if (LockState.UNLOCKING.equals(lockState)) {
+ return LockState.UNLOCKED;
+ } else if (DeployState.UNDEPLOYING.equals(deployState)) {
+ return LockState.NONE;
+ }
+ return lockState;
+ }
+
+ /**
+ * Return true if transition states is Forward.
+ *
+ * @param deployState the DeployState
+ * @param lockState the LockState
+ * @return true if transition if Forward
+ */
+ public static boolean isForward(DeployState deployState, LockState lockState) {
+ return DeployState.DEPLOYING.equals(deployState) || LockState.UNLOCKING.equals(lockState);
+ }
+
+ /**
* Set the states on the automation composition and on all its automation composition elements.
*
* @param deployState the DeployState we want the automation composition to transition to
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java
index 9f235d6ac..e044a2f22 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java
@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -43,28 +42,13 @@ class AutomationCompositionElementTest {
ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
ace1.setDescription("Description");
ace1.setId(UUID.randomUUID());
- ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
ace1.setParticipantId(CommonTestData.getParticipantId());
- ace1.setState(AutomationCompositionState.UNINITIALISED);
var ace2 = new AutomationCompositionElement(ace1);
assertEquals(ace1, ace2);
}
@Test
- void testAutomationCompositionState() {
- var ace0 = new AutomationCompositionElement();
-
- assertTrue(
- ace0.getOrderedState()
- .equalsAutomationCompositionState(AutomationCompositionState.UNINITIALISED));
-
- assertTrue(
- ace0.getOrderedState().asState()
- .equalsAutomationCompositionOrderedState(AutomationCompositionOrderedState.UNINITIALISED));
- }
-
- @Test
void testAutomationCompositionElementLombok() {
var ace0 = new AutomationCompositionElement();
@@ -78,9 +62,7 @@ class AutomationCompositionElementTest {
ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1"));
ace1.setDescription("Description");
ace1.setId(UUID.randomUUID());
- ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
ace1.setParticipantId(CommonTestData.getParticipantId());
- ace1.setState(AutomationCompositionState.UNINITIALISED);
assertThat(ace1.toString()).contains("AutomationCompositionElement(");
assertNotEquals(0, ace1.hashCode());
@@ -94,9 +76,7 @@ class AutomationCompositionElementTest {
// @formatter:off
assertThatThrownBy(() -> ace2.setDefinition(null)). isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> ace2.setId(null)). isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> ace2.setOrderedState(null)). isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> ace2.setParticipantId(null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> ace2.setState(null)). isInstanceOf(NullPointerException.class);
// @formatter:on
assertNotEquals(ace2, ace0);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
index e32735f07..64dc6f792 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
@@ -60,8 +60,6 @@ class AutomationCompositionTest {
ac1.setDescription("Description");
ac1.setElements(new LinkedHashMap<>());
ac1.setName("Name");
- ac1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- ac1.setState(AutomationCompositionState.UNINITIALISED);
ac1.setVersion("0.0.1");
assertThat(ac1.toString()).contains("AutomationComposition(");
@@ -76,20 +74,11 @@ class AutomationCompositionTest {
// @formatter:off
assertThatThrownBy(() -> ac2.setCompositionId(null)). isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class);
// @formatter:on
assertEquals(ac2, ac0);
- ac1.setCascadedOrderedState(AutomationCompositionOrderedState.PASSIVE);
- assertEquals(AutomationCompositionOrderedState.PASSIVE, ac1.getOrderedState());
-
ac1.getElements().put(UUID.randomUUID(), new AutomationCompositionElement());
- ac1.setCascadedOrderedState(AutomationCompositionOrderedState.RUNNING);
- assertEquals(AutomationCompositionOrderedState.RUNNING, ac1.getOrderedState());
- assertEquals(AutomationCompositionOrderedState.RUNNING,
- ac1.getElements().values().iterator().next().getOrderedState());
assertNull(ac0.getElements().get(UUID.randomUUID()));
assertNull(ac1.getElements().get(UUID.randomUUID()));
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
index 6e5b504af..8c50b01b6 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
@@ -29,7 +29,8 @@ import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
@@ -49,7 +50,7 @@ class AutomationCompositionDeployAckTest {
// verify with all values
orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(CommonTestData.getParticipantId());
- var acElementResult = new AcElementDeployAck(AutomationCompositionState.UNINITIALISED, null, null,
+ var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED,
true, "AutomationCompositionElement result");
final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult);
orig.setAutomationCompositionResultMap(automationCompositionResultMap);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java
index 2912dee9b..3f64eadd5 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployTest.java
@@ -30,9 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
@@ -55,16 +53,10 @@ class AutomationCompositionDeployTest {
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
- var acElement = new AutomationCompositionElement();
+ var acElement = new AcElementDeploy();
acElement.setId(UUID.randomUUID());
var id = new ToscaConceptIdentifier("id", "1.2.3");
acElement.setDefinition(id);
- acElement.setDescription("Description");
- acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- acElement.setState(AutomationCompositionState.PASSIVE);
-
- var participantId = CommonTestData.getParticipantId();
- acElement.setParticipantId(participantId);
var property = new ToscaProperty();
property.setName("test");
@@ -75,8 +67,8 @@ class AutomationCompositionDeployTest {
acElement.setProperties(propertiesMap);
var participantDeploy = new ParticipantDeploy();
- participantDeploy.setParticipantId(participantId);
- participantDeploy.setAutomationCompositionElementList(List.of(acElement));
+ participantDeploy.setParticipantId(CommonTestData.getParticipantId());
+ participantDeploy.setAcElementList(List.of(acElement));
orig.setParticipantUpdatesList(List.of(participantDeploy));
var other = new AutomationCompositionDeploy(orig);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
index 52e90b53a..968ad31bb 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
@@ -36,6 +36,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
+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.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
@@ -57,6 +59,9 @@ class ParticipantProviderTest {
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
+ private static final String AUTOMATION_COMPOSITION_JSON_DEREGISTER =
+ "src/test/resources/providers/TestAutomationCompositionsDeregister.json";
+
private static final String NODE_TEMPLATE_STATE_JSON = "src/test/resources/providers/NodeTemplateState.json";
private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
private static final UUID INVALID_ID = UUID.randomUUID();
@@ -69,6 +74,10 @@ class ParticipantProviderTest {
private List<JpaAutomationComposition> inputAutomationCompositionsJpa;
private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
+ private AutomationCompositions inputAutomationCompositionsDeregister;
+ private List<JpaAutomationComposition> inputAutomationCompositionsJpaDeregister;
+ private final String deregisterAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON_DEREGISTER);
+
private final String nodeTemplateStatesJson = ResourceUtils.getResourceAsString(NODE_TEMPLATE_STATE_JSON);
private List<NodeTemplateState> nodeTemplateStateList = new ArrayList<>();
@@ -84,6 +93,11 @@ class ParticipantProviderTest {
ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
JpaAutomationComposition::new, "automation compositions");
+ inputAutomationCompositionsDeregister = CODER.decode(deregisterAcJson, AutomationCompositions.class);
+ inputAutomationCompositionsJpaDeregister =
+ ProviderUtils.getJpaAndValidateList(inputAutomationCompositionsDeregister.getAutomationCompositionList(),
+ JpaAutomationComposition::new, "automation compositions");
+
nodeTemplateStateList.add(CODER.decode(nodeTemplateStatesJson, NodeTemplateState.class));
nodeTemplateStateList.get(0).setState(AcTypeState.COMMISSIONED);
jpaNodeTemplateStateList = ProviderUtils.getJpaAndValidateList(nodeTemplateStateList,
@@ -238,8 +252,7 @@ class ParticipantProviderTest {
assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null));
-
-
+ assertThrows(NullPointerException.class, () -> participantProvider.resetParticipantAcElementState(null));
}
@Test
@@ -254,4 +267,32 @@ class ParticipantProviderTest {
var result = participantProvider.getSupportedElementMap();
assertThat(result).hasSize(2);
}
+
+ @Test
+ void testResetParticipantAcElementState() {
+ var participantRepository = mock(ParticipantRepository.class);
+ var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
+
+ var acElementList = inputAutomationCompositionsJpaDeregister
+ .stream().map(c -> c.getElements()).collect(Collectors.toList());
+
+ when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0));
+
+ var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
+ var participantProvider = new ParticipantProvider(participantRepository,
+ automationCompositionElementRepository, nodeTemplateStateRepository);
+
+ acElementList.get(0).stream().forEach(e -> {
+ assertThat(e.getDeployState().equals(DeployState.DEPLOYED));
+ assertThat(e.getLockState().equals(LockState.LOCKED));
+ });
+
+ participantProvider.resetParticipantAcElementState(UUID.randomUUID());
+
+ acElementList.get(0).stream().forEach(e -> {
+ assertThat(e.getDeployState().equals(DeployState.UNDEPLOYED));
+ assertThat(e.getLockState().equals(LockState.NONE));
+ });
+
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index c16beaf87..b332d7d44 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
@@ -24,13 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -41,8 +40,9 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
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.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
@@ -69,25 +69,6 @@ class AcmUtilsTest {
}
@Test
- void testCommonUtilsParticipantUpdate() {
- var acElement = new AutomationCompositionElement();
- List<ParticipantDeploy> participantUpdates = new ArrayList<>();
- assertThat(participantUpdates).isEmpty();
-
- AcmUtils.prepareParticipantUpdate(acElement, participantUpdates);
- assertThat(participantUpdates).isNotEmpty();
- assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0));
-
- AcmUtils.prepareParticipantUpdate(acElement, participantUpdates);
- var participantId = CommonTestData.getParticipantId();
- assertNotEquals(participantId, participantUpdates.get(0).getParticipantId());
-
- acElement.setParticipantId(participantId);
- AcmUtils.prepareParticipantUpdate(acElement, participantUpdates);
- assertEquals(participantId, participantUpdates.get(1).getParticipantId());
- }
-
- @Test
void testCheckIfNodeTemplateIsAutomationCompositionElement() {
var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
var nodeTemplate = new ToscaNodeTemplate();
@@ -109,12 +90,12 @@ class AcmUtilsTest {
Map<ToscaConceptIdentifier, UUID> map = new HashMap<>();
var participantId = UUID.randomUUID();
assertThatThrownBy(() -> AcmUtils.prepareParticipantPriming(acElements, map)).hasMessageMatching(
- "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.1 not supported");
- map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"),
+ "Element Type org.onap.policy.clamp.acm.PolicyAutomationCompositionElement 1.0.0 not supported");
+ map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"),
participantId);
map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement",
- "1.0.1"), participantId);
- map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"),
+ "1.0.0"), participantId);
+ map.put(new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"),
participantId);
var result = AcmUtils.prepareParticipantPriming(acElements, map);
assertThat(result).isNotEmpty().hasSize(1);
@@ -159,6 +140,47 @@ class AcmUtilsTest {
assertFalse(result.isValid());
}
+ @Test
+ void testStateDeployToOrder() {
+ // from transitional state to order state
+ assertEquals(DeployOrder.DEPLOY, AcmUtils.stateDeployToOrder(DeployState.DEPLOYING));
+ assertEquals(DeployOrder.UNDEPLOY, AcmUtils.stateDeployToOrder(DeployState.UNDEPLOYING));
+ assertEquals(DeployOrder.NONE, AcmUtils.stateDeployToOrder(DeployState.DEPLOYED));
+ }
+
+ @Test
+ void testStateLockToOrder() {
+ // from transitional state to order state
+ assertEquals(LockOrder.LOCK, AcmUtils.stateLockToOrder(LockState.LOCKING));
+ assertEquals(LockOrder.UNLOCK, AcmUtils.stateLockToOrder(LockState.UNLOCKING));
+ assertEquals(LockOrder.NONE, AcmUtils.stateLockToOrder(LockState.NONE));
+ }
+
+ @Test
+ void testDeployCompleted() {
+ // from transitional state to final state
+ assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYING));
+ assertEquals(DeployState.UNDEPLOYED, AcmUtils.deployCompleted(DeployState.UNDEPLOYING));
+ assertEquals(DeployState.DEPLOYED, AcmUtils.deployCompleted(DeployState.DEPLOYED));
+ }
+
+ @Test
+ void testLockCompleted() {
+ // from transitional state to final state
+ assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYING, LockState.NONE));
+ assertEquals(LockState.LOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.LOCKING));
+ assertEquals(LockState.UNLOCKED, AcmUtils.lockCompleted(DeployState.DEPLOYED, LockState.UNLOCKING));
+ assertEquals(LockState.NONE, AcmUtils.lockCompleted(DeployState.UNDEPLOYING, LockState.LOCKED));
+ }
+
+ @Test
+ void testIsForward() {
+ assertTrue(AcmUtils.isForward(DeployState.DEPLOYING, LockState.NONE));
+ assertTrue(AcmUtils.isForward(DeployState.DEPLOYED, LockState.UNLOCKING));
+ assertFalse(AcmUtils.isForward(DeployState.DEPLOYED, LockState.LOCKING));
+ assertFalse(AcmUtils.isForward(DeployState.UNDEPLOYING, LockState.LOCKED));
+ }
+
private AutomationComposition getDummyAutomationComposition() {
var automationComposition = new AutomationComposition();
automationComposition.setCompositionId(UUID.randomUUID());
diff --git a/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json b/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json
new file mode 100644
index 000000000..0da9cdeef
--- /dev/null
+++ b/models/src/test/resources/providers/TestAutomationCompositionsDeregister.json
@@ -0,0 +1,55 @@
+{
+ "automationCompositionList": [
+ {
+ "compositionId": "709c62b3-8918-41b9-a747-e21eb79c6c40",
+ "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c89",
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c20": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c20",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "DCAE automation composition element for the PMSH instance 0 automation composition"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c21": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c21",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "Monitoring Policy element for the PMSH instance 0 automation composition"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "Operational Policy element for the PMSH instance 0 automation composition"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c23": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c23",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "CDS automation composition element for the PMSH instance 0 automation composition"
+ }
+ },
+ "name": "PMSHInstance0",
+ "version": "1.0.1",
+ "description": "PMSH automation composition instance 0"
+ }
+ ]
+}
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 bcc3fd498..a60e7b4bb 100755
--- 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,10 +36,9 @@ 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.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+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.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -73,42 +72,20 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
*
* @param automationCompositionId the ID of the automation composition
* @param automationCompositionElementId the ID of the automation composition element
- * @param currentState the current state of the automation composition element
- * @param newState the state to which the automation composition element is changing to
* @throws PfModelException in case of a model exception
*/
@Override
- public void automationCompositionElementStateChange(UUID automationCompositionId,
- UUID automationCompositionElementId, AutomationCompositionState currentState,
- AutomationCompositionOrderedState newState) throws A1PolicyServiceException {
- switch (newState) {
- case UNINITIALISED:
- var configurationEntity = configRequestMap.get(automationCompositionElementId);
- if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) {
- acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities());
- configRequestMap.remove(automationCompositionElementId);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- } else {
- LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity);
- throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE,
- "Unable to connect with A1PMS");
- }
- break;
- case PASSIVE:
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- case RUNNING:
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.RUNNING,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- default:
- LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState);
- break;
+ public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws A1PolicyServiceException {
+ var configurationEntity = configRequestMap.get(automationCompositionElementId);
+ if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) {
+ acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities());
+ configRequestMap.remove(automationCompositionElementId);
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE);
+ } else {
+ LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity);
+ throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Unable to connect with A1PMS");
}
}
@@ -116,24 +93,22 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* 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 element the information on the automation composition element
* @param properties properties Map
*/
@Override
- public void automationCompositionElementUpdate(UUID automationCompositionId,
- AutomationCompositionElement element, Map<String, Object> properties) throws A1PolicyServiceException {
+ public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
+ throws A1PolicyServiceException {
try {
var configurationEntity = CODER.convert(properties, ConfigurationEntity.class);
- var violations =
- Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity);
+ var violations = Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity);
if (violations.isEmpty()) {
if (acA1PmsClient.isPmsHealthy()) {
acA1PmsClient.createService(configurationEntity.getPolicyServiceEntities());
configRequestMap.put(element.getId(), configurationEntity);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ DeployState.DEPLOYED, LockState.LOCKED);
} else {
LOGGER.error("Failed to connect with A1PMS");
throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE,
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 ce775b616..a39076697 100755
--- 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 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,8 +39,6 @@ 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.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -79,27 +77,17 @@ class AcElementHandlerTest {
var automationCompositionElementId = element.getId();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler
- .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ automationCompositionElementHandler.deploy(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.PASSIVE));
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.UNINITIALISED));
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.RUNNING));
+ assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(
+ automationCompositionId, automationCompositionElementId));
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.UNINITIALISED));
+ () -> automationCompositionElementHandler.undeploy(
+ automationCompositionId, automationCompositionElementId));
}
@Test
@@ -107,9 +95,9 @@ class AcElementHandlerTest {
var element = commonTestData.getAutomationCompositionElement();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertDoesNotThrow(() -> automationCompositionElementHandler
- .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(
+ commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
}
@Test
@@ -118,8 +106,9 @@ class AcElementHandlerTest {
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
- .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
+ assertThrows(A1PolicyServiceException.class,
+ () -> automationCompositionElementHandler.deploy(
+ commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
}
@@ -127,7 +116,6 @@ class AcElementHandlerTest {
void test_AutomationCompositionElementUpdateWithInvalidConfiguration() {
var element = commonTestData.getAutomationCompositionElement();
assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
- .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
- Map.of()));
+ .deploy(commonTestData.getAutomationCompositionId(), element, Map.of()));
}
}
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 b68faa692..d31e81fe8 100755
--- 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 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* Modifications Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,8 +24,8 @@ package org.onap.policy.clamp.acm.participant.a1pms.utils;
import java.util.List;
import java.util.UUID;
import org.onap.policy.clamp.acm.participant.a1pms.models.A1PolicyServiceEntity;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
public class CommonTestData {
@@ -38,11 +38,11 @@ public class CommonTestData {
*
* @return automationCompositionElement object
*/
- public AutomationCompositionElement getAutomationCompositionElement() {
- var element = new AutomationCompositionElement();
+ public AcElementDeploy getAutomationCompositionElement() {
+ var element = new AcElementDeploy();
element.setId(UUID.randomUUID());
element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1"));
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ element.setOrderedState(DeployOrder.DEPLOY);
return element;
}
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 42b26c6a4..c62216dfc 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,10 +38,9 @@ import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+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.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -73,34 +72,13 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* Handle a automation composition element state change.
*
* @param automationCompositionElementId the ID of the automation composition element
- * @param currentState the current state of the automation composition element
- * @param newState the state to which the automation composition element is changing to
* @throws PfModelException in case of a model exception
*/
@Override
- public void automationCompositionElementStateChange(UUID automationCompositionId,
- UUID automationCompositionElementId, AutomationCompositionState currentState,
- AutomationCompositionOrderedState newState) {
- switch (newState) {
- case UNINITIALISED:
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- case PASSIVE:
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- case RUNNING:
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.RUNNING,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- default:
- LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState);
- break;
- }
+ public void undeploy(UUID automationCompositionId,
+ UUID automationCompositionElementId) {
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE);
}
/**
@@ -111,8 +89,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* @param properties properties Map
*/
@Override
- public void automationCompositionElementUpdate(UUID automationCompositionId,
- AutomationCompositionElement element, Map<String, Object> properties) {
+ public void deploy(UUID automationCompositionId,
+ AcElementDeploy element, Map<String, Object> properties) {
try {
var configRequest = CODER.convert(properties, ConfigRequest.class);
var violations =
@@ -124,8 +102,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
.is2xxSuccessful()).collect(Collectors.toList());
if (failedResponseStatus.isEmpty()) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ DeployState.DEPLOYED, LockState.LOCKED);
} else {
LOGGER.error("Error on Invoking the http request: {}", failedResponseStatus);
}
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 8e77b2acc..857490ef5 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-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +38,6 @@ import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData;
import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -49,13 +47,13 @@ class AcElementHandlerTest {
@InjectMocks
@Spy
private AutomationCompositionElementHandler automationCompositionElementHandler =
- new AutomationCompositionElementHandler();
+ new AutomationCompositionElementHandler();
private final CommonTestData commonTestData = new CommonTestData();
private static ToscaServiceTemplate serviceTemplate;
private static final String HTTP_AUTOMATION_COMPOSITION_ELEMENT =
- "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement";
+ "org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement";
@BeforeAll
static void init() {
@@ -76,17 +74,8 @@ class AcElementHandlerTest {
var config = Mockito.mock(ConfigRequest.class);
assertDoesNotThrow(() -> automationCompositionElementHandler.invokeHttpClient(config));
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.PASSIVE));
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.UNINITIALISED));
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.RUNNING));
+ assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(
+ automationCompositionId, automationCompositionElementId));
automationCompositionElementHandler.close();
}
@@ -100,7 +89,7 @@ class AcElementHandlerTest {
var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
map.putAll(element.getProperties());
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementUpdate(
- commonTestData.getAutomationCompositionId(), element, map));
+ assertDoesNotThrow(() -> automationCompositionElementHandler
+ .deploy(commonTestData.getAutomationCompositionId(), element, map));
}
}
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonTestData.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonTestData.java
index 48b7bdcd7..7ae9b3359 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonTestData.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,8 +26,8 @@ import java.util.Map;
import java.util.UUID;
import org.onap.policy.clamp.acm.participant.http.main.models.ConfigurationEntity;
import org.onap.policy.clamp.acm.participant.http.main.models.RestParams;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
public class CommonTestData {
@@ -41,11 +41,11 @@ public class CommonTestData {
*
* @return automationCompositionElement object
*/
- public AutomationCompositionElement getAutomationCompositionElement() {
- AutomationCompositionElement element = new AutomationCompositionElement();
+ public AcElementDeploy getAutomationCompositionElement() {
+ var element = new AcElementDeploy();
element.setId(UUID.randomUUID());
element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1"));
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ element.setOrderedState(DeployOrder.DEPLOY);
return element;
}
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 c64bc4906..3233cdc06 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,10 +38,9 @@ import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceExcepti
import org.onap.policy.clamp.acm.participant.kubernetes.helm.PodStatusValidator;
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.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+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.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -85,43 +84,21 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* Callback method to handle a automation composition element state change.
*
* @param automationCompositionElementId the ID of the automation composition element
- * @param currentState the current state of the automation composition element
- * @param newState the state to which the automation composition element is changing to
*/
@Override
- public synchronized void automationCompositionElementStateChange(UUID automationCompositionId,
- UUID automationCompositionElementId, AutomationCompositionState currentState,
- AutomationCompositionOrderedState newState) {
- switch (newState) {
- case UNINITIALISED:
- var chart = chartMap.get(automationCompositionElementId);
- if (chart != null) {
- LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName());
- try {
- chartService.uninstallChart(chart);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.UNINITIALISED,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- chartMap.remove(automationCompositionElementId);
- podStatusMap.remove(chart.getReleaseName());
- } catch (ServiceException se) {
- LOGGER.warn("Deletion of Helm deployment failed", se);
- }
- }
- break;
- case PASSIVE:
+ public synchronized void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) {
+ var chart = chartMap.get(automationCompositionElementId);
+ if (chart != null) {
+ LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName());
+ try {
+ chartService.uninstallChart(chart);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- case RUNNING:
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.RUNNING,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- default:
- LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState);
- break;
+ automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE);
+ chartMap.remove(automationCompositionElementId);
+ podStatusMap.remove(chart.getReleaseName());
+ } catch (ServiceException se) {
+ LOGGER.warn("Deletion of Helm deployment failed", se);
+ }
}
}
@@ -134,8 +111,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* @throws PfModelException in case of an exception
*/
@Override
- public synchronized void automationCompositionElementUpdate(UUID automationCompositionId,
- AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException {
+ public synchronized void deploy(UUID automationCompositionId, AcElementDeploy element,
+ Map<String, Object> properties) throws PfModelException {
@SuppressWarnings("unchecked")
var chartData = (Map<String, Object>) properties.get("chart");
@@ -149,8 +126,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
checkPodStatus(automationCompositionId, element.getId(), chartInfo,
config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
}
- } catch (ServiceException | CoderException | IOException | ExecutionException
- | InterruptedException e) {
+ } catch (ServiceException | CoderException | IOException | ExecutionException | InterruptedException e) {
LOGGER.warn("Installation of Helm chart failed", e);
}
}
@@ -160,16 +136,14 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
*
* @param chart ChartInfo
*/
- public void checkPodStatus(UUID automationCompositionId, UUID elementId,
- ChartInfo chart, int timeout, int podStatusCheckInterval) throws ExecutionException, InterruptedException {
+ public void checkPodStatus(UUID automationCompositionId, UUID elementId, ChartInfo chart, int timeout,
+ int podStatusCheckInterval) throws ExecutionException, InterruptedException {
// Invoke runnable thread to check pod status
- var result = executor.submit(new PodStatusValidator(chart, timeout,
- podStatusCheckInterval), "Done");
+ var result = executor.submit(new PodStatusValidator(chart, timeout, podStatusCheckInterval), "Done");
if (!result.get().isEmpty()) {
LOGGER.info("Pod Status Validator Completed: {}", result.isDone());
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, elementId,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ DeployState.DEPLOYED, LockState.LOCKED);
}
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/models/InstallationInfo.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/models/InstallationInfo.java
index 6ef6865cb..c09e780d1 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/models/InstallationInfo.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/models/InstallationInfo.java
@@ -19,10 +19,8 @@
package org.onap.policy.clamp.acm.participant.kubernetes.models;
import lombok.Getter;
-import org.immutables.gson.Gson;
@Getter
-@Gson.TypeAdapters
public class InstallationInfo {
private String name;
private String version;
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 f1357e435..ee0039c3f 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -50,9 +50,9 @@ 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.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -106,24 +106,13 @@ class AutomationCompositionElementHandlerTest {
doNothing().when(chartService).uninstallChart(charts.get(0));
- automationCompositionElementHandler.automationCompositionElementStateChange(
- commonTestData.getAutomationCompositionId(), automationCompositionElementId1,
- AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.UNINITIALISED);
+ automationCompositionElementHandler.undeploy(
+ commonTestData.getAutomationCompositionId(), automationCompositionElementId1);
doThrow(new ServiceException("Error uninstalling the chart")).when(chartService).uninstallChart(charts.get(0));
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- commonTestData.getAutomationCompositionId(), automationCompositionElementId1,
- AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.PASSIVE));
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- commonTestData.getAutomationCompositionId(), automationCompositionElementId1,
- AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.UNINITIALISED));
-
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- commonTestData.getAutomationCompositionId(), automationCompositionElementId1,
- AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.RUNNING));
-
+ assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(
+ commonTestData.getAutomationCompositionId(), automationCompositionElementId1));
}
@Test
@@ -132,14 +121,14 @@ class AutomationCompositionElementHandlerTest {
doReturn(true).when(chartService).installChart(any());
doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
var elementId1 = UUID.randomUUID();
- var element = new AutomationCompositionElement();
+ var element = new AcElementDeploy();
element.setId(elementId1);
element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ element.setOrderedState(DeployOrder.DEPLOY);
var nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.automationCompositionElementUpdate(
+ automationCompositionElementHandler.deploy(
commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
@@ -149,7 +138,7 @@ class AutomationCompositionElementHandlerTest {
var elementId2 = UUID.randomUUID();
element.setId(elementId2);
- automationCompositionElementHandler.automationCompositionElementUpdate(
+ automationCompositionElementHandler.deploy(
commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
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 ca27c8214..0b03e236f 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021,2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -31,10 +31,9 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
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.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+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.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
@@ -73,50 +72,22 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
/**
* Callback method to handle a automation composition element state change.
*
- * @param automationCompositionId the ID of the automation composition
+ * @param automationCompositionId the ID of the automation composition
* @param automationCompositionElementId the ID of the automation composition element
- * @param currentState the current state of the automation composition element
- * @param orderedState the state to which the automation composition element is changing to
*/
@Override
- public void automationCompositionElementStateChange(UUID automationCompositionId,
- UUID automationCompositionElementId,
- AutomationCompositionState currentState,
- AutomationCompositionOrderedState orderedState) {
- switch (orderedState) {
- case UNINITIALISED:
- try {
- undeployPolicies(automationCompositionElementId);
- deletePolicyData(automationCompositionId, automationCompositionElementId, orderedState);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, orderedState, AutomationCompositionState.UNINITIALISED,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- } catch (PfModelRuntimeException e) {
- LOGGER.error("Undeploying/Deleting policy failed {}", automationCompositionElementId, e);
- }
- break;
- case PASSIVE:
- try {
- undeployPolicies(automationCompositionElementId);
- } catch (PfModelRuntimeException e) {
- LOGGER.error("Undeploying policies failed - no policies to undeploy {}",
- automationCompositionElementId);
- }
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, orderedState, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- break;
- case RUNNING:
- LOGGER.info("Running state is not supported");
- break;
- default:
- LOGGER.debug("Unknown orderedstate {}", orderedState);
- break;
+ public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) {
+ try {
+ undeployPolicies(automationCompositionElementId);
+ deletePolicyData(automationCompositionId, automationCompositionElementId);
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.UNDEPLOYED, LockState.NONE);
+ } catch (PfModelRuntimeException e) {
+ LOGGER.error("Undeploying/Deleting policy failed {}", automationCompositionElementId, e);
}
}
- private void deletePolicyData(UUID automationCompositionId,
- UUID automationCompositionElementId, AutomationCompositionOrderedState newState) {
+ private void deletePolicyData(UUID automationCompositionId, UUID automationCompositionElementId) {
// Delete all policies of this automationComposition from policy framework
for (var policy : policyMap.entrySet()) {
apiHttpClient.deletePolicy(policy.getKey(), policy.getValue());
@@ -129,8 +100,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
policyTypeMap.clear();
}
- private void deployPolicies(UUID automationCompositionId, UUID automationCompositionElementId,
- AutomationCompositionOrderedState newState) {
+ private void deployPolicies(UUID automationCompositionId, UUID automationCompositionElementId) {
var deployFailure = false;
// Deploy all policies of this automationComposition from Policy Framework
if (!policyMap.entrySet().isEmpty()) {
@@ -145,11 +115,10 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
} else {
LOGGER.debug("No policies to deploy to {}", automationCompositionElementId);
}
- if (! deployFailure) {
+ if (!deployFailure) {
// Update the AC element state
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, newState, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ automationCompositionElementId, DeployState.DEPLOYED, LockState.LOCKED);
}
}
@@ -158,7 +127,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
if (!policyMap.entrySet().isEmpty()) {
for (var policy : policyMap.entrySet()) {
papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
- DeploymentSubGroup.Action.DELETE);
+ DeploymentSubGroup.Action.DELETE);
}
LOGGER.debug("Undeployed policies from {} successfully", automationCompositionElementId);
} else {
@@ -175,8 +144,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* @throws PfModelException in case of an exception
*/
@Override
- public void automationCompositionElementUpdate(UUID automationCompositionId,
- AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException {
+ public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
var createPolicyTypeResp = HttpStatus.SC_OK;
var createPolicyResp = HttpStatus.SC_OK;
@@ -187,7 +156,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
policyTypeMap.put(policyType.getName(), policyType.getVersion());
}
LOGGER.info("Found Policy Types in automation composition definition: {} , Creating Policy Types",
- automationCompositionDefinition.getName());
+ automationCompositionDefinition.getName());
createPolicyTypeResp = apiHttpClient.createPolicyType(automationCompositionDefinition).getStatus();
}
if (automationCompositionDefinition.getToscaTopologyTemplate().getPolicies() != null) {
@@ -197,16 +166,16 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
}
}
LOGGER.info("Found Policies in automation composition definition: {} , Creating Policies",
- automationCompositionDefinition.getName());
+ automationCompositionDefinition.getName());
createPolicyResp = apiHttpClient.createPolicy(automationCompositionDefinition).getStatus();
}
if (createPolicyTypeResp == HttpStatus.SC_OK && createPolicyResp == HttpStatus.SC_OK) {
LOGGER.info("PolicyTypes/Policies for the automation composition element : {} are created "
+ "successfully", element.getId());
- deployPolicies(automationCompositionId, element.getId(), element.getOrderedState());
+ deployPolicies(automationCompositionId, element.getId());
} else {
LOGGER.error("Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
}
}
}
-} \ No newline at end of file
+}
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 4fc10b828..e0b4a69c2 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-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,10 +33,8 @@ import org.mockito.Mockito;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
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.acm.participant.policy.main.parameters.CommonTestData;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -59,14 +57,7 @@ class AutomationCompositionElementHandlerTest {
void testHandlerDoesNotThrowExceptions() {
var handler = getTestingHandler();
- assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
- AutomationCompositionState.UNINITIALISED, AutomationCompositionOrderedState.PASSIVE));
-
- assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
- AutomationCompositionState.RUNNING, AutomationCompositionOrderedState.UNINITIALISED));
-
- assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
- AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.RUNNING));
+ assertDoesNotThrow(() -> handler.undeploy(AC_ID, automationCompositionElementId));
}
private AutomationCompositionElementHandler getTestingHandler() {
@@ -76,14 +67,11 @@ class AutomationCompositionElementHandlerTest {
return handler;
}
- private AutomationCompositionElement getTestingAcElement() {
- var element = new AutomationCompositionElement();
+ private AcElementDeploy getTestingAcElement() {
+ var element = new AcElementDeploy();
element.setDefinition(DEFINITION);
- element.setDescription("Description");
element.setId(automationCompositionElementId);
- element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- element.setParticipantId(CommonTestData.getParticipantId());
- element.setState(AutomationCompositionState.UNINITIALISED);
+ element.setOrderedState(DeployOrder.DEPLOY);
var template = new ToscaServiceTemplate();
template.setToscaTopologyTemplate(new ToscaTopologyTemplate());
template.getToscaTopologyTemplate().setPolicies(List.of(Map.of("DummyPolicy", new ToscaPolicy())));
@@ -102,17 +90,16 @@ class AutomationCompositionElementHandlerTest {
var handler = getTestingHandler();
var element = getTestingAcElement();
- assertDoesNotThrow(() -> handler.automationCompositionElementUpdate(AC_ID, element, Map.of()));
+ assertDoesNotThrow(() -> handler.deploy(AC_ID, element, Map.of()));
- assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
- AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.UNINITIALISED));
+ assertDoesNotThrow(() -> handler.undeploy(AC_ID, automationCompositionElementId));
// Mock failure in policy deployment
doReturn(Response.serverError().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
- assertDoesNotThrow(() -> handler.automationCompositionElementUpdate(AC_ID, element, Map.of()));
+ assertDoesNotThrow(() -> handler.deploy(AC_ID, element, Map.of()));
// Mock failure in policy type creation
doReturn(Response.serverError().build()).when(api).createPolicyType(any());
- assertDoesNotThrow(() -> handler.automationCompositionElementUpdate(AC_ID, element, Map.of()));
+ assertDoesNotThrow(() -> handler.deploy(AC_ID, element, Map.of()));
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
index ee769f481..da6bccb41 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 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,9 +22,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api;
import java.util.Map;
import java.util.UUID;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.models.base.PfModelException;
/**
@@ -35,13 +33,9 @@ public interface AutomationCompositionElementListener {
* Handle a automation composition element state change.
*
* @param automationCompositionElementId the ID of the automation composition element
- * @param currentState the current state of the automation composition element
- * @param newState the state to which the automation composition element is changing to
* @throws PfModelException in case of a model exception
*/
- public void automationCompositionElementStateChange(UUID automationCompositionId,
- UUID automationCompositionElementId, AutomationCompositionState currentState,
- AutomationCompositionOrderedState newState) throws PfModelException;
+ public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException;
/**
* Handle an update on a automation composition element.
@@ -51,6 +45,6 @@ public interface AutomationCompositionElementListener {
* @param properties properties Map
* @throws PfModelException from Policy framework
*/
- public void automationCompositionElementUpdate(UUID automationCompositionId,
- AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException;
+ public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException;
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
index d74c41f35..998a63269 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,10 +22,8 @@
package org.onap.policy.clamp.acm.participant.intermediary.api;
import java.util.UUID;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
/**
* This interface is used by participant implementations to use the participant intermediary.
@@ -38,17 +36,14 @@ public interface ParticipantIntermediaryApi {
* @param automationCompositionElementListener The automation composition element listener to register
*/
void registerAutomationCompositionElementListener(
- AutomationCompositionElementListener automationCompositionElementListener);
+ AutomationCompositionElementListener automationCompositionElementListener);
/**
* Update the state of a automation composition element.
*
* @param id the ID of the automation composition element to update the state on
- * @param currentState the state of the automation composition element
* @param newState the state of the automation composition element
- * @return AutomationCompositionElement updated automation composition element
*/
- AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId,
- UUID id, AutomationCompositionOrderedState currentState, AutomationCompositionState newState,
- ParticipantMessageType messageType);
+ void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState,
+ LockState lockState);
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index acbcc37a6..d729a097f 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,10 +25,8 @@ import java.util.UUID;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.springframework.stereotype.Component;
/**
@@ -56,10 +54,9 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
}
@Override
- public AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, UUID id,
- AutomationCompositionOrderedState currentState, AutomationCompositionState newState,
- ParticipantMessageType messageType) {
- return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id,
- currentState, newState);
+ public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState,
+ LockState lockState) {
+ automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState,
+ lockState);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
index 95e0f27bf..2d845d4c8 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
@@ -27,23 +27,26 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import java.util.stream.Collectors;
import lombok.Getter;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -60,6 +63,7 @@ public class AutomationCompositionHandler {
private final UUID participantId;
private final ParticipantMessagePublisher publisher;
+ private final AcInstanceStateResolver acInstanceStateResolver;
@Getter
private final Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
@@ -68,7 +72,7 @@ public class AutomationCompositionHandler {
private final Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
@Getter
- private List<AutomationCompositionElementListener> listeners = new ArrayList<>();
+ private final List<AutomationCompositionElementListener> listeners = new ArrayList<>();
/**
* Constructor, set the participant ID and messageSender.
@@ -79,6 +83,7 @@ public class AutomationCompositionHandler {
public AutomationCompositionHandler(ParticipantParameters parameters, ParticipantMessagePublisher publisher) {
this.participantId = parameters.getIntermediaryParameters().getParticipantId();
this.publisher = publisher;
+ this.acInstanceStateResolver = new AcInstanceStateResolver();
}
public void registerAutomationCompositionElementListener(AutomationCompositionElementListener listener) {
@@ -90,30 +95,32 @@ public class AutomationCompositionHandler {
*
* @param automationCompositionId the automationComposition Id
* @param id the automationComposition UUID
- * @param orderedState the current state
- * @param newState the ordered state
- * @return automationCompositionElement the updated automation composition element
+ * @param deployState the DeployState state
*/
- public AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId, UUID id,
- AutomationCompositionOrderedState orderedState, AutomationCompositionState newState) {
+ public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState,
+ LockState lockState) {
if (id == null) {
LOGGER.warn("Cannot update Automation composition element state, id is null");
- return null;
+ return;
}
// Update states of AutomationCompositionElement in automationCompositionMap
for (var automationComposition : automationCompositionMap.values()) {
var element = automationComposition.getElements().get(id);
if (element != null) {
- element.setOrderedState(orderedState);
- element.setState(newState);
+ element.setDeployState(deployState);
+ element.setLockState(lockState);
}
var checkOpt = automationComposition.getElements().values().stream()
- .filter(acElement -> !newState.equals(acElement.getState())).findAny();
+ .filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny();
+ if (checkOpt.isEmpty()) {
+ automationComposition.setDeployState(deployState);
+ }
+ checkOpt = automationComposition.getElements().values().stream()
+ .filter(acElement -> !lockState.equals(acElement.getLockState())).findAny();
if (checkOpt.isEmpty()) {
- automationComposition.setState(newState);
- automationComposition.setOrderedState(orderedState);
+ automationComposition.setLockState(lockState);
}
}
@@ -124,19 +131,17 @@ public class AutomationCompositionHandler {
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
automationCompositionStateChangeAck.setParticipantId(participantId);
automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId);
- acElement.setOrderedState(orderedState);
- acElement.setState(newState);
+ acElement.setDeployState(deployState);
+ acElement.setLockState(lockState);
automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(),
- new AcElementDeployAck(newState, null, null, true,
+ new AcElementDeployAck(deployState, lockState, true,
"Automation composition element {} state changed to {}\", id, newState)"));
- LOGGER.debug("Automation composition element {} state changed to {}", id, newState);
+ LOGGER.debug("Automation composition element {} state changed to {}", id, deployState);
automationCompositionStateChangeAck
- .setMessage("AutomationCompositionElement state changed to {} " + newState);
+ .setMessage("AutomationCompositionElement state changed to {} " + deployState);
automationCompositionStateChangeAck.setResult(true);
publisher.sendAutomationCompositionAck(automationCompositionStateChangeAck);
- return acElement;
}
- return null;
}
/**
@@ -168,8 +173,32 @@ public class AutomationCompositionHandler {
return;
}
- handleState(automationComposition, stateChangeMsg.getOrderedState(), stateChangeMsg.getStartPhase(),
- acElementDefinitions);
+ if (!checkConsistantOrderState(automationComposition, stateChangeMsg.getDeployOrderedState(),
+ stateChangeMsg.getLockOrderedState())) {
+ var automationCompositionAck =
+ new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
+ automationCompositionAck.setParticipantId(participantId);
+ automationCompositionAck.setMessage("Automation composition is already in state "
+ + stateChangeMsg.getDeployOrderedState() + " and " + stateChangeMsg.getLockOrderedState());
+ automationCompositionAck.setResult(false);
+ automationCompositionAck.setAutomationCompositionId(automationComposition.getInstanceId());
+ publisher.sendAutomationCompositionAck(automationCompositionAck);
+ return;
+ }
+
+ if (DeployOrder.NONE.equals(stateChangeMsg.getDeployOrderedState())) {
+ handleLockOrderState(automationComposition, stateChangeMsg.getLockOrderedState(),
+ stateChangeMsg.getStartPhase(), acElementDefinitions);
+ } else {
+ handleDeployOrderState(automationComposition, stateChangeMsg.getDeployOrderedState(),
+ stateChangeMsg.getStartPhase(), acElementDefinitions);
+ }
+ }
+
+ private boolean checkConsistantOrderState(AutomationComposition automationComposition, DeployOrder deployOrder,
+ LockOrder lockOrder) {
+ return acInstanceStateResolver.resolve(deployOrder, lockOrder, automationComposition.getDeployState(),
+ automationComposition.getLockState()) != null;
}
/**
@@ -180,18 +209,33 @@ public class AutomationCompositionHandler {
* @param startPhaseMsg startPhase from message
* @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- private void handleState(final AutomationComposition automationComposition,
- AutomationCompositionOrderedState orderedState, Integer startPhaseMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ private void handleDeployOrderState(final AutomationComposition automationComposition, DeployOrder orderedState,
+ Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+
+ if (DeployOrder.UNDEPLOY.equals(orderedState)) {
+ handleUndeployState(automationComposition, startPhaseMsg, acElementDefinitions);
+ } else {
+ LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey());
+ }
+ }
+
+ /**
+ * Method to handle state changes.
+ *
+ * @param automationComposition participant response
+ * @param orderedState automation composition ordered state
+ * @param startPhaseMsg startPhase from message
+ * @param acElementDefinitions the list of AutomationCompositionElementDefinition
+ */
+ private void handleLockOrderState(final AutomationComposition automationComposition, LockOrder orderedState,
+ Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+
switch (orderedState) {
- case UNINITIALISED:
- handleUninitialisedState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions);
- break;
- case PASSIVE:
- handlePassiveState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions);
+ case LOCK:
+ handleLockState(automationComposition, startPhaseMsg, acElementDefinitions);
break;
- case RUNNING:
- handleRunningState(automationComposition, orderedState, startPhaseMsg, acElementDefinitions);
+ case UNLOCK:
+ handleUnlockState(automationComposition, startPhaseMsg, acElementDefinitions);
break;
default:
LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey());
@@ -208,67 +252,49 @@ public class AutomationCompositionHandler {
public void handleAutomationCompositionDeploy(AutomationCompositionDeploy updateMsg,
List<AutomationCompositionElementDefinition> acElementDefinitions) {
- if (!updateMsg.appliesTo(participantId)) {
+ if (updateMsg.getParticipantUpdatesList().isEmpty()) {
+ LOGGER.warn("No AutomationCompositionElement updates in message {}",
+ updateMsg.getAutomationCompositionId());
return;
}
- if (0 == updateMsg.getStartPhase()) {
- handleAcUpdatePhase0(updateMsg, acElementDefinitions);
- } else {
- handleAcUpdatePhaseN(updateMsg, acElementDefinitions);
+ for (var participantDeploy : updateMsg.getParticipantUpdatesList()) {
+ if (participantId.equals(participantDeploy.getParticipantId())) {
+ if (updateMsg.isFirstStartPhase()) {
+ initializeDeploy(updateMsg.getMessageId(), updateMsg.getAutomationCompositionId(),
+ participantDeploy);
+ }
+ callParticipanDeploy(participantDeploy.getAcElementList(), acElementDefinitions,
+ updateMsg.getStartPhase(), updateMsg.getAutomationCompositionId());
+ }
}
}
- private void handleAcUpdatePhase0(AutomationCompositionDeploy updateMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
- var automationComposition = automationCompositionMap.get(updateMsg.getAutomationCompositionId());
+ private void initializeDeploy(UUID messageId, UUID instanceId, ParticipantDeploy participantDeploy) {
+ var automationComposition = automationCompositionMap.get(instanceId);
- // TODO: Updates to existing AutomationCompositions are not supported yet (Addition/Removal of
- // AutomationComposition
- // elements to existing AutomationComposition has to be supported).
if (automationComposition != null) {
var automationCompositionUpdateAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
automationCompositionUpdateAck.setParticipantId(participantId);
- automationCompositionUpdateAck.setMessage("Automation composition " + updateMsg.getAutomationCompositionId()
- + " already defined on participant " + participantId);
+ automationCompositionUpdateAck.setMessage(
+ "Automation composition " + instanceId + " already defined on participant " + participantId);
automationCompositionUpdateAck.setResult(false);
- automationCompositionUpdateAck.setResponseTo(updateMsg.getMessageId());
- automationCompositionUpdateAck.setAutomationCompositionId(updateMsg.getAutomationCompositionId());
+ automationCompositionUpdateAck.setResponseTo(messageId);
+ automationCompositionUpdateAck.setAutomationCompositionId(instanceId);
publisher.sendAutomationCompositionAck(automationCompositionUpdateAck);
return;
}
- if (updateMsg.getParticipantUpdatesList().isEmpty()) {
- LOGGER.warn("No AutomationCompositionElement updates in message {}",
- updateMsg.getAutomationCompositionId());
- return;
- }
-
automationComposition = new AutomationComposition();
- automationComposition.setInstanceId(updateMsg.getAutomationCompositionId());
- var acElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
- var acElementMap = prepareAcElementMap(acElements);
- automationComposition.setElements(acElementMap);
- automationCompositionMap.put(updateMsg.getAutomationCompositionId(), automationComposition);
-
- handleAutomationCompositionElementUpdate(acElements, acElementDefinitions, updateMsg.getStartPhase(),
- updateMsg.getAutomationCompositionId());
- }
-
- private void handleAcUpdatePhaseN(AutomationCompositionDeploy updateMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
-
- var acElementList = updateMsg.getParticipantUpdatesList().stream()
- .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream())
- .filter(element -> participantId.equals(element.getParticipantId())).collect(Collectors.toList());
-
- handleAutomationCompositionElementUpdate(acElementList, acElementDefinitions, updateMsg.getStartPhase(),
- updateMsg.getAutomationCompositionId());
+ automationComposition.setInstanceId(instanceId);
+ var acElements = storeElementsOnThisParticipant(participantDeploy);
+ automationComposition.setElements(prepareAcElementMap(acElements));
+ automationCompositionMap.put(instanceId, automationComposition);
}
- private void handleAutomationCompositionElementUpdate(List<AutomationCompositionElement> acElements,
+ private void callParticipanDeploy(List<AcElementDeploy> acElements,
List<AutomationCompositionElementDefinition> acElementDefinitions, Integer startPhaseMsg,
UUID automationCompositionId) {
try {
@@ -280,7 +306,7 @@ public class AutomationCompositionHandler {
for (var acElementListener : listeners) {
var map = new HashMap<>(acElementNodeTemplate.getProperties());
map.putAll(element.getProperties());
- acElementListener.automationCompositionElementUpdate(automationCompositionId, element, map);
+ acElementListener.deploy(automationCompositionId, element, map);
}
}
}
@@ -302,14 +328,16 @@ public class AutomationCompositionHandler {
return null;
}
- private List<AutomationCompositionElement> storeElementsOnThisParticipant(
- List<ParticipantDeploy> participantUpdates) {
- var acElementList = participantUpdates.stream()
- .flatMap(participantUpdate -> participantUpdate.getAutomationCompositionElementList().stream())
- .filter(element -> participantId.equals(element.getParticipantId())).collect(Collectors.toList());
-
- for (var element : acElementList) {
- elementsOnThisParticipant.put(element.getId(), element);
+ private List<AutomationCompositionElement> storeElementsOnThisParticipant(ParticipantDeploy participantDeploy) {
+ List<AutomationCompositionElement> acElementList = new ArrayList<>();
+ for (var element : participantDeploy.getAcElementList()) {
+ var acElement = new AutomationCompositionElement();
+ acElement.setId(element.getId());
+ acElement.setDefinition(element.getDefinition());
+ acElement.setDeployState(DeployState.DEPLOYING);
+ acElement.setLockState(LockState.NONE);
+ elementsOnThisParticipant.put(element.getId(), acElement);
+ acElementList.add(acElement);
}
return acElementList;
}
@@ -326,17 +354,18 @@ public class AutomationCompositionHandler {
* Method to handle when the new state from participant is UNINITIALISED state.
*
* @param automationComposition participant response
- * @param orderedState orderedState
* @param startPhaseMsg startPhase from message
* @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- private void handleUninitialisedState(final AutomationComposition automationComposition,
- final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg,
+ private void handleUndeployState(final AutomationComposition automationComposition, Integer startPhaseMsg,
List<AutomationCompositionElementDefinition> acElementDefinitions) {
- handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions);
+
+ automationComposition.getElements().values().stream()
+ .forEach(acElement -> automationCompositionElementUndeploy(automationComposition.getInstanceId(),
+ acElement, startPhaseMsg, acElementDefinitions));
+
boolean isAllUninitialised = automationComposition.getElements().values().stream()
- .filter(element -> !AutomationCompositionState.UNINITIALISED.equals(element.getState())).findAny()
- .isEmpty();
+ .filter(element -> !DeployState.UNDEPLOYED.equals(element.getDeployState())).findAny().isEmpty();
if (isAllUninitialised) {
automationCompositionMap.remove(automationComposition.getInstanceId());
automationComposition.getElements().values()
@@ -348,60 +377,55 @@ public class AutomationCompositionHandler {
* Method to handle when the new state from participant is PASSIVE state.
*
* @param automationComposition participant response
- * @param orderedState orderedState
* @param startPhaseMsg startPhase from message
* @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- private void handlePassiveState(final AutomationComposition automationComposition,
- final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg,
+ private void handleLockState(final AutomationComposition automationComposition, Integer startPhaseMsg,
List<AutomationCompositionElementDefinition> acElementDefinitions) {
- handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions);
+ automationComposition.getElements().values().stream()
+ .forEach(acElement -> automationCompositionElementLock(automationComposition.getInstanceId(), acElement,
+ startPhaseMsg, acElementDefinitions));
}
/**
* Method to handle when the new state from participant is RUNNING state.
*
* @param automationComposition participant response
- * @param orderedState orderedState
* @param startPhaseMsg startPhase from message
* @param acElementDefinitions the list of AutomationCompositionElementDefinition
*/
- private void handleRunningState(final AutomationComposition automationComposition,
- final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg,
+ private void handleUnlockState(final AutomationComposition automationComposition, Integer startPhaseMsg,
List<AutomationCompositionElementDefinition> acElementDefinitions) {
- handleStateChange(automationComposition, orderedState, startPhaseMsg, acElementDefinitions);
+ automationComposition.getElements().values().stream()
+ .forEach(acElement -> automationCompositionElementUnlock(automationComposition.getInstanceId(),
+ acElement, startPhaseMsg, acElementDefinitions));
}
- /**
- * Method to update the state of automation composition elements.
- *
- * @param automationComposition participant status in memory
- * @param orderedState orderedState the new ordered state the participant should have
- * @param startPhaseMsg startPhase from message
- * @param acElementDefinitions the list of AutomationCompositionElementDefinition
- */
- private void handleStateChange(AutomationComposition automationComposition,
- final AutomationCompositionOrderedState orderedState, Integer startPhaseMsg,
- List<AutomationCompositionElementDefinition> acElementDefinitions) {
-
- if (orderedState.equals(automationComposition.getOrderedState())) {
- var automationCompositionAck =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- automationCompositionAck.setParticipantId(participantId);
- automationCompositionAck.setMessage("Automation composition is already in state " + orderedState);
- automationCompositionAck.setResult(false);
- automationCompositionAck.setAutomationCompositionId(automationComposition.getInstanceId());
- publisher.sendAutomationCompositionAck(automationCompositionAck);
- return;
+ private void automationCompositionElementLock(UUID instanceId, AutomationCompositionElement acElement,
+ Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
+ if (acElementNodeTemplate != null) {
+ int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
+ if (startPhaseMsg.equals(startPhase)) {
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+ LockState.LOCKED);
+ }
}
+ }
- automationComposition.getElements().values().stream()
- .forEach(acElement -> automationCompositionElementStateChange(automationComposition, orderedState,
- acElement, startPhaseMsg, acElementDefinitions));
+ private void automationCompositionElementUnlock(UUID instanceId, AutomationCompositionElement acElement,
+ Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
+ if (acElementNodeTemplate != null) {
+ int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
+ if (startPhaseMsg.equals(startPhase)) {
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+ LockState.UNLOCKED);
+ }
+ }
}
- private void automationCompositionElementStateChange(AutomationComposition automationComposition,
- AutomationCompositionOrderedState orderedState, AutomationCompositionElement acElement,
+ private void automationCompositionElementUndeploy(UUID instanceId, AutomationCompositionElement acElement,
Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
if (acElementNodeTemplate != null) {
@@ -409,11 +433,9 @@ public class AutomationCompositionHandler {
if (startPhaseMsg.equals(startPhase)) {
for (var acElementListener : listeners) {
try {
- acElementListener.automationCompositionElementStateChange(automationComposition.getInstanceId(),
- acElement.getId(), acElement.getState(), orderedState);
+ acElementListener.undeploy(instanceId, acElement.getId());
} catch (PfModelException e) {
- LOGGER.debug("Automation composition element update failed {}",
- automationComposition.getInstanceId());
+ LOGGER.debug("Automation composition element update failed {}", instanceId);
}
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
index 3aae2c41a..719c428be 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
@@ -261,7 +261,8 @@ public class ParticipantHandler {
for (var entry : automationCompositionHandler.getAutomationCompositionMap().entrySet()) {
var acInfo = new AutomationCompositionInfo();
acInfo.setAutomationCompositionId(entry.getKey());
- acInfo.setState(entry.getValue().getState());
+ acInfo.setDeployState(entry.getValue().getDeployState());
+ acInfo.setLockState(entry.getValue().getLockState());
automationCompositionInfoList.add(acInfo);
}
return automationCompositionInfoList;
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
index 9b0f910ea..d86c9d0a4 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 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,8 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+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.CoderException;
class ParticipantIntermediaryApiImplTest {
@@ -47,11 +46,10 @@ class ParticipantIntermediaryApiImplTest {
var acElementListener = Mockito.mock(AutomationCompositionElementListener.class);
apiImpl.registerAutomationCompositionElementListener(acElementListener);
- var acElement = apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid,
- AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE,
- ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- assertEquals(AutomationCompositionOrderedState.UNINITIALISED, acElement.getOrderedState());
+ apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, DeployState.UNDEPLOYED,
+ LockState.NONE);
+ var acElement = automationComposiitonHandler.getElementsOnThisParticipant().get(uuid);
+ assertEquals(DeployState.UNDEPLOYED, acElement.getDeployState());
assertEquals(uuid, acElement.getId());
-
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
index ae8a8b2a0..35da039a5 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import java.util.List;
@@ -33,14 +32,15 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -55,15 +55,7 @@ class AutomationCompositionHandlerTest {
assertNotNull(ach.getAutomationCompositionMap());
assertNotNull(ach.getElementsOnThisParticipant());
- var elementId1 = UUID.randomUUID();
- var element = new AutomationCompositionElement();
- element.setId(elementId1);
- element.setDefinition(
- new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1"));
-
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
-
- AutomationCompositionElementListener listener = mock(AutomationCompositionElementListener.class);
+ var listener = mock(AutomationCompositionElementListener.class);
ach.registerAutomationCompositionElementListener(listener);
assertThat(ach.getListeners()).contains(listener);
}
@@ -73,11 +65,11 @@ class AutomationCompositionHandlerTest {
var id = UUID.randomUUID();
var ach = commonTestData.getMockAutomationCompositionHandler();
- assertNull(ach.updateAutomationCompositionElementState(null, null,
- AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE));
+ assertDoesNotThrow(
+ () -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, LockState.NONE));
- assertNull(ach.updateAutomationCompositionElementState(null, id,
- AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE));
+ assertDoesNotThrow(
+ () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, LockState.NONE));
}
@Test
@@ -89,29 +81,29 @@ class AutomationCompositionHandlerTest {
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
var key = ach.getElementsOnThisParticipant().keySet().iterator().next();
var value = ach.getElementsOnThisParticipant().get(key);
- assertEquals(AutomationCompositionState.UNINITIALISED, value.getState());
- ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid,
- AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE);
- assertEquals(AutomationCompositionState.PASSIVE, value.getState());
+ assertEquals(DeployState.UNDEPLOYED, value.getDeployState());
+ assertEquals(LockState.LOCKED, value.getLockState());
+ ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED,
+ LockState.UNLOCKED);
+ assertEquals(DeployState.DEPLOYED, value.getDeployState());
ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value);
- ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING);
- assertEquals(AutomationCompositionState.RUNNING, value.getState());
+ ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED,
+ LockState.UNLOCKED);
+ assertEquals(DeployState.DEPLOYED, value.getDeployState());
ach.getElementsOnThisParticipant().remove(key, value);
ach.getAutomationCompositionMap().values().iterator().next().getElements().clear();
- assertNull(ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING));
-
+ assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key,
+ DeployState.DEPLOYED, LockState.UNLOCKED));
}
@Test
- void handleAutomationCompositionUpdateExceptionTest() {
+ void handleAutomationCompositionStateChangeTest() {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
- var stateChange = commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.RUNNING);
+ var stateChange = commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
assertDoesNotThrow(() -> ach
.handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of()));
@@ -121,20 +113,30 @@ class AutomationCompositionHandlerTest {
stateChange.setAutomationCompositionId(UUID.randomUUID());
stateChange.setParticipantId(newPartecipantId);
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of()));
+ }
+ @Test
+ void handleAutomationCompositionDeployTest() {
var acd = new AutomationCompositionElementDefinition();
+ var definition = CommonTestData.getDefinition();
acd.setAcElementDefinitionId(definition);
var updateMsg = new AutomationCompositionDeploy();
updateMsg.setAutomationCompositionId(UUID.randomUUID());
+ var uuid = UUID.randomUUID();
updateMsg.setMessageId(uuid);
+ var partecipantId = CommonTestData.getParticipantId();
updateMsg.setParticipantId(partecipantId);
+ updateMsg.setFirstStartPhase(true);
updateMsg.setStartPhase(0);
var acElementDefinitions = List.of(acd);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ updateMsg.setFirstStartPhase(false);
updateMsg.setStartPhase(1);
assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
ach.getAutomationCompositionMap().clear();
+ updateMsg.setFirstStartPhase(true);
updateMsg.setStartPhase(0);
assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
@@ -145,9 +147,9 @@ class AutomationCompositionHandlerTest {
updateMsg.setStartPhase(1);
var participantDeploy = new ParticipantDeploy();
participantDeploy.setParticipantId(partecipantId);
- var element = new AutomationCompositionElement();
+ var element = new AcElementDeploy();
element.setDefinition(definition);
- participantDeploy.setAutomationCompositionElementList(List.of(element));
+ participantDeploy.setAcElementList(List.of(element));
updateMsg.setParticipantUpdatesList(List.of(participantDeploy));
var acd2 = new AutomationCompositionElementDefinition();
@@ -158,34 +160,38 @@ class AutomationCompositionHandlerTest {
}
@Test
- void automationCompositionStateChangeUninitialisedTest() {
+ void acUndeployTest() {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
- var stateChangeUninitialised =
- commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.UNINITIALISED);
+ var stateChangeUndeploy =
+ commonTestData.getStateChange(partecipantId, uuid, DeployOrder.UNDEPLOY, LockOrder.NONE);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of());
- stateChangeUninitialised.setAutomationCompositionId(UUID.randomUUID());
- stateChangeUninitialised.setParticipantId(CommonTestData.getRndParticipantId());
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of()));
+ stateChangeUndeploy
+ .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+ ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of());
+ stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID());
+ stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId());
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()));
}
@Test
- void automationCompositionStateChangePassiveTest() {
+ void automationCompositionStateUnlock() {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
- var stateChangePassive =
- commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.PASSIVE);
+ var stateChangeUnlock =
+ commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- ach.handleAutomationCompositionStateChange(stateChangePassive, List.of());
- stateChangePassive.setAutomationCompositionId(UUID.randomUUID());
- stateChangePassive.setParticipantId(CommonTestData.getRndParticipantId());
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangePassive, List.of()));
+ stateChangeUnlock
+ .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+ ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+ stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID());
+ stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId());
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()));
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
index 9641edc2e..4dcfd1428 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
@@ -37,11 +37,12 @@ import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHan
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
@@ -272,7 +273,7 @@ public class CommonTestData {
acElement.setId(uuid);
acElement.setParticipantId(participantId);
acElement.setDefinition(definition);
- acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
+ acElement.setDeployState(DeployState.UNDEPLOYED);
Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
elementsOnThisParticipant.put(uuid, acElement);
@@ -289,14 +290,8 @@ public class CommonTestData {
public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition,
UUID uuid, UUID participantId) {
var ach = getMockAutomationCompositionHandler();
-
- var key = getTestAutomationCompositionMap().keySet().iterator().next();
- var value = getTestAutomationCompositionMap().get(key);
- ach.getAutomationCompositionMap().put(key, value);
-
- var keyElem = setAutomationCompositionElementTest(uuid, definition, participantId).keySet().iterator().next();
- var valueElem = setAutomationCompositionElementTest(uuid, definition, participantId).get(keyElem);
- ach.getElementsOnThisParticipant().put(keyElem, valueElem);
+ ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap());
+ ach.getElementsOnThisParticipant().putAll(setAutomationCompositionElementTest(uuid, definition, participantId));
return ach;
}
@@ -306,17 +301,18 @@ public class CommonTestData {
*
* @param participantId the participantId
* @param uuid UUID
- * @param state a AutomationCompositionOrderedState
+ * @param deployOrder a DeployOrder
+ * @param lockOrder a LockOrder
* @return a AutomationCompositionStateChange
*/
public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid,
- AutomationCompositionOrderedState state) {
+ DeployOrder deployOrder, LockOrder lockOrder) {
var stateChange = new AutomationCompositionStateChange();
stateChange.setAutomationCompositionId(UUID.randomUUID());
stateChange.setParticipantId(participantId);
stateChange.setMessageId(uuid);
- stateChange.setOrderedState(state);
- stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED);
+ stateChange.setDeployOrderedState(deployOrder);
+ stateChange.setLockOrderedState(lockOrder);
stateChange.setTimestamp(Instant.ofEpochMilli(3000));
return stateChange;
}
diff --git a/pom.xml b/pom.xml
index 0b6d2c4fd..c8d721c79 100644
--- a/pom.xml
+++ b/pom.xml
@@ -174,10 +174,6 @@
<artifactId>springdoc-openapi-ui</artifactId>
</dependency>
<dependency>
- <groupId>org.immutables</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- <dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<scope>test</scope>
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/ParticipantControllerStub.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/ParticipantControllerStub.java
new file mode 100644
index 000000000..e87accf20
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/stub/ParticipantControllerStub.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.main.rest.stub;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import lombok.RequiredArgsConstructor;
+import org.onap.policy.clamp.acm.runtime.main.rest.gen.ParticipantMonitoringApi;
+import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Profile;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@Profile("stub")
+@RequiredArgsConstructor
+public class ParticipantControllerStub extends AbstractRestController implements ParticipantMonitoringApi {
+
+ private final StubUtils stubUtils;
+ @Value("${stub.getSingleParticipantResponse}")
+ private String pathToSingleParticipant;
+
+ @Value("${stub.getMultipleParticipantResponse}")
+ private String pathToParticipantList;
+
+ @Override
+ public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, UUID xonaprequestid) {
+ return stubUtils.getResponse(pathToSingleParticipant, ParticipantInformation.class);
+ }
+
+ @Override
+ public ResponseEntity<Void> orderAllParticipantsReport(UUID xonaprequestid) {
+ return new ResponseEntity(HttpStatus.ACCEPTED);
+ }
+
+ @Override
+ public ResponseEntity<Void> orderParticipantReport(UUID participantId, UUID xonaprequestid) {
+ return new ResponseEntity(HttpStatus.ACCEPTED);
+ }
+
+ @Override
+ public ResponseEntity<List<ParticipantInformation>> queryParticipants(String name, String version,
+ UUID xonaprequestid) {
+ List<ParticipantInformation> participantInformationList = new ArrayList<>();
+ return (ResponseEntity<List<ParticipantInformation>>) stubUtils
+ .getResponse(pathToParticipantList, participantInformationList.getClass());
+ }
+}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java
index de3fc753b..d0fcdd936 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java
@@ -59,6 +59,10 @@ public class AcmParticipantProvider {
participants.forEach(participant -> {
ParticipantInformation participantInformation = new ParticipantInformation();
participantInformation.setParticipant(participant);
+ participantInformation.setAcElementInstanceMap(getAutomationCompositionElementsForParticipant(participant
+ .getParticipantId()));
+ participantInformation.setAcNodeTemplateStateDefinitionMap(getNodeTemplateStatesForParticipant(participant
+ .getParticipantId()));
participantInformationList.add(participantInformation);
});
return participantInformationList;
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
index 3e79e78c1..5fcb3837f 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
@@ -79,7 +79,7 @@ public class SupervisionAcHandler {
AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYING, LockState.NONE);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionStateChangePublisher.undeploy(automationComposition, startPhase, true);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, true);
}
/**
@@ -92,7 +92,7 @@ public class SupervisionAcHandler {
AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.UNLOCKING);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionStateChangePublisher.unlock(automationComposition, startPhase, true);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, true);
}
/**
@@ -105,7 +105,7 @@ public class SupervisionAcHandler {
AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKING);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionStateChangePublisher.lock(automationComposition, startPhase, true);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, true);
}
/**
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
index 8d1f98388..ef50a633e 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
@@ -43,6 +43,7 @@ public class SupervisionAspect implements Closeable {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAspect.class);
private final SupervisionScanner supervisionScanner;
+ private final SupervisionPartecipantScanner partecipantScanner;
private ThreadPoolExecutor executor =
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
@@ -52,7 +53,12 @@ public class SupervisionAspect implements Closeable {
initialDelayString = "${runtime.participantParameters.heartBeatMs}")
public void schedule() {
LOGGER.info("Add scheduled scanning");
- executor.execute(() -> supervisionScanner.run(true));
+ executor.execute(this::executeScan);
+ }
+
+ private void executeScan() {
+ supervisionScanner.run(true);
+ partecipantScanner.run();
}
/**
@@ -68,7 +74,7 @@ public class SupervisionAspect implements Closeable {
@Before("@annotation(MessageIntercept) && args(participantStatusMessage,..)")
public void handleParticipantStatus(ParticipantStatus participantStatusMessage) {
- executor.execute(() -> supervisionScanner.handleParticipantStatus(participantStatusMessage.getParticipantId()));
+ executor.execute(() -> partecipantScanner.handleParticipantStatus(participantStatusMessage.getParticipantId()));
}
@Override
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
new file mode 100644
index 000000000..b396e629c
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision;
+
+import java.util.UUID;
+import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class is used to scan the automation compositions in the database and check if they are in the correct state.
+ */
+@Component
+public class SupervisionPartecipantScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class);
+
+ private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>();
+
+ private final ParticipantProvider participantProvider;
+
+ /**
+ * Constructor for instantiating SupervisionPartecipantScanner.
+ *
+ * @param participantProvider the Participant Provider
+ * @param acRuntimeParameterGroup the parameters for the automation composition runtime
+ */
+ public SupervisionPartecipantScanner(
+ final ParticipantProvider participantProvider,
+ final AcRuntimeParameterGroup acRuntimeParameterGroup) {
+ this.participantProvider = participantProvider;
+
+ participantStatusCounter.setMaxRetryCount(
+ acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
+ participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ }
+
+ /**
+ * Run Scanning.
+ */
+ public void run() {
+ LOGGER.debug("Scanning participans in the database . . .");
+
+ for (var participant : participantProvider.getParticipants()) {
+ scanParticipantStatus(participant);
+ }
+
+ LOGGER.debug("Participans scan complete . . .");
+ }
+
+ private void scanParticipantStatus(Participant participant) {
+ var id = participant.getParticipantId();
+ if (participantStatusCounter.isFault(id)) {
+ LOGGER.debug("report Participant fault");
+ return;
+ }
+ if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()
+ && !participantStatusCounter.count(id)) {
+ LOGGER.debug("report Participant fault");
+ participantStatusCounter.setFault(id);
+ participant.setParticipantState(ParticipantState.OFF_LINE);
+ participantProvider.updateParticipant(participant);
+ }
+ }
+
+ /**
+ * handle participant Status message.
+ */
+ public void handleParticipantStatus(UUID id) {
+ participantStatusCounter.clear(id);
+ }
+}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
index 75fed71e0..6cf75ccb6 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
@@ -83,6 +83,7 @@ public class SupervisionParticipantHandler {
var participant = participantOpt.get();
participant.setParticipantState(ParticipantState.OFF_LINE);
participantProvider.updateParticipant(participant);
+ participantProvider.resetParticipantAcElementState(participant.getParticipantId());
}
participantDeregisterAckPublisher.send(participantDeregisterMsg.getMessageId());
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
index 68ec44dc0..7ee7267e2 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
@@ -29,13 +29,11 @@ import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,15 +47,12 @@ public class SupervisionScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class);
private final HandleCounter<UUID> automationCompositionCounter = new HandleCounter<>();
- private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>();
-
private final Map<UUID, Integer> phaseMap = new HashMap<>();
private final AutomationCompositionProvider automationCompositionProvider;
private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
- private final ParticipantProvider participantProvider;
/**
* Constructor for instantiating SupervisionScanner.
@@ -66,29 +61,22 @@ public class SupervisionScanner {
* @param acDefinitionProvider the Policy Models Provider
* @param automationCompositionStateChangePublisher the AutomationComposition StateChange Publisher
* @param automationCompositionDeployPublisher the AutomationCompositionUpdate Publisher
- * @param participantProvider the Participant Provider
* @param acRuntimeParameterGroup the parameters for the automation composition runtime
*/
public SupervisionScanner(final AutomationCompositionProvider automationCompositionProvider,
- AcDefinitionProvider acDefinitionProvider,
- final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
- AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
- ParticipantProvider participantProvider,
- final AcRuntimeParameterGroup acRuntimeParameterGroup) {
+ final AcDefinitionProvider acDefinitionProvider,
+ final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
+ final AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
+ final AcRuntimeParameterGroup acRuntimeParameterGroup) {
this.automationCompositionProvider = automationCompositionProvider;
this.acDefinitionProvider = acDefinitionProvider;
this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher;
this.automationCompositionDeployPublisher = automationCompositionDeployPublisher;
- this.participantProvider = participantProvider;
automationCompositionCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
+ acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
automationCompositionCounter
- .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
-
- participantStatusCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
@@ -99,12 +87,6 @@ public class SupervisionScanner {
public void run(boolean counterCheck) {
LOGGER.debug("Scanning automation compositions in the database . . .");
- if (counterCheck) {
- for (var participant : participantProvider.getParticipants()) {
- scanParticipantStatus(participant);
- }
- }
-
var list = acDefinitionProvider.getAllAcDefinitions();
for (var acDefinition : list) {
var acList = automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId());
@@ -116,33 +98,12 @@ public class SupervisionScanner {
LOGGER.debug("Automation composition scan complete . . .");
}
- private void scanParticipantStatus(Participant participant) {
- var id = participant.getParticipantId();
- if (participantStatusCounter.isFault(id)) {
- LOGGER.debug("report Participant fault");
- return;
- }
- if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()
- && !participantStatusCounter.count(id)) {
- LOGGER.debug("report Participant fault");
- participantStatusCounter.setFault(id);
- participant.setParticipantState(ParticipantState.OFF_LINE);
- participantProvider.updateParticipant(participant);
- }
- }
-
- /**
- * handle participant Status message.
- */
- public void handleParticipantStatus(UUID id) {
- participantStatusCounter.clear(id);
- }
-
private void scanAutomationComposition(final AutomationComposition automationComposition,
- ToscaServiceTemplate toscaServiceTemplate, boolean counterCheck) {
+ ToscaServiceTemplate serviceTemplate, boolean counterCheck) {
LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId());
- if (automationComposition.getState().equals(automationComposition.getOrderedState().asState())) {
+ if (!AcmUtils.isInTransitionalState(automationComposition.getDeployState(),
+ automationComposition.getLockState())) {
LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId());
// Clear missed report counter on automation composition
@@ -156,12 +117,12 @@ public class SupervisionScanner {
var defaultMin = 1000; // min startPhase
var defaultMax = 0; // max startPhase
for (var element : automationComposition.getElements().values()) {
- var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
- .get(element.getDefinition().getName());
+ var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
defaultMin = Math.min(defaultMin, startPhase);
defaultMax = Math.max(defaultMax, startPhase);
- if (!element.getState().equals(element.getOrderedState().asState())) {
+ if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) {
completed = false;
minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase);
@@ -169,36 +130,35 @@ public class SupervisionScanner {
}
if (completed) {
- LOGGER.debug("automation composition scan: transition from state {} to {} completed",
- automationComposition.getState(), automationComposition.getOrderedState());
+ LOGGER.debug("automation composition scan: transition state {} {} ", automationComposition.getDeployState(),
+ automationComposition.getLockState());
- automationComposition.setState(automationComposition.getOrderedState().asState());
+ var deployState = automationComposition.getDeployState();
+ automationComposition.setDeployState(AcmUtils.deployCompleted(deployState));
+ automationComposition
+ .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState()));
automationCompositionProvider.updateAutomationComposition(automationComposition);
// Clear missed report counter on automation composition
clearFaultAndCounter(automationComposition);
} else {
LOGGER.debug("automation composition scan: transition from state {} to {} not completed",
- automationComposition.getState(), automationComposition.getOrderedState());
+ automationComposition.getDeployState(), automationComposition.getLockState());
- var nextSpNotCompleted =
- AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())
- || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState())
- ? minSpNotCompleted
- : maxSpNotCompleted;
+ var isForward =
+ AcmUtils.isForward(automationComposition.getDeployState(), automationComposition.getLockState());
- var firstStartPhase =
- AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())
- || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState())
- ? defaultMin
- : defaultMax;
+ var nextSpNotCompleted = isForward ? minSpNotCompleted : maxSpNotCompleted;
+ var firstStartPhase = isForward ? defaultMin : defaultMax;
if (nextSpNotCompleted != phaseMap.getOrDefault(automationComposition.getInstanceId(), firstStartPhase)) {
phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted);
- sendAutomationCompositionMsg(automationComposition, nextSpNotCompleted);
+ sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted,
+ firstStartPhase == nextSpNotCompleted);
} else if (counterCheck) {
phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted);
- handleCounter(automationComposition, nextSpNotCompleted);
+ handleCounter(automationComposition, serviceTemplate, nextSpNotCompleted,
+ firstStartPhase == nextSpNotCompleted);
}
}
}
@@ -208,7 +168,8 @@ public class SupervisionScanner {
phaseMap.remove(automationComposition.getInstanceId());
}
- private void handleCounter(AutomationComposition automationComposition, int startPhase) {
+ private void handleCounter(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate,
+ int startPhase, boolean firstStartPhase) {
var instanceId = automationComposition.getInstanceId();
if (automationCompositionCounter.isFault(instanceId)) {
LOGGER.debug("report AutomationComposition fault");
@@ -218,7 +179,7 @@ public class SupervisionScanner {
if (automationCompositionCounter.getDuration(instanceId) > automationCompositionCounter.getMaxWaitMs()) {
if (automationCompositionCounter.count(instanceId)) {
phaseMap.put(instanceId, startPhase);
- sendAutomationCompositionMsg(automationComposition, startPhase);
+ sendAutomationCompositionMsg(automationComposition, serviceTemplate, startPhase, firstStartPhase);
} else {
LOGGER.debug("report AutomationComposition fault");
automationCompositionCounter.setFault(instanceId);
@@ -226,13 +187,15 @@ public class SupervisionScanner {
}
}
- private void sendAutomationCompositionMsg(AutomationComposition automationComposition, int startPhase) {
- if (AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())) {
+ private void sendAutomationCompositionMsg(AutomationComposition automationComposition,
+ ToscaServiceTemplate serviceTemplate, int startPhase, boolean firstStartPhase) {
+ if (DeployState.DEPLOYING.equals(automationComposition.getDeployState())) {
LOGGER.debug("retry message AutomationCompositionUpdate");
- automationCompositionDeployPublisher.send(automationComposition, startPhase);
+ automationCompositionDeployPublisher.send(automationComposition, serviceTemplate, startPhase,
+ firstStartPhase);
} else {
LOGGER.debug("retry message AutomationCompositionStateChange");
- automationCompositionStateChangePublisher.send(automationComposition, startPhase);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase);
}
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
index cc4a05939..2628f030d 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
@@ -36,7 +36,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
-import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -53,53 +52,13 @@ import org.springframework.stereotype.Component;
public class AutomationCompositionDeployPublisher extends AbstractParticipantPublisher<AutomationCompositionDeploy> {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionDeployPublisher.class);
- private final AcDefinitionProvider acDefinitionProvider;
-
- /**
- * Send AutomationCompositionDeploy to Participant.
- *
- * @param automationComposition the AutomationComposition
- */
- @Timed(value = "publisher.automation_composition_deploy",
- description = "AUTOMATION_COMPOSITION_DEPLOY messages published")
- public void send(AutomationComposition automationComposition) {
- send(automationComposition, 0);
- }
-
- /**
- * Send AutomationCompositionDeploy to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the Start Phase
- */
- @Timed(value = "publisher.automation_composition_deploy",
- description = "AUTOMATION_COMPOSITION_DEPLOY messages published")
- public void send(AutomationComposition automationComposition, int startPhase) {
- var acDeployMsg = new AutomationCompositionDeploy();
- acDeployMsg.setCompositionId(automationComposition.getCompositionId());
- acDeployMsg.setStartPhase(startPhase);
- acDeployMsg.setAutomationCompositionId(automationComposition.getInstanceId());
- acDeployMsg.setMessageId(UUID.randomUUID());
- acDeployMsg.setTimestamp(Instant.now());
- var toscaServiceTemplate =
- acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate();
-
- List<ParticipantDeploy> participantDeploys = new ArrayList<>();
- for (var element : automationComposition.getElements().values()) {
- element.setToscaServiceTemplateFragment(AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate));
- AcmUtils.prepareParticipantUpdate(element, participantDeploys);
- }
- acDeployMsg.setParticipantUpdatesList(participantDeploys);
-
- LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg);
- super.send(acDeployMsg);
- }
/**
* Send AutomationCompositionDeploy to Participant.
*
* @param automationComposition the AutomationComposition
* @param startPhase the Start Phase
+ * @param firstStartPhase true if the first StartPhase
*/
@Timed(value = "publisher.automation_composition_deploy",
description = "AUTOMATION_COMPOSITION_DEPLOY messages published")
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java
index 56a62e13b..e59c2ac18 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java
@@ -24,8 +24,7 @@ import io.micrometer.core.annotation.Timed;
import java.util.UUID;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.springframework.stereotype.Component;
/**
@@ -36,7 +35,7 @@ public class AutomationCompositionStateChangePublisher
extends AbstractParticipantPublisher<AutomationCompositionStateChange> {
/**
- * Send undeploy message to to Participant.
+ * Send AutomationCompositionStateChange message to to Participant.
*
* @param automationComposition the AutomationComposition
* @param startPhase the startPhase
@@ -44,75 +43,16 @@ public class AutomationCompositionStateChangePublisher
@Timed(
value = "publisher.automation_composition_state_change",
description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void undeploy(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
- send(automationComposition, startPhase, firstStartPhase, DeployOrder.UNDEPLOY, LockOrder.NONE);
- }
-
- /**
- * Send unlock message to to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- */
- @Timed(
- value = "publisher.automation_composition_state_change",
- description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void unlock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
- send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.UNLOCK);
- }
-
- /**
- * Send lock message to to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- */
- @Timed(
- value = "publisher.automation_composition_state_change",
- description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void lock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
- send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.LOCK);
- }
-
- /**
- * Send undeploy message to to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- * @param deployOrder the DeployOrder
- * @param lockOrder the LockOrder
- */
- private void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase,
- DeployOrder deployOrder, LockOrder lockOrder) {
+ public void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
var acsc = new AutomationCompositionStateChange();
acsc.setCompositionId(automationComposition.getCompositionId());
acsc.setAutomationCompositionId(automationComposition.getInstanceId());
acsc.setMessageId(UUID.randomUUID());
- acsc.setDeployOrderedState(deployOrder);
- acsc.setLockOrderedState(lockOrder);
+ acsc.setDeployOrderedState(AcmUtils.stateDeployToOrder(automationComposition.getDeployState()));
+ acsc.setLockOrderedState(AcmUtils.stateLockToOrder(automationComposition.getLockState()));
acsc.setStartPhase(startPhase);
acsc.setFirstStartPhase(firstStartPhase);
super.send(acsc);
}
-
- /**
- * Send AutomationCompositionStateChange to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- */
- @Timed(
- value = "publisher.automation_composition_state_change",
- description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void send(AutomationComposition automationComposition, int startPhase) {
- var acsc = new AutomationCompositionStateChange();
- acsc.setCompositionId(automationComposition.getCompositionId());
- acsc.setAutomationCompositionId(automationComposition.getInstanceId());
- acsc.setMessageId(UUID.randomUUID());
- acsc.setOrderedState(automationComposition.getOrderedState());
- acsc.setStartPhase(startPhase);
-
- super.send(acsc);
- }
}
diff --git a/runtime-acm/src/main/resources/application-stub.yaml b/runtime-acm/src/main/resources/application-stub.yaml
index e752df3fd..39641e39d 100644
--- a/runtime-acm/src/main/resources/application-stub.yaml
+++ b/runtime-acm/src/main/resources/application-stub.yaml
@@ -8,6 +8,8 @@ stub:
getAllCompositionInstancesResponse: "/openapi/examples/getAllCompositionInstancesResponse.json"
getCompositionInstancesResponse: "/openapi/examples/getCompositionInstancesResponse.json"
getSingleCompositionDefinition: "/openapi/examples/getSingleCompositionDefinition.json"
+ getSingleParticipantResponse: "/openapi/examples/getSingleParticipantResponse.json"
+ getMultipleParticipantResponse: "/openapi/examples/getMultipleParticipantResponse.json"
postCommissionResponse: "/openapi/examples/postCommissionCompositionDefinitionsResponse.json"
postCompositionDefinitions: "/openapi/examples/postCompositionDefinitions.json"
postCompositionInstance: "/openapi/examples/postCompositionInstance.json"
@@ -16,6 +18,6 @@ stub:
putCompositionDefinitionUpdateResponse: "/openapi/examples/putCompositionDefinitionUpdateResponse.json"
putCompositionInstanceUpdate: "/openapi/examples/putCompositionInstanceUpdate.json"
putCompositionInstanceUpdateResponse: " /openapi/examples/putCompositionInstanceUpdateResponse.json"
-
-
+
+
diff --git a/runtime-acm/src/main/resources/openapi/examples/getMultipleParticipantResponse.json b/runtime-acm/src/main/resources/openapi/examples/getMultipleParticipantResponse.json
new file mode 100644
index 000000000..7e277c5a3
--- /dev/null
+++ b/runtime-acm/src/main/resources/openapi/examples/getMultipleParticipantResponse.json
@@ -0,0 +1,88 @@
+[
+ {
+ "participant": {
+ "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03",
+ "participantState": "ON_LINE",
+ "participantSupportedElementTypes": {
+ "3012010d-e59e-4dde-bab1-3ee544e49b6d": {
+ "id": "3012010d-e59e-4dde-bab1-3ee544e49b6d",
+ "typeName": "org.onap.policy.clamp.acm.AutomationCompositionElement",
+ "typeVersion": "1.0.1"
+ },
+ "8d9e947e-c444-471c-9420-29f1c6584f8c": {
+ "id": "8d9e947e-c444-471c-9420-29f1c6584f8c",
+ "typeName": "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement",
+ "typeVersion": "1.0.1"
+ }
+ }
+ },
+ "acNodeTemplateStateDefinitionMap": {
+ "8cf8b401-dfd7-4ffe-90ff-c6543da10789": {
+ "nodeTemplateStateId": "8cf8b401-dfd7-4ffe-90ff-c6543da10789",
+ "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03",
+ "nodeTemplateId": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "state": "PRIMED"
+ }
+ },
+ "acElementInstanceMap": {
+ "709c62b3-8918-41b9-a747-d21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03",
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "Automation composition element for the operational policy for Performance Management Subscription Handling",
+ "properties": {}
+ }
+ }
+ },
+ {
+ "participant": {
+ "participantId": "985d73aa-abba-11ed-afa1-0242ac120002",
+ "participantState": "ON_LINE",
+ "participantSupportedElementTypes": {
+ "cded8a5a-abba-11ed-afa1-0242ac120002": {
+ "id": "cded8a5a-abba-11ed-afa1-0242ac120002",
+ "typeName": "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement",
+ "typeVersion": "1.0.1"
+ },
+ "25ac7864-abbb-11ed-afa1-0242ac120002": {
+ "id": "25ac7864-abbb-11ed-afa1-0242ac120002",
+ "typeName": "org.onap.policy.clamp.acm.AutomationCompositionElement",
+ "typeVersion": "1.0.1"
+ }
+ }
+ },
+ "acNodeTemplateStateDefinitionMap": {
+ "34b4d248-abbb-11ed-afa1-0242ac120002": {
+ "nodeTemplateStateId": "34b4d248-abbb-11ed-afa1-0242ac120002",
+ "participantId": "985d73aa-abba-11ed-afa1-0242ac120002",
+ "nodeTemplateId": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "state": "PRIMED"
+ }
+ },
+ "acElementInstanceMap": {
+ "3dd7a936-abbb-11ed-afa1-0242ac120002": {
+ "id": "3dd7a936-abbb-11ed-afa1-0242ac120002",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "participantId": "985d73aa-abba-11ed-afa1-0242ac120002",
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "Automation composition element for the operational policy for Performance Management Subscription Handling",
+ "properties": {}
+ }
+ }
+ }
+]
diff --git a/runtime-acm/src/main/resources/openapi/examples/getSingleParticipantResponse.json b/runtime-acm/src/main/resources/openapi/examples/getSingleParticipantResponse.json
new file mode 100644
index 000000000..350fd29d7
--- /dev/null
+++ b/runtime-acm/src/main/resources/openapi/examples/getSingleParticipantResponse.json
@@ -0,0 +1,43 @@
+{
+ "participant": {
+ "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03",
+ "participantState": "ON_LINE",
+ "participantSupportedElementTypes": {
+ "3012010d-e59e-4dde-bab1-3ee544e49b6d": {
+ "id": "3012010d-e59e-4dde-bab1-3ee544e49b6d",
+ "typeName": "org.onap.policy.clamp.acm.AutomationCompositionElement",
+ "typeVersion": "1.0.1"
+ },
+ "8d9e947e-c444-471c-9420-29f1c6584f8c": {
+ "id": "8d9e947e-c444-471c-9420-29f1c6584f8c",
+ "typeName": "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement",
+ "typeVersion": "1.0.1"
+ }
+ }
+ },
+ "acNodeTemplateStateDefinitionMap": {
+ "8cf8b401-dfd7-4ffe-90ff-c6543da10789": {
+ "nodeTemplateStateId": "8cf8b401-dfd7-4ffe-90ff-c6543da10789",
+ "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03",
+ "nodeTemplateId": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "state": "PRIMED"
+ }
+ },
+ "acElementInstanceMap": {
+ "709c62b3-8918-41b9-a747-d21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
+ "version": "1.2.3"
+ },
+ "participantId": "101c62b3-8918-41b9-a747-d21eb79c6c03",
+ "deployState": "DEPLOYED",
+ "lockState": "UNLOCKED",
+ "description": "Automation composition element for the operational policy for Performance Management Subscription Handling",
+ "properties": {}
+ }
+ }
+}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java
new file mode 100644
index 000000000..f0cd359c6
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.contract;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles({ "test", "stub" })
+public class ParticipantControllerStubTest extends CommonRestController {
+ private static final String PARTICIPANT_ENDPOINT = "participants";
+ private static final String PARTICIPANT_ID = "101c62b3-8918-41b9-a747-d21eb79c6c03";
+
+ @LocalServerPort
+ private int randomServerPort;
+
+ @BeforeEach
+ public void setUpPort() {
+ super.setHttpPrefix(randomServerPort);
+ }
+
+ @Test
+ void testGet() {
+ var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT + "/" + PARTICIPANT_ID);
+ var respPost = invocationBuilder.get();
+ assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
+ }
+
+ @Test
+ void testQuery() {
+ var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT);
+ var respPost = invocationBuilder.get();
+ assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
+ }
+
+ @Test
+ void testOrderReport() {
+ var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT + "/" + PARTICIPANT_ID);
+
+ var respPost = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
+ + "", MediaType.APPLICATION_JSON));
+ assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
+ }
+
+ @Test
+ void testOrderAllReport() {
+ var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT);
+
+ var respPost = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
+ + "", MediaType.APPLICATION_JSON));
+ assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
+ }
+}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
index e16672d14..153f7a0e0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -21,9 +21,12 @@
package org.onap.policy.clamp.acm.runtime.supervision;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import java.util.Map;
import java.util.Optional;
@@ -34,6 +37,7 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionD
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
@@ -60,7 +64,7 @@ class SupervisionAcHandlerTest {
var automationCompositionAckMessage =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
+ var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
acElementDeployAck);
}
@@ -82,7 +86,7 @@ class SupervisionAcHandlerTest {
var automationCompositionAckMessage =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.LOCKED, true, "");
+ var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, true, "");
automationCompositionAckMessage
.setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
}
@@ -97,4 +101,55 @@ class SupervisionAcHandlerTest {
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
+
+ @Test
+ void testUndeploy() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ acStateChangePublisher);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Undeploy");
+ handler.undeploy(automationComposition, acDefinition);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ }
+
+ @Test
+ void testUnlock() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ acStateChangePublisher);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock");
+ handler.unlock(automationComposition, acDefinition);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ }
+
+ @Test
+ void testLock() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ acStateChangePublisher);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
+ handler.lock(automationComposition, acDefinition);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
index b913cfac9..c9985e203 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
@@ -34,16 +34,19 @@ class SupervisionAspectTest {
@Test
void testSchedule() throws Exception {
var supervisionScanner = mock(SupervisionScanner.class);
- try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ var partecipantScanner = mock(SupervisionPartecipantScanner.class);
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.schedule();
verify(supervisionScanner, timeout(500)).run(true);
+ verify(partecipantScanner, timeout(500)).run();
}
}
@Test
void testDoCheck() throws Exception {
var supervisionScanner = mock(SupervisionScanner.class);
- try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ var partecipantScanner = mock(SupervisionPartecipantScanner.class);
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.doCheck();
supervisionAspect.doCheck();
verify(supervisionScanner, timeout(500).times(2)).run(false);
@@ -56,9 +59,10 @@ class SupervisionAspectTest {
participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
var supervisionScanner = mock(SupervisionScanner.class);
- try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ var partecipantScanner = mock(SupervisionPartecipantScanner.class);
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.handleParticipantStatus(participantStatusMessage);
- verify(supervisionScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId());
+ verify(partecipantScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId());
}
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
index f47e2372a..246ba7dc7 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
@@ -57,6 +57,7 @@ class SupervisionParticipantHandlerTest {
handler.handleParticipantMessage(participantDeregisterMessage);
verify(participantProvider).updateParticipant(any());
+ verify(participantProvider).resetParticipantAcElementState(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
new file mode 100644
index 000000000..3ad9f813c
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.models.base.PfModelException;
+
+class SupervisionParticipantScannerTest {
+
+ @Test
+ void testScanParticipant() throws PfModelException {
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
+ acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
+ acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
+
+ var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
+ participant.setParticipantState(ParticipantState.OFF_LINE);
+ var participantProvider = mock(ParticipantProvider.class);
+ when(participantProvider.getParticipants()).thenReturn(List.of(participant));
+
+ var supervisionScanner = new SupervisionPartecipantScanner(participantProvider, acRuntimeParameterGroup);
+
+ supervisionScanner.handleParticipantStatus(participant.getParticipantId());
+ supervisionScanner.run();
+ verify(participantProvider, times(0)).saveParticipant(any());
+
+ supervisionScanner.run();
+ verify(participantProvider, times(1)).updateParticipant(any());
+ }
+}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index fe34c6b04..032468a56 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.runtime.supervision;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -39,13 +40,11 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionS
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+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.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class SupervisionScannerTest {
@@ -70,16 +69,15 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
- var participantProvider = mock(ParticipantProvider.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
@@ -88,20 +86,19 @@ class SupervisionScannerTest {
@Test
void testScannerOrderedStateDifferentToState() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var participantProvider = mock(ParticipantProvider.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
@@ -112,21 +109,16 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition = new AutomationComposition();
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
-
- var participantProvider = mock(ParticipantProvider.class);
- var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
- when(participantProvider.getParticipants()).thenReturn(List.of(participant));
+ .thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
- supervisionScanner.handleParticipantStatus(participant.getParticipantId());
supervisionScanner.run(true);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
@@ -134,65 +126,68 @@ class SupervisionScannerTest {
@Test
void testSendAutomationCompositionMsgUpdate() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
- .equals(element.getDefinition().getName())) {
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- element.setState(AutomationCompositionState.UNINITIALISED);
+ .equals(element.getDefinition().getName())) {
+ element.setDeployState(DeployState.DEPLOYING);
+ element.setLockState(LockState.NONE);
} else {
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- element.setState(AutomationCompositionState.PASSIVE);
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.LOCKED);
}
}
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
- var participantProvider = mock(ParticipantProvider.class);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
- verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class), anyInt());
+ verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class),
+ any(ToscaServiceTemplate.class), anyInt(), anyBoolean());
}
@Test
- void testScanParticipant() throws PfModelException {
+ void testSendAutomationCompositionMsgUnlocking() {
+ var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKING);
+ for (var element : automationComposition.getElements().values()) {
+ if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
+ .equals(element.getDefinition().getName())) {
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.UNLOCKING);
+ } else {
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.UNLOCKED);
+ }
+ }
+
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var automationComposition = new AutomationComposition();
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
-
- var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
- acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
-
- var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
- participant.setParticipantState(ParticipantState.OFF_LINE);
- var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.getParticipants()).thenReturn(List.of(participant));
+ .thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
- supervisionScanner.handleParticipantStatus(participant.getParticipantId());
- supervisionScanner.run(true);
- verify(participantProvider, times(0)).saveParticipant(any());
+ supervisionScanner.run(false);
- supervisionScanner.run(true);
- verify(participantProvider, times(1)).updateParticipant(any());
+ verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), anyInt(),
+ anyBoolean());
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 0072a1042..e0accc4a0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -42,7 +42,8 @@ import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
@@ -117,14 +118,15 @@ class SupervisionMessagesTest {
@Test
void testSendAutomationCompositionStateChangePublisherNotActive() {
var publisher = new AutomationCompositionStateChangePublisher();
- assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0)).hasMessage(NOT_ACTIVE);
+ assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0, true)).hasMessage(NOT_ACTIVE);
}
private AutomationComposition getAutomationComposition() {
var automationComposition = new AutomationComposition();
automationComposition.setName("NAME");
automationComposition.setVersion("0.0.1");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKING);
return automationComposition;
}
@@ -133,7 +135,7 @@ class SupervisionMessagesTest {
var publisher = new AutomationCompositionStateChangePublisher();
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
- publisher.send(getAutomationComposition(), 0);
+ publisher.send(getAutomationComposition(), 0, true);
verify(topicSink).send(anyString());
publisher.stop();
}
@@ -152,12 +154,12 @@ class SupervisionMessagesTest {
var participantId = UUID.randomUUID();
Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>();
supportedElementMap.put(
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"),
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"),
participantId);
supportedElementMap.put(new ToscaConceptIdentifier(
- "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.1"), participantId);
+ "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.0"), participantId);
supportedElementMap.put(
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"),
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"),
participantId);
var participantProvider = mock(ParticipantProvider.class);
when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap);