diff options
author | 2025-01-09 16:40:46 +0000 | |
---|---|---|
committer | 2025-02-20 10:09:25 +0000 | |
commit | d895513c055b2bc8a9eb1a7a1cd6511dfad93463 (patch) | |
tree | 20d4eebe3830d85ee9a89ff7831f744e7f31e93f | |
parent | 6a67b7355c2c39a72cc0cce0c995620f75a81c62 (diff) |
Add support conflit OutProperties/Change State
Issue-ID: POLICY-5257
Change-Id: Ic7017a657391b7007e6592cc8488a7be3b97a82a
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
11 files changed, 97 insertions, 949 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java index 8276d5627..d850c54fd 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java @@ -191,7 +191,7 @@ class MessageProviderTest { var messageJobRepository = mock(MessageJobRepository.class); var jpaJob1 = new JpaMessageJob(UUID.randomUUID().toString()); var jpaJob2 = new JpaMessageJob(UUID.randomUUID().toString()); - var old = Timestamp.from(Instant.now().minusSeconds(200)); + var old = Timestamp.from(Instant.now().minusSeconds(220)); jpaJob2.setJobStarted(old); when(messageJobRepository.findAll()).thenReturn(List.of(jpaJob1, jpaJob2)); var messageProvider = new MessageProvider(mock(MessageRepository.class), messageJobRepository); 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 deleted file mode 100644 index 839ae3c1d..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.sim.main.handler; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.stereotype.Component; - -@ConditionalOnExpression("'${element.handler}'=='AcElementHandlerV1'") -@Component -public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 { - - private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV1.class); - - private final SimulatorService simulatorService; - - public AutomationCompositionElementHandlerV1(ParticipantIntermediaryApi intermediaryApi, - SimulatorService simulatorService) { - super(intermediaryApi); - this.simulatorService = simulatorService; - } - - @Override - 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) { - LOGGER.debug("undeploy call instanceId: {}, elementId: {}", instanceId, elementId); - simulatorService.undeploy(instanceId, elementId); - } - - @Override - 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) { - LOGGER.debug("unlock call instanceId: {}, elementId: {}", instanceId, elementId); - simulatorService.unlock(instanceId, elementId); - } - - @Override - 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) { - LOGGER.debug("update call instanceId: {}, element: {}, properties: {}", instanceId, element, properties); - simulatorService.update(instanceId, element.getId()); - } - - @Override - 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) { - LOGGER.debug("deprime call compositionId: {}", compositionId); - simulatorService.deprime(compositionId); - } - - @Override - public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) { - LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}", - instanceId, element, compositionTargetId, properties); - - simulatorService.migrate(instanceId, element.getId(), 0, properties, new HashMap<>()); - } -} 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 deleted file mode 100644 index 154d559d9..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2.java +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.sim.main.handler; - -import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; -import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; -import org.onap.policy.clamp.acm.participant.intermediary.api.ElementState; -import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.stereotype.Component; - -/** - * This class handles implementation of automationCompositionElement updates. - */ -@ConditionalOnExpression("'${element.handler}'=='AcElementHandlerV2'") -@Component -public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 { - - private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV2.class); - - private final SimulatorService simulatorService; - - public AutomationCompositionElementHandlerV2(ParticipantIntermediaryApi intermediaryApi, - SimulatorService simulatorService) { - super(intermediaryApi); - this.simulatorService = simulatorService; - } - - /** - * Handle a deploy on a automation composition element. - * - * @param compositionElement the information of the Automation Composition Definition Element - * @param instanceElement the information of the Automation Composition Instance Element - */ - @Override - public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { - LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); - simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId()); - } - - /** - * Handle a automation composition element state change. - * - * @param compositionElement the information of the Automation Composition Definition Element - * @param instanceElement the information of the Automation Composition Instance Element - */ - @Override - 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) { - LOGGER.debug("lock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); - simulatorService.lock(instanceElement.instanceId(), instanceElement.elementId()); - } - - @Override - 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) { - LOGGER.debug("delete call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); - simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId()); - } - - @Override - public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, - InstanceElementDto instanceElementUpdated) { - LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}", - compositionElement, instanceElement, instanceElementUpdated); - simulatorService.update(instanceElement.instanceId(), instanceElement.elementId()); - } - - @Override - public void prime(CompositionDto composition) { - LOGGER.debug("prime call composition: {}", composition); - simulatorService.prime(composition.compositionId()); - } - - @Override - public void deprime(CompositionDto composition) { - LOGGER.debug("deprime call composition: {}", composition); - simulatorService.deprime(composition.compositionId()); - } - - @Override - public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, - InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) { - LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {}," - + " instanceElementMigrate: {}", - compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate); - - if (ElementState.NEW.equals(instanceElementMigrate.state())) { - LOGGER.debug("new element scenario"); - - } - if (ElementState.REMOVED.equals(instanceElementMigrate.state())) { - simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId()); - simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId()); - } else { - simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(), - 0, compositionElementTarget.inProperties(), instanceElementMigrate.outProperties()); - } - } - - @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/AutomationCompositionElementHandlerV3.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java index 8ffca7e4f..2246883d4 100644 --- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantInterme import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV3; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; /** @@ -38,7 +37,6 @@ import org.springframework.stereotype.Component; */ @Getter @Setter -@ConditionalOnExpression("'${element.handler:AcElementHandlerV3}' == 'AcElementHandlerV3'") @Component public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 { @@ -61,7 +59,8 @@ public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 { @Override public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); - simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId()); + simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId(), + instanceElement.outProperties()); } /** @@ -73,7 +72,8 @@ public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 { @Override public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { LOGGER.debug("undeploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement); - simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId()); + simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId(), + instanceElement.outProperties()); } @Override @@ -105,13 +105,13 @@ public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 { @Override public void prime(CompositionDto composition) { LOGGER.debug("prime call composition: {}", composition); - simulatorService.prime(composition.compositionId()); + simulatorService.prime(composition); } @Override public void deprime(CompositionDto composition) { LOGGER.debug("deprime call composition: {}", composition); - simulatorService.deprime(composition.compositionId()); + simulatorService.deprime(composition); } @Override @@ -125,7 +125,8 @@ public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 { LOGGER.debug("new element scenario"); } if (ElementState.REMOVED.equals(instanceElementMigrate.state())) { - simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId()); + simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId(), + instanceElement.outProperties()); simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId()); } else { simulatorService.migrate(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId(), stage, 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 284aa0e5a..b1bbb6964 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 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,6 +27,7 @@ import java.util.UUID; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.acm.participant.sim.model.InternalData; import org.onap.policy.clamp.acm.participant.sim.model.InternalDatas; @@ -53,6 +54,7 @@ public class SimulatorService { private final ParticipantIntermediaryApi intermediaryApi; private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorService.class); + private static final String INTERNAL_STATE = "InternalState"; @Getter @Setter @@ -140,7 +142,7 @@ public class SimulatorService { } - private boolean execution(int timeMs, String msg, UUID elementId) { + protected boolean execution(int timeMs, String msg, UUID elementId) { long endTime = System.currentTimeMillis() + timeMs; while (System.currentTimeMillis() < endTime) { try { @@ -163,17 +165,24 @@ public class SimulatorService { * * @param instanceId the instanceId * @param elementId the elementId + * @param outProperties the outProperties */ - public void deploy(UUID instanceId, UUID elementId) { + public void deploy(UUID instanceId, UUID elementId, Map<String, Object> outProperties) { if (!execution(getConfig().getDeployTimerMs(), "Current Thread deploy is Interrupted during execution {}", elementId)) { return; } if (getConfig().isDeploySuccess()) { + outProperties.put(INTERNAL_STATE, DeployState.DEPLOYED.name()); + intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties); + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); } else { + outProperties.put(INTERNAL_STATE, DeployState.UNDEPLOYED.name()); + intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties); + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!"); } @@ -184,17 +193,24 @@ public class SimulatorService { * * @param instanceId the instanceId * @param elementId the elementId + * @param outProperties the outProperties */ - public void undeploy(UUID instanceId, UUID elementId) { + public void undeploy(UUID instanceId, UUID elementId, Map<String, Object> outProperties) { if (!execution(getConfig().getUndeployTimerMs(), "Current Thread undeploy is Interrupted during execution {}", elementId)) { return; } if (getConfig().isUndeploySuccess()) { + outProperties.put(INTERNAL_STATE, DeployState.UNDEPLOYED.name()); + intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties); + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); } else { + outProperties.put(INTERNAL_STATE, DeployState.DEPLOYED.name()); + intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, outProperties); + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Undeploy failed!"); } @@ -287,40 +303,52 @@ public class SimulatorService { /** * Handle a prime on a automation composition definition. * - * @param compositionId the compositionId + * @param composition the information of the Automation Composition Definition */ - public void prime(UUID compositionId) { + public void prime(CompositionDto composition) { if (!execution(getConfig().getPrimeTimerMs(), - "Current Thread prime is Interrupted during execution {}", compositionId)) { + "Current Thread prime is Interrupted during execution {}", composition.compositionId())) { return; } if (getConfig().isPrimeSuccess()) { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, - "Primed"); + sendOutProperties(composition, AcTypeState.PRIMED.name()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.NO_ERROR, "Primed"); } else { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED, - "Prime failed!"); + sendOutProperties(composition, AcTypeState.COMMISSIONED.name()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.FAILED, "Prime failed!"); + } + } + + private void sendOutProperties(CompositionDto composition, String data) { + for (var elementEntry : composition.outPropertiesMap().entrySet()) { + elementEntry.getValue().put(INTERNAL_STATE, data); + intermediaryApi.sendAcDefinitionInfo( + composition.compositionId(), elementEntry.getKey(), elementEntry.getValue()); } } /** * Handle a deprime on a automation composition definition. * - * @param compositionId the compositionId + * @param composition the information of the Automation Composition Definition */ - public void deprime(UUID compositionId) { + public void deprime(CompositionDto composition) { if (!execution(getConfig().getDeprimeTimerMs(), - "Current Thread deprime is Interrupted during execution {}", compositionId)) { + "Current Thread deprime is Interrupted during execution {}", composition.compositionId())) { return; } if (getConfig().isDeprimeSuccess()) { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, - "Deprimed"); + sendOutProperties(composition, AcTypeState.COMMISSIONED.name()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.NO_ERROR, "Deprimed"); } else { - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, - "Deprime failed!"); + sendOutProperties(composition, AcTypeState.PRIMED.name()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.FAILED, "Deprime failed!"); } } diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java deleted file mode 100644 index d78b851d4..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV1Test.java +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.sim.main.handler; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -import org.onap.policy.clamp.models.acm.concepts.DeployState; -import org.onap.policy.clamp.models.acm.concepts.LockState; -import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; - -class AutomationCompositionElementHandlerV1Test { - - private static final UUID COMPOSITION_ID = UUID.randomUUID(); - private static final UUID INSTANCE_ID = UUID.randomUUID(); - private static final UUID ELEMENT_ID = UUID.randomUUID(); - - private AcElementDeploy createAcElementDeploy() { - var element = new AcElementDeploy(); - element.setId(ELEMENT_ID); - return element; - } - - @Test - void testDeploy() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - var element = createAcElementDeploy(); - acElementHandler.deploy(INSTANCE_ID, element, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); - - config.setDeploySuccess(false); - acElementHandler.deploy(INSTANCE_ID, element, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(), - DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!"); - } - - @Test - void testUndeploy() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.undeploy(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.UNDEPLOYED, - null, StateChangeResult.NO_ERROR, "Undeployed"); - - config.setUndeploySuccess(false); - acElementHandler.undeploy(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Undeploy failed!"); - } - - @Test - void testLock() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.lock(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, - null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); - - config.setLockSuccess(false); - acElementHandler.lock(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, - null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!"); - } - - @Test - void testUnlock() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.unlock(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, - null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); - - config.setUnlockSuccess(false); - acElementHandler.unlock(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, - null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!"); - } - - @Test - void testUpdate() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - var element = createAcElementDeploy(); - acElementHandler.update(INSTANCE_ID, element, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); - - config.setUpdateSuccess(false); - acElementHandler.update(INSTANCE_ID, element, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!"); - } - - @Test - void testDelete() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.delete(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.DELETED, - null, StateChangeResult.NO_ERROR, "Deleted"); - - config.setDeleteSuccess(false); - acElementHandler.delete(INSTANCE_ID, ELEMENT_ID); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, ELEMENT_ID, DeployState.UNDEPLOYED, - null, StateChangeResult.FAILED, "Delete failed!"); - } - - @Test - void testPrime() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.prime(COMPOSITION_ID, List.of()); - verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, - "Primed"); - - config.setPrimeSuccess(false); - acElementHandler.prime(COMPOSITION_ID, List.of()); - verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.COMMISSIONED, - StateChangeResult.FAILED, "Prime failed!"); - } - - @Test - void testDeprime() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.deprime(COMPOSITION_ID); - verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.COMMISSIONED, - StateChangeResult.NO_ERROR, "Deprimed"); - - config.setDeprimeSuccess(false); - acElementHandler.deprime(COMPOSITION_ID); - verify(intermediaryApi).updateCompositionState(COMPOSITION_ID, AcTypeState.PRIMED, StateChangeResult.FAILED, - "Deprime failed!"); - } - - @Test - void testMigrate() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV1(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - var element = createAcElementDeploy(); - acElementHandler.migrate(INSTANCE_ID, element, COMPOSITION_ID, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - - config.setMigrateSuccess(false); - acElementHandler.migrate(INSTANCE_ID, element, COMPOSITION_ID, Map.of()); - verify(intermediaryApi).updateAutomationCompositionElementState(INSTANCE_ID, element.getId(), - DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!"); - } -} 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 deleted file mode 100644 index 2f1e9dc9d..000000000 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java +++ /dev/null @@ -1,340 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.acm.participant.sim.main.handler; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; -import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; -import org.onap.policy.clamp.acm.participant.intermediary.api.ElementState; -import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; -import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData; -import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -import org.onap.policy.clamp.models.acm.concepts.DeployState; -import org.onap.policy.clamp.models.acm.concepts.LockState; -import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class AutomationCompositionElementHandlerV2Test { - - private static final CompositionElementDto COMPOSITION_ELEMENT = - new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of()); - private static final InstanceElementDto INSTANCE_ELEMENT = - new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of()); - private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of()); - - @Test - void testDeploy() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED, - null, StateChangeResult.NO_ERROR, "Deployed"); - - config.setDeploySuccess(false); - acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED, - null, StateChangeResult.FAILED, "Deploy failed!"); - } - - @Test - void testUndeploy() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED, - null, StateChangeResult.NO_ERROR, "Undeployed"); - - config.setUndeploySuccess(false); - acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Undeploy failed!"); - } - - @Test - void testLock() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED, - StateChangeResult.NO_ERROR, "Locked"); - - config.setLockSuccess(false); - acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED, - StateChangeResult.FAILED, "Lock failed!"); - } - - @Test - void testUnlock() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED, - StateChangeResult.NO_ERROR, "Unlocked"); - - config.setUnlockSuccess(false); - acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED, - StateChangeResult.FAILED, "Unlock failed!"); - } - - @Test - void testUpdate() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - var instanceElementUpdated = new InstanceElementDto( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - Map.of("key", "value"), Map.of()); - acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated"); - - config.setUpdateSuccess(false); - acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!"); - } - - @Test - void testDelete() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DELETED, - null, StateChangeResult.NO_ERROR, "Deleted"); - - config.setDeleteSuccess(false); - acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED, - null, StateChangeResult.FAILED, "Delete failed!"); - } - - @Test - void testPrime() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.prime(COMPOSITION); - verify(intermediaryApi).updateCompositionState( - COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); - - config.setPrimeSuccess(false); - acElementHandler.prime(COMPOSITION); - verify(intermediaryApi).updateCompositionState( - COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!"); - } - - @Test - void testDeprime() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.deprime(COMPOSITION); - verify(intermediaryApi).updateCompositionState( - COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed"); - - config.setDeprimeSuccess(false); - acElementHandler.deprime(COMPOSITION); - verify(intermediaryApi).updateCompositionState( - COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!"); - } - - @Test - void testMigrate() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), - Map.of(), Map.of()); - var instanceElementMigrated = new InstanceElementDto( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - Map.of("key", "value"), new HashMap<>()); - acElementHandler - .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - - config.setMigrateSuccess(false); - acElementHandler - .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!"); - } - - @Test - void testMigrateAdd() { - var config = CommonTestData.createSimConfig(); - 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(), ElementState.NOT_PRESENT); - - var instanceElement = new InstanceElementDto( - UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of(), ElementState.NOT_PRESENT); - - var compoElTargetAdd = new CompositionElementDto( - UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NEW); - var inElMigratedAdd = new InstanceElementDto( - instanceElement.instanceId(), instanceElement.elementId(), Map.of(), new HashMap<>(), ElementState.NEW); - acElementHandler - .migrate(compositionElement, compoElTargetAdd, instanceElement, inElMigratedAdd); - verify(intermediaryApi).updateAutomationCompositionElementState( - instanceElement.instanceId(), instanceElement.elementId(), - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); - } - - @Test - void testMigrateRemove() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - - var compoElTargetRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), - Map.of(), Map.of(), ElementState.REMOVED); - var inElMigratedRemove = new InstanceElementDto( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - Map.of("key", "value"), Map.of(), ElementState.REMOVED); - acElementHandler - .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); - } - - @Test - void testMigratePrecheck() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), - Map.of(), Map.of()); - var instanceElementMigrated = new InstanceElementDto( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - Map.of("key", "value"), Map.of()); - acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget, - INSTANCE_ELEMENT, instanceElementMigrated); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Migration precheck completed"); - - config.setMigratePrecheck(false); - acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget, - INSTANCE_ELEMENT, instanceElementMigrated); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), - DeployState.DEPLOYED, null, - StateChangeResult.FAILED, "Migration precheck failed"); - } - - @Test - void testPrepare() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED, - null, StateChangeResult.NO_ERROR, "Prepare completed"); - - config.setPrepare(false); - acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED, - null, StateChangeResult.FAILED, "Prepare failed"); - } - - @Test - void testReview() { - var config = CommonTestData.createSimConfig(); - var intermediaryApi = mock(ParticipantIntermediaryApi.class); - var simulatorService = new SimulatorService(intermediaryApi); - var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService); - simulatorService.setConfig(config); - acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED, - null, StateChangeResult.NO_ERROR, "Review completed"); - - config.setReview(false); - acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT); - verify(intermediaryApi).updateAutomationCompositionElementState( - INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Review failed"); - } -} diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java index 41b3f2001..8b947e873 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,11 +42,13 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class AutomationCompositionElementHandlerV3Test { + private static final ToscaConceptIdentifier ELEMENT_DEFINITION_ID = new ToscaConceptIdentifier("name", "1.0.0"); private static final CompositionElementDto COMPOSITION_ELEMENT = - new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of()); + new CompositionElementDto(UUID.randomUUID(), ELEMENT_DEFINITION_ID, Map.of(), Map.of()); private static final InstanceElementDto INSTANCE_ELEMENT = - new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of()); - private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of()); + new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), new HashMap<>()); + private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), + Map.of(ELEMENT_DEFINITION_ID, Map.of()), Map.of(ELEMENT_DEFINITION_ID, new HashMap<>())); @Test void testDeploy() { diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorServiceTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorServiceTest.java index 714f71781..174497966 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorServiceTest.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorServiceTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 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,10 +22,13 @@ package org.onap.policy.clamp.acm.participant.sim.main.handler; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -123,4 +126,28 @@ class SimulatorServiceTest { simulatorService.setCompositionOutProperties(compositionId, null, Map.of()); verify(intermediaryApi).sendAcDefinitionInfo(compositionId, null, Map.of()); } + + @Test + void testInterrupted() { + var intermediaryApi = mock(ParticipantIntermediaryApi.class); + var simulatorService = new SimulatorService(intermediaryApi) { + @Override + protected boolean execution(int timeMs, String msg, UUID elementId) { + return false; + } + }; + + simulatorService.deploy(UUID.randomUUID(), UUID.randomUUID(), new HashMap<>()); + simulatorService.undeploy(UUID.randomUUID(), UUID.randomUUID(), new HashMap<>()); + simulatorService.lock(UUID.randomUUID(), UUID.randomUUID()); + simulatorService.unlock(UUID.randomUUID(), UUID.randomUUID()); + simulatorService.delete(UUID.randomUUID(), UUID.randomUUID()); + simulatorService.update(UUID.randomUUID(), UUID.randomUUID()); + simulatorService.review(UUID.randomUUID(), UUID.randomUUID()); + simulatorService.prepare(UUID.randomUUID(), UUID.randomUUID()); + simulatorService.migratePrecheck(UUID.randomUUID(), UUID.randomUUID()); + verify(intermediaryApi, times(0)).sendAcDefinitionInfo(any(), any(), any()); + + } + } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java index 7bea81e4d..9c23ec7fd 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,14 +45,11 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; * Wrapper of AutomationCompositionElementListener. * Valid since 7.1.0 release. */ -public abstract class AcElementListenerV1 +public abstract class AcElementListenerV1 extends AcElementListenerV2 implements AutomationCompositionElementListener, AutomationCompositionElementListenerV1 { - protected final ParticipantIntermediaryApi intermediaryApi; - - private static final String NOT_SUPPORTED = "not supported!"; protected AcElementListenerV1(ParticipantIntermediaryApi intermediaryApi) { - this.intermediaryApi = intermediaryApi; + super(intermediaryApi); } @Override @@ -168,10 +165,6 @@ public abstract class AcElementListenerV1 "Deprimed"); } - public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { - throw new PfModelException(Response.Status.BAD_REQUEST, NOT_SUPPORTED); - } - /** * Default implementation of handle Restart Composition. * @@ -185,11 +178,6 @@ public abstract class AcElementListenerV1 throw new PfModelException(Response.Status.BAD_REQUEST, NOT_SUPPORTED); } - public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, - DeployState deployState, LockState lockState) throws PfModelException { - throw new PfModelException(Response.Status.BAD_REQUEST, NOT_SUPPORTED); - } - /** * Default implementation of handle Restart Instance. * @@ -224,29 +212,4 @@ public abstract class AcElementListenerV1 intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); } - - @Override - public void migratePrecheck(CompositionElementDto compositionElement, - CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement, - InstanceElementDto instanceElementMigrate) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(), - instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Migration Precheck completed"); - } - - @Override - public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Review completed"); - } - - @Override - public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), DeployState.UNDEPLOYED, null, - StateChangeResult.NO_ERROR, "Prepare completed"); - } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java index 7db220095..21b76d1b7 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 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,56 +36,13 @@ import org.onap.policy.models.base.PfModelException; * Wrapper of AutomationCompositionElementListener. * Valid since 7.1.1 release. */ -public abstract class AcElementListenerV2 +public abstract class AcElementListenerV2 extends AcElementListenerV3 implements AutomationCompositionElementListener, AutomationCompositionElementListenerV2 { - protected final ParticipantIntermediaryApi intermediaryApi; - private static final String NOT_SUPPORTED = "not supported!"; + protected static final String NOT_SUPPORTED = "not supported!"; protected AcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) { - this.intermediaryApi = intermediaryApi; - } - - @Override - public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); - } - - @Override - public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); - } - - @Override - public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); - } - - @Override - public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, - InstanceElementDto instanceElementUpdated) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Update not supported"); - - } - - @Override - public void prime(CompositionDto composition) throws PfModelException { - intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, - StateChangeResult.NO_ERROR, "Primed"); - } - - @Override - public void deprime(CompositionDto composition) throws PfModelException { - intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, - StateChangeResult.NO_ERROR, "Deprimed"); + super(intermediaryApi); } public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { @@ -111,29 +68,4 @@ public abstract class AcElementListenerV2 intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); } - - @Override - public void migratePrecheck(CompositionElementDto compositionElement, - CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement, - InstanceElementDto instanceElementMigrate) throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(), - instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Migration Precheck completed"); - } - - @Override - public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), DeployState.DEPLOYED, null, - StateChangeResult.NO_ERROR, "Review completed"); - } - - @Override - public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement) - throws PfModelException { - intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), - instanceElement.elementId(), DeployState.UNDEPLOYED, null, - StateChangeResult.NO_ERROR, "Prepare completed"); - } } |