01531055c07447deb692536884a8a2bcdb5f3098
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2017-2018 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
26 import org.onap.policy.common.endpoints.event.comm.Topic;
27 import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicSink;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * This implementation publishes events for the associated DMAAP topic, inline with the calling
33  * thread.
34  */
35 public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTopicSink {
36
37     protected static Logger logger = LoggerFactory.getLogger(InlineDmaapTopicSink.class);
38
39     protected final String userName;
40     protected final String password;
41
42     protected String environment = null;
43     protected String aftEnvironment = null;
44     protected String partner = null;
45     protected String latitude = null;
46     protected String longitude = null;
47
48     protected Map<String, String> additionalProps = null;
49
50     /**
51      * BusTopicParams contains the below mentioned attributes.
52      * servers              DMaaP servers
53      * topic                DMaaP Topic to be monitored
54      * apiKey               DMaaP API Key (optional)
55      * apiSecret            DMaaP API Secret (optional)
56      * environment          DME2 Environment
57      * aftEnvironment       DME2 AFT Environment
58      * partner              DME2 Partner
59      * latitude             DME2 Latitude
60      * longitude            DME2 Longitude
61      * additionalProps      Additional properties to pass to DME2
62      * useHttps             does connection use HTTPS?
63      * allowSelfSignedCerts are self-signed certificates allow
64      * @param busTopicParams Contains the above mentioned parameters
65      * @throws IllegalArgumentException An invalid parameter passed in
66      */
67     public InlineDmaapTopicSink(BusTopicParams busTopicParams) {
68
69         super(busTopicParams);
70
71         this.userName = busTopicParams.getUserName();
72         this.password = busTopicParams.getPassword();
73
74         this.environment = busTopicParams.getEnvironment();
75         this.aftEnvironment = busTopicParams.getAftEnvironment();
76         this.partner = busTopicParams.getPartner();
77
78         this.latitude = busTopicParams.getLatitude();
79         this.longitude = busTopicParams.getLongitude();
80
81         this.additionalProps = busTopicParams.getAdditionalProps();
82     }
83
84
85     @Override
86     public void init() {
87         if (allNullOrEmpty(this.environment, this.aftEnvironment, this.latitude, this.longitude, this.partner)) {
88             this.publisher = new BusPublisher.CambriaPublisherWrapper(BusTopicParams.builder()
89                     .servers(this.servers)
90                     .topic(this.topic)
91                     .apiKey(this.apiKey)
92                     .apiSecret(this.apiSecret)
93                     .userName(this.userName)
94                     .password(this.password)
95                     .useHttps(this.useHttps)
96                     .allowSelfSignedCerts(this.allowSelfSignedCerts)
97                     .build());
98         } else {
99             this.publisher = new BusPublisher.DmaapDmePublisherWrapper(BusTopicParams.builder()
100                     .servers(this.servers)
101                     .topic(this.topic)
102                     .userName(this.userName)
103                     .password(this.password)
104                     .environment(this.environment)
105                     .aftEnvironment(this.aftEnvironment)
106                     .partner(this.partner)
107                     .latitude(this.latitude)
108                     .longitude(this.longitude)
109                     .additionalProps(this.additionalProps)
110                     .useHttps(this.useHttps)
111                     .build());
112         }
113
114         logger.info("{}: DMAAP SINK created", this);
115     }
116
117     @Override
118     public CommInfrastructure getTopicCommInfrastructure() {
119         return Topic.CommInfrastructure.DMAAP;
120     }
121
122
123     @Override
124     public String toString() {
125         return "InlineDmaapTopicSink [userName=" + userName + ", password=" + password
126                 + ", getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()=" + super.toString()
127                 + "]";
128     }
129
130 }