aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/pom.xml79
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java8
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java7
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java8
-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/ParticipantReplica.java1
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java9
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java47
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/SubState.java (renamed from models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementType.java)12
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java20
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessage.java59
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionPrepare.java (renamed from models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestart.java)41
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageType.java7
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java24
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java30
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementConfig.java36
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/KafkaConfig.java39
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/SubOrder.java (renamed from models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessageType.java)11
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java50
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java33
-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/persistence/provider/AcDefinitionProvider.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java151
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java46
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java14
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionElementRepository.java15
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java115
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/StateDefinition.java4
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java (renamed from models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementStatus.java)25
-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/concepts/ParticipantUtilsTest.java24
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantAckMessageTest.java18
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageTest.java15
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestartTest.java84
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java2
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java85
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java54
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java2
-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/persistence/concepts/StringToMapConverterTest.java53
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java58
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java4
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java74
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java23
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java20
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java4
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java70
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java2
-rw-r--r--models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml14
62 files changed, 981 insertions, 663 deletions
diff --git a/models/pom.xml b/models/pom.xml
index b833277b9..8e12badac 100644
--- a/models/pom.xml
+++ b/models/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.onap.policy.clamp</groupId>
<artifactId>policy-clamp</artifactId>
- <version>8.0.0-SNAPSHOT</version>
+ <version>8.0.1-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-models</artifactId>
@@ -35,13 +35,25 @@
<dependencies>
<dependency>
- <groupId>org.onap.policy.clamp</groupId>
- <artifactId>policy-clamp-examples</artifactId>
- <version>${project.version}</version>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>common-parameters</artifactId>
+ <version>${policy.common.version}</version>
</dependency>
<dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils-test</artifactId>
+ <version>${policy.common.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-errors</artifactId>
+ <version>${policy.models.version}</version>
</dependency>
<dependency>
<groupId>org.onap.policy.models</groupId>
@@ -54,23 +66,64 @@
<version>${policy.models.version}</version>
</dependency>
<dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.persistence</groupId>
+ <artifactId>jakarta.persistence-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate.orm</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
- <version>${version.spring}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
- <version>${version.springboot}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter</artifactId>
- <version>${version.jupiter}</version>
+ <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -88,12 +141,6 @@
<artifactId>openpojo</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.onap.policy.common</groupId>
- <artifactId>utils-test</artifactId>
- <version>${policy.common.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
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 eb5b6dc9b..61610bb47 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
@@ -44,7 +44,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
private UUID compositionTargetId;
- private Boolean restarting;
+ private Boolean precheck;
@NonNull
private DeployState deployState = DeployState.UNDEPLOYED;
@@ -56,6 +56,9 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
private Integer phase;
+ @NonNull
+ private SubState subState = SubState.NONE;
+
private Map<UUID, AutomationCompositionElement> elements;
private StateChangeResult stateChangeResult;
@@ -70,11 +73,12 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
this.instanceId = otherAutomationComposition.instanceId;
this.compositionId = otherAutomationComposition.compositionId;
this.compositionTargetId = otherAutomationComposition.compositionTargetId;
- this.restarting = otherAutomationComposition.restarting;
+ this.precheck = otherAutomationComposition.precheck;
this.deployState = otherAutomationComposition.deployState;
this.lockState = otherAutomationComposition.lockState;
this.lastMsg = otherAutomationComposition.lastMsg;
this.phase = otherAutomationComposition.phase;
+ this.subState = otherAutomationComposition.subState;
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/concepts/AutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
index 987cb8832..57b6837af 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionDefinition.java
@@ -41,8 +41,6 @@ public class AutomationCompositionDefinition {
@NonNull
private ToscaServiceTemplate serviceTemplate;
- private Boolean restarting;
-
@NonNull
private AcTypeState state;
@@ -63,7 +61,6 @@ public class AutomationCompositionDefinition {
public AutomationCompositionDefinition(final AutomationCompositionDefinition otherAcmDefinition) {
this.compositionId = otherAcmDefinition.compositionId;
this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate);
- this.restarting = otherAcmDefinition.restarting;
this.state = otherAcmDefinition.state;
this.lastMsg = otherAcmDefinition.lastMsg;
this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new);
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
index 5afa7e0bb..7d3acaa52 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
@@ -55,6 +55,11 @@ public class AutomationCompositionElement {
@NonNull
private LockState lockState = LockState.LOCKED;
+ @NonNull
+ private SubState subState = SubState.NONE;
+
+ private Integer stage;
+
private String operationalState;
private String useState;
private String description;
@@ -81,8 +86,10 @@ public class AutomationCompositionElement {
this.restarting = otherElement.restarting;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.subState = otherElement.subState;
this.operationalState = otherElement.operationalState;
this.useState = otherElement.useState;
+ this.stage = otherElement.stage;
this.message = otherElement.message;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java
index 1802f814c..76443ab37 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.
@@ -40,9 +40,9 @@ public class AutomationCompositions {
/**
* Copy constructor, does a deep copy.
*
- * @param otherAutomationCompositions the other element to copy from
+ * @param other the other element to copy from
*/
- public AutomationCompositions(final AutomationCompositions otherAutomationCompositions) {
- this.automationCompositionList = PfUtils.mapList(automationCompositionList, AutomationComposition::new);
+ public AutomationCompositions(final AutomationCompositions other) {
+ this.automationCompositionList = PfUtils.mapList(other.automationCompositionList, AutomationComposition::new);
}
}
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/ParticipantReplica.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java
index 23f72191a..73dfad564 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java
@@ -37,6 +37,7 @@ public class ParticipantReplica {
@NonNull
private ParticipantState participantState = ParticipantState.ON_LINE;
+ // last time ACM-R has received a status message from participant replica
@NonNull
private String lastMsg;
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..5d4b8ac77 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,10 @@ public class ParticipantRestartAc {
private UUID automationCompositionId;
+ private DeployState deployState;
+ private LockState lockState;
+ private StateChangeResult stateChangeResult;
+
private List<AcElementRestart> acElementList = new ArrayList<>();
/**
@@ -46,6 +50,9 @@ public class ParticipantRestartAc {
*/
public ParticipantRestartAc(ParticipantRestartAc copyConstructor) {
this.automationCompositionId = copyConstructor.automationCompositionId;
+ this.deployState = copyConstructor.deployState;
+ this.lockState = copyConstructor.lockState;
+ this.stateChangeResult = copyConstructor.stateChangeResult;
this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementRestart::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java
index d6079d0e7..9c827d701 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.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.
@@ -20,7 +20,11 @@
package org.onap.policy.clamp.models.acm.concepts;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -50,8 +54,26 @@ public final class ParticipantUtils {
}
return DeployState.DEPLOYING.equals(automationComposition.getDeployState())
- || LockState.UNLOCKING.equals(automationComposition.getLockState()) ? minStartPhase
- : maxStartPhase;
+ || LockState.UNLOCKING.equals(automationComposition.getLockState()) ? minStartPhase : maxStartPhase;
+ }
+
+ /**
+ * Get the First Stage.
+ *
+ * @param automationComposition the automation composition
+ * @param toscaServiceTemplate the ToscaServiceTemplate
+ * @return the First stage
+ */
+ public static int getFirstStage(
+ AutomationComposition automationComposition, ToscaServiceTemplate toscaServiceTemplate) {
+ Set<Integer> minStage = new HashSet<>();
+ for (var element : automationComposition.getElements().values()) {
+ var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ var stage = ParticipantUtils.findStageSet(toscaNodeTemplate.getProperties());
+ minStage.addAll(stage);
+ }
+ return minStage.stream().min(Integer::compare).orElse(0);
}
/**
@@ -63,8 +85,25 @@ public final class ParticipantUtils {
public static int findStartPhase(Map<String, Object> properties) {
var objStartPhase = properties.get("startPhase");
if (objStartPhase != null) {
- return Integer.valueOf(objStartPhase.toString());
+ return Integer.parseInt(objStartPhase.toString());
}
return 0;
}
+
+
+ /**
+ * Finds stage from a map of properties.
+ *
+ * @param properties Map of properties
+ * @return stage
+ */
+ public static Set<Integer> findStageSet(Map<String, Object> properties) {
+ var objStage = properties.get("stage");
+ if (objStage instanceof List<?> stageSet) {
+ return stageSet.stream()
+ .map(obj -> Integer.valueOf(obj.toString()))
+ .collect(Collectors.toSet());
+ }
+ return Set.of(0);
+ }
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/SubState.java
index 4bc08a36e..5f979c50f 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementType.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/SubState.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 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.
@@ -18,9 +18,11 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.models.acm.messages.rest.element;
+package org.onap.policy.clamp.models.acm.concepts;
-public enum ElementType {
-
- STARTER, BRIDGE, SINK
+public enum SubState {
+ NONE,
+ MIGRATION_PRECHECKING,
+ PREPARING,
+ REVIEWING
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java
index 572332eeb..e675e2387 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaCapabilityAssignment.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -42,7 +42,10 @@ public class DocToscaCapabilityAssignment extends DocToscaWithTypeAndStringPrope
@Serial
private static final long serialVersionUID = 1L;
+ @SuppressWarnings("squid:S1948")
private Map<@NotNull String, @NotNull Object> attributes;
+
+ @SuppressWarnings("squid:S1948")
private List<@NotNull Object> occurrences;
/**
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java
index c8484654b..b931d4e0a 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaEntity.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -59,6 +59,7 @@ public class DocToscaEntity<T extends ToscaEntity> extends Validated
@SerializedName("derived_from")
private String derivedFrom;
+ @SuppressWarnings("squid:S1948")
private Map<@NotNull @NotBlank String, @NotNull @NotBlank Object> metadata = new LinkedHashMap<>();
@NotBlank
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java
index 2904962fc..5a252b8d2 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaParameter.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -48,6 +48,7 @@ public class DocToscaParameter implements PfAuthorative<ToscaParameter>, Seriali
@SerializedName("type_version")
private String typeVersion;
+ @SuppressWarnings("squid:S1948")
private Object value;
/**
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java
index b47ef56aa..774f045f5 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaProperty.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -60,6 +60,7 @@ public class DocToscaProperty implements PfAuthorative<ToscaProperty>, Serializa
@SerializedName("default")
@NotBlank
+ @SuppressWarnings("squid:S1948")
private Object defaultValue;
private boolean required = false;
@@ -208,7 +209,7 @@ public class DocToscaProperty implements PfAuthorative<ToscaProperty>, Serializa
return result;
}
- result = entrySchema.compareTo(other.entrySchema);
+ result = ObjectUtils.compare(entrySchema, other.entrySchema);
if (result != 0) {
return result;
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java
index fd67fb68d..9d3cc1051 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaRequirement.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -42,6 +42,8 @@ public class DocToscaRequirement extends DocToscaWithTypeAndStringProperties<Tos
private String capability;
private String node;
private String relationship;
+
+ @SuppressWarnings("squid:S1948")
private List<Object> occurrences;
public DocToscaRequirement(ToscaRequirement toscaRequirement) {
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java
index 9a6d60c1c..bcb63a2f1 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithToscaProperties.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -33,6 +33,7 @@ import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.models.acm.document.base.DocConceptKey;
+import org.onap.policy.clamp.models.acm.document.base.DocUtil;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@@ -49,6 +50,7 @@ public class DocToscaWithToscaProperties<T extends ToscaWithToscaProperties> ext
@Serial
private static final long serialVersionUID = 1L;
+ @SuppressWarnings("squid:S1948")
private Map<@NotNull @NotBlank String, @NotNull @Valid DocToscaProperty> properties;
/**
@@ -121,4 +123,20 @@ public class DocToscaWithToscaProperties<T extends ToscaWithToscaProperties> ext
referencedDataTypes.removeAll(set);
return referencedDataTypes;
}
+
+ @Override
+ public int compareTo(final DocToscaEntity<T> otherConcept) {
+ if (this == otherConcept) {
+ return 0;
+ }
+
+ int result = super.compareTo(otherConcept);
+ if (result != 0) {
+ return result;
+ }
+
+ final var other = (DocToscaWithToscaProperties<T>) otherConcept;
+
+ return DocUtil.compareMaps(properties, other.properties);
+ }
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java
index 55b7364c9..2d62e36ea 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/concepts/DocToscaWithTypeAndStringProperties.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,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.
@@ -50,6 +50,7 @@ public class DocToscaWithTypeAndStringProperties<T extends ToscaWithTypeAndObjec
@SerializedName("type_version")
private String typeVersion;
+ @SuppressWarnings("squid:S1948")
private Map<String, Object> properties;
/**
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessage.java
deleted file mode 100644
index 13a1b735b..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessage.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022,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.
- * 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.kafka.element;
-
-import java.time.Instant;
-import java.util.UUID;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
-@Getter
-@Setter
-@ToString
-public class ElementMessage {
-
- @Setter(AccessLevel.NONE)
- private ElementMessageType messageType;
-
- private ToscaConceptIdentifier elementId;
-
- private String message;
-
- private UUID messageId = UUID.randomUUID();
-
- /**
- * Time-stamp, in milliseconds, when the message was created. Defaults to the
- * current time.
- */
- private Instant timestamp = Instant.now();
-
- /**
- * Constructor for instantiating a element message class.
- *
- * @param messageType the message type
- */
- public ElementMessage(ElementMessageType messageType) {
- this.messageType = messageType;
- }
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java
index 2c7d51fe7..9807ff9ca 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionDeployAck.java
@@ -41,7 +41,7 @@ import org.onap.policy.models.base.PfUtils;
public class AutomationCompositionDeployAck extends ParticipantAckMessage {
private UUID automationCompositionId;
- private Integer startPhase;
+ private Integer stage;
// A map with AutomationCompositionElementID as its key, and a pair of result and message as value per
// AutomationCompositionElement.
@@ -63,7 +63,7 @@ public class AutomationCompositionDeployAck extends ParticipantAckMessage {
public AutomationCompositionDeployAck(final AutomationCompositionDeployAck source) {
super(source);
this.automationCompositionId = source.automationCompositionId;
- this.startPhase = source.startPhase;
+ this.stage = source.stage;
this.automationCompositionResultMap =
PfUtils.mapMap(source.automationCompositionResultMap, UnaryOperator.identity());
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java
index fb1f1925c..2d7608afd 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/AutomationCompositionMigration.java
@@ -37,6 +37,9 @@ public class AutomationCompositionMigration extends ParticipantMessage {
// A list of updates to AC element properties
private List<ParticipantDeploy> participantUpdatesList = new ArrayList<>();
+ private Boolean precheck = false;
+ private Integer stage = 0;
+
public AutomationCompositionMigration() {
super(ParticipantMessageType.AUTOMATION_COMPOSITION_MIGRATION);
}
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/AutomationCompositionPrepare.java
index 98c7d1071..343143eed 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/AutomationCompositionPrepare.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation.
+ * Copyright (C) 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.
@@ -25,38 +25,23 @@ 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.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.models.base.PfUtils;
@Getter
@Setter
@ToString(callSuper = true)
-public class ParticipantRestart extends ParticipantMessage {
+public class AutomationCompositionPrepare extends ParticipantMessage {
- // composition state
- AcTypeState state;
-
- // element definition
- private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
-
- // automation composition instances list
- private List<ParticipantRestartAc> automationcompositionList = new ArrayList<>();
+ private List<ParticipantDeploy> participantList = new ArrayList<>();
+ private boolean preDeploy = true;
/**
- * Constructor.
- */
- public ParticipantRestart() {
- super(ParticipantMessageType.PARTICIPANT_RESTART);
- }
-
- /**
- * Constructor with message type.
- * @param messageType messageType
+ * Constructor for instantiating class with message name.
+ *
*/
- public ParticipantRestart(ParticipantMessageType messageType) {
- super(messageType);
+ public AutomationCompositionPrepare() {
+ super(ParticipantMessageType.AUTOMATION_COMPOSITION_PREPARE);
}
/**
@@ -64,11 +49,9 @@ public class ParticipantRestart extends ParticipantMessage {
*
* @param source source from which to copy
*/
- public ParticipantRestart(ParticipantRestart source) {
+ public AutomationCompositionPrepare(AutomationCompositionPrepare source) {
super(source);
- this.state = source.state;
- this.participantDefinitionUpdates =
- PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new);
- this.automationcompositionList = PfUtils.mapList(source.automationcompositionList, ParticipantRestartAc::new);
+ this.preDeploy = source.preDeploy;
+ this.participantList = PfUtils.mapList(source.participantList, ParticipantDeploy::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageType.java
index e6e42e851..7e19f6f79 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageType.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageType.java
@@ -115,5 +115,10 @@ public enum ParticipantMessageType {
/**
* Used by runtime to send composition and instances to sync participant replicas.
*/
- PARTICIPANT_SYNC_MSG
+ PARTICIPANT_SYNC_MSG,
+
+ /**
+ * Used by the acm runtime to ask for a preparation check to participants.
+ */
+ AUTOMATION_COMPOSITION_PREPARE
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java
index 962b6137c..2780a5b1e 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSync.java
@@ -20,21 +20,38 @@
package org.onap.policy.clamp.models.acm.messages.kafka.participant;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.UUID;
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.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.models.base.PfUtils;
@Getter
@Setter
@ToString(callSuper = true)
-public class ParticipantSync extends ParticipantRestart {
+public class ParticipantSync extends ParticipantMessage {
+
+ // composition state
+ private AcTypeState state;
+
+ // element definition
+ private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+
+ // automation composition instances list
+ private List<ParticipantRestartAc> automationcompositionList = new ArrayList<>();
private Set<UUID> excludeReplicas = new HashSet<>();
private boolean restarting = false;
private boolean delete = false;
+ private StateChangeResult stateChangeResult;
/**
* Constructor.
@@ -50,8 +67,13 @@ public class ParticipantSync extends ParticipantRestart {
*/
public ParticipantSync(ParticipantSync source) {
super(source);
+ this.state = source.state;
+ this.participantDefinitionUpdates =
+ PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new);
+ this.automationcompositionList = PfUtils.mapList(source.automationcompositionList, ParticipantRestartAc::new);
this.excludeReplicas = new HashSet<>(source.excludeReplicas);
this.restarting = source.restarting;
this.delete = source.delete;
+ this.stateChangeResult = source.getStateChangeResult();
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java
deleted file mode 100644
index 3e39e970d..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.rest;
-
-import lombok.Data;
-
-@Data
-public class GenericNameVersion {
-
- private String name;
-
- private String version;
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementConfig.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementConfig.java
deleted file mode 100644
index bb3670cb7..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/ElementConfig.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022,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.
- * 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.rest.element;
-
-import lombok.Data;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
-@Data
-public class ElementConfig {
-
- private ToscaConceptIdentifier receiverId;
-
- private ElementType elementType;
-
- private Integer timerMs;
-
- private KafkaConfig topicParameterGroup;
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/KafkaConfig.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/KafkaConfig.java
deleted file mode 100644
index 35871fcbf..000000000
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/element/KafkaConfig.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022,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.
- * 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.rest.element;
-
-import lombok.Data;
-
-@Data
-public class KafkaConfig {
- private String server;
-
- private String listenerTopic;
-
- private String publisherTopic;
-
- private Integer fetchTimeout;
-
- private String topicCommInfrastructure;
-
- private boolean useHttps;
-
-}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java
index e47947a02..68c597b32 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022,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.
@@ -26,4 +26,5 @@ import lombok.Data;
public class AcInstanceStateUpdate {
private DeployOrder deployOrder;
private LockOrder lockOrder;
+ private SubOrder subOrder;
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessageType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/SubOrder.java
index cb2eaae95..9cf7efaa6 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementMessageType.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/SubOrder.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022,2024 Nordix Foundation.
+ * Copyright (C) 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.
@@ -18,8 +18,11 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.models.acm.messages.kafka.element;
+package org.onap.policy.clamp.models.acm.messages.rest.instantiation;
-public enum ElementMessageType {
- STATUS, ACK_MSG
+public enum SubOrder {
+ NONE,
+ MIGRATE_PRECHECK,
+ PREPARE,
+ REVIEW
}
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 0bf6a9e1a..001f2e7f3 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
@@ -45,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.concepts.SubState;
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;
@@ -86,9 +87,6 @@ public class JpaAutomationComposition extends Validated
private String compositionTargetId;
@Column
- private Boolean restarting;
-
- @Column
@NotNull
private DeployState deployState;
@@ -97,6 +95,10 @@ public class JpaAutomationComposition extends Validated
private LockState lockState;
@Column
+ @NotNull
+ private SubState subState;
+
+ @Column
private StateChangeResult stateChangeResult;
@Column
@@ -119,7 +121,7 @@ public class JpaAutomationComposition extends Validated
*/
public JpaAutomationComposition() {
this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(), new ArrayList<>(),
- DeployState.UNDEPLOYED, LockState.NONE);
+ DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE);
}
/**
@@ -131,10 +133,12 @@ public class JpaAutomationComposition extends Validated
* @param elements the elements of the automation composition in participants
* @param deployState the Deploy State
* @param lockState the Lock State
+ * @param subState the Sub State
*/
public JpaAutomationComposition(@NonNull final String instanceId, @NonNull final PfConceptKey key,
@NonNull final String compositionId, @NonNull final List<JpaAutomationCompositionElement> elements,
- @NonNull final DeployState deployState, @NonNull final LockState lockState) {
+ @NonNull final DeployState deployState, @NonNull final LockState lockState,
+ @NonNull final SubState subState) {
this.instanceId = instanceId;
this.name = key.getName();
this.version = key.getVersion();
@@ -142,6 +146,7 @@ public class JpaAutomationComposition extends Validated
this.deployState = deployState;
this.lockState = lockState;
this.elements = elements;
+ this.subState = subState;
}
/**
@@ -155,11 +160,11 @@ public class JpaAutomationComposition extends Validated
this.version = copyConcept.version;
this.compositionId = copyConcept.compositionId;
this.compositionTargetId = copyConcept.compositionTargetId;
- this.restarting = copyConcept.restarting;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.lastMsg = copyConcept.lastMsg;
this.phase = copyConcept.phase;
+ this.subState = copyConcept.subState;
this.description = copyConcept.description;
this.stateChangeResult = copyConcept.stateChangeResult;
this.elements = PfUtils.mapList(copyConcept.elements, JpaAutomationCompositionElement::new);
@@ -185,11 +190,11 @@ public class JpaAutomationComposition extends Validated
if (compositionTargetId != null) {
automationComposition.setCompositionTargetId(UUID.fromString(compositionTargetId));
}
- automationComposition.setRestarting(restarting);
automationComposition.setDeployState(deployState);
automationComposition.setLockState(lockState);
automationComposition.setLastMsg(lastMsg.toString());
automationComposition.setPhase(phase);
+ automationComposition.setSubState(subState);
automationComposition.setDescription(description);
automationComposition.setStateChangeResult(stateChangeResult);
automationComposition.setElements(new LinkedHashMap<>(this.elements.size()));
@@ -202,6 +207,22 @@ public class JpaAutomationComposition extends Validated
@Override
public void fromAuthorative(@NonNull final AutomationComposition automationComposition) {
+ this.fromAuthorativeBase(automationComposition);
+ this.elements = new ArrayList<>(automationComposition.getElements().size());
+ for (var elementEntry : automationComposition.getElements().entrySet()) {
+ var jpaAutomationCompositionElement =
+ new JpaAutomationCompositionElement(elementEntry.getKey().toString(), this.instanceId);
+ jpaAutomationCompositionElement.fromAuthorative(elementEntry.getValue());
+ this.elements.add(jpaAutomationCompositionElement);
+ }
+ }
+
+ /**
+ * Set an instance of the persist concept to the equivalent values as the other concept without copy the elements.
+ *
+ * @param automationComposition the authorative concept
+ */
+ public void fromAuthorativeBase(@NonNull final AutomationComposition automationComposition) {
this.instanceId = automationComposition.getInstanceId().toString();
this.name = automationComposition.getName();
this.version = automationComposition.getVersion();
@@ -209,20 +230,13 @@ public class JpaAutomationComposition extends Validated
if (automationComposition.getCompositionTargetId() != null) {
this.compositionTargetId = automationComposition.getCompositionTargetId().toString();
}
- this.restarting = automationComposition.getRestarting();
this.deployState = automationComposition.getDeployState();
this.lockState = automationComposition.getLockState();
this.lastMsg = TimestampHelper.toTimestamp(automationComposition.getLastMsg());
this.phase = automationComposition.getPhase();
+ this.subState = automationComposition.getSubState();
this.description = automationComposition.getDescription();
this.stateChangeResult = automationComposition.getStateChangeResult();
- this.elements = new ArrayList<>(automationComposition.getElements().size());
- for (var elementEntry : automationComposition.getElements().entrySet()) {
- var jpaAutomationCompositionElement =
- new JpaAutomationCompositionElement(elementEntry.getKey().toString(), this.instanceId);
- jpaAutomationCompositionElement.fromAuthorative(elementEntry.getValue());
- this.elements.add(jpaAutomationCompositionElement);
- }
}
@Override
@@ -269,17 +283,17 @@ public class JpaAutomationComposition extends Validated
return result;
}
- result = ObjectUtils.compare(restarting, other.restarting);
+ result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
}
- result = ObjectUtils.compare(deployState, other.deployState);
+ result = ObjectUtils.compare(lockState, other.lockState);
if (result != 0) {
return result;
}
- result = ObjectUtils.compare(lockState, other.lockState);
+ result = ObjectUtils.compare(subState, other.subState);
if (result != 0) {
return result;
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
index 1cab89d5d..3d61c4ed9 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java
@@ -79,9 +79,6 @@ public class JpaAutomationCompositionDefinition extends Validated
private String version;
@Column
- private Boolean restarting;
-
- @Column
@NotNull
private AcTypeState state;
@@ -107,7 +104,6 @@ public class JpaAutomationCompositionDefinition extends Validated
public AutomationCompositionDefinition toAuthorative() {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.fromString(this.compositionId));
- acmDefinition.setRestarting(this.restarting);
acmDefinition.setState(this.state);
acmDefinition.setStateChangeResult(this.stateChangeResult);
acmDefinition.setLastMsg(this.lastMsg.toString());
@@ -122,7 +118,6 @@ public class JpaAutomationCompositionDefinition extends Validated
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
this.compositionId = copyConcept.getCompositionId().toString();
- this.restarting = copyConcept.getRestarting();
this.state = copyConcept.getState();
this.stateChangeResult = copyConcept.getStateChangeResult();
this.lastMsg = TimestampHelper.toTimestamp(copyConcept.getLastMsg());
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
index 74426a747..e511ba1fc 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -42,6 +42,7 @@ import org.apache.commons.lang3.ObjectUtils;
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.SubState;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
@@ -94,12 +95,19 @@ public class JpaAutomationCompositionElement extends Validated
private LockState lockState;
@Column
+ @NotNull
+ private SubState subState;
+
+ @Column
private String operationalState;
@Column
private String useState;
@Column
+ private Integer stage;
+
+ @Column
private String description;
@Column
@@ -134,7 +142,7 @@ public class JpaAutomationCompositionElement extends Validated
*/
public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
this(elementId, instanceId, new PfConceptKey(),
- DeployState.UNDEPLOYED, LockState.LOCKED);
+ DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE);
}
/**
@@ -145,15 +153,18 @@ public class JpaAutomationCompositionElement extends Validated
* @param definition the TOSCA definition of the automation composition element
* @param deployState the Deploy State of the automation composition
* @param lockState the Lock State of the automation composition
+ * @param subState the Sub State of the automation composition
*/
public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
@NonNull final PfConceptKey definition,
- @NonNull final DeployState deployState, @NonNull final LockState lockState) {
+ @NonNull final DeployState deployState, @NonNull final LockState lockState,
+ @NonNull final SubState subState) {
this.elementId = elementId;
this.instanceId = instanceId;
this.definition = definition;
this.deployState = deployState;
this.lockState = lockState;
+ this.subState = subState;
}
/**
@@ -174,8 +185,10 @@ public class JpaAutomationCompositionElement extends Validated
this.restarting = copyConcept.restarting;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
+ this.subState = copyConcept.subState;
this.operationalState = copyConcept.operationalState;
this.useState = copyConcept.useState;
+ this.stage = copyConcept.stage;
this.message = copyConcept.message;
}
@@ -201,8 +214,10 @@ public class JpaAutomationCompositionElement extends Validated
element.setRestarting(restarting);
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setSubState(subState);
element.setOperationalState(operationalState);
element.setUseState(useState);
+ element.setStage(stage);
element.setMessage(message);
return element;
@@ -218,8 +233,10 @@ public class JpaAutomationCompositionElement extends Validated
this.restarting = element.getRestarting();
this.deployState = element.getDeployState();
this.lockState = element.getLockState();
+ this.subState = element.getSubState();
this.operationalState = element.getOperationalState();
this.useState = element.getUseState();
+ this.stage = element.getStage();
this.message = element.getMessage();
}
@@ -267,11 +284,21 @@ public class JpaAutomationCompositionElement extends Validated
return result;
}
+ result = ObjectUtils.compare(subState, other.subState);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(useState, other.useState);
if (result != 0) {
return result;
}
+ result = ObjectUtils.compare(stage, other.stage);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(operationalState, other.operationalState);
if (result != 0) {
return result;
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/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
index 46b43f950..bb05c46c6 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
@@ -138,10 +138,8 @@ public class AcDefinitionProvider {
* @param compositionId The UUID of the automation composition definition to update
* @param state the AcTypeState
* @param stateChangeResult the StateChangeResult
- * @param restarting restarting process
*/
- public void updateAcDefinitionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
- Boolean restarting) {
+ public void updateAcDefinitionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult) {
var jpaUpdate = acmDefinitionRepository.findById(compositionId.toString());
if (jpaUpdate.isEmpty()) {
String errorMessage = "update of Automation Composition Definition \"" + compositionId
@@ -151,7 +149,6 @@ public class AcDefinitionProvider {
var acDefinition = jpaUpdate.get();
acDefinition.setState(state);
acDefinition.setStateChangeResult(stateChangeResult);
- acDefinition.setRestarting(restarting);
acmDefinitionRepository.save(acDefinition);
acmDefinitionRepository.flush();
}
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 ace246c5d..7bffdd966 100644
--- 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
@@ -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.
@@ -23,8 +23,10 @@ package org.onap.policy.clamp.models.acm.persistence.provider;
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.concepts.SubState;
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.messages.rest.instantiation.SubOrder;
import org.onap.policy.clamp.models.acm.utils.StateDefinition;
import org.springframework.stereotype.Component;
@@ -39,6 +41,8 @@ public class AcInstanceStateResolver {
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 MIGRATION_PRECHECKING = SubState.MIGRATION_PRECHECKING.name();
+ private static final String SUB_STATE_NONE = SubState.NONE.name();
private static final String LOCKED = LockState.LOCKED.name();
private static final String LOCKING = LockState.LOCKING.name();
@@ -48,6 +52,7 @@ public class AcInstanceStateResolver {
private static final String DEPLOY_NONE = DeployOrder.NONE.name();
private static final String LOCK_NONE = LockOrder.NONE.name();
+ private static final String SUB_NONE = SubOrder.NONE.name();
private static final String NO_ERROR = StateChangeResult.NO_ERROR.name();
private static final String FAILED = StateChangeResult.FAILED.name();
@@ -60,55 +65,105 @@ public class AcInstanceStateResolver {
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 MIGRATE_PRECHECK = SubOrder.MIGRATE_PRECHECK.name();
+ public static final String PREPARE = SubOrder.PREPARE.name();
+ public static final String REVIEW = SubOrder.REVIEW.name();
+ public static final String UPDATE = DeployOrder.UPDATE.name();
public static final String NONE = "NONE";
/**
* Construct.
*/
public AcInstanceStateResolver() {
- this.graph = new StateDefinition<>(5, NONE);
-
- // no error
- this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYED, STATE_LOCKED_NONE, NO_ERROR}, DEPLOY);
- this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYED, LOCKED, NO_ERROR}, UNDEPLOY);
- 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[] {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, 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 = new StateDefinition<>(7, NONE);
+
+ // make an order when there are no fails
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE,
+ UNDEPLOYED, STATE_LOCKED_NONE, SUB_STATE_NONE, NO_ERROR}, DEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UNDEPLOY);
+ this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE,
+ UNDEPLOYED, LOCK_NONE, SUB_STATE_NONE, NO_ERROR}, DELETE);
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
+ DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UNLOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE,
+ DEPLOYED, UNLOCKED, SUB_STATE_NONE, NO_ERROR}, LOCK);
+ this.graph.put(new String[] {MIGRATE, LOCK_NONE, SUB_NONE,
+ DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, MIGRATE);
+ this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE,
+ DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UPDATE);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, REVIEW,
+ DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, REVIEW);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, PREPARE,
+ UNDEPLOYED, STATE_LOCKED_NONE, SUB_STATE_NONE, NO_ERROR}, PREPARE);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK,
+ DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, MIGRATE_PRECHECK);
+
+ // make an order in a failed scenario
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE,
+ UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, DEPLOY);
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE,
+ DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, DEPLOY);
+
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ UPDATING, LOCKED, SUB_STATE_NONE, FAILED}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ MIGRATING, LOCKED, SUB_STATE_NONE, FAILED}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, UNDEPLOY);
+
+ this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE,
+ DELETING, LOCK_NONE, SUB_STATE_NONE, FAILED}, DELETE);
+
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
+ DEPLOYED, LOCKING, SUB_STATE_NONE, FAILED}, UNLOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
+ DEPLOYED, UNLOCKING, SUB_STATE_NONE, FAILED}, UNLOCK);
+
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, DEPLOYED, LOCKING, SUB_STATE_NONE, FAILED}, LOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, DEPLOYED, UNLOCKING, SUB_STATE_NONE, FAILED}, LOCK);
+
+ this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, UPDATING, LOCKED, SUB_STATE_NONE, FAILED}, UPDATE);
+
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK,
+ DEPLOYED, LOCKED, MIGRATION_PRECHECKING, FAILED}, MIGRATE_PRECHECK);
// timeout
- this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, DEPLOY);
- this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, DEPLOY);
-
- this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, UNDEPLOY);
- this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, LOCKED, TIMEOUT}, UNDEPLOY);
- this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, MIGRATING, LOCKED, TIMEOUT}, UNDEPLOY);
- this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, UNDEPLOY);
-
- this.graph.put(new String[] {DELETE, LOCK_NONE, DELETING, LOCK_NONE, TIMEOUT}, DELETE);
-
- this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKING, TIMEOUT}, UNLOCK);
- this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, TIMEOUT}, LOCK);
-
- this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, TIMEOUT}, LOCK);
- this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, TIMEOUT}, UNLOCK);
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE,
+ UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, DEPLOY);
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE,
+ DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, DEPLOY);
+
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ MIGRATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ MIGRATION_PRECHECKING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+ this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE,
+ DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY);
+
+ this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE,
+ DELETING, LOCK_NONE, SUB_STATE_NONE, TIMEOUT}, DELETE);
+
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
+ DEPLOYED, LOCKING, SUB_STATE_NONE, TIMEOUT}, UNLOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE,
+ DEPLOYED, LOCKING, SUB_STATE_NONE, TIMEOUT}, LOCK);
+
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE,
+ DEPLOYED, UNLOCKING, SUB_STATE_NONE, TIMEOUT}, LOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE,
+ DEPLOYED, UNLOCKING, SUB_STATE_NONE, TIMEOUT}, UNLOCK);
+
+ this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UPDATE);
+
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK,
+ DEPLOYED, LOCKED, MIGRATION_PRECHECKING, TIMEOUT}, MIGRATE_PRECHECK);
}
/**
@@ -116,20 +171,24 @@ public class AcInstanceStateResolver {
*
* @param acDeployOrder the Deploy Ordered
* @param acLockOrder the Lock Ordered
+ * @param acSubOrder the Sub Ordered
* @param acDeployState then current Deploy State
* @param acLockState the current Lock State
+ * @param acSubState the current Sub State
* @param acStateChangeResult the current Result of the State Change
* @return the order (DEPLOY/UNDEPLOY/LOCK/UNLOCK) to send to participant or NONE if order is not consistent
*/
- public String resolve(DeployOrder acDeployOrder, LockOrder acLockOrder, DeployState acDeployState,
- LockState acLockState, StateChangeResult acStateChangeResult) {
+ public String resolve(DeployOrder acDeployOrder, LockOrder acLockOrder, SubOrder acSubOrder,
+ DeployState acDeployState, LockState acLockState, SubState acSubState, StateChangeResult acStateChangeResult) {
var deployOrder = acDeployOrder != null ? acDeployOrder : DeployOrder.NONE;
var lockOrder = acLockOrder != null ? acLockOrder : LockOrder.NONE;
+ var subOrder = acSubOrder != null ? acSubOrder : SubOrder.NONE;
var stateChangeResult = acStateChangeResult != null ? acStateChangeResult : StateChangeResult.NO_ERROR;
var deployState = acDeployState != null ? acDeployState : DeployState.UNDEPLOYED;
var lockState = acLockState != null ? acLockState : LockState.NONE;
- return this.graph.get(new String[] {deployOrder.name(), lockOrder.name(), deployState.name(), lockState.name(),
- stateChangeResult.name()});
+ var subState = acSubState != null ? acSubState : SubState.NONE;
+ return this.graph.get(new String[] {deployOrder.name(), lockOrder.name(), subOrder.name(),
+ deployState.name(), lockState.name(), subState.name(), stateChangeResult.name()});
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index 8be12960b..ab80bc277 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
@@ -35,6 +35,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
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.SubState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
@@ -117,6 +118,23 @@ public class AutomationCompositionProvider {
return result.toAuthorative();
}
+
+ /**
+ * Update automation composition state.
+ *
+ * @param acSource the automation composition to update
+ * @return the updated automation composition
+ */
+ public AutomationComposition updateAcState(final AutomationComposition acSource) {
+ var automationComposition = automationCompositionRepository
+ .getReferenceById(acSource.getInstanceId().toString());
+ automationComposition.fromAuthorativeBase(acSource);
+ var result = automationCompositionRepository.save(automationComposition);
+ automationCompositionRepository.flush();
+ // Return the saved automation composition
+ return result.toAuthorative();
+ }
+
/**
* Update automation composition.
*
@@ -155,6 +173,8 @@ public class AutomationCompositionProvider {
DeployState.UNDEPLOYING, DeployState.DELETING, DeployState.UPDATING, DeployState.MIGRATING));
jpaList.addAll(automationCompositionRepository.findByLockStateIn(
List.of(LockState.LOCKING, LockState.UNLOCKING)));
+ jpaList.addAll(automationCompositionRepository.findBySubStateIn(
+ List.of(SubState.PREPARING, SubState.MIGRATION_PRECHECKING, SubState.REVIEWING)));
return ProviderUtils.asEntityList(jpaList);
}
@@ -232,17 +252,33 @@ public class AutomationCompositionProvider {
* Update AutomationCompositionElement.
*
* @param element the AutomationCompositionElement
- * @param instanceId the instance Id
*/
- public void updateAutomationCompositionElement(@NonNull final AutomationCompositionElement element,
- @NonNull final UUID instanceId) {
- var jpaAcElement = new JpaAutomationCompositionElement(element.getId().toString(), instanceId.toString());
- jpaAcElement.fromAuthorative(element);
+ public void updateAutomationCompositionElement(@NonNull final AutomationCompositionElement element) {
+ var jpaAcElement = acElementRepository.getReferenceById(element.getId().toString());
+ jpaAcElement.setMessage(element.getMessage());
+ jpaAcElement.setOutProperties(element.getOutProperties());
+ jpaAcElement.setOperationalState(element.getOperationalState());
+ jpaAcElement.setUseState(element.getUseState());
+ jpaAcElement.setDeployState(element.getDeployState());
+ jpaAcElement.setLockState(element.getLockState());
+ jpaAcElement.setSubState(element.getSubState());
+ jpaAcElement.setStage(element.getStage());
+ jpaAcElement.setRestarting(element.getRestarting());
+
ProviderUtils.validate(element, jpaAcElement, "AutomationCompositionElement");
acElementRepository.save(jpaAcElement);
}
/**
+ * Delete AutomationCompositionElement.
+ *
+ * @param elementId the AutomationCompositionElement Id
+ */
+ public void deleteAutomationCompositionElement(@NonNull final UUID elementId) {
+ acElementRepository.deleteById(elementId.toString());
+ }
+
+ /**
* Validate ElementIds.
*
* @param automationComposition the AutomationComposition
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
index b3437c06f..85c9e67cb 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
@@ -116,20 +116,6 @@ public class ParticipantProvider {
}
/**
- * Updates an existing participant.
- *
- * @param participant participant to update
- * @return the participant updated
- */
- public Participant updateParticipant(@NonNull final Participant participant) {
- var result = participantRepository
- .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant"));
-
- // Return the saved participant
- return result.toAuthorative();
- }
-
- /**
* Delete a participant.
*
* @param participantId the Id of the participant to delete
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionElementRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionElementRepository.java
index 19d791e6c..d0a996e20 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionElementRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionElementRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 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.
@@ -20,14 +20,19 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import jakarta.persistence.LockModeType;
import java.util.List;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
+import org.springframework.data.jpa.repository.Lock;
+import org.springframework.lang.NonNull;
-public interface AutomationCompositionElementRepository extends
- JpaRepository<JpaAutomationCompositionElement, String>,
- QueryByExampleExecutor<JpaAutomationCompositionElement> {
+public interface AutomationCompositionElementRepository extends JpaRepository<JpaAutomationCompositionElement, String> {
+
+ @NonNull
+ @Override
+ @Lock(LockModeType.PESSIMISTIC_READ)
+ JpaAutomationCompositionElement getReferenceById(@NonNull String id);
List<JpaAutomationCompositionElement> findByParticipantId(String participantId);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
index d61dfb41b..7a1c61f5a 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
@@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.List;
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.SubState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -36,4 +37,6 @@ public interface AutomationCompositionRepository extends JpaRepository<JpaAutoma
List<JpaAutomationComposition> findByDeployStateIn(Collection<DeployState> deployStates);
List<JpaAutomationComposition> findByLockStateIn(Collection<LockState> lockStates);
+
+ List<JpaAutomationComposition> findBySubStateIn(Collection<SubState> subStates);
}
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..172de34fe 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,8 @@ 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.concepts.SubState;
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;
@@ -62,6 +65,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility functions used in acm-runtime and participants.
@@ -72,6 +77,8 @@ public final class AcmUtils {
public static final String ENTRY = "entry ";
private static final StringToMapConverter MAP_CONVERTER = new StringToMapConverter();
+ private static final Logger LOGGER = LoggerFactory.getLogger(AcmUtils.class);
+
/**
* Get the Policy information in the service template for the deploy message to participants.
*
@@ -115,6 +122,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 +137,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,
@@ -283,16 +293,20 @@ public final class AcmUtils {
// @formatter:on
}
+
/**
- * Return true if DeployState and LockState are in a Transitional State.
+ * Return true if DeployState, LockState and SubState are in a Transitional State.
*
- * @return true if DeployState and LockState are in a Transitional State
+ * @param deployState the DeployState
+ * @param lockState the LockState
+ * @param subState the SubState
+ * @return true if there is a state in a Transitional State
*/
- public static boolean isInTransitionalState(DeployState deployState, LockState lockState) {
+ public static boolean isInTransitionalState(DeployState deployState, LockState lockState, SubState subState) {
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.MIGRATING.equals(deployState);
+ || DeployState.MIGRATING.equals(deployState) || !SubState.NONE.equals(subState);
}
/**
@@ -376,9 +390,23 @@ public final class AcmUtils {
*/
public static void setCascadedState(final AutomationComposition automationComposition,
final DeployState deployState, final LockState lockState) {
+ setCascadedState(automationComposition, deployState, lockState, SubState.NONE);
+ }
+
+ /**
+ /**
+ * Set the states on the automation composition and on all its automation composition elements.
+ *
+ * @param deployState the DeployState we want the automation composition to transition to
+ * @param lockState the LockState we want the automation composition to transition to
+ * @param subState the SubState we want the automation composition to transition to
+ */
+ public static void setCascadedState(final AutomationComposition automationComposition,
+ final DeployState deployState, final LockState lockState, final SubState subState) {
automationComposition.setDeployState(deployState);
automationComposition.setLockState(lockState);
automationComposition.setLastMsg(TimestampHelper.now());
+ automationComposition.setSubState(subState);
if (MapUtils.isEmpty(automationComposition.getElements())) {
return;
@@ -387,7 +415,9 @@ public final class AcmUtils {
for (var element : automationComposition.getElements().values()) {
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setSubState(subState);
element.setMessage(null);
+ element.setStage(null);
}
}
@@ -432,6 +462,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 +506,55 @@ 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;
+ }
+
+ /**
+ * Validated the Message field.
+ *
+ * @param message the message
+ * @return a validated message
+ */
+ public static String validatedMessage(String message) {
+ if (message != null && message.length() > 255) {
+ LOGGER.warn("message too long {}", message);
+ return message.substring(0, 255);
+ }
+ return message;
+ }
+
+ /**
* Recursive Merge.
*
* @param map1 Map where to merge
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/StateDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/StateDefinition.java
index b7c6a31ac..491ae101e 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/StateDefinition.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/StateDefinition.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.
@@ -74,7 +74,7 @@ public class StateDefinition<V> {
if (key == null || key.contains(separator)) {
throw new PfModelRuntimeException(Status.INTERNAL_SERVER_ERROR, "wrong key " + key);
}
- sb.append(key + separator);
+ sb.append(key).append(separator);
}
return sb.toString();
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementStatus.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java
index 497dca408..5262b1316 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/kafka/element/ElementStatus.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022,2024 Nordix Foundation.
+ * Copyright (C) 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.
@@ -18,19 +18,20 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.models.acm.messages.kafka.element;
+package org.onap.policy.clamp.models.acm.concepts;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-@Getter
-@Setter
-@ToString(callSuper = true)
-public class ElementStatus extends ElementMessage {
+import java.util.List;
+import org.junit.jupiter.api.Test;
- public ElementStatus() {
- super(ElementMessageType.STATUS);
- }
+class AutomationCompositionsTest {
+ @Test
+ void testAutomationCompositions() {
+ var ac0 = new AutomationCompositions();
+ ac0.setAutomationCompositionList(List.of(new AutomationComposition()));
+ var ac1 = new AutomationCompositions(ac0);
+ assertEquals(ac0.getAutomationCompositionList(), ac1.getAutomationCompositionList());
+ }
}
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/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
index 6bb7f1eb7..bac0842f1 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java
@@ -47,9 +47,31 @@ class ParticipantUtilsTest {
@Test
void testGetFirstStartPhase() throws CoderException {
var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+ var automationComposition =
+ CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class)
+ .getAutomationCompositionList().get(0);
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
+ var result = ParticipantUtils.getFirstStartPhase(automationComposition, serviceTemplate);
+ assertThat(result).isZero();
+
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKING);
+ result = ParticipantUtils.getFirstStartPhase(automationComposition, serviceTemplate);
+ assertThat(result).isZero();
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
+ result = ParticipantUtils.getFirstStartPhase(automationComposition, serviceTemplate);
+ assertThat(result).isEqualTo(1);
+ }
+
+ @Test
+ void testGetFirstStage() throws CoderException {
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
var automationCompositions =
CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class);
- var result = ParticipantUtils.getFirstStartPhase(automationCompositions.getAutomationCompositionList().get(0),
+ var result = ParticipantUtils.getFirstStage(automationCompositions.getAutomationCompositionList().get(0),
serviceTemplate);
assertThat(result).isZero();
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantAckMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantAckMessageTest.java
index 72e4efb49..2535c375a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantAckMessageTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantAckMessageTest.java
@@ -32,7 +32,6 @@ import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
class ParticipantAckMessageTest {
- private ParticipantAckMessage message;
@Test
void testCopyConstructor() throws CoderException {
@@ -40,8 +39,8 @@ class ParticipantAckMessageTest {
.isInstanceOf(NullPointerException.class);
// verify with null values
- message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
- ParticipantAckMessage newmsg = new ParticipantAckMessage(message);
+ var message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+ var newmsg = new ParticipantAckMessage(message);
newmsg.setResponseTo(message.getResponseTo());
assertEquals(message.toString(), newmsg.toString());
@@ -56,14 +55,15 @@ class ParticipantAckMessageTest {
@Test
void testAppliesTo_NullParticipantId() {
- message = makeMessage();
- assertThatThrownBy(() -> message.appliesTo(UUID.randomUUID(), null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> message.appliesTo(null, UUID.randomUUID())).isInstanceOf(NullPointerException.class);
+ var message = makeMessage();
+ var participantId = CommonTestData.getRndParticipantId();
+ assertThatThrownBy(() -> message.appliesTo(participantId, null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> message.appliesTo(null, participantId)).isInstanceOf(NullPointerException.class);
}
@Test
void testAppliesTo_ParticipantIdMatches() {
- message = makeMessage();
+ var message = makeMessage();
// ParticipantId matches
assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
@@ -72,7 +72,7 @@ class ParticipantAckMessageTest {
@Test
void testAppliesTo_ParticipantIdNoMatch() {
- message = makeMessage();
+ var message = makeMessage();
// ParticipantId does not match
assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
@@ -80,7 +80,7 @@ class ParticipantAckMessageTest {
}
private ParticipantAckMessage makeMessage() {
- ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK);
+ var msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK);
msg.setParticipantId(CommonTestData.getParticipantId());
msg.setMessage("Successfull Ack");
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageTest.java
index db31d0f01..c6386a571 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageTest.java
@@ -33,7 +33,6 @@ import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
class ParticipantMessageTest {
- private ParticipantMessage message;
@Test
void testCopyConstructor() throws CoderException {
@@ -41,7 +40,7 @@ class ParticipantMessageTest {
.isInstanceOf(NullPointerException.class);
// verify with null values
- message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+ var message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
var newmsg = new ParticipantMessage(message);
newmsg.setMessageId(message.getMessageId());
newmsg.setTimestamp(message.getTimestamp());
@@ -59,15 +58,15 @@ class ParticipantMessageTest {
@Test
void testAppliesTo_NullParticipantId() {
- message = makeMessage();
-
- assertThatThrownBy(() -> message.appliesTo(UUID.randomUUID(), null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> message.appliesTo(null, UUID.randomUUID())).isInstanceOf(NullPointerException.class);
+ var message = makeMessage();
+ var participantId = CommonTestData.getParticipantId();
+ assertThatThrownBy(() -> message.appliesTo(participantId, null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> message.appliesTo(null, participantId)).isInstanceOf(NullPointerException.class);
}
@Test
void testAppliesTo_ParticipantIdMatches() {
- message = makeMessage();
+ var message = makeMessage();
// ParticipantId matches
assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
@@ -76,7 +75,7 @@ class ParticipantMessageTest {
@Test
void testAppliesTo_ParticipantIdNoMatch() {
- message = makeMessage();
+ var message = makeMessage();
assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestartTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestartTest.java
deleted file mode 100644
index 95b718e68..000000000
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantRestartTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * 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.
- * 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.kafka.participant;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.assertSerializable;
-import static org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessageUtils.removeVariableFields;
-
-import java.time.Instant;
-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.AcElementRestart;
-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.ParticipantDefinition;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
-import org.onap.policy.clamp.models.acm.utils.CommonTestData;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
-class ParticipantRestartTest {
-
- @Test
- void testCopyConstructor() throws CoderException {
-
- final var orig = new ParticipantRestart();
- // verify with null values
- assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantRestart(orig).toString()));
-
- orig.setMessageId(UUID.randomUUID());
- orig.setCompositionId(UUID.randomUUID());
- orig.setTimestamp(Instant.ofEpochMilli(3000));
- orig.setParticipantId(CommonTestData.getParticipantId());
-
- var participantDefinitionUpdate = new ParticipantDefinition();
- var type = new ToscaConceptIdentifier("id", "1.2.3");
- var acDefinition = CommonTestData.getAcElementDefinition(type);
- participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition));
- orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate));
-
- var acElement = new AcElementRestart();
- acElement.setId(UUID.randomUUID());
- var id = new ToscaConceptIdentifier("id", "1.2.3");
- acElement.setDefinition(id);
- acElement.setDeployState(DeployState.DEPLOYED);
- acElement.setLockState(LockState.LOCKED);
- acElement.setOperationalState("OperationalState");
- acElement.setUseState("UseState");
- acElement.setProperties(Map.of("key", "value"));
- acElement.setOutProperties(Map.of("keyOut", "valueOut"));
-
- var acRestart = new ParticipantRestartAc();
- acRestart.setAcElementList(List.of(acElement));
- acRestart.setAutomationCompositionId(UUID.randomUUID());
-
- orig.setAutomationcompositionList(List.of(acRestart));
-
- assertEquals(removeVariableFields(orig.toString()),
- removeVariableFields(new ParticipantRestart(orig).toString()));
-
- assertSerializable(orig, ParticipantRestart.class);
- }
-}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java
index 970b94824..2fee9c55a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java
@@ -40,7 +40,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-public class ParticipantSyncTest {
+class ParticipantSyncTest {
@Test
void testCopyConstructor() throws CoderException {
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
index 2eda9a9b3..fab3dac9b 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.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.
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test;
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.SubState;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -47,23 +48,27 @@ class JpaAutomationCompositionElementTest {
private static final String NULL_ERROR = " is marked .*ull but is null";
private static final String ELEMENT_ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e";
private static final String INSTANCE_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a";
+ private static final String KEY = "key";
+ private static final String BAD_VALUE = "BadValue";
+
+ private static final PfConceptKey CONCEPT_KEY = new PfConceptKey();
@Test
void testJpaAutomationCompositionElementConstructor() {
assertThatThrownBy(() -> {
new JpaAutomationCompositionElement((AutomationCompositionElement) null);
- }).hasMessageMatching("authorativeConcept is marked .*ull but is null");
+ }).hasMessageMatching("authorativeConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null);
- }).hasMessageMatching("copyConcept is marked .*ull but is null");
+ }).hasMessageMatching("copyConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement("key", null);
+ new JpaAutomationCompositionElement(KEY, null);
}).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, "key");
+ new JpaAutomationCompositionElement(null, KEY);
}).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
@@ -71,33 +76,38 @@ class JpaAutomationCompositionElementTest {
}).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, null, null, null);
+ new JpaAutomationCompositionElement(null, null, null, null, null, null);
}).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement("key", null, null,
- DeployState.UNDEPLOYED, LockState.LOCKED);
+ new JpaAutomationCompositionElement(KEY, null, null,
+ DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE);
}).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement("key", "key", null,
- DeployState.UNDEPLOYED, LockState.LOCKED);
+ new JpaAutomationCompositionElement(KEY, KEY, null,
+ DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE);
}).hasMessageMatching("definition" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement("key", "key", new PfConceptKey(),
- null, LockState.LOCKED);
+ new JpaAutomationCompositionElement(KEY, KEY, CONCEPT_KEY,
+ null, LockState.LOCKED, SubState.NONE);
}).hasMessageMatching("deployState" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement("key", "key", new PfConceptKey(),
- DeployState.UNDEPLOYED, null);
+ new JpaAutomationCompositionElement(KEY, KEY, CONCEPT_KEY,
+ DeployState.UNDEPLOYED, null, SubState.NONE);
}).hasMessageMatching("lockState" + NULL_ERROR);
+ assertThatThrownBy(() -> {
+ new JpaAutomationCompositionElement(KEY, KEY, CONCEPT_KEY,
+ DeployState.UNDEPLOYED, LockState.NONE, null);
+ }).hasMessageMatching("subState" + NULL_ERROR);
+
assertDoesNotThrow(() -> new JpaAutomationCompositionElement());
- assertDoesNotThrow(() -> new JpaAutomationCompositionElement("key", "key"));
- assertDoesNotThrow(() -> new JpaAutomationCompositionElement("key", "key",
- new PfConceptKey(), DeployState.UNDEPLOYED, LockState.LOCKED));
+ assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY));
+ assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY,
+ new PfConceptKey(), DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE));
}
@Test
@@ -109,7 +119,7 @@ class JpaAutomationCompositionElementTest {
assertThatThrownBy(() -> {
testJpaAcElement.fromAuthorative(null);
- }).hasMessageMatching("element is marked .*ull but is null");
+ }).hasMessageMatching("element" + NULL_ERROR);
assertThatThrownBy(() -> new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null))
.isInstanceOf(NullPointerException.class);
@@ -135,13 +145,13 @@ class JpaAutomationCompositionElementTest {
var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
assertThatThrownBy(() -> testJpaAutomationCompositionElement.validate(null))
- .hasMessageMatching("fieldName is marked .*ull but is null");
+ .hasMessageMatching("fieldName" + NULL_ERROR);
assertTrue(testJpaAutomationCompositionElement.validate("").isValid());
}
@Test
- void testJpaAutomationCompositionElementCompareTo() {
+ void testJpaAcElementCompareTo() {
var testJpaAcElement = createJpaAutomationCompositionElementInstance();
var otherJpaAcElement =
@@ -152,17 +162,27 @@ class JpaAutomationCompositionElementTest {
assertNotEquals(0,
testJpaAcElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
- testJpaAcElement.setElementId("BadValue");
+ assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement));
+ }
+
+ @Test
+ void testJpaAutomationCompositionElementCompareTo() {
+ var testJpaAcElement = createJpaAutomationCompositionElementInstance();
+
+ var otherJpaAcElement =
+ new JpaAutomationCompositionElement(testJpaAcElement);
+
+ testJpaAcElement.setElementId(BAD_VALUE);
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setElementId(ELEMENT_ID);
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
- testJpaAcElement.setInstanceId("BadValue");
+ testJpaAcElement.setInstanceId(BAD_VALUE);
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setInstanceId(INSTANCE_ID);
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
- testJpaAcElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ testJpaAcElement.setDefinition(new PfConceptKey(BAD_VALUE, "0.0.1"));
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
@@ -182,16 +202,26 @@ class JpaAutomationCompositionElementTest {
testJpaAcElement.setLockState(LockState.LOCKED);
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
- testJpaAcElement.setUseState("BadValue");
+ testJpaAcElement.setSubState(SubState.PREPARING);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setSubState(SubState.NONE);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setUseState(BAD_VALUE);
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setUseState("IDLE");
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
- testJpaAcElement.setOperationalState("BadValue");
+ testJpaAcElement.setOperationalState(BAD_VALUE);
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setOperationalState("DEFAULT");
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setStage(1);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setStage(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
testJpaAcElement.setMessage("Message");
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
testJpaAcElement.setMessage(null);
@@ -205,7 +235,6 @@ class JpaAutomationCompositionElementTest {
testJpaAcElement.setParticipantId(UUID.randomUUID().toString());
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
- assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement));
}
@Test
@@ -238,7 +267,7 @@ class JpaAutomationCompositionElementTest {
var testJpaAcElement =
new JpaAutomationCompositionElement(testAce.getId().toString(), INSTANCE_ID);
testJpaAcElement.fromAuthorative(testAce);
- testJpaAcElement.setProperties(Map.of("key", "{}"));
+ testJpaAcElement.setProperties(Map.of(KEY, "{}"));
return testJpaAcElement;
}
@@ -248,7 +277,7 @@ class JpaAutomationCompositionElementTest {
automationCompositionElement.setId(UUID.fromString(ELEMENT_ID));
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantId(CommonTestData.getParticipantId());
- automationCompositionElement.setProperties(Map.of("key", "{}"));
+ automationCompositionElement.setProperties(Map.of(KEY, "{}"));
automationCompositionElement.setUseState("IDLE");
automationCompositionElement.setOperationalState("DEFAULT");
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 b56e77801..38153d488 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
@@ -37,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.concepts.SubState;
import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
import org.onap.policy.models.base.PfConceptKey;
@@ -46,7 +47,7 @@ import org.onap.policy.models.base.PfConceptKey;
class JpaAutomationCompositionTest {
private static final String NULL_INSTANCE_ID_ERROR = "instanceId is marked .*ull but is null";
- private static final String NULL_TEXT_ERROR = " is marked .*ull but is null";
+ private static final String NULL_ERROR = " is marked .*ull but is null";
private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c20";
private static final String COMPOSITION_ID = "709c62b3-8918-41b9-a747-e21eb79c6c41";
@@ -54,44 +55,49 @@ class JpaAutomationCompositionTest {
void testJpaAutomationCompositionConstructor() {
assertThatThrownBy(() -> {
new JpaAutomationComposition((JpaAutomationComposition) null);
- }).hasMessageMatching("copyConcept is marked .*ull but is null");
+ }).hasMessageMatching("copyConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition((AutomationComposition) null);
- }).hasMessageMatching("authorativeConcept is marked .*ull but is null");
+ }).hasMessageMatching("authorativeConcept" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, null, null, null);
+ new JpaAutomationComposition(null, null, null, null, null, null, null);
}).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, null, null, new ArrayList<>(), DeployState.UNDEPLOYED,
- LockState.LOCKED);
- }).hasMessageMatching("key" + NULL_TEXT_ERROR);
+ LockState.LOCKED, SubState.NONE);
+ }).hasMessageMatching("key" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null, new ArrayList<>(),
- DeployState.UNDEPLOYED, LockState.LOCKED);
- }).hasMessageMatching("compositionId" + NULL_TEXT_ERROR);
+ DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE);
+ }).hasMessageMatching("compositionId" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID, null,
- DeployState.UNDEPLOYED, LockState.LOCKED);
- }).hasMessageMatching("elements" + NULL_TEXT_ERROR);
+ DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE);
+ }).hasMessageMatching("elements" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID, new ArrayList<>(),
- null, LockState.LOCKED);
- }).hasMessageMatching("deployState" + NULL_TEXT_ERROR);
+ null, LockState.LOCKED, SubState.NONE);
+ }).hasMessageMatching("deployState" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID, new ArrayList<>(),
- DeployState.UNDEPLOYED, null);
- }).hasMessageMatching("lockState" + NULL_TEXT_ERROR);
+ DeployState.UNDEPLOYED, null, SubState.NONE);
+ }).hasMessageMatching("lockState" + NULL_ERROR);
+
+ assertThatThrownBy(() -> {
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID, new ArrayList<>(),
+ DeployState.UNDEPLOYED, LockState.NONE, null);
+ }).hasMessageMatching("subState" + NULL_ERROR);
assertDoesNotThrow(() -> new JpaAutomationComposition());
assertDoesNotThrow(() -> new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID,
- new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED));
+ new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED, SubState.NONE));
}
@Test
@@ -108,7 +114,7 @@ class JpaAutomationCompositionTest {
assertThatThrownBy(() -> {
jpaAutomationComposition.fromAuthorative(null);
- }).hasMessageMatching("automationComposition is marked .*ull but is null");
+ }).hasMessageMatching("automationComposition" + NULL_ERROR);
assertThatThrownBy(() -> new JpaAutomationComposition((JpaAutomationComposition) null))
.isInstanceOf(NullPointerException.class);
@@ -137,7 +143,7 @@ class JpaAutomationCompositionTest {
}
@Test
- void testJpaAutomationCompositionCompareTo() {
+ void testJpaAutomationCompositionCompareTo1() {
var jpaAutomationComposition = new JpaAutomationComposition(createAutomationCompositionInstance());
var otherJpaAutomationComposition = new JpaAutomationComposition(jpaAutomationComposition);
@@ -180,6 +186,12 @@ class JpaAutomationCompositionTest {
assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
jpaAutomationComposition.setPhase(null);
assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ }
+
+ @Test
+ void testJpaAutomationCompositionCompareTo2() {
+ var jpaAutomationComposition = new JpaAutomationComposition(createAutomationCompositionInstance());
+ var otherJpaAutomationComposition = new JpaAutomationComposition(jpaAutomationComposition);
jpaAutomationComposition.setDeployState(DeployState.DEPLOYED);
assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
@@ -191,14 +203,14 @@ class JpaAutomationCompositionTest {
jpaAutomationComposition.setLockState(LockState.NONE);
assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- jpaAutomationComposition.setDescription("A description");
+ jpaAutomationComposition.setSubState(SubState.PREPARING);
assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- jpaAutomationComposition.setDescription(null);
+ jpaAutomationComposition.setSubState(SubState.NONE);
assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- jpaAutomationComposition.setRestarting(true);
+ jpaAutomationComposition.setDescription("A description");
assertNotEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- jpaAutomationComposition.setRestarting(null);
+ jpaAutomationComposition.setDescription(null);
assertEquals(0, jpaAutomationComposition.compareTo(otherJpaAutomationComposition));
jpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java
index d77760860..8cc9580cb 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java
@@ -28,9 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
class JpaParticipantReplicaTest {
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/persistence/concepts/StringToMapConverterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverterTest.java
new file mode 100644
index 000000000..67240047a
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverterTest.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.persistence.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.models.base.PfModelRuntimeException;
+
+class StringToMapConverterTest {
+
+ @Test
+ void testConvert() {
+ var stringToMapConverter = new StringToMapConverter();
+ Map<String, Object> map = Map.of("key", List.of("value"));
+ var dbData = stringToMapConverter.convertToDatabaseColumn(map);
+ var result = stringToMapConverter.convertToEntityAttribute(dbData);
+ assertEquals(map, result);
+ }
+
+ @Test
+ void testNull() {
+ var stringToMapConverter = new StringToMapConverter();
+ var dbData = stringToMapConverter.convertToDatabaseColumn(null);
+ assertThat(dbData).isNull();
+ var map = stringToMapConverter.convertToEntityAttribute(null);
+ assertThat(map).isNotNull();
+ assertThatThrownBy(() -> stringToMapConverter.convertToEntityAttribute("1"))
+ .isInstanceOf(PfModelRuntimeException.class);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java
new file mode 100644
index 000000000..98f22afcc
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToServiceTemplateConverterTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.persistence.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
+import org.onap.policy.models.base.PfModelRuntimeException;
+
+class StringToServiceTemplateConverterTest {
+
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML_PROP =
+ "clamp/acm/test/tosca-template-additional-properties.yaml";
+
+ @Test
+ void testConvert() {
+ var inputServiceTemplateProperties = CommonTestData.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML_PROP);
+ var docServiceTemplate = new DocToscaServiceTemplate(inputServiceTemplateProperties);
+ var stringToServiceTemplateConverter = new StringToServiceTemplateConverter();
+ var dbData = stringToServiceTemplateConverter.convertToDatabaseColumn(docServiceTemplate);
+ var result = stringToServiceTemplateConverter.convertToEntityAttribute(dbData);
+ assertThat(docServiceTemplate.compareTo(result)).isEqualByComparingTo(0);
+ }
+
+ @Test
+ void testNull() {
+ var stringToServiceTemplateConverter = new StringToServiceTemplateConverter();
+ var dbData = stringToServiceTemplateConverter.convertToDatabaseColumn(null);
+ assertThat(dbData).isNull();
+ var docServiceTemplate = stringToServiceTemplateConverter.convertToEntityAttribute(null);
+ assertThat(docServiceTemplate).isNotNull();
+ docServiceTemplate = stringToServiceTemplateConverter.convertToEntityAttribute("");
+ assertThat(docServiceTemplate).isNull();
+ assertThatThrownBy(() -> stringToServiceTemplateConverter.convertToEntityAttribute("1"))
+ .isInstanceOf(PfModelRuntimeException.class);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
index 85dadc3de..95811917d 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProviderTest.java
@@ -83,7 +83,7 @@ class AcDefinitionProviderTest {
.hasMessageStartingWith("\"AutomationCompositionDefinition\" INVALID, item has status INVALID");
assertThatThrownBy(() -> acDefinitionProvider.updateAcDefinitionState(compositionId, AcTypeState.PRIMED,
- StateChangeResult.NO_ERROR, false))
+ StateChangeResult.NO_ERROR))
.hasMessageStartingWith("update of Automation Composition Definition");
}
@@ -195,7 +195,7 @@ class AcDefinitionProviderTest {
when(acmDefinitionRepository.findById(acmDefinition.getCompositionId().toString()))
.thenReturn(Optional.of(jpa));
acDefinitionProvider.updateAcDefinitionState(acmDefinition.getCompositionId(), AcTypeState.PRIMED,
- StateChangeResult.NO_ERROR, false);
+ StateChangeResult.NO_ERROR);
verify(acmDefinitionRepository).save(jpa);
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java
index 7f6cb2f0c..a807a1179 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.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.
@@ -26,42 +26,78 @@ import org.junit.jupiter.api.Test;
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.concepts.SubState;
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.messages.rest.instantiation.SubOrder;
class AcInstanceStateResolverTest {
@Test
void testResolve() {
var acTypeStateResolver = new AcInstanceStateResolver();
- var result = acTypeStateResolver.resolve(DeployOrder.DEPLOY, LockOrder.NONE, DeployState.UNDEPLOYED,
- LockState.NONE, StateChangeResult.NO_ERROR);
+ // deploy
+ var result = acTypeStateResolver.resolve(DeployOrder.DEPLOY, LockOrder.NONE, SubOrder.NONE,
+ DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.DEPLOY);
- result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, DeployState.DEPLOYED,
- LockState.LOCKED, StateChangeResult.NO_ERROR);
+
+ // undeploy
+ result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, SubOrder.NONE,
+ DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.UNDEPLOY);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.DEPLOYED, LockState.LOCKED,
- StateChangeResult.NO_ERROR);
+
+ // unlock
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, SubOrder.NONE,
+ DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.UNLOCK);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.LOCK, DeployState.DEPLOYED, LockState.UNLOCKED,
- StateChangeResult.NO_ERROR);
+
+ // lock
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.LOCK, SubOrder.NONE,
+ DeployState.DEPLOYED, LockState.UNLOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.LOCK);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, DeployState.UNDEPLOYED, LockState.NONE,
- StateChangeResult.NO_ERROR);
+ // migrate
+ result = acTypeStateResolver.resolve(DeployOrder.MIGRATE, LockOrder.NONE, SubOrder.NONE,
+ DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
+ assertThat(result).isEqualTo(AcInstanceStateResolver.MIGRATE);
+
+ // migrate-precheck
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, SubOrder.MIGRATE_PRECHECK,
+ DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
+ assertThat(result).isEqualTo(AcInstanceStateResolver.MIGRATE_PRECHECK);
+
+ // prepare
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, SubOrder.PREPARE,
+ DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE, StateChangeResult.NO_ERROR);
+ assertThat(result).isEqualTo(AcInstanceStateResolver.PREPARE);
+
+ // review
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, SubOrder.REVIEW,
+ DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
+ assertThat(result).isEqualTo(AcInstanceStateResolver.REVIEW);
+ }
+
+ @Test
+ void testResolveWrongOrder() {
+ var acTypeStateResolver = new AcInstanceStateResolver();
+
+ var result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, SubOrder.NONE,
+ DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
- result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.UNLOCK, DeployState.DEPLOYED,
- LockState.LOCKED, StateChangeResult.NO_ERROR);
+
+ result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.UNLOCK, SubOrder.NONE,
+ DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.UNDEPLOYED, LockState.NONE,
- StateChangeResult.NO_ERROR);
+
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, SubOrder.NONE,
+ DeployState.UNDEPLOYED, LockState.NONE, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
- result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, DeployState.DEPLOYING,
- LockState.NONE, StateChangeResult.NO_ERROR);
+
+ result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, SubOrder.NONE,
+ DeployState.DEPLOYING, LockState.NONE, SubState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
- result = acTypeStateResolver.resolve(null, null, null, null, null);
+ result = acTypeStateResolver.resolve(null, null, null, null, null, null, null);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
}
-
}
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 8e7e50de7..c2368fe10 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
@@ -56,6 +56,7 @@ class AutomationCompositionProviderTest {
private static final String AC_IS_NULL = "automationComposition is marked non-null but is null";
private static final String ACELEMENT_IS_NULL = "element is marked non-null but is null";
+ private static final String ACELEMENT_ID_IS_NULL = "elementId is marked non-null but is null";
private static final Coder CODER = new StandardCoder();
private static final String AUTOMATION_COMPOSITION_JSON =
@@ -225,16 +226,34 @@ class AutomationCompositionProviderTest {
var automationCompositionProvider = new AutomationCompositionProvider(
mock(AutomationCompositionRepository.class), acElementRepository);
- assertThatThrownBy(() -> automationCompositionProvider.updateAutomationCompositionElement(null, null))
+ assertThatThrownBy(() -> automationCompositionProvider.updateAutomationCompositionElement(null))
.hasMessageMatching(ACELEMENT_IS_NULL);
var acElement = inputAutomationCompositions.getAutomationCompositionList().get(0).getElements().values()
.iterator().next();
- automationCompositionProvider.updateAutomationCompositionElement(acElement, UUID.randomUUID());
+ var jpa = new JpaAutomationCompositionElement();
+ jpa.setElementId(acElement.getId().toString());
+ jpa.setInstanceId(UUID.randomUUID().toString());
+ jpa.fromAuthorative(acElement);
+ when(acElementRepository.getReferenceById(acElement.getId().toString())).thenReturn(jpa);
+
+ automationCompositionProvider.updateAutomationCompositionElement(acElement);
verify(acElementRepository).save(any());
}
@Test
+ void testDeleteElementById() {
+ var acElementRepository = mock(AutomationCompositionElementRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(
+ mock(AutomationCompositionRepository.class), acElementRepository);
+ assertThatThrownBy(() -> automationCompositionProvider.deleteAutomationCompositionElement(null))
+ .hasMessageMatching(ACELEMENT_ID_IS_NULL);
+ var elementId = UUID.randomUUID();
+ automationCompositionProvider.deleteAutomationCompositionElement(elementId);
+ verify(acElementRepository).deleteById(elementId.toString());
+ }
+
+ @Test
void testValidateElementIds() {
var acElementRepository = mock(AutomationCompositionElementRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
index 9ceeef640..ac3aa87c5 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
@@ -114,25 +114,6 @@ class ParticipantProviderTest {
}
@Test
- void testParticipantUpdate() {
- var participantRepository = mock(ParticipantRepository.class);
- var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
- var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
-
- var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository,
- mock(ParticipantReplicaRepository.class));
-
- assertThatThrownBy(() -> participantProvider.updateParticipant(null)).hasMessageMatching(LIST_IS_NULL);
-
- when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
-
- var updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0));
- updatedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId());
- assertThat(updatedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0));
- }
-
- @Test
void testGetAutomationCompositions() {
var participantRepository = mock(ParticipantRepository.class);
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
@@ -240,7 +221,6 @@ class ParticipantProviderTest {
assertThrows(NullPointerException.class, () -> participantProvider.getParticipantById(null));
assertThrows(NullPointerException.class, () -> participantProvider.findParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.saveParticipant(null));
- assertThrows(NullPointerException.class, () -> participantProvider.updateParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null));
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java
index e6135fe5b..91f26f7c1 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 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.
@@ -47,7 +47,7 @@ class RestUtilsTest {
var response = RestUtils.toSimpleResponse(ex);
- assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode());
+ assertThat(response.getStatusCode().value()).isEqualTo(STATUS_ERROR.getStatusCode());
assertThat(response.getBody()).isNotNull();
assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR);
}
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..97af64cf7 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,10 +37,13 @@ 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;
+import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
@@ -66,14 +69,16 @@ class AcmUtilsTest {
@Test
void testIsInTransitionalState() {
- assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.LOCKED)).isFalse();
- assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYING, LockState.NONE)).isTrue();
- 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();
- assertThat(AcmUtils.isInTransitionalState(DeployState.MIGRATING, LockState.LOCKED)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.LOCKED, SubState.NONE)).isFalse();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYING, LockState.NONE, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.UNDEPLOYING, LockState.NONE, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.LOCKING, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.UNLOCKING, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.DELETING, LockState.NONE, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.UPDATING, LockState.LOCKED, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.MIGRATING, LockState.LOCKED, SubState.NONE)).isTrue();
+ assertThat(AcmUtils.isInTransitionalState(DeployState.DEPLOYED, LockState.LOCKED,
+ SubState.MIGRATION_PRECHECKING)).isTrue();
}
@Test
@@ -233,6 +238,16 @@ class AcmUtilsTest {
assertEquals(element.getOutProperties(), result.getOutProperties());
}
+ @Test
+ void testValidatedMessage() {
+ var message = "completed";
+ assertEquals(message, AcmUtils.validatedMessage(message));
+
+ var serviceTemplate = CommonTestData.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
+ message = serviceTemplate.toString();
+ assertEquals(message.substring(0, 255), AcmUtils.validatedMessage(message));
+ }
+
private AutomationComposition getDummyAutomationComposition() {
var automationComposition = new AutomationComposition();
automationComposition.setCompositionId(UUID.randomUUID());
@@ -276,9 +291,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 +303,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:
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java
index aaba0bcc8..d87b8bcd2 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java
@@ -30,7 +30,7 @@ class TimestampHelperTest {
void testNow() {
assertThat(TimestampHelper.nowTimestamp()).isNotNull();
assertThat(TimestampHelper.now()).isNotNull();
- assertThat(TimestampHelper.nowEpochMilli()).isNotNull();
+ assertThat(TimestampHelper.nowEpochMilli()).isNotZero();
}
@Test
diff --git a/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml b/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml
index 2b0b4feff..6539a9c75 100644
--- a/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml
+++ b/models/src/test/resources/examples/acm/test-pm-subscription-handling.yaml
@@ -317,6 +317,15 @@ node_types:
provider:
type: string
required: false
+ stage:
+ type: array
+ required: false
+ items:
+ type: integer
+ constraints:
+ - greater-or-equal: 0
+ metadata:
+ common: true
startPhase:
type: integer
required: false
@@ -394,6 +403,7 @@ topology_template:
description: Participant for DCAE microservices
properties:
provider: ONAP
+ startPhase: 0
org.onap.policy.acm.PolicyAutomationCompositionParticipant:
version: 2.3.1
type: org.onap.policy.clamp.acm.Participant
@@ -401,6 +411,7 @@ topology_template:
description: Participant for DCAE microservices
properties:
provider: ONAP
+ startPhase: 0
org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant:
version: 2.2.1
type: org.onap.policy.clamp.acm.Participant
@@ -408,6 +419,7 @@ topology_template:
description: Participant for DCAE microservices
properties:
provider: ONAP
+ startPhase: 1
org.onap.domain.pmsh.PMSH_DCAEMicroservice:
version: 1.2.3
type: org.onap.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElement
@@ -415,6 +427,7 @@ topology_template:
description: Automation composition element for the DCAE microservice for Performance Management Subscription Handling
properties:
provider: Ericsson
+ startPhase: 1
dcae_blueprint:
tosca_definitions_version: cloudify_dsl_1_3
imports:
@@ -641,6 +654,7 @@ topology_template:
version: 1.0.0
policy_id:
get_input: pmsh_monitoring_policy
+ stage: [0,1,2]
org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement:
version: 1.2.3
type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement