a78dd0fcb6b6c9e2e9f8ecf900b3b6828cc83f17
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.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.openecomp.policy.drools.event.comm.Topic;
29 import org.openecomp.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                         throws IllegalArgumentException {
80                         
81                 super(servers, topic, apiKey, apiSecret, partitionKey, useHttps, allowSelfSignedCerts);
82                 
83                 this.userName = userName;
84                 this.password = password;
85                 
86                 this.environment = environment;
87                 this.aftEnvironment = aftEnvironment;
88                 this.partner = partner;
89                 
90                 this.latitude = latitude;
91                 this.longitude = longitude;
92                 
93                 this.additionalProps = additionalProps;
94                 
95                 this.init();
96         }
97         
98         public InlineDmaapTopicSink(List<String> servers, String topic, 
99                                             String apiKey, String apiSecret,
100                                     String userName, String password,
101                                             String partitionKey, boolean useHttps,  boolean allowSelfSignedCerts) 
102                 throws IllegalArgumentException {
103                 
104                 super(servers, topic, apiKey, apiSecret, partitionKey, useHttps, allowSelfSignedCerts);
105                 
106                 this.userName = userName;
107                 this.password = password;
108         }
109         
110
111         @Override
112         public void init() {
113                 if ((this.environment == null   || this.environment.isEmpty()) &&
114                    (this.aftEnvironment == null || this.aftEnvironment.isEmpty()) &&
115                    (this.latitude == null               || this.latitude.isEmpty()) &&
116                    (this.longitude == null              || this.longitude.isEmpty()) &&
117                    (this.partner == null                || this.partner.isEmpty())) {
118                         this.publisher = 
119                                 new BusPublisher.DmaapAafPublisherWrapper(this.servers, 
120                                                                                this.topic, 
121                                                                                this.userName, 
122                                                                                this.password, this.useHttps);
123                 } else {
124                         this.publisher = 
125                                 new BusPublisher.DmaapDmePublisherWrapper(this.servers, this.topic, 
126                                                                                this.userName, this.password,
127                                                                                this.environment, this.aftEnvironment,
128                                                                                this.partner, this.latitude, this.longitude,
129                                                                                this.additionalProps, this.useHttps);
130                 }
131                 
132                 logger.info("{}: DMAAP SINK created", this);
133         }
134
135         /**
136          * {@inheritDoc}
137          */
138         @Override
139         public CommInfrastructure getTopicCommInfrastructure() {
140                 return Topic.CommInfrastructure.DMAAP;
141         }
142
143
144         @Override
145         public String toString() {
146                 StringBuilder builder = new StringBuilder();
147                 builder.append("InlineDmaapTopicSink [userName=").append(userName).append(", password=").append(password)
148                                 .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()).append(", toString()=")
149                                 .append(super.toString()).append("]");
150                 return builder.toString();
151         }
152
153 }