From 8bac6571a34c49de5917055853ad4f04f38ea258 Mon Sep 17 00:00:00 2001 From: "Balaji, Ramya (rb111y)" Date: Fri, 23 Nov 2018 13:25:21 -0500 Subject: Possible fix for NoClassDefFoundError Changed package structure, pom file for Utils classto expose it under export-package for DMaap adapter bundle Issue-ID: APPC-1247 Change-Id: I1662d3af027982a87c063cabee77a645f2bc3afa Signed-off-by: Balaji, Ramya (rb111y) --- ...TopicOne_junit-consumer-one_consumer.properties | 68 +++--- ...TopicOne_junit-consumer-two_consumer.properties | 60 ++--- ...TopicOne_junit-producer-one_producer.properties | 70 +++--- .../messaging/dmaap/impl/DmaapConsumerImpl.java | 1 + .../messaging/dmaap/impl/DmaapProducerImpl.java | 1 + .../adapter/messaging/dmaap/impl/DmaapUtil.java | 155 ------------ .../adapter/messaging/dmaap/utils/DmaapUtil.java | 155 ++++++++++++ .../messaging/dmaap/SimpleExamplePublisher.java | 2 +- .../messaging/dmaap/impl/TestDmaapUtil.java | 268 --------------------- .../messaging/dmaap/utils/TestDmaapUtil.java | 268 +++++++++++++++++++++ 10 files changed, 525 insertions(+), 523 deletions(-) delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapUtil.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/utils/DmaapUtil.java delete mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java create mode 100644 appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java (limited to 'appc-adapters/appc-dmaap-adapter') diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-one_consumer.properties b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-one_consumer.properties index 6dddbc0e4..c92e987c2 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-one_consumer.properties +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-one_consumer.properties @@ -1,34 +1,34 @@ -#consumer.properties file created on the fly for topic:JunitTopicOne on:1534178988019 -#Mon Aug 13 09:49:48 PDT 2018 -AFT_DME2_EP_CONN_TIMEOUT=15000 -MethodType=GET -password=secret -routeOffer=MR1 -DME2preferredRouterFilePath=JunitTopicOnepreferredRoute.properties -Longitude=-100.000000 -username=key -Version=1.0 -group=junit-client -timeout=1000 -SubContextPath=/ -authDate=2016-02-18T13\:57\:37-0800 -filter= -authKey=01234567890abcde\:01234567890abcdefghijklmn -Environment=TEST -host=192.168.1.1 -Protocol=http -Partner=BOT_R -contenttype=application/json -id=junit-consumer-one -Latitude=50.000000 -ServiceName=dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events -AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler -AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler -topic=JunitTopicOne -TransportType=HTTPNOAUTH -AFT_ENVIRONMENT=AFTUAT -limit=5 -AFT_DME2_EP_READ_TIMEOUT_MS=50000 -sessionstickinessrequired=NO -AFT_DME2_REQ_TRACE_ON=true -AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 +#consumer.properties file created on the fly for topic:JunitTopicOne on:1542997120536 +#Fri Nov 23 13:18:40 EST 2018 +AFT_DME2_EP_CONN_TIMEOUT=15000 +MethodType=GET +password=admin +routeOffer=MR1 +DME2preferredRouterFilePath=JunitTopicOnepreferredRoute.properties +Longitude=-100.000000 +username=admin +Version=1.0 +group=junit-client +timeout=15000 +SubContextPath=/ +authDate=2016-02-18T13\:57\:37-0800 +filter=none +authKey=01234567890abcde\:01234567890abcdefghijklmn +Environment=TEST +host=192.168.10.10 +Protocol=http +Partner=BOT_R +contenttype=application/json +id=junit-consumer-one +Latitude=50.000000 +ServiceName=dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events +AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler +AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler +topic=JunitTopicOne +TransportType=HTTPNOAUTH +AFT_ENVIRONMENT=AFTUAT +limit=1000 +AFT_DME2_EP_READ_TIMEOUT_MS=50000 +sessionstickinessrequired=NO +AFT_DME2_REQ_TRACE_ON=true +AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-two_consumer.properties b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-two_consumer.properties index f80f762aa..d36ad03f3 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-two_consumer.properties +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-consumer-two_consumer.properties @@ -1,30 +1,30 @@ -#consumer.properties file created on the fly for topic:JunitTopicOne on:1534178854566 -#Mon Aug 13 09:47:34 PDT 2018 -AFT_DME2_EP_CONN_TIMEOUT=15000 -MethodType=GET -routeOffer=MR1 -DME2preferredRouterFilePath=JunitTopicOnepreferredRoute.properties -Longitude=-100.000000 -Version=1.0 -group=junit-client -timeout=15000 -SubContextPath=/ -filter=none -Environment=TEST -host=192.168.10.10 -Protocol=http -Partner=BOT_R -contenttype=application/json -Latitude=50.000000 -id=junit-consumer-two -ServiceName=dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events -AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler -AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler -topic=JunitTopicOne -TransportType=HTTPAAF -AFT_ENVIRONMENT=AFTUAT -limit=1000 -AFT_DME2_EP_READ_TIMEOUT_MS=50000 -sessionstickinessrequired=NO -AFT_DME2_REQ_TRACE_ON=true -AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 +#consumer.properties file created on the fly for topic:JunitTopicOne on:1542997120526 +#Fri Nov 23 13:18:40 EST 2018 +AFT_DME2_EP_CONN_TIMEOUT=15000 +MethodType=GET +routeOffer=MR1 +DME2preferredRouterFilePath=JunitTopicOnepreferredRoute.properties +Longitude=-100.000000 +Version=1.0 +group=junit-client +timeout=15000 +SubContextPath=/ +filter=none +Environment=TEST +host=192.168.10.10 +Protocol=http +Partner=BOT_R +contenttype=application/json +Latitude=50.000000 +id=junit-consumer-two +ServiceName=dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events +AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler +AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler +topic=JunitTopicOne +TransportType=HTTPAAF +AFT_ENVIRONMENT=AFTUAT +limit=1000 +AFT_DME2_EP_READ_TIMEOUT_MS=50000 +sessionstickinessrequired=NO +AFT_DME2_REQ_TRACE_ON=true +AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-producer-one_producer.properties b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-producer-one_producer.properties index 910e713d5..055e8ccd6 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-producer-one_producer.properties +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/JunitTopicOne_junit-producer-one_producer.properties @@ -1,35 +1,35 @@ -#producer.properties file created on the fly for topic:JunitTopicOne on:1534178854558 -#Mon Aug 13 09:47:34 PDT 2018 -AFT_DME2_EP_CONN_TIMEOUT=15000 -MethodType=POST -password=admin -DME2preferredRouterFilePath=JunitTopicOnepreferredRoute.properties -Longitude=-100.000000 -username=admin -partition=2 -Version=1.0 -maxBatchSize=100 -group=junit-client -SubContextPath=/ -authDate=2016-07-20T11\:30\:56-0700 -filter=none -authKey=01234567890abcde\:01234567890abcdefghijklmn -Environment=TEST -host=192.168.10.10 -Protocol=http -Partner=BOT_R -contenttype=application/json -id=junit-producer-one -Latitude=50.000000 -ServiceName=dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events -AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler -AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler -topic=JunitTopicOne -TransportType=HTTPNOAUTH -AFT_ENVIRONMENT=AFTUAT -AFT_DME2_EP_READ_TIMEOUT_MS=50000 -sessionstickinessrequired=NO -AFT_DME2_REQ_TRACE_ON=true -AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 -MessageSentThreadOccurance=50 -maxAgeMs=250 +#producer.properties file created on the fly for topic:JunitTopicOne on:1542997120515 +#Fri Nov 23 13:18:40 EST 2018 +AFT_DME2_EP_CONN_TIMEOUT=15000 +MethodType=POST +password=admin +DME2preferredRouterFilePath=JunitTopicOnepreferredRoute.properties +Longitude=-100.000000 +username=admin +partition=2 +Version=1.0 +maxBatchSize=100 +group=junit-client +SubContextPath=/ +authDate=2016-07-20T11\:30\:56-0700 +filter=none +authKey=01234567890abcde\:01234567890abcdefghijklmn +Environment=TEST +host=192.168.10.10 +Protocol=http +Partner=BOT_R +contenttype=application/json +id=junit-producer-one +Latitude=50.000000 +ServiceName=dmaap-v1.dev.dmaap.dt.saat.acsi.openecomp.org/events +AFT_DME2_EXCHANGE_REPLY_HANDLERS=com.att.nsa.test.PreferredRouteReplyHandler +AFT_DME2_EXCHANGE_REQUEST_HANDLERS=com.att.nsa.test.PreferredRouteRequestHandler +topic=JunitTopicOne +TransportType=HTTPNOAUTH +AFT_ENVIRONMENT=AFTUAT +AFT_DME2_EP_READ_TIMEOUT_MS=50000 +sessionstickinessrequired=NO +AFT_DME2_REQ_TRACE_ON=true +AFT_DME2_ROUNDTRIP_TIMEOUT_MS=240000 +MessageSentThreadOccurance=50 +maxAgeMs=250 diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java index 7291e4603..ca551c6af 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.onap.appc.adapter.message.Consumer; +import org.onap.appc.adapter.messaging.dmaap.utils.DmaapUtil; import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; import org.onap.appc.metricservice.MetricRegistry; diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java index e86ca97c1..445f91960 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java @@ -37,6 +37,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; import org.onap.appc.adapter.message.Producer; +import org.onap.appc.adapter.messaging.dmaap.utils.DmaapUtil; import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; import org.onap.appc.metricservice.MetricRegistry; diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapUtil.java deleted file mode 100644 index 72e0a265b..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapUtil.java +++ /dev/null @@ -1,155 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DmaapUtil { - - private static final char DELIMITER = '_'; - - static final String DMAAP_PROPERTIES_PATH = "org.onap.appc.dmaap.profile.path"; - - private static final Logger log = LoggerFactory.getLogger(DmaapUtil.class); - - private DmaapUtil() { - } - - private static String createPreferredRouteFileIfNotExist(String topic) throws IOException { - String topicPreferredRouteFileName; - topicPreferredRouteFileName = topic + "preferredRoute.properties"; - File fo = new File(topicPreferredRouteFileName); - if (!fo.exists()) { - ClassLoader classLoader = DmaapUtil.class.getClassLoader(); - InputStream inputStream = classLoader.getResourceAsStream("preferredRoute.txt"); - Properties props = new Properties(); - props.load(inputStream); - String fileName = topic != null ? topic + DELIMITER + "MR1" : DELIMITER + "MR1"; - props.setProperty("preferredRouteKey", fileName); - topicPreferredRouteFileName = topic + "preferredRoute.properties"; - props.store(new FileOutputStream(topicPreferredRouteFileName), - "preferredRoute.properties file created on the fly for topic:" + topic + " on:" - + System.currentTimeMillis()); - } - return topicPreferredRouteFileName; - } - - public static String createConsumerPropFile(String topic, Properties props) throws IOException { - String defaultProfFileName = "consumer.properties"; - - log.debug("Creating DMaaP Consumer Property File for topic " + topic); - return createConsumerProducerPropFile(topic, defaultProfFileName, props); - } - - public static String createProducerPropFile(String topic, Properties props) throws IOException { - String defaultProfFileName = "producer.properties"; - - log.debug("Creating DMaaP Producer Property File for topic " + topic); - return createConsumerProducerPropFile(topic, defaultProfFileName, props); - } - - private static String createConsumerProducerPropFile(String topic, String defaultProfFileName, Properties props) - throws IOException { - Properties defaultProps = getDefaultProperties(defaultProfFileName); - - defaultProps.setProperty("topic", topic); - - String preferredRouteFileName = DmaapUtil.createPreferredRouteFileIfNotExist(topic); - if (props != null && !props.isEmpty()) { - defaultProps.putAll(props); - } - defaultProps.setProperty("topic", topic); - defaultProps.setProperty("DME2preferredRouterFilePath", preferredRouteFileName); - String id = defaultProps.getProperty("id"); - String topicConsumerPropFileName = defaultProfFileName; - topicConsumerPropFileName = id != null ? id + DELIMITER + topicConsumerPropFileName - : DELIMITER + topicConsumerPropFileName; - topicConsumerPropFileName = topic != null ? topic + DELIMITER + topicConsumerPropFileName - : DELIMITER + topicConsumerPropFileName; - - defaultProps.store(new FileOutputStream(topicConsumerPropFileName), defaultProfFileName - + " file created on the fly for topic:" + topic + " on:" + System.currentTimeMillis()); - return topicConsumerPropFileName; - } - - private static Properties getDefaultProperties(String profileName) { - Properties props = new Properties(); - - // use appc configuration to get all properties which includes - // appc.properties and system properties - // allowing variable to be set in any location - Configuration config = ConfigurationFactory.getConfiguration(); - String dmaapPropPath = config.getProperty(DMAAP_PROPERTIES_PATH); - - if (dmaapPropPath != null) { - // load from file system - - File profileFile = new File(dmaapPropPath, profileName); - FileInputStream inputStream = null; - - log.info("Loading DMaaP Profile from " + profileFile.getAbsolutePath()); - - if (profileFile.exists()) { - try { - inputStream = new FileInputStream(profileFile); - props.load(inputStream); - } catch (IOException e) { - log.error("Exception loading DMaaP Profile from " + profileFile.getAbsolutePath(), e); - } finally { - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (IOException ex) { - log.warn("Exception closing DMaaP Profile file " + profileFile.getAbsolutePath(), ex); - } - } - } - } - if (props.isEmpty()) { - // load default Profile from class - log.info("Loading Default DMaaP Profile"); - - ClassLoader classLoader = DmaapUtil.class.getClassLoader(); - InputStream inputStream = classLoader.getResourceAsStream(profileName); - try { - props.load(inputStream); - } catch (IOException e) { - log.error("Exception loading Default DMaaP Profile", e); - } - } - - return props; - } -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/utils/DmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/utils/DmaapUtil.java new file mode 100644 index 000000000..7e5f15898 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/utils/DmaapUtil.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class DmaapUtil { + + private static final char DELIMITER = '_'; + + static final String DMAAP_PROPERTIES_PATH = "org.onap.appc.dmaap.profile.path"; + + private static final EELFLogger log = EELFManager.getInstance().getLogger(DmaapUtil.class); + + private DmaapUtil() { + } + + private static String createPreferredRouteFileIfNotExist(String topic) throws IOException { + String topicPreferredRouteFileName; + topicPreferredRouteFileName = topic + "preferredRoute.properties"; + File fo = new File(topicPreferredRouteFileName); + if (!fo.exists()) { + ClassLoader classLoader = DmaapUtil.class.getClassLoader(); + InputStream inputStream = classLoader.getResourceAsStream("preferredRoute.txt"); + Properties props = new Properties(); + props.load(inputStream); + String fileName = topic != null ? topic + DELIMITER + "MR1" : DELIMITER + "MR1"; + props.setProperty("preferredRouteKey", fileName); + topicPreferredRouteFileName = topic + "preferredRoute.properties"; + props.store(new FileOutputStream(topicPreferredRouteFileName), + "preferredRoute.properties file created on the fly for topic:" + topic + " on:" + + System.currentTimeMillis()); + } + return topicPreferredRouteFileName; + } + + public static String createConsumerPropFile(String topic, Properties props) throws IOException { + String defaultProfFileName = "consumer.properties"; + + log.debug("Creating DMaaP Consumer Property File for topic " + topic); + return createConsumerProducerPropFile(topic, defaultProfFileName, props); + } + + public static String createProducerPropFile(String topic, Properties props) throws IOException { + String defaultProfFileName = "producer.properties"; + + log.debug("Creating DMaaP Producer Property File for topic " + topic); + return createConsumerProducerPropFile(topic, defaultProfFileName, props); + } + + private static String createConsumerProducerPropFile(String topic, String defaultProfFileName, Properties props) + throws IOException { + Properties defaultProps = getDefaultProperties(defaultProfFileName); + + defaultProps.setProperty("topic", topic); + + String preferredRouteFileName = DmaapUtil.createPreferredRouteFileIfNotExist(topic); + if (props != null && !props.isEmpty()) { + defaultProps.putAll(props); + } + defaultProps.setProperty("topic", topic); + defaultProps.setProperty("DME2preferredRouterFilePath", preferredRouteFileName); + String id = defaultProps.getProperty("id"); + String topicConsumerPropFileName = defaultProfFileName; + topicConsumerPropFileName = id != null ? id + DELIMITER + topicConsumerPropFileName + : DELIMITER + topicConsumerPropFileName; + topicConsumerPropFileName = topic != null ? topic + DELIMITER + topicConsumerPropFileName + : DELIMITER + topicConsumerPropFileName; + + defaultProps.store(new FileOutputStream(topicConsumerPropFileName), defaultProfFileName + + " file created on the fly for topic:" + topic + " on:" + System.currentTimeMillis()); + return topicConsumerPropFileName; + } + + private static Properties getDefaultProperties(String profileName) { + Properties props = new Properties(); + + // use appc configuration to get all properties which includes + // appc.properties and system properties + // allowing variable to be set in any location + Configuration config = ConfigurationFactory.getConfiguration(); + String dmaapPropPath = config.getProperty(DMAAP_PROPERTIES_PATH); + + if (dmaapPropPath != null) { + // load from file system + + File profileFile = new File(dmaapPropPath, profileName); + FileInputStream inputStream = null; + + log.info("Loading DMaaP Profile from " + profileFile.getAbsolutePath()); + + if (profileFile.exists()) { + try { + inputStream = new FileInputStream(profileFile); + props.load(inputStream); + } catch (IOException e) { + log.error("Exception loading DMaaP Profile from " + profileFile.getAbsolutePath(), e); + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException ex) { + log.warn("Exception closing DMaaP Profile file " + profileFile.getAbsolutePath(), ex); + } + } + } + } + if (props.isEmpty()) { + // load default Profile from class + log.info("Loading Default DMaaP Profile"); + + ClassLoader classLoader = DmaapUtil.class.getClassLoader(); + InputStream inputStream = classLoader.getResourceAsStream(profileName); + try { + props.load(inputStream); + } catch (IOException e) { + log.error("Exception loading Default DMaaP Profile", e); + } + } + + return props; + } +} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java index 16cd5d832..3d50ea588 100644 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/SimpleExamplePublisher.java @@ -31,7 +31,7 @@ import java.util.concurrent.TimeUnit; import com.att.nsa.mr.client.MRConsumer; import org.json.JSONObject; -import org.onap.appc.adapter.messaging.dmaap.impl.DmaapUtil; +import org.onap.appc.adapter.messaging.dmaap.utils.DmaapUtil; import com.att.nsa.mr.client.MRBatchingPublisher; import com.att.nsa.mr.client.MRClientFactory; diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java deleted file mode 100644 index 03e61916b..000000000 --- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapUtil.java +++ /dev/null @@ -1,268 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.messaging.dmaap.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.util.Properties; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.appc.configuration.ConfigurationFactory; - -public class TestDmaapUtil { - private static Class configurationFactoryClass; - private static Field configField; - - @Test - public void testCreateConsumerPropFile() { - String topic = "JunitTopicOne"; - Properties junitProps = new Properties(); - junitProps.put("host", "192.168.10.10"); - junitProps.put("group", "junit-client"); - junitProps.put("id", "junit-consumer-one"); - junitProps.put("filter", "none"); - - String junitFile = null; - - // ensure file path property is not set - if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { - System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); - - // set configuration to null to force reloading of properties - try { - configField.set(null, null); - } catch (IllegalArgumentException | IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - try { - junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception creating consumer property file"); - } - - assertNotNull(junitFile); - - // open file and verify properties - File testFile = new File(junitFile); - assertTrue(testFile.exists()); - - InputStream is = null; - Properties testProps = new Properties(); - try { - is = new FileInputStream(testFile); - testProps.load(is); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - fail("Exception closing consumer property file"); - } - } - - assertFalse(testProps.isEmpty()); - - assertEquals(testProps.get("host"), "192.168.10.10"); - assertEquals(testProps.get("group"), "junit-client"); - assertEquals(testProps.get("id"), "junit-consumer-one"); - assertEquals(testProps.get("filter"), "none"); - assertEquals(testProps.get("TransportType"), "HTTPNOAUTH"); - } - - @Test - public void testCreateConsumerPropFileWithCustomProfile() { - String topic = "JunitTopicOne"; - Properties junitProps = new Properties(); - junitProps.put("host", "192.168.10.10"); - junitProps.put("group", "junit-client"); - junitProps.put("id", "junit-consumer-two"); - junitProps.put("filter", "none"); - - String junitFile = null; - - // set property for DMaaP profile - System.setProperty(DmaapUtil.DMAAP_PROPERTIES_PATH, "src/test/resources/org/onap/appc"); - - // set configuration to null to force reloading of properties - try { - configField.set(null, null); - } catch (IllegalArgumentException | IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - try { - junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception creating consumer property file"); - } - - assertNotNull(junitFile); - - // open file and verify properties - File testFile = new File(junitFile); - assertTrue(testFile.exists()); - - InputStream is = null; - Properties testProps = new Properties(); - try { - is = new FileInputStream(testFile); - testProps.load(is); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - fail("Exception closing consumer property file"); - } - } - - assertFalse(testProps.isEmpty()); - - assertEquals(testProps.get("host"), "192.168.10.10"); - assertEquals(testProps.get("group"), "junit-client"); - assertEquals(testProps.get("id"), "junit-consumer-two"); - assertEquals(testProps.get("filter"), "none"); - assertEquals(testProps.get("TransportType"), "HTTPAAF"); - } - - @Test - public void testCreateProducerPropFile() { - String topic = "JunitTopicOne"; - Properties junitProps = new Properties(); - junitProps.put("host", "192.168.10.10"); - junitProps.put("group", "junit-client"); - junitProps.put("id", "junit-producer-one"); - junitProps.put("filter", "none"); - - String junitFile = null; - - // ensure file path property is not set - if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { - System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); - - // set configuration to null to force reloading of properties - try { - configField.set(null, null); - } catch (IllegalArgumentException | IllegalAccessException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - - try { - junitFile = DmaapUtil.createProducerPropFile(topic, junitProps); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception creating consumer property file"); - } - - assertNotNull(junitFile); - - // open file and verify properties - File testFile = new File(junitFile); - assertTrue(testFile.exists()); - - InputStream is = null; - Properties testProps = new Properties(); - try { - is = new FileInputStream(testFile); - testProps.load(is); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } catch (IOException e) { - e.printStackTrace(); - fail("Exception opening consumer property file"); - } finally { - try { - if (is != null) { - is.close(); - } - } catch (IOException ex) { - ex.printStackTrace(); - fail("Exception closing consumer property file"); - } - } - - assertFalse(testProps.isEmpty()); - - assertEquals(testProps.get("host"), "192.168.10.10"); - assertEquals(testProps.get("group"), "junit-client"); - assertEquals(testProps.get("id"), "junit-producer-one"); - assertEquals(testProps.get("filter"), "none"); - assertEquals("HTTPNOAUTH", testProps.get("TransportType")); - } - - /** - * Use reflection to locate fields and methods so that they can be - * manipulated during the test to change the internal state accordingly. - * - * @throws NoSuchFieldException - * if the field(s) dont exist - * @throws SecurityException - * if reflective access is not allowed - * @throws NoSuchMethodException - * If the method(s) dont exist - */ - @SuppressWarnings("nls") - @BeforeClass - public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { - configurationFactoryClass = ConfigurationFactory.class; - - configField = configurationFactoryClass.getDeclaredField("config"); - configField.setAccessible(true); - } -} diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java new file mode 100644 index 000000000..1567242b5 --- /dev/null +++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/utils/TestDmaapUtil.java @@ -0,0 +1,268 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.messaging.dmaap.utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.Properties; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.appc.configuration.ConfigurationFactory; + +public class TestDmaapUtil { + private static Class configurationFactoryClass; + private static Field configField; + + @Test + public void testCreateConsumerPropFile() { + String topic = "JunitTopicOne"; + Properties junitProps = new Properties(); + junitProps.put("host", "192.168.10.10"); + junitProps.put("group", "junit-client"); + junitProps.put("id", "junit-consumer-one"); + junitProps.put("filter", "none"); + + String junitFile = null; + + // ensure file path property is not set + if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { + System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); + + // set configuration to null to force reloading of properties + try { + configField.set(null, null); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + try { + junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception creating consumer property file"); + } + + assertNotNull(junitFile); + + // open file and verify properties + File testFile = new File(junitFile); + assertTrue(testFile.exists()); + + InputStream is = null; + Properties testProps = new Properties(); + try { + is = new FileInputStream(testFile); + testProps.load(is); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + fail("Exception closing consumer property file"); + } + } + + assertFalse(testProps.isEmpty()); + + assertEquals(testProps.get("host"), "192.168.10.10"); + assertEquals(testProps.get("group"), "junit-client"); + assertEquals(testProps.get("id"), "junit-consumer-one"); + assertEquals(testProps.get("filter"), "none"); + assertEquals(testProps.get("TransportType"), "HTTPNOAUTH"); + } + + @Test + public void testCreateConsumerPropFileWithCustomProfile() { + String topic = "JunitTopicOne"; + Properties junitProps = new Properties(); + junitProps.put("host", "192.168.10.10"); + junitProps.put("group", "junit-client"); + junitProps.put("id", "junit-consumer-two"); + junitProps.put("filter", "none"); + + String junitFile = null; + + // set property for DMaaP profile + System.setProperty(DmaapUtil.DMAAP_PROPERTIES_PATH, "src/test/resources/org/onap/appc"); + + // set configuration to null to force reloading of properties + try { + configField.set(null, null); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + junitFile = DmaapUtil.createConsumerPropFile(topic, junitProps); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception creating consumer property file"); + } + + assertNotNull(junitFile); + + // open file and verify properties + File testFile = new File(junitFile); + assertTrue(testFile.exists()); + + InputStream is = null; + Properties testProps = new Properties(); + try { + is = new FileInputStream(testFile); + testProps.load(is); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + fail("Exception closing consumer property file"); + } + } + + assertFalse(testProps.isEmpty()); + + assertEquals(testProps.get("host"), "192.168.10.10"); + assertEquals(testProps.get("group"), "junit-client"); + assertEquals(testProps.get("id"), "junit-consumer-two"); + assertEquals(testProps.get("filter"), "none"); + assertEquals(testProps.get("TransportType"), "HTTPAAF"); + } + + @Test + public void testCreateProducerPropFile() { + String topic = "JunitTopicOne"; + Properties junitProps = new Properties(); + junitProps.put("host", "192.168.10.10"); + junitProps.put("group", "junit-client"); + junitProps.put("id", "junit-producer-one"); + junitProps.put("filter", "none"); + + String junitFile = null; + + // ensure file path property is not set + if (System.getProperty(DmaapUtil.DMAAP_PROPERTIES_PATH) != null) { + System.clearProperty(DmaapUtil.DMAAP_PROPERTIES_PATH); + + // set configuration to null to force reloading of properties + try { + configField.set(null, null); + } catch (IllegalArgumentException | IllegalAccessException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + + try { + junitFile = DmaapUtil.createProducerPropFile(topic, junitProps); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception creating consumer property file"); + } + + assertNotNull(junitFile); + + // open file and verify properties + File testFile = new File(junitFile); + assertTrue(testFile.exists()); + + InputStream is = null; + Properties testProps = new Properties(); + try { + is = new FileInputStream(testFile); + testProps.load(is); + } catch (FileNotFoundException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } catch (IOException e) { + e.printStackTrace(); + fail("Exception opening consumer property file"); + } finally { + try { + if (is != null) { + is.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + fail("Exception closing consumer property file"); + } + } + + assertFalse(testProps.isEmpty()); + + assertEquals(testProps.get("host"), "192.168.10.10"); + assertEquals(testProps.get("group"), "junit-client"); + assertEquals(testProps.get("id"), "junit-producer-one"); + assertEquals(testProps.get("filter"), "none"); + assertEquals("HTTPNOAUTH", testProps.get("TransportType")); + } + + /** + * Use reflection to locate fields and methods so that they can be + * manipulated during the test to change the internal state accordingly. + * + * @throws NoSuchFieldException + * if the field(s) dont exist + * @throws SecurityException + * if reflective access is not allowed + * @throws NoSuchMethodException + * If the method(s) dont exist + */ + @SuppressWarnings("nls") + @BeforeClass + public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { + configurationFactoryClass = ConfigurationFactory.class; + + configField = configurationFactoryClass.getDeclaredField("config"); + configField.setAccessible(true); + } +} -- cgit 1.2.3-korg