summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java58
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java22
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java26
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java2
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java13
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java107
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java22
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java12
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java19
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java22
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java67
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java11
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java105
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java3
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java7
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java5
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java4
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java10
21 files changed, 448 insertions, 83 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
index 8f8a54f39..611336058 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
@@ -37,6 +37,10 @@ public class AcElementDeployAck {
// State of the AutomationCompositionElement
private LockState lockState;
+ private String operationalState;
+
+ private String useState;
+
// Result: Success/Fail.
private Boolean result;
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 018031624..edc9e1c5f 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
@@ -54,6 +54,10 @@ public class AutomationCompositionElement {
@NonNull
private LockState lockState = LockState.LOCKED;
+ private String operationalState;
+
+ private String useState;
+
private String description;
// A map indexed by the property name. Each map entry is the serialized value of the property,
@@ -73,5 +77,7 @@ public class AutomationCompositionElement {
this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.operationalState = otherElement.operationalState;
+ this.useState = otherElement.useState;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java
new file mode 100644
index 000000000..1eb4bf8cb
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java
@@ -0,0 +1,58 @@
+/*-
+ * ============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.UUID;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * Class to represent a automation composition element info instance.
+ */
+@NoArgsConstructor
+@Data
+@ToString
+public class AutomationCompositionElementInfo {
+
+ private UUID automationCompositionElementId;
+
+ private DeployState deployState = DeployState.UNDEPLOYED;
+
+ private LockState lockState = LockState.LOCKED;
+
+ private String operationalState;
+
+ private String useState;
+
+ /**
+ * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
+ *
+ * @param otherElement the other element to copy from
+ */
+ public AutomationCompositionElementInfo(AutomationCompositionElementInfo otherElement) {
+ this.automationCompositionElementId = otherElement.automationCompositionElementId;
+ this.deployState = otherElement.deployState;
+ this.lockState = otherElement.lockState;
+ this.operationalState = otherElement.operationalState;
+ this.useState = otherElement.useState;
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
index 17875c429..64cfa8034 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
@@ -20,10 +20,13 @@
package org.onap.policy.clamp.models.acm.concepts;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
/**
* Class to represent a automation composition info instance.
@@ -39,6 +42,8 @@ public class AutomationCompositionInfo {
private LockState lockState = LockState.LOCKED;
+ private List<AutomationCompositionElementInfo> elements = new ArrayList<>();
+
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
*
@@ -48,5 +53,6 @@ public class AutomationCompositionInfo {
this.automationCompositionId = otherElement.automationCompositionId;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.elements = PfUtils.mapList(otherElement.elements, AutomationCompositionElementInfo::new);
}
}
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 4c3a6a3be..4ba336edf 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
@@ -93,6 +93,12 @@ public class JpaAutomationCompositionElement extends Validated
private LockState lockState;
@Column
+ private String operationalState;
+
+ @Column
+ private String useState;
+
+ @Column
private String description;
@Lob
@@ -152,6 +158,8 @@ public class JpaAutomationCompositionElement extends Validated
this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
+ this.operationalState = copyConcept.operationalState;
+ this.useState = copyConcept.useState;
}
/**
@@ -174,6 +182,8 @@ public class JpaAutomationCompositionElement extends Validated
element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setOperationalState(operationalState);
+ element.setUseState(useState);
return element;
}
@@ -186,6 +196,8 @@ public class JpaAutomationCompositionElement extends Validated
this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
this.deployState = element.getDeployState();
this.lockState = element.getLockState();
+ this.operationalState = element.getOperationalState();
+ this.useState = element.getUseState();
}
@Override
@@ -227,6 +239,16 @@ public class JpaAutomationCompositionElement extends Validated
return result;
}
+ result = ObjectUtils.compare(useState, other.useState);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(operationalState, other.operationalState);
+ 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/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index 058feae76..959fd7637 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
@@ -22,6 +22,7 @@
package org.onap.policy.clamp.models.acm.persistence.provider;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -30,9 +31,12 @@ import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+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.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfModelRuntimeException;
@@ -50,6 +54,7 @@ import org.springframework.transaction.annotation.Transactional;
public class AutomationCompositionProvider {
private final AutomationCompositionRepository automationCompositionRepository;
+ private final AutomationCompositionElementRepository acElementRepository;
/**
* Get automation composition.
@@ -182,4 +187,25 @@ public class AutomationCompositionProvider {
return jpaDeleteAutomationComposition.get().toAuthorative();
}
+
+ /**
+ * Upgrade States.
+ *
+ * @param automationCompositionInfoList list of AutomationCompositionInfo
+ */
+ public void upgradeStates(@NonNull final List<AutomationCompositionInfo> automationCompositionInfoList) {
+ if (automationCompositionInfoList.isEmpty()) {
+ return;
+ }
+ List<JpaAutomationCompositionElement> jpaList = new ArrayList<>();
+ for (var acInstance : automationCompositionInfoList) {
+ for (var element : acInstance.getElements()) {
+ var jpa = acElementRepository.getReferenceById(element.getAutomationCompositionElementId().toString());
+ jpa.setUseState(element.getUseState());
+ jpa.setOperationalState(element.getOperationalState());
+ jpaList.add(jpa);
+ }
+ }
+ acElementRepository.saveAll(jpaList);
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
index 8c50b01b6..95a169960 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
@@ -50,7 +50,7 @@ class AutomationCompositionDeployAckTest {
// verify with all values
orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(CommonTestData.getParticipantId());
- var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED,
+ var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "",
true, "AutomationCompositionElement result");
final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult);
orig.setAutomationCompositionResultMap(automationCompositionResultMap);
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
index 711af2f81..894d67daf 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
@@ -30,6 +30,7 @@ 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.AutomationCompositionElementInfo;
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;
@@ -54,6 +55,7 @@ class ParticipantStatusTest {
// verify with all values
var automationCompositionId = UUID.randomUUID();
+ var acElementId = UUID.randomUUID();
orig.setAutomationCompositionId(automationCompositionId);
var participantId = CommonTestData.getParticipantId();
orig.setParticipantId(participantId);
@@ -61,7 +63,7 @@ class ParticipantStatusTest {
orig.setState(ParticipantState.ON_LINE);
orig.setTimestamp(Instant.ofEpochMilli(3000));
- var acInfo = getAutomationCompositionInfo(automationCompositionId);
+ var acInfo = getAutomationCompositionInfo(automationCompositionId, acElementId);
orig.setAutomationCompositionInfoList(List.of(acInfo));
var participantDefinitionUpdate = new ParticipantDefinition();
@@ -76,12 +78,19 @@ class ParticipantStatusTest {
assertSerializable(orig, ParticipantStatus.class);
}
- private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) {
+ private AutomationCompositionInfo getAutomationCompositionInfo(UUID id, UUID acElementId) {
var acInfo = new AutomationCompositionInfo();
acInfo.setDeployState(DeployState.DEPLOYED);
acInfo.setLockState(LockState.LOCKED);
acInfo.setAutomationCompositionId(id);
+ var acInfoElement = new AutomationCompositionElementInfo();
+ acInfoElement.setAutomationCompositionElementId(acElementId);
+ acInfoElement.setDeployState(DeployState.DEPLOYED);
+ acInfoElement.setLockState(LockState.LOCKED);
+ acInfoElement.setOperationalState("DEFAULT");
+ acInfoElement.setUseState("IDLE");
+ acInfo.getElements().add(acInfoElement);
return acInfo;
}
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 e9df9b7e5..2a79aee08 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
@@ -122,8 +122,13 @@ class JpaAutomationCompositionElementTest {
assertEquals(ELEMENT_ID, testJpaAcElement.getElementId());
- var testJpaAutomationCompositionElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
- assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2);
+ var testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
+ assertEquals(testJpaAcElement, testJpaAcElement2);
+
+ testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement.toAuthorative());
+ testJpaAcElement2.setElementId(ELEMENT_ID);
+ testJpaAcElement2.setInstanceId(INSTANCE_ID);
+ assertEquals(testJpaAcElement, testJpaAcElement2);
}
@Test
@@ -138,52 +143,60 @@ class JpaAutomationCompositionElementTest {
@Test
void testJpaAutomationCompositionElementCompareTo() {
- var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
+ var testJpaAcElement = createJpaAutomationCompositionElementInstance();
- var otherJpaAutomationCompositionElement =
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null));
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement));
+ var otherJpaAcElement =
+ new JpaAutomationCompositionElement(testJpaAcElement);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ assertEquals(-1, testJpaAcElement.compareTo(null));
+ assertEquals(0, testJpaAcElement.compareTo(testJpaAcElement));
assertNotEquals(0,
- testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
-
- testJpaAutomationCompositionElement.setElementId("BadValue");
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setElementId(ELEMENT_ID);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setInstanceId("BadValue");
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setInstanceId(INSTANCE_ID);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setDescription("Description");
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setDescription(null);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setDeployState(DeployState.DEPLOYED);
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setDeployState(DeployState.UNDEPLOYED);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setLockState(LockState.UNLOCKED);
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setLockState(LockState.LOCKED);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setParticipantId(UUID.randomUUID().toString());
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- assertEquals(testJpaAutomationCompositionElement,
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
+ testJpaAcElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
+
+ testJpaAcElement.setElementId("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setElementId(ELEMENT_ID);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setInstanceId("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setInstanceId(INSTANCE_ID);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setDescription("Description");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setDescription(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setDeployState(DeployState.DEPLOYED);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setDeployState(DeployState.UNDEPLOYED);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setLockState(LockState.UNLOCKED);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setLockState(LockState.LOCKED);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setUseState("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setUseState("IDLE");
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setOperationalState("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setOperationalState("DEFAULT");
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setParticipantId(UUID.randomUUID().toString());
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement));
}
@Test
@@ -229,6 +242,8 @@ class JpaAutomationCompositionElementTest {
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantId(CommonTestData.getParticipantId());
automationCompositionElement.setProperties(Map.of("key", "{}"));
+ automationCompositionElement.setUseState("IDLE");
+ automationCompositionElement.setOperationalState("DEFAULT");
return automationCompositionElement;
}
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 ba1e33c27..0991c1bd0 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
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -64,7 +65,8 @@ class AutomationCompositionProviderTest {
@Test
void testAutomationCompositionCreate() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
when(automationCompositionRepository.save(any(JpaAutomationComposition.class)))
.thenReturn(inputAutomationCompositionsJpa.get(0));
@@ -78,7 +80,8 @@ class AutomationCompositionProviderTest {
@Test
void testAutomationCompositionUpdate() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
assertThatThrownBy(() -> automationCompositionProvider.updateAutomationComposition(null))
.hasMessageMatching(OBJECT_IS_NULL);
@@ -95,7 +98,8 @@ class AutomationCompositionProviderTest {
@Test
void testGetAutomationCompositions() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(),
@@ -112,7 +116,8 @@ class AutomationCompositionProviderTest {
@Test
void testGetAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
assertThatThrownBy(
@@ -128,7 +133,8 @@ class AutomationCompositionProviderTest {
@Test
void testFindAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
var acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
@@ -151,7 +157,8 @@ class AutomationCompositionProviderTest {
@Test
void testGetAcInstancesByCompositionId() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
when(automationCompositionRepository.findByCompositionId(automationComposition.getCompositionId().toString()))
@@ -164,7 +171,8 @@ class AutomationCompositionProviderTest {
@Test
void testDeleteAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
assertThatThrownBy(() -> automationCompositionProvider.deleteAutomationComposition(UUID.randomUUID()))
.hasMessageMatching(".*.failed, automation composition does not exist");
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 3e740192b..d40ac3276 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -201,4 +201,16 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
return policyList;
}
+
+ @Override
+ public String getUseState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ return "IDLE";
+ }
+
+ @Override
+ public String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ return "ENABLED";
+ }
}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index 47c279988..ecc0b88e7 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.participant.policy.main.handler;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -133,4 +134,22 @@ class AutomationCompositionElementHandlerTest {
assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
.hasMessageMatching("Deploy of Policy failed.");
}
+
+ @Test
+ void testGetOperationalState() throws PfModelException {
+ var api = mock(PolicyApiHttpClient.class);
+ var pap = mock(PolicyPapHttpClient.class);
+ var handler = new AutomationCompositionElementHandler(api, pap);
+
+ assertEquals("ENABLED", handler.getOperationalState(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testGetUseState() throws PfModelException {
+ var api = mock(PolicyApiHttpClient.class);
+ var pap = mock(PolicyPapHttpClient.class);
+ var handler = new AutomationCompositionElementHandler(api, pap);
+
+ assertEquals("IDLE", handler.getUseState(UUID.randomUUID(), UUID.randomUUID()));
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
index da6bccb41..c99241f27 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
@@ -47,4 +47,26 @@ public interface AutomationCompositionElementListener {
*/
public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
throws PfModelException;
+
+ public default void lock(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Lock Operation
+ }
+
+ public default void unlock(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Unlock Operation
+ }
+
+ public default String getUseState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Use State
+ return "";
+ }
+
+ public default String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Operational State
+ return "";
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
index d76700171..1eaf63dcc 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
@@ -111,6 +111,8 @@ public class AutomationCompositionHandler {
if (element != null) {
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setUseState(getUseState(automationCompositionId, id));
+ element.setOperationalState(getOperationalState(automationCompositionId, id));
}
var checkOpt = automationComposition.getElements().values().stream()
.filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny();
@@ -133,8 +135,11 @@ public class AutomationCompositionHandler {
automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId);
acElement.setDeployState(deployState);
acElement.setLockState(lockState);
+ acElement.setUseState(getUseState(automationCompositionId, id));
+ acElement.setOperationalState(getOperationalState(automationCompositionId, id));
automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(),
- new AcElementDeployAck(deployState, lockState, true,
+ new AcElementDeployAck(deployState, lockState,
+ acElement.getOperationalState(), acElement.getUseState(), true,
"Automation composition element {} state changed to {}\", id, newState)"));
LOGGER.debug("Automation composition element {} state changed to {}", id, deployState);
automationCompositionStateChangeAck
@@ -408,8 +413,15 @@ public class AutomationCompositionHandler {
if (acElementNodeTemplate != null) {
int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
if (startPhaseMsg.equals(startPhase)) {
- updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
- LockState.LOCKED);
+ for (var acElementListener : listeners) {
+ try {
+ acElementListener.lock(instanceId, acElement.getId());
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+ LockState.LOCKED);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element lock failed {}", instanceId);
+ }
+ }
}
}
}
@@ -420,8 +432,15 @@ public class AutomationCompositionHandler {
if (acElementNodeTemplate != null) {
int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
if (startPhaseMsg.equals(startPhase)) {
- updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
- LockState.UNLOCKED);
+ for (var acElementListener : listeners) {
+ try {
+ acElementListener.unlock(instanceId, acElement.getId());
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+ LockState.UNLOCKED);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element unlock failed {}", instanceId);
+ }
+ }
}
}
}
@@ -436,10 +455,46 @@ public class AutomationCompositionHandler {
try {
acElementListener.undeploy(instanceId, acElement.getId());
} catch (PfModelException e) {
- LOGGER.debug("Automation composition element update failed {}", instanceId);
+ LOGGER.error("Automation composition element update failed {}", instanceId);
}
}
}
}
}
+
+ /**
+ * Get UseState.
+ *
+ * @param instanceId the instance Id
+ * @param acElementId the Automation Composition Element Id
+ * @return the UseState of the Automation Composition Element
+ */
+ public String getUseState(UUID instanceId, UUID acElementId) {
+ for (var acElementListener : listeners) {
+ try {
+ return acElementListener.getUseState(instanceId, acElementId);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element get Use State failed {}", acElementId);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get OperationalState.
+ *
+ * @param instanceId the instance Id
+ * @param acElementId the Automation Composition Element Id
+ * @return the OperationalState of the Automation Composition Element
+ */
+ public String getOperationalState(UUID instanceId, UUID acElementId) {
+ for (var acElementListener : listeners) {
+ try {
+ return acElementListener.getOperationalState(instanceId, acElementId);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element get Use State failed {}", acElementId);
+ }
+ }
+ return null;
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
index 5565e0bd0..9e2484c7d 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java
@@ -33,6 +33,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessag
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
@@ -290,6 +291,16 @@ public class ParticipantHandler {
acInfo.setAutomationCompositionId(entry.getKey());
acInfo.setDeployState(entry.getValue().getDeployState());
acInfo.setLockState(entry.getValue().getLockState());
+ for (var element : entry.getValue().getElements().values()) {
+ var elementInfo = new AutomationCompositionElementInfo();
+ elementInfo.setAutomationCompositionElementId(element.getId());
+ elementInfo.setDeployState(element.getDeployState());
+ elementInfo.setLockState(element.getLockState());
+ elementInfo.setOperationalState(
+ automationCompositionHandler.getOperationalState(entry.getKey(), element.getId()));
+ elementInfo.setUseState(automationCompositionHandler.getUseState(entry.getKey(), element.getId()));
+ acInfo.getElements().add(elementInfo);
+ }
automationCompositionInfoList.add(acInfo);
}
return automationCompositionInfoList;
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
index 35da039a5..25b1facf5 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
@@ -24,7 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.List;
import java.util.UUID;
@@ -41,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCom
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
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.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -49,6 +55,8 @@ class AutomationCompositionHandlerTest {
private final CommonTestData commonTestData = new CommonTestData();
+ private static final String STATE_VALUE = "STATE_VALUE";
+
@Test
void automationCompositionHandlerTest() {
var ach = commonTestData.getMockAutomationCompositionHandler();
@@ -116,10 +124,11 @@ class AutomationCompositionHandlerTest {
}
@Test
- void handleAutomationCompositionDeployTest() {
+ void handleAutomationCompositionDeployTest() throws PfModelException {
var acd = new AutomationCompositionElementDefinition();
var definition = CommonTestData.getDefinition();
acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
var updateMsg = new AutomationCompositionDeploy();
updateMsg.setAutomationCompositionId(UUID.randomUUID());
var uuid = UUID.randomUUID();
@@ -130,19 +139,25 @@ class AutomationCompositionHandlerTest {
updateMsg.setStartPhase(0);
var acElementDefinitions = List.of(acd);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
updateMsg.setFirstStartPhase(false);
updateMsg.setStartPhase(1);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
ach.getAutomationCompositionMap().clear();
updateMsg.setFirstStartPhase(true);
updateMsg.setStartPhase(0);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
updateMsg.setAutomationCompositionId(UUID.randomUUID());
updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class)));
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
updateMsg.setStartPhase(1);
var participantDeploy = new ParticipantDeploy();
@@ -152,15 +167,13 @@ class AutomationCompositionHandlerTest {
participantDeploy.setAcElementList(List.of(element));
updateMsg.setParticipantUpdatesList(List.of(participantDeploy));
- var acd2 = new AutomationCompositionElementDefinition();
- acd2.setAcElementDefinitionId(definition);
- acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, List.of(acd2)));
-
+ updateMsg.setStartPhase(0);
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(1)).deploy(any(), any(), anyMap());
}
@Test
- void acUndeployTest() {
+ void acUndeployTest() throws PfModelException {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
@@ -171,14 +184,46 @@ class AutomationCompositionHandlerTest {
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
stateChangeUndeploy
.setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of());
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
+
+ var acd = new AutomationCompositionElementDefinition();
+ acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of(acd));
+ verify(listener, times(1)).undeploy(any(), any());
+
stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID());
stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId());
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()));
}
@Test
- void automationCompositionStateUnlock() {
+ void automationCompositionStateLock() throws PfModelException {
+ var uuid = UUID.randomUUID();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+
+ var stateChangeLock =
+ commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK);
+
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
+ stateChangeLock
+ .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+ var acd = new AutomationCompositionElementDefinition();
+ acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ ach.handleAutomationCompositionStateChange(stateChangeLock, List.of(acd));
+ stateChangeLock.setAutomationCompositionId(UUID.randomUUID());
+ stateChangeLock.setParticipantId(CommonTestData.getRndParticipantId());
+ ach.handleAutomationCompositionStateChange(stateChangeLock, List.of());
+ verify(listener, times(1)).lock(any(), any());
+ }
+
+ @Test
+ void automationCompositionStateUnlock() throws PfModelException {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
@@ -187,11 +232,41 @@ class AutomationCompositionHandlerTest {
commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
stateChangeUnlock
.setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+ var acd = new AutomationCompositionElementDefinition();
+ acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of(acd));
stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID());
stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId());
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()));
+ ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+ verify(listener, times(1)).unlock(any(), any());
+ }
+
+ @Test
+ void testGetUseState() throws PfModelException {
+ var uuid = UUID.randomUUID();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ when(listener.getUseState(uuid, uuid)).thenReturn(STATE_VALUE);
+ ach.registerAutomationCompositionElementListener(listener);
+ assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid));
+ }
+
+ @Test
+ void testGetOperationalState() throws PfModelException {
+ var uuid = UUID.randomUUID();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ when(listener.getOperationalState(uuid, uuid)).thenReturn(STATE_VALUE);
+ ach.registerAutomationCompositionElementListener(listener);
+ assertEquals(STATE_VALUE, ach.getOperationalState(uuid, uuid));
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
index 4dcfd1428..140fd947a 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
@@ -163,7 +163,7 @@ public class CommonTestData {
}
public static ToscaConceptIdentifier getDefinition() {
- return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
+ return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3");
}
/**
@@ -308,6 +308,7 @@ public class CommonTestData {
public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid,
DeployOrder deployOrder, LockOrder lockOrder) {
var stateChange = new AutomationCompositionStateChange();
+ stateChange.setStartPhase(0);
stateChange.setAutomationCompositionId(UUID.randomUUID());
stateChange.setParticipantId(participantId);
stateChange.setMessageId(uuid);
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
index 5fcb3837f..85beb76c4 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
@@ -163,6 +163,13 @@ public class SupervisionAcHandler {
if (element != null) {
element.setDeployState(acElementAck.getValue().getDeployState());
element.setLockState(acElementAck.getValue().getLockState());
+ if (DeployState.DEPLOYED.equals(element.getDeployState())) {
+ element.setOperationalState(acElementAck.getValue().getOperationalState());
+ element.setUseState(acElementAck.getValue().getUseState());
+ } else {
+ element.setOperationalState(null);
+ element.setUseState(null);
+ }
updated = true;
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
index c1bfcf07a..564fa8d0e 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
@@ -36,6 +36,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +53,7 @@ public class SupervisionParticipantHandler {
private final ParticipantProvider participantProvider;
private final ParticipantRegisterAckPublisher participantRegisterAckPublisher;
private final ParticipantDeregisterAckPublisher participantDeregisterAckPublisher;
+ private final AutomationCompositionProvider automationCompositionProvider;
/**
* Handle a ParticipantRegister message from a participant.
@@ -101,6 +103,9 @@ public class SupervisionParticipantHandler {
LOGGER.debug("Participant Status received {}", participantStatusMsg);
saveParticipantStatus(participantStatusMsg,
listToMap(participantStatusMsg.getParticipantSupportedElementType()));
+ if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) {
+ automationCompositionProvider.upgradeStates(participantStatusMsg.getAutomationCompositionInfoList());
+ }
}
private void saveParticipantStatus(ParticipantMessage participantMessage,
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
index 153f7a0e0..c44fa1d21 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -64,7 +64,7 @@ class SupervisionAcHandlerTest {
var automationCompositionAckMessage =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
+ var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, "", "", true, "");
automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
acElementDeployAck);
}
@@ -86,7 +86,7 @@ class SupervisionAcHandlerTest {
var automationCompositionAckMessage =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, true, "");
+ var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "", true, "");
automationCompositionAckMessage
.setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
index fb12e040a..f00747c6b 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
@@ -38,6 +38,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
class SupervisionParticipantHandlerTest {
@@ -54,7 +55,8 @@ class SupervisionParticipantHandlerTest {
participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId());
var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider,
- mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
+ mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher,
+ mock(AutomationCompositionProvider.class));
handler.handleParticipantMessage(participantDeregisterMessage);
@@ -76,7 +78,8 @@ class SupervisionParticipantHandlerTest {
var participantProvider = mock(ParticipantProvider.class);
var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
- mock(ParticipantDeregisterAckPublisher.class));
+ mock(ParticipantDeregisterAckPublisher.class),
+ mock(AutomationCompositionProvider.class));
handler.handleParticipantMessage(participantRegisterMessage);
verify(participantProvider).saveParticipant(any());
@@ -97,7 +100,8 @@ class SupervisionParticipantHandlerTest {
var participantProvider = mock(ParticipantProvider.class);
var handler = new SupervisionParticipantHandler(participantProvider,
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
+ mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
+ mock(AutomationCompositionProvider.class));
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
.thenReturn(Optional.of(participant));