summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
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 /runtime-acm/src/main
parentbceec3f67b8d6fa79cc3594f7672924b27e39984 (diff)
Add migration publisher message in ACM runtime
Issue-ID: POLICY-4823 Change-Id: Id4480a0800e41ec8e2f0f9931a9a93752b2ef952 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/main')
-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
6 files changed, 122 insertions, 42 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