a7a692de8f74d435e99736d95e6295a27239c299
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
6  * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
23
24 import java.util.Map;
25 import org.onap.policy.common.endpoints.event.comm.Topic;
26 import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicSink;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * This implementation publishes events for the associated DMAAP topic, inline with the calling
32  * thread.
33  */
34 public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTopicSink {
35
36     protected static Logger logger = LoggerFactory.getLogger(InlineDmaapTopicSink.class);
37
38     protected final String userName;
39     protected final String password;
40
41     protected String environment = null;
42     protected String aftEnvironment = null;
43     protected String partner = null;
44     protected String latitude = null;
45     protected String longitude = null;
46
47     protected Map<String, String> additionalProps = null;
48
49     /**
50      * BusTopicParams contains the below mentioned attributes.
51      * servers              DMaaP servers
52      * topic                DMaaP Topic to be monitored
53      * apiKey               DMaaP API Key (optional)
54      * apiSecret            DMaaP API Secret (optional)
55      * environment          DME2 Environment
56      * aftEnvironment       DME2 AFT Environment
57      * partner              DME2 Partner
58      * latitude             DME2 Latitude
59      * longitude            DME2 Longitude
60      * additionalProps      Additional properties to pass to DME2
61      * useHttps             does connection use HTTPS?
62      * allowSelfSignedCerts are self-signed certificates allow
63      * @param busTopicParams Contains the above mentioned parameters
64      * @throws IllegalArgumentException An invalid parameter passed in
65      */
66     public InlineDmaapTopicSink(BusTopicParams busTopicParams) {
67
68         super(busTopicParams);
69
70         this.userName = busTopicParams.getUserName();
71         this.password = busTopicParams.getPassword();
72
73         this.environment = busTopicParams.getEnvironment();
74         this.aftEnvironment = busTopicParams.getAftEnvironment();
75         this.partner = busTopicParams.getPartner();
76
77         this.latitude = busTopicParams.getLatitude();
78         this.longitude = busTopicParams.getLongitude();
79
80         this.additionalProps = busTopicParams.getAdditionalProps();
81     }
82
83
84     @Override
85     public void init() {
86         if (allNullOrEmpty(this.environment, this.aftEnvironment, this.latitude, this.longitude, this.partner)) {
87             this.publisher = new BusPublisher.CambriaPublisherWrapper(BusTopicParams.builder()
88                     .servers(this.servers)
89                     .topic(this.effectiveTopic)
90                     .apiKey(this.apiKey)
91                     .apiSecret(this.apiSecret)
92                     .userName(this.userName)
93                     .password(this.password)
94                     .useHttps(this.useHttps)
95                     .allowSelfSignedCerts(this.allowSelfSignedCerts)
96                     .build());
97         } else {
98             this.publisher = new BusPublisher.DmaapDmePublisherWrapper(BusTopicParams.builder()
99                     .servers(this.servers)
100                     .topic(this.effectiveTopic)
101                     .userName(this.userName)
102                     .password(this.password)
103                     .environment(this.environment)
104                     .aftEnvironment(this.aftEnvironment)
105                     .partner(this.partner)
106                     .latitude(this.latitude)
107                     .longitude(this.longitude)
108                     .additionalProps(this.additionalProps)
109                     .useHttps(this.useHttps)
110                     .build());
111         }
112
113         logger.info("{}: DMAAP SINK created", this);
114     }
115
116     @Override
117     public CommInfrastructure getTopicCommInfrastructure() {
118         return Topic.CommInfrastructure.DMAAP;
119     }
120
121
122     @Override
123     public String toString() {
124         return "InlineDmaapTopicSink [userName=" + userName + ", password=" + password
125                 + ", getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()=" + super.toString()
126                 + "]";
127     }
128
129 }