diff options
Diffstat (limited to 'services/appc-dmaap-service/appc-message-adapter-api')
11 files changed, 574 insertions, 0 deletions
diff --git a/services/appc-dmaap-service/appc-message-adapter-api/.gitignore b/services/appc-dmaap-service/appc-message-adapter-api/.gitignore new file mode 100644 index 000000000..eacf31a67 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/.gitignore @@ -0,0 +1 @@ +/target-ide/ diff --git a/services/appc-dmaap-service/appc-message-adapter-api/pom.xml b/services/appc-dmaap-service/appc-message-adapter-api/pom.xml new file mode 100644 index 000000000..84cd805aa --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP : APPC + ================================================================================ + Copyright (C) 2017-2019 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========================================================= + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.appc.parent</groupId> + <artifactId>binding-parent</artifactId> + <version>2.6.2</version> + <relativePath /> + </parent> + + <groupId>org.onap.appc.services.dmaap</groupId> + <artifactId>appc-message-adapter-api</artifactId> + <packaging>jar</packaging> + <name>appc-message-adapter-api</name> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-common</artifactId> + <scope>compile</scope> + <!-- Added exclusion to prevent missing dependency issue on dblib --> + <exclusions> + <exclusion> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>dblib-provider</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider</artifactId> + <scope>compile</scope> + <!-- Added exclusion to prevent missing dependency issue on dblib --> + <exclusions> + <exclusion> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>dblib-provider</artifactId> + </exclusion> + </exclusions> + </dependency> + + </dependencies> + + <version>1.7.0-SNAPSHOT</version> +</project> diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/CallableConsumer.java b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/CallableConsumer.java new file mode 100644 index 000000000..4359c51fb --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/CallableConsumer.java @@ -0,0 +1,60 @@ +/*- + * ============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.message; + +import java.util.List; +import java.util.concurrent.Callable; + +public class CallableConsumer implements Callable<List<String>> { + + private Consumer consumer; + + private int timeout = 15000; + private int limit = 1000; + + public CallableConsumer(Consumer c) { + this.consumer = c; + } + + public CallableConsumer(Consumer c, int waitMs, int fetchSize) { + this.consumer = c; + this.timeout = waitMs; + this.limit = fetchSize; + } + + @Override + public List<String> call() { + return consumer.fetch(timeout, limit); + } + + /** + * The maximum amount of time to keep a connection alive. Currently is set to waitMs + 10s + * + * @return An integer representing the maximum amount of time to keep this thread alive + */ + public int getMaxLife() { + return 10000 + timeout; + } + +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Consumer.java b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Consumer.java new file mode 100644 index 000000000..542797ed2 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Consumer.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2019 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.message; + +import java.util.List; + +public interface Consumer { + + /** + * Gets a batch of messages from the topic. Defaults to 1000 messages with 15s wait for messages if empty. + * + * @return A list of strings representing the messages pulled from the topic. + */ + List<String> fetch(); + + /** + * Gets a batch of messages from the topic. + * + * @param waitMs + * The amount of time to wait in milliseconds if the topic is empty for data to be written. Should be no + * less than 15000ms to prevent too many requests + * @param limit + * The amount of messages to fetch + * @return A list of strings representing the messages pulled from the topic. + */ + List<String> fetch(int waitMs, int limit); + + /** + * Updates the api credentials for making authenticated requests. + * + * @param apiKey + * The public key to authenticate with + * @param apiSecret + * The secret key to authenticate with + */ + void updateCredentials(String apiKey, String apiSecret); + + /** + * Creates a dmaap client using a https connection + * + * @param yes + * True if https should be used, false otherwise. + */ + default void useHttps(boolean yes) {} + + /** + * Sets Blacklist time for a server with response problem in seconds + */ + default void setResponseProblemBlacklistTime(String duration) {} + + /** + * Sets Blacklist time for a server with server problem in seconds + */ + default void setServerProblemBlacklistTime(String duration) {} + + /** + * Sets Blacklist time for a server with DNS problem in seconds + */ + default void setDnsIssueBlacklistTime(String duration) {} + + /** + * Sets Blacklist time for a server with IO Exception problem in seconds + */ + default void setIOExceptionBlacklistTime(String duration) {} + + /** + * Closes the dmaap client https connection. + */ + default void close() {} + +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Manager.java b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Manager.java new file mode 100644 index 000000000..315e4bd0b --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Manager.java @@ -0,0 +1,47 @@ +/*- + * ============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.message; + +import java.util.Set; + +public interface Manager { + + /** + * Updates the api credentials for making authenticated requests + * + * @param apiKey + * The public key to authenticate with + * @param apiSecret + * The secret key to authenticate with + */ + public void updateCredentials(String apiKey, String apiSecret); + + /** + * Return a set of strings representing topics that the user can see + * + * @return A set of strings with topic names or an empty set if no topics are visible + */ + public Set<String> getTopics(); + +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageAdapterFactory.java b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageAdapterFactory.java new file mode 100644 index 000000000..03bc2b28a --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageAdapterFactory.java @@ -0,0 +1,41 @@ +/*- + * ============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.message; + +import java.util.Collection; +import java.util.Set; + +import org.onap.appc.adapter.message.Consumer; +import org.onap.appc.adapter.message.Producer; + +public interface MessageAdapterFactory { + + // TODO: how do you configure the MessageService type? + + public Producer createProducer(Collection<String> pools, String writeTopic, String apiKey, String apiSecret); + + public Producer createProducer(Collection<String> pools, Set<String> writeTopics, String apiKey, String apiSecret); + + public Consumer createConsumer(Collection<String> pool, String readTopic, + String clientName, String clientId, String filter_json, String apiKey, String apiSecret); +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageDestination.java b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageDestination.java new file mode 100644 index 000000000..02244ccd5 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageDestination.java @@ -0,0 +1,28 @@ +/*- + * ============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.message; + +public enum MessageDestination { + DCAE +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Producer.java b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Producer.java new file mode 100644 index 000000000..8536d8257 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Producer.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017-2019 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.message; + +public interface Producer { + + boolean post(String partition, String data); + + /** + * Updates the api credentials for making authenticated requests. + * + * @param apiKey + * The public key to authenticate with + * @param apiSecret + * The secret key to authenticate with + */ + void updateCredentials(String apiKey, String apiSecret); + + /** + * Creates a dmaap client using a https connection. + * + * @param yes + * True if https should be used, false otherwise + */ + default void useHttps(boolean yes) {} + + /** + * Sets Blacklist time for a server with response problem in seconds + */ + default void setResponseProblemBlacklistTime(String duration) { } + + /** + * Sets Blacklist time for a server with server problem in seconds + */ + default void setServerProblemBlacklistTime(String duration) {} + + /** + * Sets Blacklist time for a server with DNS problem in seconds + */ + default void setDnsIssueBlacklistTime(String duration) {} + + /** + * Sets Blacklist time for a server with IO Exception problem in seconds + */ + default void setIOExceptionBlacklistTime(String duration) {} + + + /** + * Closes the dmaap client https connection. + */ + default void close() {} + +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/main/resources/org/onap/appc/default.properties b/services/appc-dmaap-service/appc-message-adapter-api/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..da25a66a4 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,25 @@ +### +# ============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========================================================= +### + +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},. diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestCallableConsumer.java b/services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestCallableConsumer.java new file mode 100644 index 000000000..8c9dec31c --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestCallableConsumer.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2019 IBM. + * =================================================================== + * 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.message; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class TestCallableConsumer { + + CallableConsumer callableConsumer; + + @Mock + private Consumer consumer; + + private List<String> list; + private int waitMs = 15000; + private int limit = 1000; + private int maxLife = 25000; + + @Before + public void setUp() { + list = new ArrayList<String>(); + callableConsumer = new CallableConsumer(consumer, waitMs, limit); + } + + @Test + public void testCallableConsumer() { + CallableConsumer callableConsumer = new CallableConsumer(consumer); + Mockito.when(consumer.fetch()).thenReturn(list); + assertEquals(list, callableConsumer.call()); + } + + @Test + public void testCall() { + Mockito.when(consumer.fetch()).thenReturn(list); + assertEquals(list, callableConsumer.call()); + } + + @Test + public void testGetMaxLife() { + assertEquals(maxLife, callableConsumer.getMaxLife()); + } + +} diff --git a/services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestMessageDestination.java b/services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestMessageDestination.java new file mode 100644 index 000000000..53b4ad463 --- /dev/null +++ b/services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestMessageDestination.java @@ -0,0 +1,39 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : APPC +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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.message; + +import org.junit.Assert; +import org.junit.Test; + +public class TestMessageDestination { + + private MessageDestination messageDestination=MessageDestination.DCAE; + + @Test + public void testName() { + Assert.assertEquals("DCAE", messageDestination.name()); + } + + @Test + public void testEqual() { + Assert.assertTrue(messageDestination.equals(MessageDestination.DCAE)); + Assert.assertFalse(messageDestination.equals(null)); + } +} |