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.exception.DCAEAnalyticsRuntimeException;
\r
25 import org.slf4j.Logger;
\r
26 import org.slf4j.LoggerFactory;
\r
28 import java.util.Locale;
\r
30 import static org.openecomp.dcae.apod.analytics.common.utils.HTTPUtils.JSON_APPLICATION_TYPE;
\r
34 * Contains common parameters for both DMaaP Message Router Publisher and Subscriber Configs
\r
36 * @author Rajiv Singla . Creation Date: 10/12/2016.
\r
38 public abstract class DMaaPMRBaseConfig implements DMaaPMRConfig {
\r
40 protected static final Logger LOG = LoggerFactory.getLogger(DMaaPMRBaseConfig.class);
\r
42 protected String hostName;
\r
43 protected Integer portNumber;
\r
44 protected String topicName;
\r
45 protected String protocol;
\r
46 protected String userName;
\r
47 protected String userPassword;
\r
48 protected String contentType;
\r
51 * Provides host name e.g. mrlocal-mtnjftle01.homer.com
\r
55 public String getHostName() {
\r
61 * Provides Port Number of DMaaP MR Topic Host. Defaults to 80
\r
63 * @return host port number
\r
65 public Integer getPortNumber() {
\r
70 * Provides topic name e.g. com.dcae.dmaap.mtnje2.DcaeTestVES
\r
72 * @return topic name
\r
74 public String getTopicName() {
\r
79 * Provides protocol type e.g. http or https
\r
81 * @return protocol type
\r
83 public String getProtocol() {
\r
88 * Provides content type e.g. application/json
\r
90 * @return content type
\r
92 public String getContentType() {
\r
98 * Provides User name for the DMaaP MR Topic authentication
\r
100 * @return user name
\r
102 public String getUserName() {
\r
107 * Provides User password for the DMaaP MR Topic authentication
\r
109 * @return user Password
\r
111 public String getUserPassword() {
\r
112 return userPassword;
\r
117 * Trims, adjusts casing and validates user input String for protocol selection
\r
119 * @param protocol - User input for protocol String
\r
120 * @return - network protocol e.g http or https
\r
122 protected static String normalizeValidateProtocol(final String protocol) {
\r
123 // validate that only http and https are supported protocols are Supported for DMaaP MR
\r
124 String normalizedProtocolString = protocol.trim().toLowerCase(Locale.ENGLISH);
\r
125 if (normalizedProtocolString.isEmpty() ||
\r
126 !("http".equals(normalizedProtocolString) || "https".equals(normalizedProtocolString))) {
\r
128 final String errorMessage =
\r
129 "Unsupported protocol selection. Only HTTPS and HTTPS are currently supported for DMaaP MR";
\r
131 throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage));
\r
133 return normalizedProtocolString;
\r
138 * Trims, adjust casing and validates content type is supported by DMaaP.
\r
140 * NOTE: DMaaP currently only support application/json content type
\r
142 * @param contentType content type that needs to checked for DMaaP MR support
\r
143 * @return true if content type is supported by DMaaP MR
\r
145 protected static String normalizeValidateContentType(final String contentType) {
\r
146 // Current DMaaP MR is only supporting "application/json" content type
\r
147 String normalizedContentType = contentType.trim().toLowerCase(Locale.ENGLISH);
\r
148 final boolean isSupported = contentType.equals(JSON_APPLICATION_TYPE);
\r
149 if (!isSupported) {
\r
150 final String errorMessage =
\r
151 "Unsupported content type selection. Only application/json is currently supported for DMaaP MR";
\r
153 throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, new IllegalArgumentException(errorMessage));
\r
155 return normalizedContentType;
\r
160 public boolean equals(Object o) {
\r
164 if (!(o instanceof DMaaPMRBaseConfig)) {
\r
167 DMaaPMRBaseConfig that = (DMaaPMRBaseConfig) o;
\r
168 return Objects.equal(hostName, that.hostName) &&
\r
169 Objects.equal(portNumber, that.portNumber) &&
\r
170 Objects.equal(topicName, that.topicName) &&
\r
171 Objects.equal(protocol, that.protocol) &&
\r
172 Objects.equal(userName, that.userName) &&
\r
173 Objects.equal(userPassword, that.userPassword) &&
\r
174 Objects.equal(contentType, that.contentType);
\r
178 public int hashCode() {
\r
179 return Objects.hashCode(hostName, portNumber, topicName, protocol, userName, userPassword, contentType);
\r
183 public String toString() {
\r
184 return Objects.toStringHelper(this)
\r
185 .add("hostName", hostName)
\r
186 .add("portNumber", portNumber)
\r
187 .add("topicName", topicName)
\r
188 .add("protocol", protocol)
\r
189 .add("userName", userName)
\r
190 .add("contentType", contentType)
\r