4917813990008d124e17c277ff3ee79a583aea2c
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.runtime.supervision.comm;
22
23 import io.micrometer.core.annotation.Timed;
24 import java.util.List;
25 import java.util.UUID;
26 import java.util.stream.Collectors;
27 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
28 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
29 import org.onap.policy.clamp.models.acm.concepts.DeployState;
30 import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
31 import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionMigration;
32 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
33 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
34 import org.springframework.stereotype.Component;
35
36 @Component
37 public class AutomationCompositionMigrationPublisher
38         extends AbstractParticipantPublisher<AutomationCompositionMigration> {
39
40     /**
41      * Send AutomationCompositionMigration message to Participant.
42      *
43      * @param automationComposition the AutomationComposition
44      * @param stage the stage to execute
45      * @param revisionIdComposition the last Update from Composition
46      * @param revisionIdCompositionTarget the last Update from Composition Target
47      */
48     @Timed(
49             value = "publisher.automation_composition_migration",
50             description = "AUTOMATION_COMPOSITION_MIGRATION messages published")
51     public void send(AutomationComposition automationComposition, int stage, UUID revisionIdComposition,
52                      UUID revisionIdCompositionTarget, List<AutomationCompositionElement> removedElements) {
53         var acMigration = new AutomationCompositionMigration();
54         acMigration.setRollback(DeployState.MIGRATION_REVERTING.equals(automationComposition.getDeployState()));
55         acMigration.setPrecheck(Boolean.TRUE.equals(automationComposition.getPrecheck()));
56         acMigration.setCompositionId(automationComposition.getCompositionId());
57         acMigration.setAutomationCompositionId(automationComposition.getInstanceId());
58         acMigration.setMessageId(UUID.randomUUID());
59         acMigration.setCompositionTargetId(automationComposition.getCompositionTargetId());
60         acMigration.setStage(stage);
61         acMigration.setRevisionIdInstance(automationComposition.getRevisionId());
62         acMigration.setRevisionIdComposition(revisionIdComposition);
63         acMigration.setRevisionIdCompositionTarget(revisionIdCompositionTarget);
64         var participantUpdatesList = AcmUtils.createParticipantDeployList(automationComposition, DeployOrder.MIGRATE,
65                 removedElements);
66         acMigration.setParticipantUpdatesList(participantUpdatesList);
67         acMigration.setParticipantIdList(participantUpdatesList.stream()
68                 .map(ParticipantDeploy::getParticipantId).collect(Collectors.toSet()));
69
70         super.send(acMigration);
71     }
72 }