3fe46a928cc56b5d43cf77e8f0a93d965ed960fa
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-2024 Nordix Foundation.
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.time.Instant;
25 import java.util.List;
26 import java.util.UUID;
27 import lombok.AllArgsConstructor;
28 import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
29 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
31 import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
32 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRestart;
33 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.stereotype.Component;
37
38 @Component
39 @AllArgsConstructor
40 public class ParticipantRestartPublisher extends AbstractParticipantPublisher<ParticipantRestart> {
41
42     private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantRestartPublisher.class);
43     private final AcRuntimeParameterGroup acRuntimeParameterGroup;
44
45     /**
46      * Send Restart to Participant.
47      *
48      * @param participantId the ParticipantId
49      * @param acmDefinition the AutomationComposition Definition
50      * @param automationCompositions the list of automationCompositions
51      */
52     @Timed(value = "publisher.participant_restart", description = "Participant Restart published")
53     public void send(UUID participantId, AutomationCompositionDefinition acmDefinition,
54             List<AutomationComposition> automationCompositions) {
55
56         var message = new ParticipantRestart();
57         message.setParticipantId(participantId);
58         message.setCompositionId(acmDefinition.getCompositionId());
59         message.setMessageId(UUID.randomUUID());
60         message.setTimestamp(Instant.now());
61         message.setState(acmDefinition.getState());
62         message.setParticipantDefinitionUpdates(
63                 AcmUtils.prepareParticipantRestarting(participantId, acmDefinition,
64                         acRuntimeParameterGroup.getAcmParameters().getToscaElementName()));
65         var toscaServiceTemplateFragment = AcmUtils.getToscaServiceTemplateFragment(acmDefinition.getServiceTemplate());
66
67         for (var automationComposition : automationCompositions) {
68             var restartAc = AcmUtils
69                     .createAcRestart(automationComposition, participantId, toscaServiceTemplateFragment);
70             message.getAutomationcompositionList().add(restartAc);
71         }
72
73         LOGGER.debug("Participant Restart sent {}", message);
74         super.send(message);
75     }
76 }