2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.dmaap.domain.config;
\r
23 import com.google.common.base.Objects;
\r
24 import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
\r
26 import javax.annotation.Nonnull;
\r
30 * Immutable DMaaP MR Configuration for DMaaP MR Publisher.
\r
32 * Use {@link DMaaPMRPublisherConfig.Builder} to construct Subscriber Configuration
\r
35 * @author Rajiv Singla . Creation Date: 10/12/2016.
\r
37 public class DMaaPMRPublisherConfig extends DMaaPMRBaseConfig {
\r
40 * Publisher batching queue size
\r
42 private int maxBatchSize;
\r
45 * Publisher Recovery Queue Size
\r
47 private int maxRecoveryQueueSize;
\r
50 private DMaaPMRPublisherConfig(@Nonnull String hostName,
\r
51 @Nonnull Integer portNumber,
\r
52 @Nonnull String topicName,
\r
53 @Nonnull String protocol,
\r
55 String userPassword,
\r
56 @Nonnull String contentType,
\r
58 int maxRecoveryQueueSize) {
\r
59 this.hostName = hostName;
\r
60 this.portNumber = portNumber;
\r
61 this.topicName = topicName;
\r
62 this.protocol = protocol;
\r
63 this.userName = userName;
\r
64 this.userPassword = userPassword;
\r
65 this.contentType = contentType;
\r
66 this.maxBatchSize = maxBatchSize;
\r
67 this.maxRecoveryQueueSize = maxRecoveryQueueSize;
\r
72 * Builder to initialize immutable {@link DMaaPMRPublisherConfig} object
\r
74 public static class Builder {
\r
76 private String hostName;
\r
77 private Integer portNumber;
\r
78 private String topicName;
\r
79 private String userName;
\r
80 private String userPassword;
\r
81 private String protocol;
\r
82 private String contentType;
\r
83 private int maxBatchSize;
\r
84 private int maxRecoveryQueueSize;
\r
86 public Builder(@Nonnull String hostName, @Nonnull String topicName) {
\r
88 this.hostName = hostName;
\r
89 this.topicName = topicName;
\r
91 this.portNumber = AnalyticsConstants.DEFAULT_PORT_NUMBER;
\r
92 this.userName = AnalyticsConstants.DEFAULT_USER_NAME;
\r
93 this.userPassword = AnalyticsConstants.DEFAULT_USER_PASSWORD;
\r
94 this.protocol = AnalyticsConstants.DEFAULT_PROTOCOL;
\r
95 this.contentType = AnalyticsConstants.DEFAULT_CONTENT_TYPE;
\r
96 this.maxBatchSize = AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE;
\r
97 this.maxRecoveryQueueSize = AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE;
\r
101 * Setup for custom host port number - Defaults to 80.
\r
103 * @param portNumber custom port number
\r
104 * @return Builder object itself for chaining
\r
106 public Builder setPortNumber(@Nonnull Integer portNumber) {
\r
107 this.portNumber = portNumber;
\r
113 * Setup user name for authentication. If no username is provided authentication will be disabled
\r
115 * @param userName user name for DMaaP Topic Authentication
\r
116 * @return Builder object itself for chaining
\r
118 public Builder setUserName(@Nonnull String userName) {
\r
119 this.userName = userName;
\r
125 * Setup user password for authentication. If no password is provided authentication will be disabled
\r
127 * @param userPassword user password for DMaaP Topic Authentication
\r
128 * @return Builder object itself for chaining
\r
130 public Builder setUserPassword(@Nonnull String userPassword) {
\r
131 this.userPassword = userPassword;
\r
137 * Setup custom Publisher protocol - Defaults to https.
\r
138 * Note: Only http and https are currently supported.
\r
140 * @param protocol protocol e.g. https
\r
141 * @return Builder object itself for chaining
\r
143 public Builder setProtocol(@Nonnull String protocol) {
\r
144 this.protocol = normalizeValidateProtocol(protocol);
\r
150 * Setup custom Publisher content-type - Defaults to application/json
\r
152 * @param contentType content type e.g. application/json
\r
153 * @return Builder object itself for chaining
\r
155 public Builder setContentType(@Nonnull String contentType) {
\r
156 final String normalizedContentType = normalizeValidateContentType(contentType);
\r
157 this.contentType = normalizedContentType;
\r
163 * Setup custom Publisher Max Batch Size - Defaults to 100
\r
165 * @param maxBatchSize max Batch Size
\r
166 * @return Builder object itself for chaining
\r
168 public Builder setMaxBatchSize(int maxBatchSize) {
\r
169 this.maxBatchSize = maxBatchSize;
\r
175 * Setup custom Maximum Recovery Queue Size. Recovery Queue is used to hold messages temporarily in case
\r
176 * DMaaP MR Publisher topic is not responding for any reason. Defaults to 100,000
\r
178 * @param maxRecoveryQueueSize max recovery queue size
\r
179 * @return Builder object itself for chaining
\r
181 public Builder setMaxRecoveryQueueSize(int maxRecoveryQueueSize) {
\r
182 this.maxRecoveryQueueSize = maxRecoveryQueueSize;
\r
187 * Creates immutable instance of {@link DMaaPMRPublisherConfig}
\r
189 * @return Builds and returns thread safe, immutable {@link DMaaPMRPublisherConfig} object
\r
191 public DMaaPMRPublisherConfig build() {
\r
192 return new DMaaPMRPublisherConfig(hostName, portNumber, topicName, protocol, userName, userPassword,
\r
193 contentType, maxBatchSize, maxRecoveryQueueSize);
\r
200 * Returns max Publisher Batch Queue Size
\r
202 * @return max Publisher Batch Queue size
\r
204 public int getMaxBatchSize() {
\r
205 return maxBatchSize;
\r
209 * Returns max Publisher Recovery Queue Size
\r
211 * @return max Recovery Queue size
\r
213 public int getMaxRecoveryQueueSize() {
\r
214 return maxRecoveryQueueSize;
\r
219 public boolean equals(Object o) {
\r
223 if (o == null || getClass() != o.getClass()) {
\r
226 if (!super.equals(o)) {
\r
229 DMaaPMRPublisherConfig that = (DMaaPMRPublisherConfig) o;
\r
230 return maxBatchSize == that.maxBatchSize &&
\r
231 maxRecoveryQueueSize == that.maxRecoveryQueueSize;
\r
235 public int hashCode() {
\r
236 return Objects.hashCode(super.hashCode(), maxBatchSize, maxRecoveryQueueSize);
\r
241 public String toString() {
\r
242 return Objects.toStringHelper(this)
\r
243 .add("baseConfig", super.toString())
\r
244 .add("maxBatchSize", maxBatchSize)
\r
245 .add("maxRecoveryQueueSize", maxRecoveryQueueSize)
\r