48116e3450b3d436474aa0a983c36232242e6901
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.event.comm.bus.internal;
22
23 import java.util.List;
24 import java.util.Map;
25
26 import org.slf4j.LoggerFactory;
27 import org.slf4j.Logger;
28 import org.onap.policy.drools.event.comm.Topic;
29 import org.onap.policy.drools.event.comm.bus.DmaapTopicSink;
30
31 /**
32  * This implementation publishes events for the associated DMAAP topic,
33  * inline with the calling thread.
34  */
35 public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTopicSink {
36         
37         protected static Logger logger = 
38                         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          * 
53          * @param servers DMaaP servers
54          * @param topic DMaaP Topic to be monitored
55          * @param apiKey DMaaP API Key (optional)
56          * @param apiSecret DMaaP API Secret (optional)
57          * @param consumerGroup DMaaP Reader Consumer Group
58          * @param consumerInstance DMaaP Reader Instance
59          * @param fetchTimeout DMaaP fetch timeout
60          * @param fetchLimit DMaaP fetch limit
61          * @param environment DME2 Environment
62          * @param aftEnvironment DME2 AFT Environment
63          * @param partner DME2 Partner
64          * @param latitude DME2 Latitude
65          * @param longitude DME2 Longitude
66          * @param additionalProps Additional properties to pass to DME2
67          * @param useHttps does connection use HTTPS?
68          * @param allowSelfSignedCerts are self-signed certificates allow
69          * 
70          * @throws IllegalArgumentException An invalid parameter passed in
71          */
72         public InlineDmaapTopicSink(List<String> servers, String topic, 
73                                                                                         String apiKey, String apiSecret,
74                                                                                         String userName, String password,
75                                                                                         String partitionKey,
76                                                                                         String environment, String aftEnvironment, String partner,
77                                                                                         String latitude, String longitude, Map<String,String> additionalProps,
78                                                                                         boolean useHttps, boolean allowSelfSignedCerts) {
79                         
80                 super(servers, topic, apiKey, apiSecret, partitionKey, useHttps, allowSelfSignedCerts);
81                 
82                 this.userName = userName;
83                 this.password = password;
84                 
85                 this.environment = environment;
86                 this.aftEnvironment = aftEnvironment;
87                 this.partner = partner;
88                 
89                 this.latitude = latitude;
90                 this.longitude = longitude;
91                 
92                 this.additionalProps = additionalProps;
93         }
94         
95         public InlineDmaapTopicSink(List<String> servers, String topic, 
96                                             String apiKey, String apiSecret,
97                                     String userName, String password,
98                                             String partitionKey, boolean useHttps,  boolean allowSelfSignedCerts) {
99                 
100                 super(servers, topic, apiKey, apiSecret, partitionKey, useHttps, allowSelfSignedCerts);
101                 
102                 this.userName = userName;
103                 this.password = password;
104         }
105         
106
107         @Override
108         public void init() {
109                 if (allNullOrEmpty(this.environment, this.aftEnvironment, this.latitude, this.longitude, this.partner)) {
110                         this.publisher = 
111                                 new BusPublisher.CambriaPublisherWrapper(this.servers, 
112                                                                                this.topic, 
113                                                                                this.apiKey, this.apiSecret,
114                                                                                this.userName, this.password,
115                                                                                this.useHttps);
116                 } else {
117                         this.publisher = 
118                                 new BusPublisher.DmaapDmePublisherWrapper(this.servers, this.topic, 
119                                                                                this.userName, this.password,
120                                                                                this.environment, this.aftEnvironment,
121                                                                                this.partner, this.latitude, this.longitude,
122                                                                                this.additionalProps, this.useHttps);
123                 }
124                 
125                 logger.info("{}: DMAAP SINK created", this);
126         }
127
128         /**
129          * {@inheritDoc}
130          */
131         @Override
132         public CommInfrastructure getTopicCommInfrastructure() {
133                 return Topic.CommInfrastructure.DMAAP;
134         }
135
136
137         @Override
138         public String toString() {
139         return "InlineDmaapTopicSink [userName=" + userName + ", password=" + password
140                         + ", getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()="
141                         + super.toString() + "]";
142         }
143
144 }