2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018-2019 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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
24 import java.net.MalformedURLException;
27 import org.onap.policy.common.endpoints.event.comm.Topic;
28 import org.onap.policy.common.endpoints.event.comm.bus.DmaapTopicSource;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * This topic reader implementation specializes in reading messages over DMAAP topic and notifying
36 public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource implements DmaapTopicSource, Runnable {
38 private static Logger logger = LoggerFactory.getLogger(SingleThreadedDmaapTopicSource.class);
41 protected final String userName;
42 protected final String password;
44 protected String environment = null;
45 protected String aftEnvironment = null;
46 protected String partner = null;
47 protected String latitude = null;
48 protected String longitude = null;
50 protected Map<String, String> additionalProps = null;
56 * @param busTopicParams Parameters object containing all the required inputs
58 * @throws IllegalArgumentException An invalid parameter passed in
60 public SingleThreadedDmaapTopicSource(BusTopicParams busTopicParams) {
62 super(busTopicParams);
64 this.userName = busTopicParams.getUserName();
65 this.password = busTopicParams.getPassword();
67 this.environment = busTopicParams.getEnvironment();
68 this.aftEnvironment = busTopicParams.getAftEnvironment();
69 this.partner = busTopicParams.getPartner();
71 this.latitude = busTopicParams.getLatitude();
72 this.longitude = busTopicParams.getLongitude();
74 this.additionalProps = busTopicParams.getAdditionalProps();
77 } catch (Exception e) {
78 throw new IllegalArgumentException("ERROR during init in dmaap-source: cannot create topic " + topic, e);
84 * Initialize the Cambria or MR Client.
87 public void init() throws MalformedURLException {
88 BusTopicParams.TopicParamsBuilder builder = BusTopicParams.builder()
89 .servers(this.servers)
90 .topic(this.effectiveTopic)
92 .apiSecret(this.apiSecret)
93 .consumerGroup(this.consumerGroup)
94 .consumerInstance(this.consumerInstance)
95 .fetchTimeout(this.fetchTimeout)
96 .fetchLimit(this.fetchLimit)
97 .useHttps(this.useHttps);
99 if (anyNullOrEmpty(this.userName, this.password)) {
100 this.consumer = new BusConsumer.CambriaConsumerWrapper(builder
101 .allowSelfSignedCerts(this.allowSelfSignedCerts)
103 } else if (allNullOrEmpty(this.environment, this.aftEnvironment, this.latitude, this.longitude, this.partner)) {
104 this.consumer = new BusConsumer.CambriaConsumerWrapper(builder
105 .userName(this.userName)
106 .password(this.password)
107 .allowSelfSignedCerts(this.allowSelfSignedCerts)
110 this.consumer = new BusConsumer.DmaapDmeConsumerWrapper(builder
111 .userName(this.userName)
112 .password(this.password)
113 .environment(this.environment)
114 .aftEnvironment(this.aftEnvironment)
115 .partner(this.partner)
116 .latitude(this.latitude)
117 .longitude(this.longitude)
118 .additionalProps(this.additionalProps)
122 logger.info("{}: INITTED", this);
126 public CommInfrastructure getTopicCommInfrastructure() {
127 return Topic.CommInfrastructure.DMAAP;
131 public String toString() {
132 StringBuilder builder = new StringBuilder();
133 builder.append("SingleThreadedDmaapTopicSource [userName=").append(userName).append(", password=")
134 .append((password == null || password.isEmpty()) ? "-" : password.length())
135 .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()).append(", toString()=")
136 .append(super.toString()).append("]");
137 return builder.toString();