summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-09-27 11:03:48 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-09-28 14:42:20 +0100
commita769d1215cff61aa8ec1cb026cd91c3318c5eee5 (patch)
treea1411b7a5cace1cced3c5ed6da7464078d71d2da
parentbceec3f67b8d6fa79cc3594f7672924b27e39984 (diff)
Add migration publisher message in ACM runtime
Issue-ID: POLICY-4823 Change-Id: Id4480a0800e41ec8e2f0f9931a9a93752b2ef952 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
-rwxr-xr-xruntime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java56
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java14
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java8
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java26
-rwxr-xr-xruntime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java55
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/main/resources/openapi/openapi.yaml5
-rwxr-xr-xruntime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java73
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java38
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java40
-rwxr-xr-x[-rw-r--r--]runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java12
10 files changed, 266 insertions, 61 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 977708ee1..af4e844d5 100755
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -27,6 +27,7 @@ import jakarta.ws.rs.core.Response.Status;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
+import lombok.NonNull;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
@@ -150,6 +151,12 @@ public class AutomationCompositionInstantiationProvider {
public InstantiationResponse updateDeployedAutomationComposition(UUID compositionId,
AutomationComposition automationComposition, AutomationComposition acToBeUpdated) {
+ if (automationComposition.getCompositionTargetId() != null
+ && !DeployState.DEPLOYED.equals(acToBeUpdated.getDeployState())) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ "Not allowed to migrate in the state " + acToBeUpdated.getDeployState());
+ }
+
// Iterate and update the element property values
for (var dbAcElement : acToBeUpdated.getElements().entrySet()) {
var elementId = dbAcElement.getKey();
@@ -161,13 +168,25 @@ public class AutomationCompositionInstantiationProvider {
if (automationComposition.getRestarting() != null) {
throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Update not allowed");
}
- var validationResult = validateAutomationComposition(acToBeUpdated);
- if (!validationResult.isValid()) {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
- }
- // Publish property update event to the participants
- supervisionAcHandler.update(acToBeUpdated);
+ if (automationComposition.getCompositionTargetId() != null) {
+ var validationResult =
+ validateAutomationComposition(acToBeUpdated, automationComposition.getCompositionTargetId());
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ }
+ acToBeUpdated.setCompositionTargetId(automationComposition.getCompositionTargetId());
+
+ // Publish migrate event to the participants
+ supervisionAcHandler.migrate(acToBeUpdated, automationComposition.getCompositionTargetId());
+ } else {
+ var validationResult = validateAutomationComposition(acToBeUpdated);
+ if (!validationResult.isValid()) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
+ }
+ // Publish property update event to the participants
+ supervisionAcHandler.update(acToBeUpdated);
+ }
automationComposition = automationCompositionProvider.updateAutomationComposition(acToBeUpdated);
var response = new InstantiationResponse();
@@ -177,18 +196,24 @@ public class AutomationCompositionInstantiationProvider {
return response;
}
+ private BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition) {
+ return validateAutomationComposition(automationComposition, automationComposition.getCompositionId());
+ }
+
/**
* Validate AutomationComposition.
*
* @param automationComposition AutomationComposition to validate
+ * @param compositionId the composition id
* @return the result of validation
*/
- private BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition) {
+ private BeanValidationResult validateAutomationComposition(AutomationComposition automationComposition,
+ UUID compositionId) {
var result = new BeanValidationResult("AutomationComposition", automationComposition);
- var acDefinitionOpt = acDefinitionProvider.findAcDefinition(automationComposition.getCompositionId());
+ var acDefinitionOpt = acDefinitionProvider.findAcDefinition(compositionId);
if (acDefinitionOpt.isEmpty()) {
- result.addResult(new ObjectValidationResult("ServiceTemplate", "", ValidationStatus.INVALID,
+ result.addResult(new ObjectValidationResult("ServiceTemplate", compositionId, ValidationStatus.INVALID,
"Commissioned automation composition definition not found"));
return result;
}
@@ -231,9 +256,10 @@ public class AutomationCompositionInstantiationProvider {
* @return the Automation Composition
*/
@Transactional(readOnly = true)
- public AutomationComposition getAutomationComposition(UUID compositionId, UUID instanceId) {
+ public AutomationComposition getAutomationComposition(@NonNull UUID compositionId, UUID instanceId) {
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
- if (!automationComposition.getCompositionId().equals(compositionId)) {
+ if (!compositionId.equals(automationComposition.getCompositionId())
+ && !compositionId.equals(automationComposition.getCompositionTargetId())) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
@@ -267,11 +293,9 @@ public class AutomationCompositionInstantiationProvider {
throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Delete not allowed");
}
var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
- if (acDefinition != null) {
- var participantIds = acDefinition.getElementStateMap().values().stream()
- .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet());
- acmParticipantProvider.verifyParticipantState(participantIds);
- }
+ var participantIds = acDefinition.getElementStateMap().values().stream()
+ .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet());
+ acmParticipantProvider.verifyParticipantState(participantIds);
supervisionAcHandler.delete(automationComposition, acDefinition);
var response = new InstantiationResponse();
response.setInstanceId(automationComposition.getInstanceId());
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 df5d0ff0e..dbed7f790 100644..100755
--- 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
@@ -28,6 +28,7 @@ import java.util.UUID;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionMigrationPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
@@ -59,6 +60,7 @@ public class SupervisionAcHandler {
private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
private final AcElementPropertiesPublisher acElementPropertiesPublisher;
+ private final AutomationCompositionMigrationPublisher acCompositionMigrationPublisher;
/**
* Handle Deploy an AutomationComposition instance.
@@ -277,4 +279,16 @@ public class SupervisionAcHandler {
return updated;
}
+
+ /**
+ * Handle Migration of an AutomationComposition instance to other ACM Definition.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param compositionTargetId the ACM Definition Id
+ */
+ public void migrate(AutomationComposition automationComposition, UUID compositionTargetId) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.MIGRATING, LockState.LOCKED);
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ acCompositionMigrationPublisher.send(automationComposition, compositionTargetId);
+ }
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
index 15283609a..33118fab7 100644..100755
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
@@ -172,7 +172,8 @@ public class SupervisionScanner {
LOGGER.debug("automation composition scan: transition from state {} to {} not completed",
automationComposition.getDeployState(), automationComposition.getLockState());
- if (DeployState.UPDATING.equals(automationComposition.getDeployState())) {
+ if (DeployState.UPDATING.equals(automationComposition.getDeployState())
+ || DeployState.MIGRATING.equals(automationComposition.getDeployState())) {
// UPDATING do not need phases
handleTimeout(automationComposition);
return;
@@ -196,6 +197,11 @@ public class SupervisionScanner {
private void complete(final AutomationComposition automationComposition) {
var deployState = automationComposition.getDeployState();
+ if (DeployState.MIGRATING.equals(automationComposition.getDeployState())) {
+ // migration scenario
+ automationComposition.setCompositionId(automationComposition.getCompositionTargetId());
+ automationComposition.setCompositionTargetId(null);
+ }
automationComposition.setDeployState(AcmUtils.deployCompleted(deployState));
automationComposition.setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState()));
if (StateChangeResult.TIMEOUT.equals(automationComposition.getStateChangeResult())) {
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java
index 78a9e8a72..5a3da33df 100644..100755
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AcElementPropertiesPublisher.java
@@ -22,15 +22,9 @@ package org.onap.policy.clamp.acm.runtime.supervision.comm;
import io.micrometer.core.annotation.Timed;
import java.time.Instant;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import java.util.UUID;
import lombok.AllArgsConstructor;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
@@ -52,29 +46,15 @@ public class AcElementPropertiesPublisher extends AbstractParticipantPublisher<P
*
* @param automationComposition the AutomationComposition
*/
- @Timed(value = "publisher.properties_update",
- description = "AC Element Properties Update published")
+ @Timed(value = "publisher.properties_update", description = "AC Element Properties Update published")
public void send(AutomationComposition automationComposition) {
- Map<UUID, List<AcElementDeploy>> map = new HashMap<>();
- for (var element : automationComposition.getElements().values()) {
- var acElementDeploy = AcmUtils.createAcElementDeploy(element, DeployOrder.UPDATE);
- map.putIfAbsent(element.getParticipantId(), new ArrayList<>());
- map.get(element.getParticipantId()).add(acElementDeploy);
- }
- List<ParticipantDeploy> participantDeploys = new ArrayList<>();
- for (var entry : map.entrySet()) {
- var participantDeploy = new ParticipantDeploy();
- participantDeploy.setParticipantId(entry.getKey());
- participantDeploy.setAcElementList(entry.getValue());
- participantDeploys.add(participantDeploy);
- }
-
var propertiesUpdate = new PropertiesUpdate();
propertiesUpdate.setCompositionId(automationComposition.getCompositionId());
propertiesUpdate.setAutomationCompositionId(automationComposition.getInstanceId());
propertiesUpdate.setMessageId(UUID.randomUUID());
propertiesUpdate.setTimestamp(Instant.now());
- propertiesUpdate.setParticipantUpdatesList(participantDeploys);
+ propertiesUpdate.setParticipantUpdatesList(
+ AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.UPDATE));
LOGGER.debug("AC Element properties update sent {}", propertiesUpdate);
super.send(propertiesUpdate);
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java
new file mode 100755
index 000000000..361e43e45
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionMigrationPublisher.java
@@ -0,0 +1,55 @@
+/*-
+ * ============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.acm.runtime.supervision.comm;
+
+import io.micrometer.core.annotation.Timed;
+import java.util.UUID;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionMigration;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.springframework.stereotype.Component;
+
+@Component
+public class AutomationCompositionMigrationPublisher
+ extends AbstractParticipantPublisher<AutomationCompositionMigration> {
+
+ /**
+ * Send AutomationCompositionMigration message to Participant.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param compositionTargetId the Composition Definition Target
+ */
+ @Timed(
+ value = "publisher.automation_composition_migration",
+ description = "AUTOMATION_COMPOSITION_MIGRATION messages published")
+ public void send(AutomationComposition automationComposition, UUID compositionTargetId) {
+ var acsc = new AutomationCompositionMigration();
+ acsc.setCompositionId(automationComposition.getCompositionId());
+ acsc.setAutomationCompositionId(automationComposition.getInstanceId());
+ acsc.setMessageId(UUID.randomUUID());
+ acsc.setCompositionTargetId(compositionTargetId);
+ acsc.setParticipantUpdatesList(
+ AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.MIGRATE));
+
+ super.send(acsc);
+ }
+}
diff --git a/runtime-acm/src/main/resources/openapi/openapi.yaml b/runtime-acm/src/main/resources/openapi/openapi.yaml
index 988b9d164..21e850b92 100644..100755
--- a/runtime-acm/src/main/resources/openapi/openapi.yaml
+++ b/runtime-acm/src/main/resources/openapi/openapi.yaml
@@ -1073,9 +1073,10 @@ paths:
post:
tags:
- Automation Composition Instance
- summary: Create or Update automation composition instance
- description: Creates or updates an automation composition instance that uses the specified automation composition definition. The ID of the created
+ summary: Create, Update or Migrate an automation composition instance
+ description: Create, Update or Migrate an automation composition instance that uses the specified automation composition definition. The ID of the created
automation composition instance is returned. In the case of an update, the instanceId should be included in the request body.
+ In the case of a migrate, the instanceId and the compositionTargetId should be included in the request body.
operationId: createCompositionInstance
parameters:
- name : compositionId
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 308eed5da..8f7a4fe8f 100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -79,7 +79,7 @@ class AutomationCompositionInstantiationProviderTest {
+ " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\""
+ " INVALID, Not found\n";
private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " item \"ServiceTemplate\" value \"\" INVALID,"
+ + " item \"ServiceTemplate\" value \"%s\" INVALID,"
+ " Commissioned automation composition definition not found\n";
private static final String DO_NOT_MATCH = " do not match with ";
@@ -94,11 +94,12 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testInstantiationCrud() throws AutomationCompositionException {
+ void testInstantiationCrud() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var compositionId = acDefinition.getCompositionId();
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition);
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var acmParticipantProvider = mock(AcmParticipantProvider.class);
@@ -199,6 +200,14 @@ class AutomationCompositionInstantiationProviderTest {
() -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
.hasMessageMatching(
"Not allowed to update in the state " + automationCompositionUpdate.getDeployState());
+
+ automationCompositionUpdate.setDeployState(DeployState.UPDATING);
+ automationCompositionUpdate.setLockState(LockState.LOCKED);
+ automationCompositionUpdate.setCompositionTargetId(UUID.randomUUID());
+ assertThatThrownBy(
+ () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
+ .hasMessageMatching(
+ "Not allowed to migrate in the state " + automationCompositionUpdate.getDeployState());
}
@Test
@@ -262,12 +271,58 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
+ void testInstantiationMigration() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ automationComposition.setCompositionId(compositionId);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ automationComposition.setCompositionTargetId(UUID.randomUUID());
+ var acProvider = mock(AutomationCompositionProvider.class);
+ when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(acProvider.updateAutomationComposition(automationComposition)).thenReturn(automationComposition);
+
+ var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
+ null, supervisionAcHandler, acmParticipantProvider, new AcRuntimeParameterGroup());
+
+ assertThatThrownBy(() -> instantiationProvider
+ .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition))
+ .hasMessageMatching(
+ String.format(AC_DEFINITION_NOT_FOUND, automationComposition.getCompositionTargetId()));
+
+ var acDefinitionTarget = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionTargetId = acDefinitionTarget.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionTargetId)).thenReturn(Optional.of(acDefinitionTarget));
+
+ automationComposition.setCompositionTargetId(compositionTargetId);
+
+ var instantiationResponse = instantiationProvider
+ .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition);
+
+ verify(supervisionAcHandler).migrate(any(), any());
+ verify(acProvider).updateAutomationComposition(automationComposition);
+ InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationComposition);
+ }
+
+ @Test
void testInstantiationDelete() {
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
var acProvider = mock(AutomationCompositionProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition);
+ automationComposition.setCompositionId(compositionId);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var acmParticipantProvider = mock(AcmParticipantProvider.class);
var acRuntimeParameterGroup = mock(AcRuntimeParameterGroup.class);
@@ -280,7 +335,6 @@ class AutomationCompositionInstantiationProviderTest {
var wrongCompositionId = UUID.randomUUID();
var instanceId = automationComposition.getInstanceId();
- var compositionId = automationComposition.getCompositionId();
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(wrongCompositionId, instanceId))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
@@ -390,10 +444,10 @@ class AutomationCompositionInstantiationProviderTest {
var compositionId = automationComposition.getCompositionId();
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
- .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ .hasMessageMatching(String.format(AC_DEFINITION_NOT_FOUND, compositionId));
assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition))
- .hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ .hasMessageMatching(String.format(AC_DEFINITION_NOT_FOUND, compositionId));
}
@Test
@@ -422,6 +476,15 @@ class AutomationCompositionInstantiationProviderTest {
assertThatThrownBy(() -> provider.compositionInstanceState(wrongCompositionId,
automationComposition.getInstanceId(), new AcInstanceStateUpdate()))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
+
+ var compositionTargetId = UUID.randomUUID();
+ automationComposition.setCompositionTargetId(compositionTargetId);
+ assertThatThrownBy(
+ () -> provider.getAutomationComposition(wrongCompositionId, automationComposition.getInstanceId()))
+ .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
+
+ var result = provider.getAutomationComposition(compositionTargetId, automationComposition.getInstanceId());
+ assertThat(result).isNotNull();
}
@Test
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 1f63c3da8..d3f859843 100644..100755
--- 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
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionMigrationPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
@@ -62,7 +63,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var automationCompositionAckMessage =
getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK,
@@ -101,7 +102,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
@@ -136,7 +137,8 @@ class SupervisionAcHandlerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher, null);
+ mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher, null,
+ null);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
@@ -148,7 +150,7 @@ class SupervisionAcHandlerTest {
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = new SupervisionAcHandler(automationCompositionProvider, automationCompositionDeployPublisher,
- mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class));
+ mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
@@ -167,7 +169,7 @@ class SupervisionAcHandlerTest {
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -184,7 +186,7 @@ class SupervisionAcHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
@@ -204,7 +206,7 @@ class SupervisionAcHandlerTest {
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -221,7 +223,7 @@ class SupervisionAcHandlerTest {
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -240,7 +242,7 @@ class SupervisionAcHandlerTest {
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -257,7 +259,7 @@ class SupervisionAcHandlerTest {
var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher,
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var automationComposition =
@@ -287,7 +289,7 @@ class SupervisionAcHandlerTest {
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(AcElementPropertiesPublisher.class));
+ mock(AcElementPropertiesPublisher.class), null);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
@@ -299,10 +301,22 @@ class SupervisionAcHandlerTest {
var acElementPropertiesPublisher = mock(AcElementPropertiesPublisher.class);
var handler = new SupervisionAcHandler(mock(AutomationCompositionProvider.class),
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- acElementPropertiesPublisher);
+ acElementPropertiesPublisher, null);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
handler.update(automationComposition);
verify(acElementPropertiesPublisher).send(any(AutomationComposition.class));
}
+
+ @Test
+ void testMigrate() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acCompositionMigrationPublisher = mock(AutomationCompositionMigrationPublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider, null, null, null,
+ acCompositionMigrationPublisher);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate");
+ handler.migrate(automationComposition, UUID.randomUUID());
+ verify(acCompositionMigrationPublisher).send(any(AutomationComposition.class), any());
+ }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index 5fe4f4c25..a1fad46b1 100644..100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.clamp.acm.runtime.supervision;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -207,13 +208,20 @@ class SupervisionScannerTest {
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
scannerObj2.run();
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
+ assertEquals(StateChangeResult.TIMEOUT, automationComposition.getStateChangeResult());
+ for (Map.Entry<UUID, AutomationCompositionElement> entry : automationComposition.getElements().entrySet()) {
+ entry.getValue().setDeployState(DeployState.DEPLOYED);
+ }
+ scannerObj2.run();
+ assertEquals(StateChangeResult.NO_ERROR, automationComposition.getStateChangeResult());
}
@Test
- void testSendAutomationCompositionMsgUpdate() {
+ void testSendAutomationCompositionMsgStartPhase() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setLockState(LockState.NONE);
@@ -247,6 +255,36 @@ class SupervisionScannerTest {
}
@Test
+ void testSendAutomationCompositionMigrate() {
+ var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
+ automationComposition.setDeployState(DeployState.MIGRATING);
+ var compositionTargetId = UUID.randomUUID();
+ automationComposition.setCompositionTargetId(compositionTargetId);
+ automationComposition.setLockState(LockState.LOCKED);
+ for (var element : automationComposition.getElements().values()) {
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.LOCKED);
+ }
+
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
+ .thenReturn(List.of(automationComposition));
+
+ var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
+ var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+
+ var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
+
+ supervisionScanner.run();
+ verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
+ assertEquals(DeployState.DEPLOYED, automationComposition.getDeployState());
+ assertEquals(compositionTargetId, automationComposition.getCompositionId());
+ }
+
+ @Test
void testSendAutomationCompositionMsgUnlocking() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYED);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 85444ed2f..87e00da93 100644..100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -227,6 +227,17 @@ class SupervisionMessagesTest {
}
@Test
+ void testAutomationCompositionMigrationPublisher() {
+ var publisher = new AutomationCompositionMigrationPublisher();
+ var topicSink = mock(TopicSink.class);
+ publisher.active(List.of(topicSink));
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
+ publisher.send(automationComposition, UUID.randomUUID());
+ verify(topicSink).send(anyString());
+ }
+
+ @Test
void testParticipantRestartPublisher() {
var publisher = new ParticipantRestartPublisher(CommonTestData.getTestParamaterGroup());
var topicSink = mock(TopicSink.class);
@@ -289,5 +300,4 @@ class SupervisionMessagesTest {
acStateChangeAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
verify(supervisionHandler).handleAutomationCompositionStateChangeAckMessage(automationCompositionAck);
}
-
}