diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-07-31 13:16:30 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-08-02 09:20:11 +0100 |
commit | e1589aa82ddfb58b0d4bcabe1c63cdda29939e6a (patch) | |
tree | b0af11b028c1517720c946455134df0f621336d2 /participant/participant-impl/participant-impl-simulator/src/main/java/org | |
parent | 0c43d421586d24312dd6932e9a99e71fa8243b6b (diff) |
Allow migration to be performed in stages in ACM participant
Issue-ID: POLICY-5092
Change-Id: I47efc0fd6abf62c3a1cc6c12f0971b4460468733
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator/src/main/java/org')
4 files changed, 188 insertions, 15 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 ef8db0e99..534b01b32 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 @@ -99,6 +99,6 @@ public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 { Map<String, Object> properties) { LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}", instanceId, element, compositionTargetId, properties); - simulatorService.migrate(instanceId, element.getId()); + simulatorService.migrate(instanceId, element.getId(), 0, Map.of()); } } 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 7eff849a1..a7f72ecb4 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 @@ -25,7 +25,6 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElement 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.onap.policy.models.base.PfModelException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; @@ -34,7 +33,7 @@ import org.springframework.stereotype.Component; /** * This class handles implementation of automationCompositionElement updates. */ -@ConditionalOnExpression("'${element.handler:AcElementHandlerV2}' == 'AcElementHandlerV2'") +@ConditionalOnExpression("'${element.handler}'=='AcElementHandlerV2'") @Component public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 { @@ -112,21 +111,22 @@ public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 { @Override public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, - InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) - throws PfModelException { + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) { LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {}," + " instanceElementMigrate: {}", compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate); - if (instanceElement.newElement()) { - simulatorService.migrate(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId()); - } else if (instanceElementMigrate.removedElement()) { + if (instanceElementMigrate.newElement()) { + LOGGER.debug("new element scenario"); + + } + if (instanceElementMigrate.removedElement()) { simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId()); simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId()); } else { - simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId()); + simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(), + 0, compositionElementTarget.inProperties()); } - } @Override 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 new file mode 100644 index 000000000..66f4c30b9 --- /dev/null +++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3.java @@ -0,0 +1,156 @@ +/*- + * ============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 lombok.Getter; +import lombok.Setter; +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.InstanceElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +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; + +/** + * This class handles implementation of automationCompositionElement updates. + */ +@Getter +@Setter +@ConditionalOnExpression("'${element.handler:AcElementHandlerV3}' == 'AcElementHandlerV3'") +@Component +public class AutomationCompositionElementHandlerV3 extends AcElementListenerV3 { + + private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV3.class); + + private final SimulatorService simulatorService; + + public AutomationCompositionElementHandlerV3(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, int stage) { + LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {}," + + " instanceElementMigrate: {}, stage: {}", + compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate, stage); + + if (instanceElementMigrate.newElement()) { + LOGGER.debug("new element scenario"); + } + if (instanceElementMigrate.removedElement()) { + simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId()); + simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId()); + } else { + simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(), stage, + compositionElementTarget.inProperties()); + } + } + + @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 e1e3ad49f..b0006f711 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 @@ -35,6 +35,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.slf4j.Logger; @@ -327,18 +328,34 @@ public class SimulatorService { * * @param instanceId the instanceId * @param elementId the elementId + * @param stage the stage */ - public void migrate(UUID instanceId, UUID elementId) { + public void migrate(UUID instanceId, UUID elementId, int stage, Map<String, Object> compositionInProperties) { if (!execution(getConfig().getMigrateTimerMs(), "Current Thread migrate is Interrupted during execution {}", elementId)) { return; } - if (getConfig().isMigrateSuccess()) { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, - DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + if (config.isMigrateSuccess()) { + var stageSet = ParticipantUtils.findStageSet(compositionInProperties); + var nextStage = 1000; + for (var s : stageSet) { + if (s > stage) { + nextStage = Math.min(s, nextStage); + } + } + if (nextStage == 1000) { + intermediaryApi.updateAutomationCompositionElementState( + instanceId, elementId, + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + } else { + intermediaryApi.updateAutomationCompositionElementStage( + instanceId, elementId, + StateChangeResult.NO_ERROR, nextStage, "stage " + stage + " Migrated"); + } } else { - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, + intermediaryApi.updateAutomationCompositionElementState( + instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!"); } } |