diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-09-26 14:31:58 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-09-26 13:34:28 +0000 |
commit | 54155ebf6232417d264159acf9fbfcdc08c11244 (patch) | |
tree | 60bbe3a27a5468a8d69b9ebe99f0534e05f66ff6 /models/src/main/java | |
parent | 4407ea6948a060734a4f2836b11bd2d5c6ea6194 (diff) |
Add migration message support
Issue-ID: POLICY-4822
Change-Id: Ibde7c14424c63a96c64378d8897e8887935d6c79
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java')
8 files changed, 123 insertions, 49 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java index b92b03fba..0cf1f99ec 100644..100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -42,6 +42,8 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut @NonNull private UUID compositionId; + private UUID compositionTargetId; + private Boolean restarting; @NonNull @@ -63,6 +65,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut super(otherAutomationComposition); this.instanceId = otherAutomationComposition.instanceId; this.compositionId = otherAutomationComposition.compositionId; + this.compositionTargetId = otherAutomationComposition.compositionTargetId; this.restarting = otherAutomationComposition.restarting; this.deployState = otherAutomationComposition.deployState; this.lockState = otherAutomationComposition.lockState; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java index 9dde703b6..57669fe77 100644..100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java @@ -27,5 +27,6 @@ public enum DeployState { UNDEPLOYING, DELETING, DELETED, - UPDATING + UPDATING, + MIGRATING } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionMigration.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionMigration.java new file mode 100755 index 000000000..dd5e528c5 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionMigration.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.models.acm.messages.dmaap.participant; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; + +@Getter +@Setter +@ToString(callSuper = true) +public class AutomationCompositionMigration extends ParticipantMessage { + + private UUID compositionTargetId; + // A list of updates to AC element properties + private List<ParticipantDeploy> participantUpdatesList = new ArrayList<>(); + + public AutomationCompositionMigration() { + super(ParticipantMessageType.AUTOMATION_COMPOSITION_MIGRATION); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java index c42778aae..7609accee 100644..100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java @@ -104,5 +104,11 @@ public enum ParticipantMessageType { /** * Used by runtime to send composition and instances to a restarted participant. */ - PARTICIPANT_RESTART + PARTICIPANT_RESTART, + + /** + * Used by acm runtime to migrate from a composition to another one in participants, triggers a + * AUTOMATION_COMPOSITION_MIGRATION message with result of AUTOMATION_COMPOSITION_STATE_CHANGE operation. + */ + AUTOMATION_COMPOSITION_MIGRATION } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java index 24197f1ab..758a5057f 100644..100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java @@ -26,5 +26,6 @@ public enum DeployOrder { DEPLOY, DELETE, UPDATE, - RESTARTING + RESTARTING, + MIGRATE } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java index 104792143..5e27fde53 100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java @@ -81,6 +81,9 @@ public class JpaAutomationComposition extends Validated private String compositionId; @Column + private String compositionTargetId; + + @Column private Boolean restarting; @Column @@ -106,8 +109,8 @@ public class JpaAutomationComposition extends Validated * The Default Constructor creates a {@link JpaAutomationComposition} object with a null key. */ public JpaAutomationComposition() { - this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(), - new ArrayList<>(), DeployState.UNDEPLOYED, LockState.NONE); + this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(), new ArrayList<>(), + DeployState.UNDEPLOYED, LockState.NONE); } /** @@ -121,8 +124,7 @@ public class JpaAutomationComposition extends Validated * @param lockState the Lock State */ public JpaAutomationComposition(@NonNull final String instanceId, @NonNull final PfConceptKey key, - @NonNull final String compositionId, - @NonNull final List<JpaAutomationCompositionElement> elements, + @NonNull final String compositionId, @NonNull final List<JpaAutomationCompositionElement> elements, @NonNull final DeployState deployState, @NonNull final LockState lockState) { this.instanceId = instanceId; this.name = key.getName(); @@ -143,6 +145,7 @@ public class JpaAutomationComposition extends Validated this.name = copyConcept.name; this.version = copyConcept.version; this.compositionId = copyConcept.compositionId; + this.compositionTargetId = copyConcept.compositionTargetId; this.restarting = copyConcept.restarting; this.deployState = copyConcept.deployState; this.lockState = copyConcept.lockState; @@ -168,6 +171,9 @@ public class JpaAutomationComposition extends Validated automationComposition.setName(name); automationComposition.setVersion(version); automationComposition.setCompositionId(UUID.fromString(compositionId)); + if (compositionTargetId != null) { + automationComposition.setCompositionTargetId(UUID.fromString(compositionTargetId)); + } automationComposition.setRestarting(restarting); automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); @@ -187,6 +193,9 @@ public class JpaAutomationComposition extends Validated this.name = automationComposition.getName(); this.version = automationComposition.getVersion(); this.compositionId = automationComposition.getCompositionId().toString(); + if (automationComposition.getCompositionTargetId() != null) { + this.compositionTargetId = automationComposition.getCompositionTargetId().toString(); + } this.restarting = automationComposition.getRestarting(); this.deployState = automationComposition.getDeployState(); this.lockState = automationComposition.getLockState(); @@ -230,6 +239,11 @@ public class JpaAutomationComposition extends Validated return result; } + result = ObjectUtils.compare(compositionTargetId, other.compositionTargetId); + if (result != 0) { + return result; + } + result = ObjectUtils.compare(restarting, other.restarting); if (result != 0) { return result; diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java index e2f4fdf9b..7fed8a756 100644..100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java @@ -38,6 +38,7 @@ public class AcInstanceStateResolver { private static final String UNDEPLOYING = DeployState.UNDEPLOYING.name(); private static final String UPDATING = DeployState.UPDATING.name(); private static final String DELETING = DeployState.DELETING.name(); + private static final String MIGRATING = DeployState.MIGRATING.name(); private static final String LOCKED = LockState.LOCKED.name(); private static final String LOCKING = LockState.LOCKING.name(); @@ -58,6 +59,7 @@ public class AcInstanceStateResolver { public static final String DELETE = DeployOrder.DELETE.name(); public static final String LOCK = LockOrder.LOCK.name(); public static final String UNLOCK = LockOrder.UNLOCK.name(); + public static final String MIGRATE = DeployOrder.MIGRATE.name(); public static final String NONE = "NONE"; /** @@ -72,22 +74,24 @@ public class AcInstanceStateResolver { this.graph.put(new String[] {DELETE, LOCK_NONE, UNDEPLOYED, LOCK_NONE, NO_ERROR}, DELETE); this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED, NO_ERROR}, UNLOCK); this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED, NO_ERROR}, LOCK); + this.graph.put(new String[] {MIGRATE, LOCK_NONE, DEPLOYED, LOCKED, NO_ERROR}, MIGRATE); // failed this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); - this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); + + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, LOCKED, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, MIGRATING, LOCKED, FAILED}, UNDEPLOY); this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); this.graph.put(new String[] {DELETE, LOCK_NONE, DELETING, LOCK_NONE, FAILED}, DELETE); this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKING, FAILED}, UNLOCK); - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK); this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, FAILED}, LOCK); - this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK); // timeout this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, DEPLOY); diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index 258c6dc93..fe44050d5 100755 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -45,6 +45,7 @@ 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.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.common.parameters.BeanValidationResult; @@ -289,7 +290,8 @@ public final class AcmUtils { public static boolean isInTransitionalState(DeployState deployState, LockState lockState) { return DeployState.DEPLOYING.equals(deployState) || DeployState.UNDEPLOYING.equals(deployState) || LockState.LOCKING.equals(lockState) || LockState.UNLOCKING.equals(lockState) - || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState); + || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState) + || DeployState.MIGRATING.equals(deployState); } /** @@ -299,24 +301,12 @@ public final class AcmUtils { * @return the DeployOrder */ public static DeployOrder stateDeployToOrder(DeployState deployState) { - DeployOrder result = null; - switch (deployState) { - case DEPLOYING: - result = DeployOrder.DEPLOY; - break; - - case UNDEPLOYING: - result = DeployOrder.UNDEPLOY; - break; - - case DELETING: - result = DeployOrder.DELETE; - break; - - default: - result = DeployOrder.NONE; - } - return result; + return switch (deployState) { + case DEPLOYING -> DeployOrder.DEPLOY; + case UNDEPLOYING -> DeployOrder.UNDEPLOY; + case DELETING -> DeployOrder.DELETE; + default -> DeployOrder.NONE; + }; } /** @@ -341,24 +331,12 @@ public final class AcmUtils { * @return the DeployState */ public static DeployState deployCompleted(DeployState deployState) { - DeployState result = null; - switch (deployState) { - case UPDATING, DEPLOYING: - result = DeployState.DEPLOYED; - break; - - case UNDEPLOYING: - result = DeployState.UNDEPLOYED; - break; - - case DELETING: - result = DeployState.DELETED; - break; - - default: - return deployState; - } - return result; + return switch (deployState) { + case MIGRATING, UPDATING, DEPLOYING -> DeployState.DEPLOYED; + case UNDEPLOYING -> DeployState.UNDEPLOYED; + case DELETING -> DeployState.DELETED; + default -> deployState; + }; } /** @@ -427,6 +405,30 @@ public final class AcmUtils { } /** + * Create a list of AcElementDeploy for update/migrate message. + * + * @param automationComposition the AutomationComposition + * @param deployOrder the DeployOrder + */ + public static List<ParticipantDeploy> createParticipantDeployList(AutomationComposition automationComposition, + DeployOrder deployOrder) { + Map<UUID, List<AcElementDeploy>> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + var acElementDeploy = createAcElementDeploy(element, deployOrder); + map.putIfAbsent(element.getParticipantId(), new ArrayList<>()); + map.get(element.getParticipantId()).add(acElementDeploy); + } + List<ParticipantDeploy> participantDeploys = new ArrayList<>(); + for (var entry : map.entrySet()) { + var participantDeploy = new ParticipantDeploy(); + participantDeploy.setParticipantId(entry.getKey()); + participantDeploy.setAcElementList(entry.getValue()); + participantDeploys.add(participantDeploy); + } + return participantDeploys; + } + + /** * Create a new AcElementRestart from an AutomationCompositionElement. * * @param element the AutomationCompositionElement |