29fbf1d5fc629537b1b5abdc9f65d5d47d7286c9
[policy/common.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.common.endpoints.event.comm.bus.internal.impl;
22
23 import com.att.nsa.mr.client.impl.MRConsumerImpl;
24 import com.att.nsa.mr.test.clients.ProtocolTypeConstants;
25
26 import java.net.MalformedURLException;
27 import java.util.List;
28 import java.util.Properties;
29
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * MR based consumer
35  */
36 public class DmaapAafConsumerWrapper extends DmaapConsumerWrapper {
37
38     private static Logger logger = LoggerFactory.getLogger(DmaapAafConsumerWrapper.class);
39
40     private final Properties props;
41
42     /**
43      * MR Consumer Wrapper
44      *
45      * @param servers messaging bus hosts
46      * @param topic topic
47      * @param apiKey API Key
48      * @param apiSecret API Secret
49      * @param aafLogin AAF Login
50      * @param aafPassword AAF Password
51      * @param consumerGroup Consumer Group
52      * @param consumerInstance Consumer Instance
53      * @param fetchTimeout Fetch Timeout
54      * @param fetchLimit Fetch Limit
55      * @throws MalformedURLException
56      */
57     public DmaapAafConsumerWrapper(List<String> servers, String topic, String apiKey, String apiSecret, String aafLogin,
58             String aafPassword, String consumerGroup, String consumerInstance, int fetchTimeout, int fetchLimit,
59             boolean useHttps) throws MalformedURLException {
60
61         super(servers, topic, apiKey, apiSecret, aafLogin, aafPassword, consumerGroup, consumerInstance, fetchTimeout,
62                 fetchLimit);
63
64         // super constructor sets servers = {""} if empty to avoid errors when using DME2
65         if ((servers.size() == 1 && ("".equals(servers.get(0)))) || (servers == null) || (servers.isEmpty())) {
66             throw new IllegalArgumentException("Must provide at least one host for HTTP AAF");
67         }
68
69         this.consumer.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
70
71         props = new Properties();
72
73         if (useHttps) {
74             props.setProperty(PROTOCOL_PROP, "https");
75             this.consumer.setHost(servers.get(0) + ":3905");
76
77         } else {
78             props.setProperty(PROTOCOL_PROP, "http");
79             this.consumer.setHost(servers.get(0) + ":3904");
80         }
81
82         this.consumer.setProps(props);
83         logger.info("{}: CREATION", this);
84     }
85
86     @Override
87     public String toString() {
88         final MRConsumerImpl consumer = this.consumer;
89
90         return "DmaapConsumerWrapper [" + "consumer.getAuthDate()=" + consumer.getAuthDate()
91                 + ", consumer.getAuthKey()=" + consumer.getAuthKey() + ", consumer.getHost()=" + consumer.getHost()
92                 + ", consumer.getProtocolFlag()=" + consumer.getProtocolFlag() + ", consumer.getUsername()="
93                 + consumer.getUsername() + "]";
94     }
95 }