From 9bb841d5faa995c2170057f93cd65303fba7979c Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 29 Mar 2021 11:48:10 +0800 Subject: Fix mongodb errors on application startup Revert Dockerfile refactor due to permissions issues Issue-ID: DCAEGEN2-2747 Issue-ID: DCAEGEN2-2590 Signed-off-by: Kai Lu Change-Id: I84075575cc75090876416cb13e0ac197a8e0f6e3 Signed-off-by: Remigiusz Janeczek --- .../dcae/analytics/web/config/DmaapMrConfig.java | 28 ++++++++++++---------- .../analytics/web/config/DmaapPollerConfig.java | 6 ++--- .../analytics/web/config/DmaapRetryConfig.java | 3 ++- .../analytics/web/config/MessageStoreConfig.java | 5 ++-- .../web/dmaap/MrSubscriberPollingAdvice.java | 18 ++++++-------- 5 files changed, 31 insertions(+), 29 deletions(-) (limited to 'dcae-analytics/dcae-analytics-web/src') diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java index 1fe9e51..705a724 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapMrConfig.java @@ -1,6 +1,8 @@ /* * ================================================================================ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2021 China Mobile Property. All rights reserved. + * Copyright (c) 2021 Nokia Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +21,6 @@ package org.onap.dcae.analytics.web.config; -import com.fasterxml.jackson.databind.ObjectMapper; - -import java.util.Map; - import org.onap.dcae.analytics.model.AnalyticsHttpConstants; import org.onap.dcae.analytics.model.AnalyticsProfile; import org.onap.dcae.analytics.model.DmaapMrConstants; @@ -44,16 +42,20 @@ import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.MessageSource; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.dsl.channel.MessageChannels; +import org.springframework.integration.dsl.MessageChannels; import org.springframework.integration.endpoint.MethodInvokingMessageSource; +import org.springframework.integration.handler.GenericHandler; import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice; import org.springframework.integration.http.dsl.Http; import org.springframework.integration.scheduling.PollerMetadata; import org.springframework.integration.store.BasicMessageGroupStore; import org.springframework.integration.store.MessageGroupQueue; import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.MessageHeaders; import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * @author Rajiv Singla */ @@ -139,21 +141,23 @@ public class DmaapMrConfig { final RestTemplate mrPublisherRestTemplate, final DirectChannel mrPublisherInputChannel, final RequestHandlerRetryAdvice requestHandlerRetryAdvice) { - return IntegrationFlows.from(mrPublisherInputChannel) .handle(Http.outboundGateway(mrPublisherPreferences.getRequestURL(), mrPublisherRestTemplate) .mappedRequestHeaders(DMAAP_MAPPED_REQUEST_HEADERS) .httpMethod(HttpMethod.POST) .extractPayload(true) .expectedResponseType(String.class), c -> c.advice(requestHandlerRetryAdvice)) - // add end timestamp - .handle((String p, Map headers) -> - MessageBuilder.withPayload(p).copyHeaders(headers) - .setHeader(AnalyticsHttpConstants.REQUEST_END_TS_HEADER_KEY, - AnalyticsWebUtils.CREATION_TIMESTAMP_SUPPLIER.get()).build() - ) + .handle(new GenericHandler() { + @Override + public Object handle(String payload, MessageHeaders headers) { + return MessageBuilder.withPayload(payload).copyHeaders(headers) + .setHeader(AnalyticsHttpConstants.REQUEST_END_TS_HEADER_KEY, + AnalyticsWebUtils.CREATION_TIMESTAMP_SUPPLIER.get()).build(); + } + }) .channel(DmaapMrConstants.DMAAP_MR_PUBLISHER_OUTPUT_CHANNEL) .get(); } } + diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapPollerConfig.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapPollerConfig.java index ab85d5f..9fec649 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapPollerConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapPollerConfig.java @@ -1,6 +1,7 @@ /* * ================================================================================ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2021 China Mobile Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +20,6 @@ package org.onap.dcae.analytics.web.config; -import java.util.concurrent.TimeUnit; - import org.onap.dcae.analytics.model.AnalyticsProfile; import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingAdvice; import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingPreferences; @@ -56,7 +55,7 @@ public class DmaapPollerConfig { final MrSubscriberPollingPreferences pollingPreferences = mrSubscriberPreferences.getPollingPreferences(); final int minInterval = pollingPreferences.getMinPollingInterval(); final DynamicPeriodicTrigger dynamicPeriodicTrigger = - new DynamicPeriodicTrigger(minInterval, TimeUnit.MILLISECONDS); + new DynamicPeriodicTrigger(minInterval); dynamicPeriodicTrigger.setFixedRate(true); return dynamicPeriodicTrigger; } @@ -77,3 +76,4 @@ public class DmaapPollerConfig { } } + diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapRetryConfig.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapRetryConfig.java index 48f0144..319be8b 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapRetryConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/DmaapRetryConfig.java @@ -1,6 +1,7 @@ /* * ================================================================================ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2021 China Mobile Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +32,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; -import org.springframework.integration.dsl.channel.MessageChannels; +import org.springframework.integration.dsl.MessageChannels; import org.springframework.integration.handler.LoggingHandler; import org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer; import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice; diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/MessageStoreConfig.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/MessageStoreConfig.java index aa1c502..c645b6c 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/MessageStoreConfig.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/config/MessageStoreConfig.java @@ -1,6 +1,7 @@ /* * ================================================================================ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2021 Nokia Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +24,7 @@ import org.onap.dcae.analytics.model.AnalyticsProfile; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import org.springframework.data.mongodb.MongoDbFactory; +import org.springframework.data.mongodb.MongoDatabaseFactory; import org.springframework.integration.mongodb.store.MongoDbChannelMessageStore; import org.springframework.integration.store.BasicMessageGroupStore; import org.springframework.integration.store.SimpleMessageStore; @@ -43,7 +44,7 @@ public class MessageStoreConfig { @Bean @Profile(AnalyticsProfile.MONGO_PROFILE_NAME) - public BasicMessageGroupStore mongoMessageGroupStore(final MongoDbFactory mongoDbFactory) { + public BasicMessageGroupStore mongoMessageGroupStore(final MongoDatabaseFactory mongoDbFactory) { final MongoDbChannelMessageStore store = new MongoDbChannelMessageStore(mongoDbFactory); store.setPriorityEnabled(true); return store; diff --git a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java index 2ebb38d..6572a25 100644 --- a/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java +++ b/dcae-analytics/dcae-analytics-web/src/main/java/org/onap/dcae/analytics/web/dmaap/MrSubscriberPollingAdvice.java @@ -1,6 +1,8 @@ /* * ================================================================================ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2021 China Mobile Property. All rights reserved. + * Copyright (c) 2021 Nokia Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +21,7 @@ package org.onap.dcae.analytics.web.dmaap; +import java.time.Duration; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -84,8 +87,7 @@ public class MrSubscriberPollingAdvice extends AbstractRequestHandlerAdvice { @Override @SuppressWarnings("unchecked") - protected Object doInvoke(final ExecutionCallback callback, final Object target, final Message message) - throws Exception { + protected Object doInvoke(final ExecutionCallback callback, final Object target, final Message message) { // execute call back Object result = callback.execute(); @@ -98,14 +100,7 @@ public class MrSubscriberPollingAdvice extends AbstractRequestHandlerAdvice { final MessageBuilder resultMessageBuilder = (MessageBuilder) result; final String payload = resultMessageBuilder.getPayload(); final Map headers = resultMessageBuilder.getHeaders(); - final Object httpStatusCode = headers.get(AnalyticsHttpConstants.HTTP_STATUS_CODE_HEADER_KEY); - - // get http status code - if (httpStatusCode == null) { - return result; - } - final HttpStatus httpStatus = HttpStatus.resolve(Integer.parseInt(httpStatusCode.toString())); - + final HttpStatus httpStatus = (HttpStatus) headers.get(AnalyticsHttpConstants.HTTP_STATUS_CODE_HEADER_KEY); // if status code is present and successful apply polling adjustments if (httpStatus != null && httpStatus.is2xxSuccessful()) { @@ -119,7 +114,7 @@ public class MrSubscriberPollingAdvice extends AbstractRequestHandlerAdvice { "Next Polling Interval will be: {}", debugLogSpec, requestId, transactionId, String.valueOf(areMessagesPresent), nextPollingInterval.toString()); - trigger.setPeriod(nextPollingInterval.get()); + trigger.setDuration(Duration.ofMillis(nextPollingInterval.get())); // if no messages were found in dmaap poll - terminate further processing if (!areMessagesPresent) { @@ -148,3 +143,4 @@ public class MrSubscriberPollingAdvice extends AbstractRequestHandlerAdvice { } } } + -- cgit 1.2.3-korg