summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-27 16:40:31 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-06-28 11:37:58 +0000
commit85751a7d52cc6efbea69c08f71f550ae32c61043 (patch)
tree25ed305c375d344ff398109a768f9d78ecbf6599 /models
parent059adbc2c51c79d97aeb19faac81f1128529e4f7 (diff)
Add restart publisher to support participant restart scenario in ACM
Issue-ID: POLICY-4743 Change-Id: Iecb8b4f5f5bf9be788d3507354f267f73d8c53d8 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/AcTypeState.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java57
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java11
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java61
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java3
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java20
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java30
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java81
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java9
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java22
10 files changed, 257 insertions, 40 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java
index 76851b490..8e36f7a3b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcTypeState.java
@@ -25,5 +25,6 @@ public enum AcTypeState {
COMMISSIONED,
PRIMING,
PRIMED,
- DEPRIMING
+ DEPRIMING,
+ RESTARTING
}
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
new file mode 100644
index 000000000..b8ee0200d
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java
@@ -0,0 +1,57 @@
+/*-
+ * ============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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@ToString
+public class ParticipantRestartAc {
+
+ private UUID automationCompositionId;
+
+ // current state of auto composition
+ private DeployState deployState;
+ private LockState lockState;
+
+ private List<AcElementDeploy> acElementList = new ArrayList<>();
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConstructor the participant with updates to copy from
+ */
+ public ParticipantRestartAc(ParticipantRestartAc copyConstructor) {
+ this.automationCompositionId = copyConstructor.automationCompositionId;
+ this.deployState = copyConstructor.deployState;
+ this.lockState = copyConstructor.lockState;
+ this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementDeploy::new);
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java
index e60a13202..c42778aae 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java
@@ -49,12 +49,6 @@ public enum ParticipantMessageType {
AUTOMATION_COMPOSITION_STATE_CHANGE,
/**
- * Used by the automation composition runtime to order a health check on participants, triggers a
- * PARTICIPANT_STATUS message with the result of the PARTICIPANT_HEALTH_CHECK operation.
- */
- PARTICIPANT_HEALTH_CHECK,
-
- /**
* Used by participant to register itself with automation composition runtime.
*/
PARTICIPANT_REGISTER,
@@ -108,8 +102,7 @@ public enum ParticipantMessageType {
PROPERTIES_UPDATE,
/**
- * Used by participant to acknowledge the receipt of PROPERTIES_UPDATE message
- * from automation composition runtime.
+ * Used by runtime to send composition and instances to a restarted participant.
*/
- PROPERTIES_UPDATE_ACK
+ PARTICIPANT_RESTART
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java
new file mode 100644
index 000000000..6b801ce8d
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestart.java
@@ -0,0 +1,61 @@
+/*-
+ * ============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.messages.dmaap.participant;
+
+import java.util.ArrayList;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
+import org.onap.policy.models.base.PfUtils;
+
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class ParticipantRestart extends ParticipantMessage {
+
+ // priming
+ private List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
+
+ // autocomposition list
+ private List<ParticipantRestartAc> autocompositionList = new ArrayList<>();
+
+ /**
+ * Constructor.
+ */
+ public ParticipantRestart() {
+ super(ParticipantMessageType.PARTICIPANT_RESTART);
+ }
+
+ /**
+ * Constructs the object, making a deep copy.
+ *
+ * @param source source from which to copy
+ */
+ public ParticipantRestart(ParticipantRestart source) {
+ super(source);
+ this.participantDefinitionUpdates =
+ PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new);
+ this.autocompositionList = PfUtils.mapList(source.autocompositionList, ParticipantRestartAc::new);
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java
index 318b36a19..24197f1ab 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java
@@ -25,5 +25,6 @@ public enum DeployOrder {
UNDEPLOY,
DEPLOY,
DELETE,
- UPDATE
+ UPDATE,
+ RESTARTING
}
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 671aca60f..ee8e010d2 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
@@ -35,8 +35,10 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
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.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
@@ -49,6 +51,7 @@ import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfUtils;
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;
@@ -406,4 +409,21 @@ public final class AcmUtils {
element.setLockState(lockState);
}
}
+
+ /**
+ * Create a new AcElementDeploy from an AutomationCompositionElement.
+ *
+ * @param element the AutomationCompositionElement
+ * @param deployOrder the DeployOrder
+ * @return the AcElementDeploy
+ */
+ public static AcElementDeploy createAcElementDeploy(AutomationCompositionElement element, DeployOrder deployOrder) {
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setId(element.getId());
+ acElementDeploy.setDefinition(new ToscaConceptIdentifier(element.getDefinition()));
+ acElementDeploy.setOrderedState(deployOrder);
+ acElementDeploy.setProperties(PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()));
+ return acElementDeploy;
+ }
+
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java
index 890fc55ae..859b4224d 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java
@@ -29,13 +29,10 @@ import java.time.Instant;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
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;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Test the copy constructor.
@@ -52,21 +49,9 @@ class ParticipantPrimeTest {
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
- var toscaServiceTemplate = new ToscaServiceTemplate();
- toscaServiceTemplate.setName("serviceTemplate");
- toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
- toscaServiceTemplate.setDescription("Description of serviceTemplate");
- toscaServiceTemplate.setVersion("1.2.3");
-
- var toscaNodeTemplate = new ToscaNodeTemplate();
- toscaNodeTemplate.setName("nodeTemplate");
- toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
- toscaNodeTemplate.setDescription("Description of nodeTemplate");
- toscaNodeTemplate.setVersion("1.2.3");
-
var participantDefinitionUpdate = new ParticipantDefinition();
var type = new ToscaConceptIdentifier("id", "1.2.3");
- var acDefinition = getAcElementDefinition(type);
+ var acDefinition = CommonTestData.getAcElementDefinition(type);
participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition));
orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate));
@@ -76,17 +61,4 @@ class ParticipantPrimeTest {
assertSerializable(orig, ParticipantPrime.class);
}
-
- private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) {
- var toscaNodeTemplate = new ToscaNodeTemplate();
- toscaNodeTemplate.setName("nodeTemplate");
- toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
- toscaNodeTemplate.setDescription("Description of nodeTemplate");
- toscaNodeTemplate.setVersion("1.2.3");
-
- var acDefinition = new AutomationCompositionElementDefinition();
- acDefinition.setAcElementDefinitionId(id);
- acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate);
- return acDefinition;
- }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java
new file mode 100644
index 000000000..1ae607ebe
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRestartTest.java
@@ -0,0 +1,81 @@
+/*-
+ * ============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.messages.dmaap.participant;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable;
+import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+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 {
+ assertThatThrownBy(() -> new ParticipantRestart(null)).isInstanceOf(NullPointerException.class);
+
+ 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 AcElementDeploy();
+ acElement.setId(UUID.randomUUID());
+ var id = new ToscaConceptIdentifier("id", "1.2.3");
+ acElement.setDefinition(id);
+
+ var acRestart = new ParticipantRestartAc();
+ acRestart.setAcElementList(List.of(acElement));
+ acRestart.setAutomationCompositionId(UUID.randomUUID());
+ acRestart.setDeployState(DeployState.DEPLOYED);
+ acRestart.setLockState(LockState.LOCKED);
+
+ orig.setAutocompositionList(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/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index 046d1b848..7e8f60525 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
@@ -183,6 +183,15 @@ class AcmUtilsTest {
assertFalse(AcmUtils.isForward(DeployState.UNDEPLOYING, LockState.LOCKED));
}
+ @Test
+ void testCreateAcElementDeploy() {
+ var element = getDummyAutomationComposition().getElements().values().iterator().next();
+ var result = AcmUtils.createAcElementDeploy(element, DeployOrder.DEPLOY);
+ assertEquals(DeployOrder.DEPLOY, result.getOrderedState());
+ assertEquals(element.getId(), result.getId());
+ assertEquals(element.getDefinition(), result.getDefinition());
+ }
+
private AutomationComposition getDummyAutomationComposition() {
var automationComposition = new AutomationComposition();
automationComposition.setCompositionId(UUID.randomUUID());
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
index 21666e484..03a3fb11a 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
@@ -23,9 +23,12 @@ package org.onap.policy.clamp.models.acm.utils;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.UUID;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+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;
/**
@@ -78,4 +81,23 @@ public class CommonTestData {
return null;
}
}
+
+ /**
+ * Get new AutomationCompositionElementDefinition.
+ *
+ * @param id the ToscaConceptIdentifier
+ * @return a new AutomationCompositionElementDefinition
+ */
+ public static AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) {
+ var toscaNodeTemplate = new ToscaNodeTemplate();
+ toscaNodeTemplate.setName("nodeTemplate");
+ toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
+ toscaNodeTemplate.setDescription("Description of nodeTemplate");
+ toscaNodeTemplate.setVersion("1.2.3");
+
+ var acDefinition = new AutomationCompositionElementDefinition();
+ acDefinition.setAcElementDefinitionId(id);
+ acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate);
+ return acDefinition;
+ }
}