diff options
Diffstat (limited to 'models')
6 files changed, 57 insertions, 17 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 0cf1f99ec..eb5b6dc9b 100644 --- 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-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. @@ -52,6 +52,10 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut @NonNull private LockState lockState = LockState.NONE; + private String lastMsg; + + private Integer phase; + private Map<UUID, AutomationCompositionElement> elements; private StateChangeResult stateChangeResult; @@ -69,6 +73,8 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut this.restarting = otherAutomationComposition.restarting; this.deployState = otherAutomationComposition.deployState; this.lockState = otherAutomationComposition.lockState; + this.lastMsg = otherAutomationComposition.lastMsg; + this.phase = otherAutomationComposition.phase; this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new); this.stateChangeResult = otherAutomationComposition.stateChangeResult; } 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 5e27fde53..0bf6a9e1a 100644 --- 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-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. @@ -32,6 +32,7 @@ import jakarta.persistence.InheritanceType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -44,6 +45,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; 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.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.models.base.PfAuthorative; @@ -98,6 +100,13 @@ public class JpaAutomationComposition extends Validated private StateChangeResult stateChangeResult; @Column + @NotNull + private Timestamp lastMsg; + + @Column + private Integer phase; + + @Column private String description; @NotNull @@ -149,6 +158,8 @@ public class JpaAutomationComposition extends Validated this.restarting = copyConcept.restarting; this.deployState = copyConcept.deployState; this.lockState = copyConcept.lockState; + this.lastMsg = copyConcept.lastMsg; + this.phase = copyConcept.phase; this.description = copyConcept.description; this.stateChangeResult = copyConcept.stateChangeResult; this.elements = PfUtils.mapList(copyConcept.elements, JpaAutomationCompositionElement::new); @@ -177,6 +188,8 @@ public class JpaAutomationComposition extends Validated automationComposition.setRestarting(restarting); automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); + automationComposition.setLastMsg(lastMsg.toString()); + automationComposition.setPhase(phase); automationComposition.setDescription(description); automationComposition.setStateChangeResult(stateChangeResult); automationComposition.setElements(new LinkedHashMap<>(this.elements.size())); @@ -199,6 +212,8 @@ public class JpaAutomationComposition extends Validated this.restarting = automationComposition.getRestarting(); this.deployState = automationComposition.getDeployState(); this.lockState = automationComposition.getLockState(); + this.lastMsg = TimestampHelper.toTimestamp(automationComposition.getLastMsg()); + this.phase = automationComposition.getPhase(); this.description = automationComposition.getDescription(); this.stateChangeResult = automationComposition.getStateChangeResult(); this.elements = new ArrayList<>(automationComposition.getElements().size()); @@ -229,6 +244,16 @@ public class JpaAutomationComposition extends Validated return result; } + result = lastMsg.compareTo(other.lastMsg); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(phase, other.phase); + if (result != 0) { + return result; + } + result = ObjectUtils.compare(version, other.version); if (result != 0) { return result; 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 0293bd3c5..5f523ad27 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 @@ -29,7 +29,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Queue; import java.util.UUID; import java.util.function.Function; import java.util.function.UnaryOperator; @@ -71,7 +70,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class AcmUtils { public static final String ENTRY = "entry "; - private static StringToMapConverter MAP_CONVERTER = new StringToMapConverter(); + private static final StringToMapConverter MAP_CONVERTER = new StringToMapConverter(); /** * Get the Policy information in the service template for the deploy message to participants. @@ -379,6 +378,7 @@ public final class AcmUtils { final DeployState deployState, final LockState lockState) { automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); + automationComposition.setLastMsg(TimestampHelper.now()); if (MapUtils.isEmpty(automationComposition.getElements())) { return; diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java index 66554e7ec..b56e77801 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-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. @@ -27,6 +27,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.sql.Timestamp; +import java.time.Instant; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.UUID; @@ -35,6 +37,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; 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.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfConceptKey; /** @@ -93,9 +96,9 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationComposition() { - var jpaAutomationComposition = createJpaAutomationCompositionInstance(); - var automationComposition = createAutomationCompositionInstance(); + var jpaAutomationComposition = new JpaAutomationComposition(automationComposition); + assertEquals(automationComposition, jpaAutomationComposition.toAuthorative()); var target = UUID.randomUUID(); @@ -125,7 +128,7 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationCompositionValidation() { - var testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + var testJpaAutomationComposition = new JpaAutomationComposition(createAutomationCompositionInstance()); assertThatThrownBy(() -> testJpaAutomationComposition.validate(null)) .hasMessageMatching("fieldName is marked .*ull but is null"); @@ -135,7 +138,7 @@ class JpaAutomationCompositionTest { @Test void testJpaAutomationCompositionCompareTo() { - var jpaAutomationComposition = createJpaAutomationCompositionInstance(); + var jpaAutomationComposition = new JpaAutomationComposition(createAutomationCompositionInstance()); var otherJpaAutomationComposition = new JpaAutomationComposition(jpaAutomationComposition); assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); @@ -168,6 +171,16 @@ class JpaAutomationCompositionTest { jpaAutomationComposition.setVersion("0.0.1"); assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setLastMsg(Timestamp.from(Instant.EPOCH)); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setLastMsg(otherJpaAutomationComposition.getLastMsg()); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + jpaAutomationComposition.setPhase(0); + assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setPhase(null); + assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + jpaAutomationComposition.setDeployState(DeployState.DEPLOYED); assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition)); jpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED); @@ -225,19 +238,12 @@ class JpaAutomationCompositionTest { assertEquals(ac2, ac0); } - private JpaAutomationComposition createJpaAutomationCompositionInstance() { - var testAutomationComposition = createAutomationCompositionInstance(); - var testJpaAutomationComposition = new JpaAutomationComposition(); - testJpaAutomationComposition.fromAuthorative(testAutomationComposition); - - return testJpaAutomationComposition; - } - private AutomationComposition createAutomationCompositionInstance() { var testAutomationComposition = new AutomationComposition(); testAutomationComposition.setName("automation-composition"); testAutomationComposition.setInstanceId(UUID.fromString(INSTANCE_ID)); testAutomationComposition.setVersion("0.0.1"); + testAutomationComposition.setLastMsg(TimestampHelper.now()); testAutomationComposition.setCompositionId(UUID.fromString(COMPOSITION_ID)); testAutomationComposition.setElements(new LinkedHashMap<>()); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java index 463e958f3..8e7e50de7 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java @@ -85,6 +85,7 @@ class AutomationCompositionProviderTest { var createdAutomationComposition = automationCompositionProvider.createAutomationComposition(inputAc); inputAc.setInstanceId(createdAutomationComposition.getInstanceId()); + inputAc.setLastMsg(createdAutomationComposition.getLastMsg()); assertEquals(inputAc, createdAutomationComposition); } diff --git a/models/src/test/resources/providers/TestAutomationCompositions.json b/models/src/test/resources/providers/TestAutomationCompositions.json index 24f5a4870..c75337bc1 100644 --- a/models/src/test/resources/providers/TestAutomationCompositions.json +++ b/models/src/test/resources/providers/TestAutomationCompositions.json @@ -5,6 +5,7 @@ "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c89", "deployState": "UNDEPLOYED", "lockState": "NONE", + "lastMsg": "2024-05-22 10:04:37.6020187", "elements": { "709c62b3-8918-41b9-a747-e21eb79c6c20": { "id": "709c62b3-8918-41b9-a747-e21eb79c6c20", @@ -56,6 +57,7 @@ "instanceId": "809c62b3-8918-41b9-a748-e21eb79c6c90", "deployState": "UNDEPLOYED", "lockState": "NONE", + "lastMsg": "2024-05-22 10:04:37.6020187", "elements": { "709c62b3-8918-41b9-a747-e21eb79c6c24": { "id": "709c62b3-8918-41b9-a747-e21eb79c6c24", |