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