summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-02-10 15:28:50 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-02-13 16:28:28 +0000
commite45da39db2625accf9ba3a77dc936a87d560fb5e (patch)
tree626de1ca14703df7dd1a81526966481cd57cc456
parent1191f992ddf1f6bcc94e7fa246ee3efbc71a3a8f (diff)
Deployment and undeployment on Participant Intermediary
Handle AC Element Instance Deployment and undeployment on Participant Intermediary. Issue-ID: POLICY-4507 Change-Id: I6a6976a8893450467ee609a1a476dbfa473a0e82 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java3
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java5
-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/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--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java4
21 files changed, 379 insertions, 524 deletions
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/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/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/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/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..fb285a84c 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
@@ -60,7 +60,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 +82,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));
}