aboutsummaryrefslogtreecommitdiffstats
path: root/services/appc-dmaap-service/appc-message-adapter-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'services/appc-dmaap-service/appc-message-adapter-api/src')
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/CallableConsumer.java60
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Consumer.java92
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Manager.java47
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageAdapterFactory.java41
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/MessageDestination.java28
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/java/org/onap/appc/adapter/message/Producer.java74
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/main/resources/org/onap/appc/default.properties25
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestCallableConsumer.java73
-rw-r--r--services/appc-dmaap-service/appc-message-adapter-api/src/test/java/org/onap/appc/adapter/message/TestMessageDestination.java39
9 files changed, 479 insertions, 0 deletions
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));
+ }
+}