2  * ============LICENSE_START=======================================================
 
   3  * Copyright (C) 2021,2022 Nordix Foundation.
 
   4  * ================================================================================
 
   5  * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  19  * SPDX-License-Identifier: Apache-2.0
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.policy.clamp.acm.runtime.supervision.comm;
 
  25 import io.micrometer.core.annotation.Timed;
 
  26 import java.time.Instant;
 
  27 import java.util.ArrayList;
 
  28 import java.util.List;
 
  29 import java.util.UUID;
 
  30 import lombok.AllArgsConstructor;
 
  31 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
 
  32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
 
  33 import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
 
  34 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate;
 
  35 import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
 
  36 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
 
  37 import org.slf4j.Logger;
 
  38 import org.slf4j.LoggerFactory;
 
  39 import org.springframework.stereotype.Component;
 
  42  * This class is used to send AutomationCompositionUpdate messages to participants on DMaaP.
 
  46 public class AutomationCompositionUpdatePublisher extends AbstractParticipantPublisher<AutomationCompositionUpdate> {
 
  48     private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionUpdatePublisher.class);
 
  49     private final AcDefinitionProvider acDefinitionProvider;
 
  52      * Send AutomationCompositionUpdate to Participant.
 
  54      * @param automationComposition the AutomationComposition
 
  56     @Timed(value = "publisher.automation_composition_update",
 
  57             description = "AUTOMATION_COMPOSITION_UPDATE messages published")
 
  58     public void send(AutomationComposition automationComposition) {
 
  59         send(automationComposition, 0);
 
  63      * Send AutomationCompositionUpdate to Participant.
 
  65      * @param automationComposition the AutomationComposition
 
  66      * @param startPhase the Start Phase
 
  68     @Timed(value = "publisher.automation_composition_update",
 
  69             description = "AUTOMATION_COMPOSITION_UPDATE messages published")
 
  70     public void send(AutomationComposition automationComposition, int startPhase) {
 
  71         var automationCompositionUpdateMsg = new AutomationCompositionUpdate();
 
  72         automationCompositionUpdateMsg.setStartPhase(startPhase);
 
  73         automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getInstanceId());
 
  74         automationCompositionUpdateMsg.setMessageId(UUID.randomUUID());
 
  75         automationCompositionUpdateMsg.setTimestamp(Instant.now());
 
  76         var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
 
  78         List<ParticipantUpdates> participantUpdates = new ArrayList<>();
 
  79         for (AutomationCompositionElement element : automationComposition.getElements().values()) {
 
  80             AcmUtils.setAcPolicyInfo(element, toscaServiceTemplate);
 
  81             AcmUtils.prepareParticipantUpdate(element, participantUpdates);
 
  83         automationCompositionUpdateMsg.setParticipantUpdatesList(participantUpdates);
 
  85         LOGGER.debug("AutomationCompositionUpdate message sent {}", automationCompositionUpdateMsg);
 
  86         super.send(automationCompositionUpdateMsg);