56a62e13b9e9f53e930848172aab3e6ca8333396
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2021-2023 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.util.UUID;
25 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
26 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
27 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
28 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
29 import org.springframework.stereotype.Component;
30
31 /**
32  * This class is used to send AutomationCompositionStateChangePublisher messages to participants on DMaaP.
33  */
34 @Component
35 public class AutomationCompositionStateChangePublisher
36         extends AbstractParticipantPublisher<AutomationCompositionStateChange> {
37
38     /**
39      * Send undeploy message to to Participant.
40      *
41      * @param automationComposition the AutomationComposition
42      * @param startPhase the startPhase
43      */
44     @Timed(
45             value = "publisher.automation_composition_state_change",
46             description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
47     public void undeploy(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
48         send(automationComposition, startPhase, firstStartPhase, DeployOrder.UNDEPLOY, LockOrder.NONE);
49     }
50
51     /**
52      * Send unlock message to to Participant.
53      *
54      * @param automationComposition the AutomationComposition
55      * @param startPhase the startPhase
56      */
57     @Timed(
58             value = "publisher.automation_composition_state_change",
59             description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
60     public void unlock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
61         send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.UNLOCK);
62     }
63
64     /**
65      * Send lock message to to Participant.
66      *
67      * @param automationComposition the AutomationComposition
68      * @param startPhase the startPhase
69      */
70     @Timed(
71             value = "publisher.automation_composition_state_change",
72             description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
73     public void lock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
74         send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.LOCK);
75     }
76
77     /**
78      * Send undeploy message to to Participant.
79      *
80      * @param automationComposition the AutomationComposition
81      * @param startPhase the startPhase
82      * @param deployOrder the DeployOrder
83      * @param lockOrder the LockOrder
84      */
85     private void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase,
86             DeployOrder deployOrder, LockOrder lockOrder) {
87         var acsc = new AutomationCompositionStateChange();
88         acsc.setCompositionId(automationComposition.getCompositionId());
89         acsc.setAutomationCompositionId(automationComposition.getInstanceId());
90         acsc.setMessageId(UUID.randomUUID());
91         acsc.setDeployOrderedState(deployOrder);
92         acsc.setLockOrderedState(lockOrder);
93         acsc.setStartPhase(startPhase);
94         acsc.setFirstStartPhase(firstStartPhase);
95
96         super.send(acsc);
97     }
98
99     /**
100      * Send AutomationCompositionStateChange to Participant.
101      *
102      * @param automationComposition the AutomationComposition
103      * @param startPhase the startPhase
104      */
105     @Timed(
106             value = "publisher.automation_composition_state_change",
107             description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
108     public void send(AutomationComposition automationComposition, int startPhase) {
109         var acsc = new AutomationCompositionStateChange();
110         acsc.setCompositionId(automationComposition.getCompositionId());
111         acsc.setAutomationCompositionId(automationComposition.getInstanceId());
112         acsc.setMessageId(UUID.randomUUID());
113         acsc.setOrderedState(automationComposition.getOrderedState());
114         acsc.setStartPhase(startPhase);
115
116         super.send(acsc);
117     }
118 }