8d40c5e69822307e9c42e1a3345aa0136a5200dd
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2021 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.controlloop.runtime.supervision.comm;
22
23 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
24 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
25 import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
26 import org.onap.policy.models.base.PfModelException;
27 import org.springframework.stereotype.Component;
28
29 /**
30  * This class is used to send ParticipantControlLoopUpdate messages to participants on DMaaP.
31  */
32 @Component
33 public class ParticipantControlLoopUpdatePublisher extends AbstractParticipantPublisher<ParticipantControlLoopUpdate> {
34
35     private final CommissioningProvider commissioningProvider;
36
37     /**
38      * Constructor.
39      *
40      * @param commissioningProvider the CommissioningProvider
41      */
42     public ParticipantControlLoopUpdatePublisher(CommissioningProvider commissioningProvider) {
43         this.commissioningProvider = commissioningProvider;
44     }
45
46     /**
47      * Send ControlLoopUpdate to Participant.
48      *
49      * @param controlLoop the ControlLoop
50      * @throws PfModelException on errors getting the Control Loop Definition
51      */
52     public void send(ControlLoop controlLoop) throws PfModelException {
53         var pclu = new ParticipantControlLoopUpdate();
54         pclu.setControlLoopId(controlLoop.getKey().asIdentifier());
55         pclu.setControlLoop(controlLoop);
56         // TODO: We should look up the correct TOSCA node template here for the control loop
57         // Tiny hack implemented to return the tosca service template entry from the database and be passed onto dmaap
58         pclu.setControlLoopDefinition(commissioningProvider.getToscaServiceTemplate(null, null));
59         super.send(pclu);
60     }
61 }