aboutsummaryrefslogtreecommitdiffstats
path: root/models/src
diff options
context:
space:
mode:
authorRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2024-06-19 12:25:33 +0000
committerGerrit Code Review <gerrit@onap.org>2024-06-19 12:25:33 +0000
commita1ce07d06745bfe966ffc000ad2be84789a555d3 (patch)
treecae1549e985875afa33a237893c16c7f5c1249ec /models/src
parentbe79e86eb56d7d72c7504cee491b79498f78d6ba (diff)
parent9cdfa4dc5aadaaf8ec11223c4991b61c0aa6d0b0 (diff)
Merge "Add support for sync messages in ACM-runtime"
Diffstat (limited to 'models/src')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java8
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java7
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java2
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java38
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java69
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java3
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java10
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java39
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java42
9 files changed, 124 insertions, 94 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
index 6ddec6179..457eb65e3 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java
@@ -41,12 +41,6 @@ public class Participant {
private UUID participantId;
@NonNull
- private ParticipantState participantState = ParticipantState.ON_LINE;
-
- @NonNull
- private String lastMsg;
-
- @NonNull
private Map<UUID, ParticipantSupportedElementType> participantSupportedElementTypes = new HashMap<>();
@NonNull
@@ -58,9 +52,7 @@ public class Participant {
* @param otherParticipant the participant to copy from
*/
public Participant(Participant otherParticipant) {
- this.participantState = otherParticipant.participantState;
this.participantId = otherParticipant.participantId;
- this.lastMsg = otherParticipant.lastMsg;
this.participantSupportedElementTypes = PfUtils.mapMap(otherParticipant.getParticipantSupportedElementTypes(),
ParticipantSupportedElementType::new);
this.replicas = PfUtils.mapMap(otherParticipant.replicas, ParticipantReplica::new);
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 e5f4ad4ae..3312752fa 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-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.
@@ -37,6 +37,9 @@ public class ParticipantRestartAc {
private UUID automationCompositionId;
+ private DeployState deployState;
+ private LockState lockState;
+
private List<AcElementRestart> acElementList = new ArrayList<>();
/**
@@ -46,6 +49,8 @@ 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, AcElementRestart::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java
index 98c7d1071..ff9755ec1 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java
@@ -36,7 +36,7 @@ import org.onap.policy.models.base.PfUtils;
public class ParticipantRestart extends ParticipantMessage {
// composition state
- AcTypeState state;
+ private AcTypeState state;
// element definition
private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
index f35fff9e7..5bc2fc4cf 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java
@@ -32,7 +32,6 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.io.Serializable;
-import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -44,8 +43,6 @@ import org.apache.commons.lang3.ObjectUtils;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-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;
@@ -70,51 +67,42 @@ public class JpaParticipant extends Validated
private String participantId;
@Column
- @NotNull
- private ParticipantState participantState;
-
- @Column
private String description;
- @Column
- @NotNull
- private Timestamp lastMsg;
-
@NotNull
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "participantId", referencedColumnName = "participantId",
foreignKey = @ForeignKey(name = "supported_element_fk"))
+ @SuppressWarnings("squid:S1948")
private List<@NotNull @Valid JpaParticipantSupportedElementType> supportedElements;
@NotNull
- @OneToMany
+ @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name = "participantId", referencedColumnName = "participantId",
foreignKey = @ForeignKey(name = "participant_replica_fk"))
+ @SuppressWarnings("squid:S1948")
private List<@NotNull @Valid JpaParticipantReplica> replicas;
/**
* The Default Constructor creates a {@link JpaParticipant} object with a null key.
*/
public JpaParticipant() {
- this(UUID.randomUUID().toString(), ParticipantState.ON_LINE, new ArrayList<>(), new ArrayList<>());
+ this(UUID.randomUUID().toString(), new ArrayList<>(), new ArrayList<>());
}
/**
* The Key Constructor creates a {@link JpaParticipant} object with all mandatory fields.
*
* @param participantId the participant id
- * @param participantState the state of the participant
* @param supportedElements the list of supported Element Type
* @param replicas the list of replica
*/
- public JpaParticipant(@NonNull String participantId, @NonNull final ParticipantState participantState,
+ public JpaParticipant(@NonNull String participantId,
@NonNull final List<JpaParticipantSupportedElementType> supportedElements,
@NonNull final List<JpaParticipantReplica> replicas) {
this.participantId = participantId;
- this.participantState = participantState;
this.supportedElements = supportedElements;
- this.lastMsg = TimestampHelper.nowTimestamp();
this.replicas = replicas;
}
@@ -124,12 +112,10 @@ public class JpaParticipant extends Validated
* @param copyConcept the concept to copy from
*/
public JpaParticipant(@NonNull final JpaParticipant copyConcept) {
- this.participantState = copyConcept.participantState;
this.description = copyConcept.description;
this.participantId = copyConcept.participantId;
this.supportedElements = copyConcept.supportedElements;
this.replicas = copyConcept.replicas;
- this.lastMsg = copyConcept.lastMsg;
}
/**
@@ -145,9 +131,7 @@ public class JpaParticipant extends Validated
public Participant toAuthorative() {
var participant = new Participant();
- participant.setParticipantState(participantState);
participant.setParticipantId(UUID.fromString(participantId));
- participant.setLastMsg(this.lastMsg.toString());
participant.setParticipantSupportedElementTypes(new LinkedHashMap<>(this.supportedElements.size()));
for (var element : this.supportedElements) {
participant.getParticipantSupportedElementTypes()
@@ -161,9 +145,7 @@ public class JpaParticipant extends Validated
@Override
public void fromAuthorative(@NonNull final Participant participant) {
- this.setParticipantState(participant.getParticipantState());
this.participantId = participant.getParticipantId().toString();
- this.lastMsg = TimestampHelper.toTimestamp(participant.getLastMsg());
this.supportedElements = new ArrayList<>(participant.getParticipantSupportedElementTypes().size());
for (var elementEntry : participant.getParticipantSupportedElementTypes().entrySet()) {
@@ -196,16 +178,6 @@ public class JpaParticipant extends Validated
return result;
}
- result = lastMsg.compareTo(other.lastMsg);
- if (result != 0) {
- return result;
- }
-
- result = ObjectUtils.compare(participantState, other.participantState);
- if (result != 0) {
- return result;
- }
-
return ObjectUtils.compare(description, other.description);
}
}
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 f19d5db8b..f90e5a807 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
@@ -42,6 +42,7 @@ 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.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
@@ -49,6 +50,7 @@ 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.concepts.ParticipantRestartAc;
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.clamp.models.acm.persistence.concepts.StringToMapConverter;
@@ -115,6 +117,10 @@ public final class AcmUtils {
return false;
}
+ public static ToscaConceptIdentifier getType(ToscaNodeTemplate nodeTemplate) {
+ return new ToscaConceptIdentifier(nodeTemplate.getType(), nodeTemplate.getTypeVersion());
+ }
+
/**
* Prepare list of ParticipantDefinition for the Priming message.
*
@@ -126,8 +132,7 @@ public final class AcmUtils {
Map<UUID, List<AutomationCompositionElementDefinition>> map = new HashMap<>();
for (var elementEntry : acElements) {
- var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(),
- elementEntry.getValue().getTypeVersion());
+ var type = getType(elementEntry.getValue());
var participantId = supportedElementMap.get(type);
if (participantId == null) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
@@ -432,6 +437,30 @@ public final class AcmUtils {
}
/**
+ * Create a new ParticipantRestartAc for restarting scenario.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param participantId the participantId of the participant restarted
+ * @param serviceTemplateFragment the ToscaServiceTemplate with policies and policy types
+ * @return the ParticipantRestartAc
+ */
+ public static ParticipantRestartAc createAcRestart(AutomationComposition automationComposition,
+ UUID participantId, ToscaServiceTemplate serviceTemplateFragment) {
+ var syncAc = new ParticipantRestartAc();
+ syncAc.setDeployState(automationComposition.getDeployState());
+ syncAc.setLockState(automationComposition.getLockState());
+ syncAc.setAutomationCompositionId(automationComposition.getInstanceId());
+ for (var element : automationComposition.getElements().values()) {
+ if (participantId.equals(element.getParticipantId())) {
+ var acElementSync = createAcElementRestart(element);
+ acElementSync.setToscaServiceTemplateFragment(serviceTemplateFragment);
+ syncAc.getAcElementList().add(acElementSync);
+ }
+ }
+ return syncAc;
+ }
+
+ /**
* Create a new AcElementRestart from an AutomationCompositionElement.
*
* @param element the AutomationCompositionElement
@@ -452,6 +481,42 @@ public final class AcmUtils {
}
/**
+ * Prepare the list of ParticipantDefinition for Participant Restarting/Sync msg.
+ *
+ * @param participantId the participantId
+ * @param acmDefinition the AutomationCompositionDefinition
+ * @param toscaElementName the ElementName
+ * @return List of ParticipantDefinition
+ */
+ public static List<ParticipantDefinition> prepareParticipantRestarting(UUID participantId,
+ AutomationCompositionDefinition acmDefinition, String toscaElementName) {
+ var acElements = extractAcElementsFromServiceTemplate(acmDefinition.getServiceTemplate(),
+ toscaElementName);
+
+ // list of entry filtered by participantId
+ List<Entry<String, ToscaNodeTemplate>> elementList = new ArrayList<>();
+ Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>();
+ for (var elementEntry : acElements) {
+ var elementState = acmDefinition.getElementStateMap().get(elementEntry.getKey());
+ if (participantId == null || participantId.equals(elementState.getParticipantId())) {
+ supportedElementMap.put(getType(elementEntry.getValue()), elementState.getParticipantId());
+ elementList.add(elementEntry);
+ }
+ }
+ var list = prepareParticipantPriming(elementList, supportedElementMap);
+ for (var participantDefinition : list) {
+ for (var elementDe : participantDefinition.getAutomationCompositionElementDefinitionList()) {
+ var state = acmDefinition.getElementStateMap().get(elementDe.getAcElementDefinitionId().getName());
+ if (state != null) {
+ elementDe.setOutProperties(state.getOutProperties());
+ }
+ }
+ }
+ return list;
+ }
+
+
+ /**
* Recursive Merge.
*
* @param map1 Map where to merge
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
index a843c8279..1a7a419d6 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantInformationTest.java
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
class ParticipantInformationTest {
@@ -33,8 +32,6 @@ class ParticipantInformationTest {
void testCopyConstructor() {
var participant = new Participant();
participant.setParticipantId(UUID.randomUUID());
- participant.setParticipantState(ParticipantState.ON_LINE);
- participant.setLastMsg(TimestampHelper.now());
participant.setParticipantSupportedElementTypes(new HashMap<>());
var participantInfo1 = new ParticipantInformation();
participantInfo1.setParticipant(participant);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
index 7486d0d70..2c6c60edc 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.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.
@@ -21,7 +21,6 @@
package org.onap.policy.clamp.models.acm.concepts;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -46,7 +45,6 @@ class ParticipantTest {
var p1 = new Participant();
p1.setParticipantId(CommonTestData.getParticipantId());
- p1.setParticipantState(ParticipantState.ON_LINE);
assertThat(p1.toString()).contains("Participant(");
assertNotEquals(0, p1.hashCode());
@@ -56,11 +54,6 @@ class ParticipantTest {
assertNotEquals(p1, p0);
var p2 = new Participant();
-
- // @formatter:off
- assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class);
- // @formatter:on
-
assertEquals(p2, p0);
}
@@ -68,7 +61,6 @@ class ParticipantTest {
void testCopyConstructor() {
var p0 = new Participant();
p0.setParticipantId(UUID.randomUUID());
- p0.setParticipantState(ParticipantState.ON_LINE);
var supportedElementType = new ParticipantSupportedElementType();
supportedElementType.setId(UUID.randomUUID());
supportedElementType.setTypeName("type");
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
index e0f2f55c1..d2d253e06 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
@@ -27,15 +27,11 @@ 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;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
/**
* Test the {@link JpaParticipant} class.
@@ -47,30 +43,23 @@ class JpaParticipantTest {
@Test
void testJpaParticipantConstructor() {
assertThatThrownBy(() -> new JpaParticipant((Participant) null))
- .hasMessageMatching("authorativeConcept is marked .*ull but is null");
+ .hasMessageMatching("authorativeConcept is marked .*ull but is null");
assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null))
.hasMessageMatching("copyConcept is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(null, ParticipantState.ON_LINE,
- new ArrayList<>(), new ArrayList<>()))
+ assertThatThrownBy(() -> new JpaParticipant(null, new ArrayList<>(), new ArrayList<>()))
.hasMessageMatching(NULL_KEY_ERROR);
- assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null,
- new ArrayList<>(), new ArrayList<>()))
- .hasMessageMatching("participantState is marked .*ull but is null");
-
- assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE,
- null, new ArrayList<>()))
+ assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), null, new ArrayList<>()))
.hasMessageMatching("supportedElements is marked .*ull but is null");
- assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), ParticipantState.ON_LINE,
- new ArrayList<>(), null))
- .hasMessageMatching("replicas is marked .*ull but is null");
+ assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), new ArrayList<>(), null))
+ .hasMessageMatching("replicas is marked .*ull but is null");
assertDoesNotThrow(() -> new JpaParticipant());
assertDoesNotThrow(() -> new JpaParticipant(UUID.randomUUID().toString(),
- ParticipantState.ON_LINE, new ArrayList<>(), new ArrayList<>()));
+ new ArrayList<>(), new ArrayList<>()));
}
@Test
@@ -116,18 +105,6 @@ class JpaParticipantTest {
assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant));
assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild()));
- testJpaParticipant.setParticipantState(ParticipantState.OFF_LINE);
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setParticipantState(ParticipantState.ON_LINE);
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
-
- testJpaParticipant.setLastMsg(Timestamp.from(Instant.EPOCH));
- assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- testJpaParticipant.setLastMsg(otherJpaParticipant.getLastMsg());
- assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant));
- assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant));
-
var newJpaParticipant = new JpaParticipant(testJpaParticipant);
newJpaParticipant.setParticipantId(testJpaParticipant.getParticipantId());
assertEquals(testJpaParticipant, newJpaParticipant);
@@ -143,8 +120,6 @@ class JpaParticipantTest {
var p1 = new JpaParticipant();
- p1.setParticipantState(ParticipantState.ON_LINE);
-
assertThat(p1.toString()).contains("Participant(");
assertNotEquals(0, p1.hashCode());
assertNotEquals(p1, p0);
@@ -154,14 +129,12 @@ class JpaParticipantTest {
var p2 = new JpaParticipant();
p2.setParticipantId(p0.getParticipantId());
- p2.setLastMsg(p0.getLastMsg());
assertEquals(p2, p0);
}
private Participant createParticipantInstance() {
var testParticipant = new Participant();
testParticipant.setParticipantId(UUID.randomUUID());
- testParticipant.setLastMsg(TimestampHelper.now());
testParticipant.setParticipantSupportedElementTypes(new LinkedHashMap<>());
testParticipant.setReplicas(new LinkedHashMap<>());
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 a5c93e86a..024060f0a 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
@@ -37,7 +37,9 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+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.AutomationCompositionDefinition;
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;
@@ -45,6 +47,7 @@ import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplat
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.utils.coder.StandardCoder;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -276,9 +279,7 @@ class AcmUtilsTest {
}
private Map<String, ToscaPolicyType> getDummyPolicyTypesMap() {
- Map<String, ToscaPolicyType> policyTypes = new HashMap<>();
- policyTypes.put("onap.policies.Match", new ToscaPolicyType());
- return policyTypes;
+ return Map.of("onap.policies.Match", new ToscaPolicyType());
}
private Map<String, ToscaDataType> getDummyToscaDataTypeMap() {
@@ -290,12 +291,45 @@ class AcmUtilsTest {
private Map<String, ToscaNodeTemplate> getDummyNodeTemplates() {
Map<String, ToscaNodeTemplate> nodeTemplates = new HashMap<>();
var nodeTemplate = new ToscaNodeTemplate();
- nodeTemplate.setType("org.onap.policy.clamp.acm.AutomationCompositionElement");
+ nodeTemplate.setType(AUTOMATION_COMPOSITION_ELEMENT);
nodeTemplates.put("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", nodeTemplate);
return nodeTemplates;
}
@Test
+ void testcreateAcRestart() {
+ var automationComposition = getDummyAutomationComposition();
+ automationComposition.setInstanceId(UUID.randomUUID());
+ var toscaServiceTemplate = getDummyToscaServiceTemplate();
+ var participantId = automationComposition.getElements().values().iterator().next().getParticipantId();
+ var serviceTemplateFragment = AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate);
+ var result = AcmUtils.createAcRestart(automationComposition, participantId, serviceTemplateFragment);
+ assertEquals(result.getAutomationCompositionId(), automationComposition.getInstanceId());
+ assertThat(result.getAcElementList()).hasSize(1);
+ }
+
+ @Test
+ void testPrepareParticipantRestarting() {
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+ var acmDefinition = new AutomationCompositionDefinition();
+ acmDefinition.setElementStateMap(Map.of());
+ acmDefinition.setServiceTemplate(serviceTemplate);
+ var acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate, AUTOMATION_COMPOSITION_ELEMENT);
+ acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
+ acmDefinition.getElementStateMap()
+ .values().forEach(element -> element.setParticipantId(UUID.randomUUID()));
+ var participantId = UUID.randomUUID();
+ var result = AcmUtils.prepareParticipantRestarting(participantId, acmDefinition,
+ AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(result).isEmpty();
+
+ participantId = acmDefinition.getElementStateMap().values().iterator().next().getParticipantId();
+ result = AcmUtils.prepareParticipantRestarting(participantId, acmDefinition,
+ AUTOMATION_COMPOSITION_ELEMENT);
+ assertThat(result).hasSize(1);
+ }
+
+ @Test
void testRecursiveMergeMap() {
var oldProperties = """
chart: