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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.analytics.web.dmaap;
24 import java.util.List;
25 import java.util.function.Supplier;
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;
39 * Provides DMaaP MR Subscriber Trigger Message
41 * @author Rajiv Singla
43 public class MrTriggerMessageProvider {
45 private static final EELFLogger logger = EELFLogFactory.getLogger(MrTriggerMessageProvider.class);
47 public static final String TRIGGER_METHOD_NAME = "getTriggerMessage";
49 private final Supplier<URL> subscriberUrlSupplier;
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()]));
57 * DMaaP MR subscriber trigger message
59 * @return dmaap mr subscriber trigger message
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);
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)