fix debug log
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / main / java / org / onap / dcae / analytics / web / dmaap / MrTriggerMessageProvider.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
23 import java.net.URL;
24 import java.util.List;
25 import java.util.function.Supplier;
26
27 import org.onap.dcae.analytics.model.AnalyticsHttpConstants;
28 import org.onap.dcae.analytics.model.util.supplier.UnboundedSupplier;
29 import org.onap.dcae.analytics.tca.core.util.LogSpec;
30 import org.onap.dcae.analytics.web.util.AnalyticsWebUtils;
31 import org.onap.dcae.analytics.web.util.function.MrSubscriberURLFunction;
32 import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory;
33 import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger;
34 import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec;
35 import org.springframework.integration.support.MessageBuilder;
36 import org.springframework.messaging.Message;
37
38 /**
39  * Provides DMaaP MR Subscriber Trigger Message
40  *
41  * @author Rajiv Singla
42  */
43 public class MrTriggerMessageProvider {
44
45     private static final EELFLogger logger = EELFLogFactory.getLogger(MrTriggerMessageProvider.class);
46
47     public static final String TRIGGER_METHOD_NAME = "getTriggerMessage";
48
49     private final Supplier<URL> subscriberUrlSupplier;
50
51     public MrTriggerMessageProvider(final MrSubscriberPreferences subscriberPreferences) {
52         final List<URL> urls = new MrSubscriberURLFunction().apply(subscriberPreferences);
53         subscriberUrlSupplier = new UnboundedSupplier<>(urls.toArray(new URL[urls.size()]));
54     }
55
56     /**
57      * DMaaP MR subscriber trigger message
58      *
59      * @return dmaap mr subscriber trigger message
60      */
61     public Message<String> getTriggerMessage() {
62         final String requestId = AnalyticsWebUtils.REQUEST_ID_SUPPLIER.get();
63         final String transactionId = AnalyticsWebUtils.RANDOM_ID_SUPPLIER.get();
64         final String beginTimestamp = AnalyticsWebUtils.CREATION_TIMESTAMP_SUPPLIER.get();
65         final DebugLogSpec debugLogSpec = LogSpec.createDebugLogSpec(requestId);
66         logger.debugLog().debug("Request Id: {}. Transaction Id: {}. Begin TS: {}. Starting new DMaaP MR Subscriber poll.",
67                 debugLogSpec, requestId, transactionId, beginTimestamp);
68         return MessageBuilder
69                 .withPayload(subscriberUrlSupplier.get().toString())
70                 .setHeader(AnalyticsHttpConstants.REQUEST_ID_HEADER_KEY, requestId)
71                 .setHeader(AnalyticsHttpConstants.REQUEST_TRANSACTION_ID_HEADER_KEY, transactionId)
72                 .setHeader(AnalyticsHttpConstants.REQUEST_BEGIN_TS_HEADER_KEY, beginTimestamp)
73                 .build();
74     }
75 }