diff options
Diffstat (limited to 'models')
7 files changed, 115 insertions, 21 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java new file mode 100644 index 000000000..3815989f7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java @@ -0,0 +1,73 @@ +/*- + * ============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.concepts; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.function.UnaryOperator; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +@NoArgsConstructor +@Data +@ToString +public class AcElementRestart { + + @NonNull + private UUID id = UUID.randomUUID(); + + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + // State of the AutomationCompositionElement + private DeployState deployState; + + // State of the AutomationCompositionElement + private LockState lockState; + + private ToscaServiceTemplate toscaServiceTemplateFragment; + + // A map indexed by the property name. Each map entry is the serialized value of the property, + // which can be deserialized into an instance of the type of the property. + private Map<String, Object> properties = new LinkedHashMap<>(); + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param otherElement the other element to copy from + */ + public AcElementRestart(final AcElementRestart otherElement) { + this.id = otherElement.id; + this.definition = new ToscaConceptIdentifier(otherElement.definition); + this.deployState = otherElement.deployState; + this.lockState = otherElement.lockState; + this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; + this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity()); + } + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java index 8e36f7a3b..76851b490 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java @@ -25,6 +25,5 @@ public enum AcTypeState { COMMISSIONED, PRIMING, PRIMED, - DEPRIMING, - RESTARTING + DEPRIMING } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java index b8ee0200d..e5f4ad4ae 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java @@ -37,11 +37,7 @@ public class ParticipantRestartAc { private UUID automationCompositionId; - // current state of auto composition - private DeployState deployState; - private LockState lockState; - - private List<AcElementDeploy> acElementList = new ArrayList<>(); + private List<AcElementRestart> acElementList = new ArrayList<>(); /** * Copy constructor. @@ -50,8 +46,6 @@ public class ParticipantRestartAc { */ public ParticipantRestartAc(ParticipantRestartAc copyConstructor) { this.automationCompositionId = copyConstructor.automationCompositionId; - this.deployState = copyConstructor.deployState; - this.lockState = copyConstructor.lockState; - this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementDeploy::new); + this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementRestart::new); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java index 6b801ce8d..c86a3e460 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java @@ -25,6 +25,7 @@ import java.util.List; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; import org.onap.policy.models.base.PfUtils; @@ -34,11 +35,14 @@ import org.onap.policy.models.base.PfUtils; @ToString(callSuper = true) public class ParticipantRestart extends ParticipantMessage { - // priming + // composition state + AcTypeState state; + + // element definition private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>(); - // autocomposition list - private List<ParticipantRestartAc> autocompositionList = new ArrayList<>(); + // automationcomposition instances list + private List<ParticipantRestartAc> automationcompositionList = new ArrayList<>(); /** * Constructor. @@ -56,6 +60,6 @@ public class ParticipantRestart extends ParticipantMessage { super(source); this.participantDefinitionUpdates = PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new); - this.autocompositionList = PfUtils.mapList(source.autocompositionList, ParticipantRestartAc::new); + this.automationcompositionList = PfUtils.mapList(source.automationcompositionList, ParticipantRestartAc::new); } } 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 ee8e010d2..ae49ec69f 100644 --- 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 @@ -36,6 +36,7 @@ import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; 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.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; @@ -426,4 +427,19 @@ public final class AcmUtils { return acElementDeploy; } + /** + * Create a new AcElementRestart from an AutomationCompositionElement. + * + * @param element the AutomationCompositionElement + * @return the AcElementRestart + */ + public static AcElementRestart createAcElementRestart(AutomationCompositionElement element) { + var acElementRestart = new AcElementRestart(); + acElementRestart.setId(element.getId()); + acElementRestart.setDefinition(new ToscaConceptIdentifier(element.getDefinition())); + acElementRestart.setDeployState(element.getDeployState()); + acElementRestart.setLockState(element.getLockState()); + acElementRestart.setProperties(PfUtils.mapMap(element.getProperties(), UnaryOperator.identity())); + return acElementRestart; + } } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java index 1ae607ebe..ba84ac76f 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java @@ -29,9 +29,7 @@ import java.time.Instant; import java.util.List; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -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.AcElementRestart; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; import org.onap.policy.clamp.models.acm.utils.CommonTestData; @@ -60,7 +58,7 @@ class ParticipantRestartTest { participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); - var acElement = new AcElementDeploy(); + var acElement = new AcElementRestart(); acElement.setId(UUID.randomUUID()); var id = new ToscaConceptIdentifier("id", "1.2.3"); acElement.setDefinition(id); @@ -68,10 +66,8 @@ class ParticipantRestartTest { var acRestart = new ParticipantRestartAc(); acRestart.setAcElementList(List.of(acElement)); acRestart.setAutomationCompositionId(UUID.randomUUID()); - acRestart.setDeployState(DeployState.DEPLOYED); - acRestart.setLockState(LockState.LOCKED); - orig.setAutocompositionList(List.of(acRestart)); + orig.setAutomationcompositionList(List.of(acRestart)); assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new ParticipantRestart(orig).toString())); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java index 7e8f60525..a9bd25f81 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -66,6 +66,8 @@ class AcmUtilsTest { assertThat(AcmUtils.isInTransitionalState(DeployState.UNDEPLOYING, LockState.NONE)).isTrue(); assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.LOCKING)).isTrue(); assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.UNLOCKING)).isTrue(); + assertThat(AcmUtils.isInTransitionalState(DeployState.DELETING, LockState.NONE)).isTrue(); + assertThat(AcmUtils.isInTransitionalState(DeployState.UPDATING, LockState.LOCKED)).isTrue(); } @Test @@ -192,6 +194,16 @@ class AcmUtilsTest { assertEquals(element.getDefinition(), result.getDefinition()); } + @Test + void testCreateAcElementRestart() { + var element = getDummyAutomationComposition().getElements().values().iterator().next(); + var result = AcmUtils.createAcElementRestart(element); + assertEquals(element.getId(), result.getId()); + assertEquals(element.getDefinition(), result.getDefinition()); + assertEquals(element.getDeployState(), result.getDeployState()); + assertEquals(element.getLockState(), result.getLockState()); + } + private AutomationComposition getDummyAutomationComposition() { var automationComposition = new AutomationComposition(); automationComposition.setCompositionId(UUID.randomUUID()); |