summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-05-31 16:38:22 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-06-01 14:51:37 +0100
commitebb4d0cf867d752ae148880dd0109fc3cf6d6025 (patch)
treed36a6bf5e7395a743096a65d10fee5c047c9077c /models
parent89a73dbc76cf6d3380fb8263a6eb4a33ef3e4a8c (diff)
Add Failure handling support in the ACM-R
Issue-ID: POLICY-4705 Change-Id: I919b7981cdbe69ac7ce703fceb2e980a6d9a056e 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/AutomationComposition.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/StateChangeResult.java26
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java15
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java10
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java49
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java3
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolverTest.java28
9 files changed, 115 insertions, 29 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java
index dc8a39b34..54c9b6190 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
@@ -50,6 +50,8 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
private Map<UUID, AutomationCompositionElement> elements;
+ private StateChangeResult stateChangeResult;
+
/**
* Copy contructor, does a deep copy.
*
@@ -62,6 +64,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable<Aut
this.deployState = otherAutomationComposition.deployState;
this.lockState = otherAutomationComposition.lockState;
this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new);
+ this.stateChangeResult = otherAutomationComposition.stateChangeResult;
}
@Override
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 8095b5cee..ea54076ba 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,10 +55,9 @@ public class AutomationCompositionElement {
private LockState lockState = LockState.LOCKED;
private String operationalState;
-
private String useState;
-
private String description;
+ private String message;
// A map indexed by the property name. Each map entry is the serialized value of the property,
// which can be deserialized into an instance of the type of the property.
@@ -82,5 +81,6 @@ public class AutomationCompositionElement {
this.lockState = otherElement.lockState;
this.operationalState = otherElement.operationalState;
this.useState = otherElement.useState;
+ this.message = otherElement.message;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/StateChangeResult.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/StateChangeResult.java
new file mode 100644
index 000000000..de4404fdd
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/StateChangeResult.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.concepts;
+
+public enum StateChangeResult {
+ NO_ERROR,
+ FAILED
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
index e73f2e795..3182332d5 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java
@@ -26,6 +26,7 @@ import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
/**
* Class to represent participant Ack message.
@@ -38,9 +39,12 @@ public class ParticipantAckMessage {
// The responseTo field should match the original request id in the request.
private UUID responseTo;
- // Result: Success/Fail.
+ // Intermediary result: Success/Fail.
private Boolean result;
+ // Indicating participant failure
+ private StateChangeResult stateChangeResult;
+
// Message indicating reason for failure
private String message;
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 33ec649f4..3a448f262 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
@@ -43,6 +43,7 @@ import org.apache.commons.lang3.ObjectUtils;
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.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
@@ -88,6 +89,9 @@ public class JpaAutomationComposition extends Validated
private LockState lockState;
@Column
+ private StateChangeResult stateChangeResult;
+
+ @Column
private String description;
@NotNull
@@ -100,7 +104,7 @@ public class JpaAutomationComposition extends Validated
*/
public JpaAutomationComposition() {
this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(),
- new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED);
+ new ArrayList<>(), DeployState.UNDEPLOYED, LockState.NONE);
}
/**
@@ -139,6 +143,7 @@ public class JpaAutomationComposition extends Validated
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.description = copyConcept.description;
+ this.stateChangeResult = copyConcept.stateChangeResult;
this.elements = PfUtils.mapList(copyConcept.elements, JpaAutomationCompositionElement::new);
}
@@ -162,6 +167,7 @@ public class JpaAutomationComposition extends Validated
automationComposition.setDeployState(deployState);
automationComposition.setLockState(lockState);
automationComposition.setDescription(description);
+ automationComposition.setStateChangeResult(stateChangeResult);
automationComposition.setElements(new LinkedHashMap<>(this.elements.size()));
for (var element : this.elements) {
automationComposition.getElements().put(UUID.fromString(element.getElementId()), element.toAuthorative());
@@ -179,7 +185,7 @@ public class JpaAutomationComposition extends Validated
this.deployState = automationComposition.getDeployState();
this.lockState = automationComposition.getLockState();
this.description = automationComposition.getDescription();
-
+ this.stateChangeResult = automationComposition.getStateChangeResult();
this.elements = new ArrayList<>(automationComposition.getElements().size());
for (var elementEntry : automationComposition.getElements().entrySet()) {
var jpaAutomationCompositionElement =
@@ -232,6 +238,11 @@ public class JpaAutomationComposition extends Validated
if (result != 0) {
return result;
}
+
+ result = ObjectUtils.compare(stateChangeResult, other.stateChangeResult);
+ if (result != 0) {
+ return result;
+ }
return PfUtils.compareObjects(elements, other.elements);
}
}
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 27da0399c..60a911b21 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
@@ -101,6 +101,9 @@ public class JpaAutomationCompositionElement extends Validated
@Column
private String description;
+ @Column
+ private String message;
+
@Lob
@NotNull
@Valid
@@ -169,6 +172,7 @@ public class JpaAutomationCompositionElement extends Validated
this.lockState = copyConcept.lockState;
this.operationalState = copyConcept.operationalState;
this.useState = copyConcept.useState;
+ this.message = copyConcept.message;
}
/**
@@ -194,6 +198,7 @@ public class JpaAutomationCompositionElement extends Validated
element.setLockState(lockState);
element.setOperationalState(operationalState);
element.setUseState(useState);
+ element.setMessage(message);
return element;
}
@@ -209,6 +214,7 @@ public class JpaAutomationCompositionElement extends Validated
this.lockState = element.getLockState();
this.operationalState = element.getOperationalState();
this.useState = element.getUseState();
+ this.message = element.getMessage();
}
@Override
@@ -260,6 +266,10 @@ public class JpaAutomationCompositionElement extends Validated
return result;
}
+ result = ObjectUtils.compare(message, other.message);
+ 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/AcInstanceStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java
index 8676b3397..659169b9f 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
@@ -22,6 +22,7 @@ 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.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.clamp.models.acm.utils.StateDefinition;
@@ -32,15 +33,24 @@ public class AcInstanceStateResolver {
private final StateDefinition<String> graph;
private static final String DEPLOYED = DeployState.DEPLOYED.name();
+ private static final String DEPLOYING = DeployState.DEPLOYING.name();
private static final String UNDEPLOYED = DeployState.UNDEPLOYED.name();
+ private static final String UNDEPLOYING = DeployState.UNDEPLOYING.name();
+ private static final String UPDATING = DeployState.UPDATING.name();
+ private static final String DELETING = DeployState.DELETING.name();
private static final String LOCKED = LockState.LOCKED.name();
+ private static final String LOCKING = LockState.LOCKING.name();
private static final String UNLOCKED = LockState.UNLOCKED.name();
+ private static final String UNLOCKING = LockState.UNLOCKING.name();
private static final String STATE_LOCKED_NONE = LockState.NONE.name();
private static final String DEPLOY_NONE = DeployOrder.NONE.name();
private static final String LOCK_NONE = LockOrder.NONE.name();
+ private static final String NO_ERROR = StateChangeResult.NO_ERROR.name();
+ private static final String FAILED = StateChangeResult.FAILED.name();
+
// list of results
public static final String DEPLOY = DeployOrder.DEPLOY.name();
public static final String UNDEPLOY = DeployOrder.UNDEPLOY.name();
@@ -53,13 +63,30 @@ public class AcInstanceStateResolver {
* Construct.
*/
public AcInstanceStateResolver() {
- this.graph = new StateDefinition<>(4, NONE);
+ 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);
+
+ // failed
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, 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, STATE_LOCKED_NONE, FAILED}, UNDEPLOY);
+
+ this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY);
+ 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, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK);
- this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYED, STATE_LOCKED_NONE}, DEPLOY);
- this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYED, LOCKED}, UNDEPLOY);
- this.graph.put(new String[] {DELETE, LOCK_NONE, UNDEPLOYED, LOCK_NONE}, DELETE);
- this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED}, UNLOCK);
- this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED}, LOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, FAILED}, LOCK);
+ this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK);
}
/**
@@ -68,17 +95,19 @@ public class AcInstanceStateResolver {
* @param acDeployOrder the Deploy Ordered
* @param acLockOrder the Lock Ordered
* @param acDeployState then current Deploy State
- * @param acLockState the current Lock State
+ * @param acLockState the current Lock 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) {
+ LockState acLockState, StateChangeResult acStateChangeResult) {
var deployOrder = acDeployOrder != null ? acDeployOrder : DeployOrder.NONE;
var lockOrder = acLockOrder != null ? acLockOrder : LockOrder.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()});
+ return this.graph.get(new String[] {deployOrder.name(), lockOrder.name(), deployState.name(), lockState.name(),
+ stateChangeResult.name()});
}
}
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 7de4720ad..671aca60f 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
@@ -285,7 +285,7 @@ public final class AcmUtils {
public static boolean isInTransitionalState(DeployState deployState, LockState lockState) {
return DeployState.DEPLOYING.equals(deployState) || DeployState.UNDEPLOYING.equals(deployState)
|| LockState.LOCKING.equals(lockState) || LockState.UNLOCKING.equals(lockState)
- || DeployState.DELETING.equals(deployState);
+ || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState);
}
/**
@@ -339,6 +339,7 @@ public final class AcmUtils {
public static DeployState deployCompleted(DeployState deployState) {
DeployState result = null;
switch (deployState) {
+ case UPDATING:
case DEPLOYING:
result = DeployState.DEPLOYED;
break;
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 103bca2ec..7f6cb2f0c 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
@@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat;
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.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
@@ -33,32 +34,33 @@ class AcInstanceStateResolverTest {
@Test
void testResolve() {
var acTypeStateResolver = new AcInstanceStateResolver();
- var result =
- acTypeStateResolver.resolve(DeployOrder.DEPLOY, LockOrder.NONE, DeployState.UNDEPLOYED, LockState.NONE);
+ var result = acTypeStateResolver.resolve(DeployOrder.DEPLOY, LockOrder.NONE, DeployState.UNDEPLOYED,
+ LockState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.DEPLOY);
result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, DeployState.DEPLOYED,
- LockState.LOCKED);
+ LockState.LOCKED, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.UNDEPLOY);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.DEPLOYED,
- LockState.LOCKED);
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.DEPLOYED, LockState.LOCKED,
+ StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.UNLOCK);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.LOCK, DeployState.DEPLOYED,
- LockState.UNLOCKED);
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.LOCK, DeployState.DEPLOYED, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.LOCK);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, DeployState.UNDEPLOYED, LockState.NONE);
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.NONE, DeployState.UNDEPLOYED, LockState.NONE,
+ StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.UNLOCK, DeployState.DEPLOYED,
- LockState.LOCKED);
+ LockState.LOCKED, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
- result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.UNDEPLOYED,
- LockState.NONE);
+ result = acTypeStateResolver.resolve(DeployOrder.NONE, LockOrder.UNLOCK, DeployState.UNDEPLOYED, LockState.NONE,
+ StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
result = acTypeStateResolver.resolve(DeployOrder.UNDEPLOY, LockOrder.NONE, DeployState.DEPLOYING,
- LockState.NONE);
+ LockState.NONE, StateChangeResult.NO_ERROR);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
- result = acTypeStateResolver.resolve(null, null, null, null);
+ result = acTypeStateResolver.resolve(null, null, null, null, null);
assertThat(result).isEqualTo(AcInstanceStateResolver.NONE);
}