diff options
author | 2023-07-04 09:26:41 +0100 | |
---|---|---|
committer | 2023-07-13 13:20:31 +0000 | |
commit | ef0a60deb046c5bf5ed1a6209493dfde6a6457a9 (patch) | |
tree | 3e92ffecd8579cfb0ddabef80dee5586c695eda1 /participant/participant-intermediary/src/main/java/org/onap | |
parent | 51ef04415186a0de3e50339b7fca04fb5ef079c9 (diff) |
Add restart support inside participants
Issue-ID: POLICY-4747
Change-Id: I09ca3e373f8271fbfe612c031920058b744cf413
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/main/java/org/onap')
4 files changed, 77 insertions, 4 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java index 48b60dc76..2002ba48d 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java @@ -24,7 +24,10 @@ import java.util.List; import java.util.Map; import java.util.UUID; 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.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.models.base.PfModelException; /** @@ -63,4 +66,11 @@ public interface AutomationCompositionElementListener { throws PfModelException; void deprime(UUID compositionId) throws PfModelException; + + void handleRestartComposition(UUID compositionId, + List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) + throws PfModelException; + + void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, + DeployState deployState, LockState lockState) throws PfModelException; } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java index c75750c0d..8b800a8fd 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.UUID; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; @@ -38,23 +39,32 @@ public interface ParticipantIntermediaryApi { * Update the state of a automation composition element. * * @param automationCompositionId the ID of the automation composition to update the state on - * @param id the ID of the automation composition element to update the state on + * @param elementId the ID of the automation composition element to update the state on * @param deployState the Deploy State of the automation composition element * @param lockState the Lock State of the automation composition element * @param stateChangeResult the indicator if error occurs * @param message the message */ - void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState deployState, + void updateAutomationCompositionElementState(UUID automationCompositionId, UUID elementId, DeployState deployState, LockState lockState, StateChangeResult stateChangeResult, String message); /** - * Get AutomationCompositions. + * Get a copy of all AutomationCompositions. * * @return get all AutomationCompositions */ Map<UUID, AutomationComposition> getAutomationCompositions(); /** + * Get a copy of the AutomationCompositionElement by automationCompositionId and elementId. + * + * @param automationCompositionId the ID of the automation composition to update the state on + * @param elementId the ID of the automation composition element to update the state on + * @return get the AutomationCompositionElement + */ + AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId); + + /** * Send Automation Composition Element update Info to AC-runtime. * * @param automationCompositionId the ID of the automation composition to update the states diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java index 96d96cac9..ca5f08793 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java @@ -29,6 +29,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationComp import org.onap.policy.clamp.acm.participant.intermediary.handler.CacheProvider; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; @@ -70,4 +71,14 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp String message) { automationCompositionHandler.updateCompositionState(compositionId, state, stateChangeResult, message); } + + @Override + public AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId) { + var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId); + if (automationComposition == null) { + return null; + } + var element = automationComposition.getElements().get(elementId); + return element != null ? new AutomationCompositionElement(element) : null; + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java index 65ad131df..2018d435f 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; import java.io.Closeable; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -33,6 +34,7 @@ import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.clamp.models.acm.concepts.AcElementRestart; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.DeployState; @@ -272,7 +274,47 @@ public class ThreadHandler implements Closeable { */ public void restarted(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list, AcTypeState state, List<ParticipantRestartAc> automationCompositionList) { - // TODO + try { + listener.handleRestartComposition(compositionId, list, state); + } catch (PfModelException e) { + LOGGER.error("Composition Defintion restarted failed {} {}", compositionId, e.getMessage()); + intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.FAILED, + "Composition Defintion restarted failed"); + } + + for (var automationComposition : automationCompositionList) { + for (var element : automationComposition.getAcElementList()) { + cleanExecution(element.getId(), messageId); + var result = executor.submit(() -> this + .restartedInstanceProcess(automationComposition.getAutomationCompositionId(), element)); + executionMap.put(element.getId(), result); + } + } + } + + private void restartedInstanceProcess(UUID instanceId, AcElementRestart element) { + try { + var map = new HashMap<>(cacheProvider.getCommonProperties(instanceId, element.getId())); + map.putAll(element.getProperties()); + + listener.handleRestartInstance(instanceId, getAcElementDeploy(element), map, element.getDeployState(), + element.getLockState()); + executionMap.remove(element.getId()); + } catch (PfModelException e) { + LOGGER.error("Automation composition element deploy failed {} {}", instanceId, e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), + element.getDeployState(), element.getLockState(), StateChangeResult.FAILED, + "Automation composition element restart failed"); + } + } + + private AcElementDeploy getAcElementDeploy(AcElementRestart element) { + var acElementDeploy = new AcElementDeploy(); + acElementDeploy.setId(element.getId()); + acElementDeploy.setDefinition(element.getDefinition()); + acElementDeploy.setProperties(element.getProperties()); + acElementDeploy.setToscaServiceTemplateFragment(element.getToscaServiceTemplateFragment()); + return acElementDeploy; } /** |