summaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-07-23 12:45:09 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2024-07-23 15:16:00 +0000
commitb2bc0f63a484abe5b77b1e921d820ae80481602b (patch)
tree57450bb88f425afcb10332c65d36ffe9703a9159 /participant/participant-impl
parent1c144c87fbe077eb471650064c64888c4501f581 (diff)
Add support for Prepare, Review and Migrate pre-check in participant
Add support for Prepare, Review and Migrate pre-check in ACM participant simulator. Issue-ID: POLICY-5088 Change-Id: Ibad54aacc6102654f93a86169212d91ba3a59b8b Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl')
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java22
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java45
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java63
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/model/SimConfig.java14
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java94
5 files changed, 201 insertions, 37 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
index aa9d90e91..ef8db0e99 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java
@@ -27,7 +27,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantInterme
import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
@@ -48,59 +47,56 @@ public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 {
}
@Override
- public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
- throws PfModelException {
+ public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) {
LOGGER.debug("deploy call instanceId: {}, element: {}, properties: {}", instanceId, element, properties);
simulatorService.deploy(instanceId, element.getId());
}
@Override
- public void undeploy(UUID instanceId, UUID elementId) throws PfModelException {
+ public void undeploy(UUID instanceId, UUID elementId) {
LOGGER.debug("undeploy call instanceId: {}, elementId: {}", instanceId, elementId);
simulatorService.undeploy(instanceId, elementId);
}
@Override
- public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ public void lock(UUID instanceId, UUID elementId) {
LOGGER.debug("lock call instanceId: {}, elementId: {}", instanceId, elementId);
simulatorService.lock(instanceId, elementId);
}
@Override
- public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ public void unlock(UUID instanceId, UUID elementId) {
LOGGER.debug("unlock call instanceId: {}, elementId: {}", instanceId, elementId);
simulatorService.unlock(instanceId, elementId);
}
@Override
- public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ public void delete(UUID instanceId, UUID elementId) {
LOGGER.debug("delete call instanceId: {}, elementId: {}", instanceId, elementId);
simulatorService.delete(instanceId, elementId);
}
@Override
- public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
- throws PfModelException {
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) {
LOGGER.debug("update call instanceId: {}, element: {}, properties: {}", instanceId, element, properties);
simulatorService.update(instanceId, element.getId());
}
@Override
- public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
- throws PfModelException {
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) {
LOGGER.debug("prime call compositionId: {}, elementDefinitionList: {}", compositionId, elementDefinitionList);
simulatorService.prime(compositionId);
}
@Override
- public void deprime(UUID compositionId) throws PfModelException {
+ public void deprime(UUID compositionId) {
LOGGER.debug("deprime call compositionId: {}", compositionId);
simulatorService.deprime(compositionId);
}
@Override
public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId,
- Map<String, Object> properties) throws PfModelException {
+ Map<String, Object> properties) {
LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
instanceId, element, compositionTargetId, properties);
simulatorService.migrate(instanceId, element.getId());
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
index eaad5d902..5f866eb0c 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java
@@ -53,11 +53,9 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
*
* @param compositionElement the information of the Automation Composition Definition Element
* @param instanceElement the information of the Automation Composition Instance Element
- * @throws PfModelException from Policy framework
*/
@Override
- public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
- throws PfModelException {
+ public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId());
}
@@ -67,52 +65,47 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
*
* @param compositionElement the information of the Automation Composition Definition Element
* @param instanceElement the information of the Automation Composition Instance Element
- * @throws PfModelException from Policy framework
*/
@Override
- public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
- throws PfModelException {
+ public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
LOGGER.debug("undeploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
}
@Override
- public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
- throws PfModelException {
+ public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
LOGGER.debug("lock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
simulatorService.lock(instanceElement.instanceId(), instanceElement.elementId());
}
@Override
- public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
- throws PfModelException {
+ public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
LOGGER.debug("unlock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
simulatorService.unlock(instanceElement.instanceId(), instanceElement.elementId());
}
@Override
- public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
- throws PfModelException {
+ public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
LOGGER.debug("delete call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
}
@Override
public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
- InstanceElementDto instanceElementUpdated) throws PfModelException {
+ InstanceElementDto instanceElementUpdated) {
LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}",
compositionElement, instanceElement, instanceElementUpdated);
simulatorService.update(instanceElement.instanceId(), instanceElement.elementId());
}
@Override
- public void prime(CompositionDto composition) throws PfModelException {
+ public void prime(CompositionDto composition) {
LOGGER.debug("prime call composition: {}", composition);
simulatorService.prime(composition.compositionId());
}
@Override
- public void deprime(CompositionDto composition) throws PfModelException {
+ public void deprime(CompositionDto composition) {
LOGGER.debug("deprime call composition: {}", composition);
simulatorService.deprime(composition.compositionId());
}
@@ -126,4 +119,26 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId());
}
+
+ @Override
+ public void migratePrecheck(CompositionElementDto compositionElement,
+ CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
+ InstanceElementDto instanceElementMigrate) {
+ LOGGER.debug("migrate precheck call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
+ + " instanceElementMigrate: {}",
+ compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
+ simulatorService.migratePrecheck(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("prepare call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.prepare(instanceElement.instanceId(), instanceElement.elementId());
+ }
+
+ @Override
+ public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
+ LOGGER.debug("review call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
+ simulatorService.review(instanceElement.instanceId(), instanceElement.elementId());
+ }
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
index d37edf761..e1e3ad49f 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
@@ -342,4 +342,67 @@ public class SimulatorService {
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
}
}
+
+ /**
+ * Handle a Migrate Precheck on a automation composition element.
+ *
+ * @param instanceId the instanceId
+ * @param elementId the elementId
+ */
+ public void migratePrecheck(UUID instanceId, UUID elementId) {
+ if (!execution(config.getMigratePrecheckTimerMs(),
+ "Current Thread migrate precheck is Interrupted during execution {}", elementId)) {
+ return;
+ }
+
+ if (config.isMigratePrecheck()) {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migration precheck completed");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migration precheck failed");
+ }
+ }
+
+ /**
+ * Handle a Prepare on a automation composition element.
+ *
+ * @param instanceId the instanceId
+ * @param elementId the elementId
+ */
+ public void prepare(UUID instanceId, UUID elementId) {
+ if (!execution(config.getPrepareTimerMs(),
+ "Current Thread prepare is Interrupted during execution {}", elementId)) {
+ return;
+ }
+
+ if (config.isPrepare()) {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Prepare completed");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Prepare failed");
+ }
+ }
+
+ /**
+ * Handle a Review on a automation composition element.
+ *
+ * @param instanceId the instanceId
+ * @param elementId the elementId
+ */
+ public void review(UUID instanceId, UUID elementId) {
+ if (!execution(config.getReviewTimerMs(),
+ "Current Thread review is Interrupted during execution {}", elementId)) {
+ return;
+ }
+
+ if (config.isReview()) {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Review completed");
+ } else {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Review failed");
+ }
+ }
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/model/SimConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/model/SimConfig.java
index f4d4c6e2e..f38f3079b 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/model/SimConfig.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/model/SimConfig.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,12 @@ public class SimConfig {
private boolean migrateSuccess = true;
+ private boolean migratePrecheck = true;
+
+ private boolean prepare = true;
+
+ private boolean review = true;
+
private boolean primeSuccess = true;
private boolean deprimeSuccess = true;
@@ -54,6 +60,12 @@ public class SimConfig {
private int migrateTimerMs = 100;
+ private int migratePrecheckTimerMs = 100;
+
+ private int prepareTimerMs = 100;
+
+ private int reviewTimerMs = 100;
+
private int deleteTimerMs = 100;
private int primeTimerMs = 100;
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
index 51e39067f..1e2ec2c33 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
@@ -42,7 +42,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class AutomationCompositionElementHandlerV2Test {
@Test
- void testDeploy() throws PfModelException {
+ void testDeploy() {
var config = new SimConfig();
config.setDeployTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -65,7 +65,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testUndeploy() throws PfModelException {
+ void testUndeploy() {
var config = new SimConfig();
config.setUndeployTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -88,7 +88,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testLock() throws PfModelException {
+ void testLock() {
var config = new SimConfig();
config.setLockTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -111,7 +111,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testUnlock() throws PfModelException {
+ void testUnlock() {
var config = new SimConfig();
config.setUnlockTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -134,7 +134,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testUpdate() throws PfModelException {
+ void testUpdate() {
var config = new SimConfig();
config.setUpdateTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -160,7 +160,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testDelete() throws PfModelException {
+ void testDelete() {
var config = new SimConfig();
config.setDeleteTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -183,7 +183,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testPrime() throws PfModelException {
+ void testPrime() {
var config = new SimConfig();
config.setPrimeTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -203,7 +203,7 @@ class AutomationCompositionElementHandlerV2Test {
}
@Test
- void testDeprime() throws PfModelException {
+ void testDeprime() {
var config = new SimConfig();
config.setDeprimeTimerMs(1);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
@@ -251,4 +251,82 @@ class AutomationCompositionElementHandlerV2Test {
verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
}
+
+ @Test
+ void testMigratePrecheck() {
+ var config = new SimConfig();
+ config.setUpdateTimerMs(1);
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of());
+ var compositionElementTraget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of());
+ var instanceId = UUID.randomUUID();
+ var element = new AcElementDeploy();
+ element.setId(UUID.randomUUID());
+ var instanceElement = new InstanceElementDto(instanceId, element.getId(), null, Map.of(), Map.of());
+ var instanceElementMigrated = new InstanceElementDto(instanceId, element.getId(),
+ null, Map.of("key", "value"), Map.of());
+ acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
+ instanceElement, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Migration precheck completed");
+
+ config.setMigratePrecheck(false);
+ acElementHandler.migratePrecheck(compositionElement, compositionElementTraget,
+ instanceElement, instanceElementMigrated);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
+ DeployState.DEPLOYED, null,
+ StateChangeResult.FAILED, "Migration precheck failed");
+ }
+
+ @Test
+ void testPrepare() {
+ var config = new SimConfig();
+ config.setDeployTimerMs(1);
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of());
+ var instanceId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
+ acElementHandler.prepare(compositionElement, instanceElement);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ null, StateChangeResult.NO_ERROR, "Prepare completed");
+
+ config.setPrepare(false);
+ acElementHandler.prepare(compositionElement, instanceElement);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED,
+ null, StateChangeResult.FAILED, "Prepare failed");
+ }
+
+ @Test
+ void testReview() {
+ var config = new SimConfig();
+ config.setDeployTimerMs(1);
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ var simulatorService = new SimulatorService(intermediaryApi);
+ var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
+ simulatorService.setConfig(config);
+ var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
+ Map.of(), Map.of());
+ var instanceId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ var instanceElement = new InstanceElementDto(instanceId, elementId, null, Map.of(), Map.of());
+ acElementHandler.review(compositionElement, instanceElement);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ null, StateChangeResult.NO_ERROR, "Review completed");
+
+ config.setReview(false);
+ acElementHandler.review(compositionElement, instanceElement);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED,
+ null, StateChangeResult.FAILED, "Review failed");
+ }
}