Standalone TCA with EELF Logger
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / main / java / org / onap / dcae / analytics / web / dmaap / MrSubscriberPreferences.java
1 /*
2  * ================================================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  *
18  */
19
20 package org.onap.dcae.analytics.web.dmaap;
21
22 import lombok.EqualsAndHashCode;
23 import lombok.Getter;
24 import lombok.ToString;
25
26 import java.net.URL;
27 import java.util.List;
28
29 import javax.annotation.Nonnull;
30 import javax.annotation.Nullable;
31
32 import org.onap.dcae.analytics.model.DmaapMrConstants;
33 import org.onap.dcae.analytics.web.http.BaseHttpClientPreferences;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.http.HttpHeaders;
37
38 /**
39  * DMaaP MR Subscriber config
40  *
41  * @author Rajiv Singla
42  */
43 @Getter
44 @ToString(callSuper = true)
45 @EqualsAndHashCode(callSuper = true)
46 public class MrSubscriberPreferences extends BaseHttpClientPreferences {
47
48     private static final long serialVersionUID = 1L;
49
50     private static final Logger logger = LoggerFactory.getLogger(MrSubscriberPreferences.class);
51
52     private String consumerGroup;
53     private List<String> consumerIds;
54     private Integer messageLimit;
55     private Integer timeout;
56     private MrSubscriberPollingPreferences pollingPreferences;
57
58     public MrSubscriberPreferences(@Nonnull final String requestURL) {
59         super(requestURL);
60     }
61
62     public MrSubscriberPreferences(@Nonnull final String requestURL,
63                                    @Nullable final String httpClientId,
64                                    @Nullable final HttpHeaders httpHeaders,
65                                    @Nullable final String username,
66                                    @Nullable final String password,
67                                    @Nullable final URL proxyURL,
68                                    @Nullable final Boolean ignoreSSLValidation,
69                                    @Nullable final Boolean enableEcompAuditLogging,
70                                    @Nullable final String consumerGroup,
71                                    @Nullable final List<String> consumerIds,
72                                    @Nullable final Integer messageLimit,
73                                    @Nullable final Integer timeout,
74                                    @Nullable final MrSubscriberPollingPreferences pollingPreferences) {
75         super(requestURL, httpClientId, httpHeaders, username, password, proxyURL,
76                 ignoreSSLValidation, enableEcompAuditLogging);
77         this.consumerGroup = consumerGroup;
78         this.consumerIds = consumerIds;
79         this.messageLimit = messageLimit;
80         this.timeout = timeout;
81         this.pollingPreferences = pollingPreferences;
82     }
83
84
85     public MrSubscriberPollingPreferences getPollingPreferences() {
86         if (pollingPreferences == null) {
87             logger.warn("DMaaP MR Subscriber Polling details are missing. " +
88                             "Fixed polling rate will be used by default with polling interval: {}",
89                     DmaapMrConstants.SUBSCRIBER_DEFAULT_FIXED_POLLING_INTERVAL);
90             setFixedPollingRate(DmaapMrConstants.SUBSCRIBER_DEFAULT_FIXED_POLLING_INTERVAL);
91         }
92         return pollingPreferences;
93     }
94
95     private void setFixedPollingRate(final int fixedPollingInterval) {
96         this.pollingPreferences =
97                 new MrSubscriberPollingPreferences(fixedPollingInterval, 0, fixedPollingInterval, 0);
98     }
99
100 }