summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-16 10:42:14 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-06-16 09:51:29 +0000
commit0f24f33b124bf326e4b7dbaa2a55cab72696b9ee (patch)
tree6fcf5bc915bd52d1e0071401293ebe0fdc4d9495 /models
parenta2320d29b9373041db88395d9fdda7ea84d38807 (diff)
Add support for Prime Deprime Failure Handling in ACM-Runtime
Issue-ID: POLICY-4714 Change-Id: I1f3cf8f0fcebc7c48b3632ad10aa8907c41cdb5a Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models')
-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/NodeTemplateState.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionDefinition.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java5
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java29
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolverTest.java20
6 files changed, 50 insertions, 16 deletions
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 a8c069723..eb8a919d6 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
@@ -44,6 +44,8 @@ public class AutomationCompositionDefinition {
@NonNull
private AcTypeState state;
+ private StateChangeResult stateChangeResult;
+
@NonNull
// Map used to store prime state with key as NodeTemplate Name and value as NodeTemplateState
private Map<String, NodeTemplateState> elementStateMap = new HashMap<>();
@@ -58,5 +60,6 @@ public class AutomationCompositionDefinition {
this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate);
this.state = otherAcmDefinition.state;
this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new);
+ this.stateChangeResult = otherAcmDefinition.stateChangeResult;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
index 5d28cd736..62e92087e 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/NodeTemplateState.java
@@ -40,6 +40,8 @@ public class NodeTemplateState {
private AcTypeState state;
+ private String message;
+
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
*
@@ -50,5 +52,6 @@ public class NodeTemplateState {
this.participantId = copyConstructor.participantId;
this.nodeTemplateId = new ToscaConceptIdentifier(copyConstructor.nodeTemplateId);
this.state = copyConstructor.state;
+ this.message = copyConstructor.message;
}
}
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 11e3f583e..50949d751 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
@@ -41,6 +41,7 @@ import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.common.parameters.BeanValidationResult;
@@ -76,6 +77,9 @@ public class JpaAutomationCompositionDefinition extends Validated
@NotNull
private AcTypeState state;
+ @Column
+ private StateChangeResult stateChangeResult;
+
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "compositionId", foreignKey = @ForeignKey(name = "dt_element_fk"))
private Set<JpaNodeTemplateState> elements = new HashSet<>();
@@ -91,6 +95,7 @@ public class JpaAutomationCompositionDefinition extends Validated
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.fromString(this.compositionId));
acmDefinition.setState(this.state);
+ acmDefinition.setStateChangeResult(this.stateChangeResult);
acmDefinition.setServiceTemplate(this.serviceTemplate.toAuthorative());
for (var element : this.elements) {
var key = element.getNodeTemplateId().getName();
@@ -103,6 +108,7 @@ public class JpaAutomationCompositionDefinition extends Validated
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
this.compositionId = copyConcept.getCompositionId().toString();
this.state = copyConcept.getState();
+ this.stateChangeResult = copyConcept.getStateChangeResult();
this.serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate());
setName(this.serviceTemplate.getName());
setVersion(this.serviceTemplate.getVersion());
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
index 19d25e1b5..8ee1075f6 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaNodeTemplateState.java
@@ -70,6 +70,9 @@ public class JpaNodeTemplateState extends Validated implements PfAuthorative<Nod
@NotNull
private AcTypeState state;
+ @Column
+ private String message;
+
/**
* The Default Constructor.
*/
@@ -96,6 +99,7 @@ public class JpaNodeTemplateState extends Validated implements PfAuthorative<Nod
}
this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
this.state = copyConcept.getState();
+ this.message = copyConcept.getMessage();
}
@Override
@@ -107,6 +111,7 @@ public class JpaNodeTemplateState extends Validated implements PfAuthorative<Nod
}
nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
nodeTemplateState.setState(this.state);
+ nodeTemplateState.setMessage(this.message);
return nodeTemplateState;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java
index 7070a312c..f1c930955 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolver.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.models.acm.persistence.provider;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder;
import org.onap.policy.clamp.models.acm.utils.StateDefinition;
import org.springframework.stereotype.Component;
@@ -33,17 +34,29 @@ public class AcTypeStateResolver {
private static final String PRIME = PrimeOrder.PRIME.toString();
private static final String DEPRIME = PrimeOrder.DEPRIME.toString();
private static final String PRIMED = AcTypeState.PRIMED.toString();
+ private static final String PRIMING = AcTypeState.PRIMING.toString();
private static final String COMMISSIONED = AcTypeState.COMMISSIONED.toString();
+ private static final String DEPRIMING = AcTypeState.DEPRIMING.toString();
+ private static final String NO_ERROR = StateChangeResult.NO_ERROR.name();
+ private static final String FAILED = StateChangeResult.FAILED.name();
/**
* Construct.
*/
public AcTypeStateResolver() {
- this.graph = new StateDefinition<>(2, PrimeOrder.NONE);
- this.graph.put(new String[] {PRIME, PRIMED}, PrimeOrder.PRIME);
- this.graph.put(new String[] {PRIME, COMMISSIONED}, PrimeOrder.PRIME);
- this.graph.put(new String[] {DEPRIME, PRIMED}, PrimeOrder.DEPRIME);
- this.graph.put(new String[] {DEPRIME, COMMISSIONED}, PrimeOrder.DEPRIME);
+ this.graph = new StateDefinition<>(3, PrimeOrder.NONE);
+
+ // no error
+ this.graph.put(new String[] {PRIME, PRIMED, NO_ERROR}, PrimeOrder.PRIME);
+ this.graph.put(new String[] {PRIME, COMMISSIONED, NO_ERROR}, PrimeOrder.PRIME);
+ this.graph.put(new String[] {DEPRIME, PRIMED, NO_ERROR}, PrimeOrder.DEPRIME);
+ this.graph.put(new String[] {DEPRIME, COMMISSIONED, NO_ERROR}, PrimeOrder.DEPRIME);
+
+ // failed
+ this.graph.put(new String[] {PRIME, PRIMING, FAILED}, PrimeOrder.PRIME);
+ this.graph.put(new String[] {DEPRIME, PRIMING, FAILED}, PrimeOrder.DEPRIME);
+ this.graph.put(new String[] {DEPRIME, DEPRIMING, FAILED}, PrimeOrder.DEPRIME);
+ this.graph.put(new String[] {PRIME, DEPRIMING, FAILED}, PrimeOrder.PRIME);
}
/**
@@ -51,11 +64,13 @@ public class AcTypeStateResolver {
*
* @param primeOrder the PrimeOrder
* @param acTypeState then current AcTypeState
+ * @param acStateChangeResult the current Result of the State Change
* @return primeOrder or NONE if the primeOrder is not consistent
*/
- public PrimeOrder resolve(PrimeOrder primeOrder, AcTypeState acTypeState) {
+ public PrimeOrder resolve(PrimeOrder primeOrder, AcTypeState acTypeState, StateChangeResult acStateChangeResult) {
var po = primeOrder != null ? primeOrder : PrimeOrder.NONE;
var state = acTypeState != null ? acTypeState : AcTypeState.COMMISSIONED;
- return this.graph.get(new String[] {po.toString(), state.toString()});
+ var stateChangeResult = acStateChangeResult != null ? acStateChangeResult : StateChangeResult.NO_ERROR;
+ return this.graph.get(new String[] {po.name(), state.name(), stateChangeResult.name()});
}
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolverTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolverTest.java
index bf27c3e4f..5ea13c94a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolverTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcTypeStateResolverTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder;
class AcTypeStateResolverTest {
@@ -31,25 +32,26 @@ class AcTypeStateResolverTest {
@Test
void testAcTypeState() {
var acTypeStateResolver = new AcTypeStateResolver();
- var result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.COMMISSIONED);
+ var result =
+ acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.PRIME);
- result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.PRIMED);
+ result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.PRIMED, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.PRIME);
- result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.PRIMING);
+ result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.PRIMING, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.NONE);
- result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.DEPRIMING);
+ result = acTypeStateResolver.resolve(PrimeOrder.PRIME, AcTypeState.DEPRIMING, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.NONE);
- result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.COMMISSIONED);
+ result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.DEPRIME);
- result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.PRIMED);
+ result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.PRIMED, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.DEPRIME);
- result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.PRIMING);
+ result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.PRIMING, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.NONE);
- result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.DEPRIMING);
+ result = acTypeStateResolver.resolve(PrimeOrder.DEPRIME, AcTypeState.DEPRIMING, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(PrimeOrder.NONE);
- result = acTypeStateResolver.resolve(null, null);
+ result = acTypeStateResolver.resolve(null, null, null);
assertThat(result).isEqualTo(PrimeOrder.NONE);
}
}