summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aai-client-loadbalancer/LICENSE.TXT17
-rw-r--r--aai-client-loadbalancer/pom.xml158
-rw-r--r--aai-client-loadbalancer/src/main/java/org/onap/aai/AAIRibbonConfiguration.java52
-rw-r--r--aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPing.java66
-rw-r--r--aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPingImpl.java249
-rw-r--r--aai-core/pom.xml21
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java12
-rw-r--r--aai-core/src/main/java/org/onap/aai/config/EventClientPublisher.java95
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java89
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java158
-rw-r--r--aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java56
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java36
-rw-r--r--pom.xml1
13 files changed, 141 insertions, 869 deletions
diff --git a/aai-client-loadbalancer/LICENSE.TXT b/aai-client-loadbalancer/LICENSE.TXT
deleted file mode 100644
index 34558621..00000000
--- a/aai-client-loadbalancer/LICENSE.TXT
+++ /dev/null
@@ -1,17 +0,0 @@
-============LICENSE_START=======================================================
-org.onap.aai
-================================================================================
-Copyright © 2017-2018 AT&T 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.
-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=========================================================
diff --git a/aai-client-loadbalancer/pom.xml b/aai-client-loadbalancer/pom.xml
deleted file mode 100644
index ace8aa0d..00000000
--- a/aai-client-loadbalancer/pom.xml
+++ /dev/null
@@ -1,158 +0,0 @@
-<!--
-
- ============LICENSE_START=======================================================
- org.onap.aai
- ================================================================================
- Copyright © 2017-2018 AT&T 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.
- 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.aai.aai-common</groupId>
- <artifactId>aai-common</artifactId>
- <version>1.2.4-SNAPSHOT</version>
- </parent>
- <artifactId>aai-client-loadbalancer</artifactId>
- <version>1.2.4-SNAPSHOT</version>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>${java.version}</source>
- <target>${java.version}</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <packaging>jar</packaging>
-
- <name>aai-client-loadbalancer</name>
- <description>AAI Client Side Loader Balancer to replace Dmaap</description>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <java.version>1.8</java.version>
- <logback.version>1.2.3</logback.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-ribbon</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcprov-jdk15on</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcpkix-jdk15on</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-commons</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <version>1.5.12.RELEASE</version>
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>4.3.16.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>com.att.eelf</groupId>
- <artifactId>eelf-core</artifactId>
- <version>1.0.0</version>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-codec-http</artifactId>
- <version>4.1.9.Final</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-access</artifactId>
- <version>${logback.version}</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>2.8.11</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.8.11</version>
- </dependency>
- </dependencies>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>Camden.SR5</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <repositories>
- <repository>
- <id>spring-snapshots</id>
- <name>Spring Snapshots</name>
- <url>https://repo.spring.io/snapshot</url>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- <repository>
- <id>spring-milestones</id>
- <name>Spring Milestones</name>
- <url>https://repo.spring.io/milestone</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- </repositories>
-
-</project>
diff --git a/aai-client-loadbalancer/src/main/java/org/onap/aai/AAIRibbonConfiguration.java b/aai-client-loadbalancer/src/main/java/org/onap/aai/AAIRibbonConfiguration.java
deleted file mode 100644
index 601c8734..00000000
--- a/aai-client-loadbalancer/src/main/java/org/onap/aai/AAIRibbonConfiguration.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T 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.
- * 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.aai;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.LoadBalancerBuilder;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cloud.client.loadbalancer.LoadBalanced;
-import org.springframework.context.annotation.Bean;
-import org.springframework.web.client.RestTemplate;
-
-/**
- * AAIRibbonConfiguration is responsible for configuring the dmaap
- * and it reads the users the application properties class
- * and is mostly configurable via properties
- */
-public class AAIRibbonConfiguration {
-
- @Autowired
- IClientConfig ribbonClientConfig;
-
- @Bean
- public ILoadBalancer ribbonLoadBalancer() {
- return LoadBalancerBuilder.newBuilder()
- .withClientConfig(ribbonClientConfig)
- .buildLoadBalancerFromConfigWithReflection();
- }
-
- @LoadBalanced
- @Bean
- public RestTemplate loadBalancedRestTemplate(){
- return new RestTemplate();
- }
-}
diff --git a/aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPing.java b/aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPing.java
deleted file mode 100644
index fcda0747..00000000
--- a/aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPing.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T 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.
- * 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.aai.config;
-
-import java.util.Optional;
-
-/**
- * <b>HttpPing</b> interface provides access to update the endpoint and
- * and the security level of the server that the user is trying to access
- */
-public interface HttpPing {
-
- /**
- * Sets the endpoint that the http get request will
- * make to verify if the url can be reached
- *
- * @param endpoint - the endpoint of the url that is used to do healthcheck
- */
- void setHealthCheckEndpoint(String endpoint);
-
- /**
- * Returns the health check endpoint that the implementation
- * will use in order to verify if the server is reachable at that location
- *
- * @return endpoint - the endpoint of the url that is used to do healthcheck
- */
- String getHealthCheckEndpoint();
-
- /**
- * Set the credentials for the rest endpoint to verify authorization
- *
- * @param username - the username to the server trying to connect to
- * @param password - the password to the server trying to connect to
- */
- void setCredentials(String username, String password);
-
- /**
- * Return the base64 authorization string set from the username and password
- *
- * @return encoded string using base64 of the username and password values
- * like this:
- * <pre>
- * @{code
- * "username:password" => "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
- * }
- * </pre>
- */
- Optional<String> getAuthorization();
-}
diff --git a/aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPingImpl.java b/aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPingImpl.java
deleted file mode 100644
index dd198016..00000000
--- a/aai-client-loadbalancer/src/main/java/org/onap/aai/config/HttpPingImpl.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T 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.
- * 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.aai.config;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.netflix.client.config.DefaultClientConfigImpl;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.IPing;
-import com.netflix.loadbalancer.Server;
-import org.springframework.http.*;
-import org.springframework.web.client.HttpClientErrorException;
-import org.springframework.web.client.RestTemplate;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.util.Base64;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-
-public class HttpPingImpl implements HttpPing, IPing {
-
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(HttpPingImpl.class);
-
- private static final Base64.Encoder base64Encoder = Base64.getEncoder();
-
- private static final HttpHeaders HTTP_HEADERS = new HttpHeaders();
-
- // This is a workaround for the topics that the user
- // does not have the access to read their own topic status
- private static final String MR_STATUS_PATTERN = ".*\"mrstatus\":\\s*4002.*";
-
- private static final int HTTPS_PORT = 3905;
- private static final int DEFAULT_TIMEOUT = 2;
-
- private String healthCheckEndpoint;
- private String username;
- private String password;
-
- private int timeout;
-
- private final RestTemplate restTemplate;
-
- public HttpPingImpl(String healthCheckEndpoint) {
- this(new RestTemplate());
- this.healthCheckEndpoint = healthCheckEndpoint;
- this.timeout = DEFAULT_TIMEOUT;
- }
-
- public HttpPingImpl(RestTemplate restTemplate) {
- this.restTemplate = restTemplate;
- this.healthCheckEndpoint = "";
- this.timeout = DEFAULT_TIMEOUT;
- }
-
- public HttpPingImpl() {
- this("");
- }
-
- public HttpPingImpl(IClientConfig clientConfig) {
-
- if (!(clientConfig instanceof DefaultClientConfigImpl)) {
- throw new UnsupportedOperationException("Unable to support the client config implementation: " + clientConfig.getClass().getName());
- }
-
- DefaultClientConfigImpl defaultClientConfig = (DefaultClientConfigImpl) clientConfig;
-
- Map<String, Object> map = defaultClientConfig.getProperties();
-
- this.setCredentials(map.get("username").toString(), map.get("password").toString());
- this.setHealthCheckEndpoint(map.get("health.endpoint").toString());
- this.setTimeoutInSecs(Integer.valueOf(map.get("pingport.timeout").toString()));
-
- this.restTemplate = new RestTemplate();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setHealthCheckEndpoint(String endpoint) {
- this.healthCheckEndpoint = endpoint;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getHealthCheckEndpoint() {
- return healthCheckEndpoint;
- }
-
- @Override
- public void setCredentials(String username, String password) {
- this.username = username;
- this.password = password;
- }
-
- public void setTimeoutInSecs(int timeout) {
- this.timeout = timeout;
- }
-
- @Override
- public Optional<String> getAuthorization() {
-
- if (username == null && password == null) {
- return Optional.empty();
- }
-
- if (username == null || username.isEmpty()) {
- logger.error("Username is null while the password is not correctly set");
- return Optional.empty();
- }
-
- if (password == null || password.isEmpty()) {
- logger.error("Password is null while the username is not correctly set");
- return Optional.empty();
- }
-
- String auth = String.format("%s:%s", username, password);
- return Optional.ofNullable("Basic " + base64Encoder.encodeToString(auth.getBytes()));
- }
-
- /**
- * @{inheritDoc}
- */
- @Override
- public boolean isAlive(Server server) {
-
- String url = null;
-
- // If unable to ping the port then return immediately
- if (!pingPort(server)) {
- return false;
- }
-
- if (server.getPort() == HTTPS_PORT) {
- url = "https://";
- } else {
-
- url = "http://";
- }
-
- url = url + server.getId();
- url = url + this.getHealthCheckEndpoint();
-
- boolean isAlive = false;
-
- Optional<String> authorization = getAuthorization();
-
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
-
- if (authorization.isPresent()) {
- httpHeaders.add("Authorization", authorization.get());
- }
-
- HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
- try {
-
- ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
-
- HttpStatus httpStatus = responseEntity.getStatusCode();
-
- if (httpStatus == HttpStatus.OK) {
- isAlive = true;
- logger.info("Successfully established connection to the following url {}", url);
- return isAlive;
- }
-
- logger.warn("Unable to establish a connection the following url {} due to HTTP Code {}, and reason {}",
- url, httpStatus.value(), httpStatus.getReasonPhrase());
-
- } catch (HttpClientErrorException ex) {
- HttpStatus httpStatus = ex.getStatusCode();
- if (httpStatus == HttpStatus.FORBIDDEN) {
- // This is a workaround being in play for the topics
- // that are unable to read themselves for this user
- // In the case of the username and password being
- // wrong the response would be unauthorized (401) but if the
- // user is authorized but unable to read this topic, then
- // we get back the (403) with the message mrstatus 4002
- // This is a temporary workaround to properly identify which server is down
- String body = ex.getResponseBodyAsString();
- if (body.matches(MR_STATUS_PATTERN)) {
- isAlive = true;
- logger.info("Successfully connected by workaround due to unable to read own topic {}", url);
- return isAlive;
- } else {
- logger.warn("Unable to establish a connection to {} due to {}", server.getHostPort(), ex.getMessage());
- }
- } else {
- logger.warn("Unable to establish a connection to {} due to {}", server.getHostPort(), ex.getMessage());
- }
- } catch (Exception ex) {
- logger.warn("Unable to establish a connection to {} due to {}", server.getHostPort(), ex.getMessage());
- }
-
- return isAlive;
- }
-
- /**
- * Returns true if it can connect to the host and port within
- * the given timeout from the given server parameter
- *
- * @param server - server that will be taken from the src/main/resources/application.yml file
- * @return true if it can make a successful socket connection to the port on the host
- */
- public boolean pingPort(Server server) {
-
- String host = server.getHost();
- Integer port = server.getPort();
-
- boolean success = false;
- SocketAddress socketAddress = new InetSocketAddress(host, port);
-
- try (Socket socket = new Socket()) {
- socket.connect(socketAddress, timeout * 1000);
- if (socket.isConnected()) {
- success = true;
- }
- } catch (IOException e) {
- logger.warn("Unable to connect to the host {} on port {} due to {}", host, port, e.getLocalizedMessage());
- success = false;
- }
-
- return success;
- }
-}
diff --git a/aai-core/pom.xml b/aai-core/pom.xml
index c00d38ea..dc9b2787 100644
--- a/aai-core/pom.xml
+++ b/aai-core/pom.xml
@@ -588,17 +588,6 @@
<version>1.9</version>
</dependency>
<dependency>
- <groupId>com.att.nsa</groupId>
- <artifactId>dmaapClient</artifactId>
- <version>0.2.12</version>
- <exclusions>
- <exclusion>
- <groupId>com.att.aft</groupId>
- <artifactId>dme2</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-javaagent</artifactId>
<version>1.6.2</version>
@@ -616,11 +605,6 @@
<version>${httpclient.version}</version>
</dependency>
<dependency>
- <groupId>org.onap.aai.aai-common</groupId>
- <artifactId>aai-client-loadbalancer</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-groovy</artifactId>
<version>${gremlin.version}</version>
@@ -645,6 +629,11 @@
<artifactId>jackson-annotations</artifactId>
<version>2.8.11</version>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ </dependency>
</dependencies>
<!-- Plugins and repositories -->
diff --git a/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java b/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java
index 29fac33a..7634b74c 100644
--- a/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java
+++ b/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java
@@ -22,8 +22,8 @@ package org.onap.aai.config;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue;
-import org.onap.aai.dmaap.JMSConsumer;
-import org.onap.aai.dmaap.JMSProducer;
+import org.onap.aai.dmaap.AAIDmaapEventJMSConsumer;
+import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -85,13 +85,13 @@ public class DmaapConfig {
}
@Bean
- public JMSProducer jmsProducer(){
- return new JMSProducer();
+ public AAIDmaapEventJMSProducer jmsProducer(){
+ return new AAIDmaapEventJMSProducer();
}
@Bean
- public JMSConsumer jmsConsumer() throws Exception {
- return new JMSConsumer();
+ public AAIDmaapEventJMSConsumer jmsConsumer() throws Exception {
+ return new AAIDmaapEventJMSConsumer();
}
@Bean
diff --git a/aai-core/src/main/java/org/onap/aai/config/EventClientPublisher.java b/aai-core/src/main/java/org/onap/aai/config/EventClientPublisher.java
new file mode 100644
index 00000000..1268bf84
--- /dev/null
+++ b/aai-core/src/main/java/org/onap/aai/config/EventClientPublisher.java
@@ -0,0 +1,95 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T 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.
+ * 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.aai.config;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Base64;
+
+@Configuration
+public class EventClientPublisher {
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(EventClientPublisher.class);
+
+ @Value("${dmaap.ribbon.listOfServers}")
+ private String hosts;
+
+ @Value("${dmaap.ribbon.username:}")
+ private String username;
+
+ @Value("${dmaap.ribbon.password:}")
+ private String password;
+
+ @Value("${dmaap.ribbon.topic:AAI-EVENT}")
+ private String topic;
+
+ @Value("${dmaap.ribbon.batchSize:100}")
+ private int maxBatchSize;
+
+ @Value("${dmaap.ribbon.maxAgeMs:250}")
+ private int maxAgeMs;
+
+ @Value("${dmaap.ribbon.delayBetweenBatches:100}")
+ private int delayBetweenBatches;
+
+ @Value("${dmaap.ribbon.protocol:http}")
+ private String protocol;
+
+ @Value("${dmaap.ribbon.transportType:HTTPNOAUTH}")
+ private String tranportType;
+
+ @Value("${dmaap.ribbon.contentType:application/json}")
+ private String contentType;
+
+ @Bean
+ public RestTemplate dmaapRestTemplate(){
+ return new RestTemplate();
+ }
+
+ @Bean
+ public HttpHeaders dmaapHeaders() throws UnsupportedEncodingException
+ {
+
+ HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+
+ if(username != null && password != null){
+
+ if(!StringUtils.EMPTY.equals(username) && !StringUtils.EMPTY.equals(password)){
+
+ byte[] userPass = (username + ":" + password).getBytes("UTF-8");
+
+ httpHeaders.set("Authorization", "Basic " + Base64.getEncoder().encodeToString(userPass));
+ }
+ }
+
+ return httpHeaders;
+ }
+
+}
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java
index cc3afa62..5e28b3af 100644
--- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java
+++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java
@@ -21,63 +21,53 @@ package org.onap.aai.dmaap;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
import org.apache.log4j.MDC;
import org.json.JSONException;
import org.json.JSONObject;
-import org.onap.aai.logging.ErrorLogHelper;
-import org.onap.aai.util.AAIConstants;
+import org.onap.aai.config.SpringContextAware;
+import org.onap.aai.logging.LogFormatTools;
import org.onap.aai.logging.LoggingContext;
import org.onap.aai.logging.LoggingContext.LoggingField;
import org.onap.aai.logging.LoggingContext.StatusCode;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.web.client.RestTemplate;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
-import javax.ws.rs.core.MediaType;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Properties;
public class AAIDmaapEventJMSConsumer implements MessageListener {
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIDmaapEventJMSConsumer.class);
- private Client httpClient;
+ private RestTemplate restTemplate;
- private Properties aaiEventProps;
- private String aaiEventUrl = "";
+ private HttpHeaders httpHeaders;
- public AAIDmaapEventJMSConsumer() throws org.apache.commons.configuration.ConfigurationException {
- super();
- try(FileReader reader = new FileReader(new File(AAIConstants.AAI_EVENT_DMAAP_PROPS))) {
+ private Environment environment;
- if (this.httpClient == null) {
- aaiEventProps = new Properties();
- aaiEventProps.load(reader);
+ public AAIDmaapEventJMSConsumer() {
+ ApplicationContext applicationContext = SpringContextAware.getApplicationContext();
- String host = aaiEventProps.getProperty("host");
- String topic = aaiEventProps.getProperty("topic");
- String protocol = aaiEventProps.getProperty("Protocol");
-
- aaiEventUrl = protocol + "://" + host + "/events/" + topic;
- httpClient = Client.create();
- }
-
- } catch (IOException e) {
- ErrorLogHelper.logError("AAI_4000", "Error updating dmaap config file for aai event.");
- LOGGER.error(e.getMessage(), e);
+ if(applicationContext != null){
+ restTemplate = (RestTemplate) applicationContext.getBean("dmaapRestTemplate");
+ httpHeaders = (HttpHeaders) applicationContext.getBean("dmaapHeaders");
+ environment = applicationContext.getEnvironment();
}
-
}
@Override
public void onMessage(Message message) {
+ if(restTemplate == null){
+ return;
+ }
+
String jsmMessageTxt = "";
String aaiEvent = "";
String eventName = "";
@@ -111,49 +101,28 @@ public class AAIDmaapEventJMSConsumer implements MessageListener {
MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString());
MDC.put(LoggingField.RESPONSE_CODE.toString(), "0");
LOGGER.info(eventName + "|" + aaiEvent);
+ HttpEntity httpEntity = new HttpEntity(aaiEvent, httpHeaders);
+
+ String transportType = environment.getProperty("dmaap.ribbon.transportType", "http");
+ String baseUrl = transportType + "://" + environment.getProperty("dmaap.ribbon.listOfServers");
+ String endpoint = "/events/" + eventName;
if ("AAI-EVENT".equals(eventName)) {
- this.sentWithHttp(this.httpClient, this.aaiEventUrl, aaiEvent);
+ restTemplate.exchange(baseUrl + endpoint, HttpMethod.POST, httpEntity, String.class);
} else {
LoggingContext.statusCode(StatusCode.ERROR);
LOGGER.error(eventName + "|Event Topic invalid.");
}
- } catch (java.net.SocketException e) {
- if (!e.getMessage().contains("Connection reset")) {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7304 Error reaching DMaaP to send event. " + aaiEvent, e);
- }
- } catch (IOException e) {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7304 Error reaching DMaaP to send event. " + aaiEvent, e);
} catch (JMSException | JSONException e) {
MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. " + jsmMessageTxt, e);
+ LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. {} {}", jsmMessageTxt, LogFormatTools.getStackTop(e));
} catch (Exception e) {
MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7350 Error sending message to dmaap. " + jsmMessageTxt, e);
+ LOGGER.error("AAI_7350 Error sending message to dmaap. {} {}" , jsmMessageTxt, LogFormatTools.getStackTop(e));
}
}
}
-
- private boolean sentWithHttp(Client client, String url, String aaiEvent) throws IOException {
-
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource
- .accept(MediaType.APPLICATION_JSON)
- .type(MediaType.APPLICATION_JSON)
- .post(ClientResponse.class, aaiEvent);
-
- if (response.getStatus() != 200) {
- LOGGER.info("Failed : HTTP error code : " + response.getStatus());
- return false;
- }
- return true;
- }
}
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java
deleted file mode 100644
index 16092865..00000000
--- a/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T 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.
- * 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.aai.dmaap;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import org.apache.log4j.MDC;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.onap.aai.config.SpringContextAware;
-import org.onap.aai.logging.LoggingContext.LoggingField;
-import org.onap.aai.logging.LoggingContext.StatusCode;
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
-import org.springframework.core.env.Environment;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
-import org.springframework.web.client.RestTemplate;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.TextMessage;
-import java.util.Base64;
-import java.util.Collections;
-
-public class JMSConsumer implements MessageListener {
-
- private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(JMSConsumer.class);
-
- private static final int HTTPS_PORT = 3905;
- private static final Base64.Encoder base64Encoder = Base64.getEncoder();
-
- private HttpHeaders httpHeaders;
- private RestTemplate restTemplate;
-
- private Environment environment;
- private LoadBalancerClient loadBalancerClient;
-
- public JMSConsumer() throws Exception {
- this((LoadBalancerClient)SpringContextAware.getApplicationContext().getBean("loadBalancerClient"));
- }
-
- public JMSConsumer(LoadBalancerClient loadBalancerClient) throws Exception {
- this.loadBalancerClient = loadBalancerClient;
- this.httpHeaders = new HttpHeaders();
- this.httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- this.environment = SpringContextAware.getApplicationContext().getEnvironment();
-
- String username = this.environment.getProperty("dmaap.ribbon.username");
- String password = this.environment.getProperty("dmaap.ribbon.password");
-
- if(username == null || password == null){
- throw new Exception("Unable to retrive username/password from the application properties");
- }
-
- String auth = String.format("%s:%s", username, password);
- String authString = "Basic " + base64Encoder.encodeToString(auth.getBytes());
- httpHeaders.add("Authorization", authString);
-
- restTemplate = new RestTemplate();
- }
-
- @Override
- public void onMessage(Message message) {
-
- String jsmMessageTxt = "";
- String aaiEvent = "";
- String eventName = "";
-
- String environment = System.getProperty("lrmRO");
- if (environment == null) {
- environment = "";
- }
-
- if (message instanceof TextMessage) {
- try {
- jsmMessageTxt = ((TextMessage) message).getText();
- JSONObject jo = new JSONObject(jsmMessageTxt);
-
- if (jo.has("aaiEventPayload")) {
- aaiEvent = jo.getJSONObject("aaiEventPayload").toString();
- } else {
- return;
- }
- if (jo.getString("transId") != null) {
- MDC.put("requestId", jo.getString("transId"));
- }
- if (jo.getString("fromAppId") != null) {
- MDC.put("partnerName", jo.getString("fromAppId"));
- }
- MDC.put("targetEntity", "DMAAP");
- if (jo.getString("event-topic") != null) {
- eventName = jo.getString("event-topic");
- MDC.put("targetServiceName", eventName);
- }
- MDC.put("serviceName", "AAI");
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "0");
- LOGGER.info(eventName + "|" + aaiEvent);
-
- HttpEntity<String> httpEntity = new HttpEntity<>(aaiEvent, httpHeaders);
- ServiceInstance serviceInstance = loadBalancerClient.choose("dmaap");
- String url = serviceInstance.getHost() + ":" + serviceInstance.getPort();
-
- if(serviceInstance.getPort() == HTTPS_PORT){
- url = "https://" + url;
- } else {
- url = "http://" + url;
- }
-
- url += "/events/" + eventName;
-
- if ("AAI-EVENT".equals(eventName)) {
- restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
- LOGGER.info(eventName + "|Event sent.");
- } else if ("AAI-VCE-INTERFACE-DATA".equals(eventName)) {
- restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
- String msg = "";
- LOGGER.info(eventName + "|Event sent. " + msg);
- } else {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "900");
- LOGGER.error(eventName + "|Event Topic invalid.");
- }
- } catch (JMSException | JSONException e) {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7350 Error parsing aaievent jms message for sending to dmaap. " + jsmMessageTxt, e);
- } catch (Exception e) {
- MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString());
- MDC.put(LoggingField.RESPONSE_CODE.toString(), "200");
- LOGGER.error("AAI_7350 Error sending message to dmaap. " + jsmMessageTxt, e);
- }
- }
-
- }
-
-} \ No newline at end of file
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java
deleted file mode 100644
index 6ddb1411..00000000
--- a/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T 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.
- * 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.aai.dmaap;
-
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.json.JSONObject;
-import org.onap.aai.config.SpringContextAware;
-import org.onap.aai.util.AAIConfig;
-import org.springframework.context.ApplicationContext;
-import org.springframework.jms.connection.CachingConnectionFactory;
-import org.springframework.jms.core.JmsTemplate;
-
-public class JMSProducer implements MessageProducer {
-
- private JmsTemplate jmsTemplate;
-
- private ApplicationContext applicationContext;
-
- public JMSProducer() {
- if(AAIConfig.get("aai.jms.enable", "true").equals("true")){
- applicationContext = SpringContextAware.getApplicationContext();
- if(applicationContext == null){
- this.jmsTemplate = new JmsTemplate();
- String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547");
- this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl)));
- this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE"));
- } else {
- jmsTemplate = (JmsTemplate) applicationContext.getBean("jmsTemplate");
- }
- }
- }
-
- public void sendMessageToDefaultDestination(JSONObject finalJson) {
- if(jmsTemplate != null){
- jmsTemplate.convertAndSend(finalJson.toString());
- }
- }
-}
diff --git a/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java b/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java
index 375a2adc..6bde4823 100644
--- a/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java
+++ b/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java
@@ -19,31 +19,27 @@
*/
package org.onap.aai.util;
-import java.io.StringWriter;
-import java.util.Iterator;
-import java.util.UUID;
-
-import javax.xml.bind.Marshaller;
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.json.JSONException;
import org.json.JSONObject;
-import org.onap.aai.config.SpringContextAware;
import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
-import org.onap.aai.dmaap.JMSProducer;
import org.onap.aai.dmaap.MessageProducer;
import org.onap.aai.domain.notificationEvent.NotificationEvent;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
+import javax.xml.bind.Marshaller;
+import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.UUID;
+
public class StoreNotificationEvent {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(StoreNotificationEvent.class);
@@ -60,27 +56,7 @@ public class StoreNotificationEvent {
* Instantiates a new store notification event.
*/
public StoreNotificationEvent(String transactionId, String sourceOfTruth) {
- this.context = SpringContextAware.getApplicationContext();
- // If the context is null then this is being invoked from
- // non spring context so creating the jms producer each time
- // Otherwise, get the jms producer from the spring context so
- // no need to create a instance of this each time
- // Also check if the environment has the dmaap profile
- // TODO - Add the constants for profile so do this when adding the https two-way ssl and one way with basic auth
- if(this.context == null){
- this.messageProducer = new AAIDmaapEventJMSProducer();
- } else {
- env = context.getEnvironment();
- if(env.acceptsProfiles("dmaap")){
- try {
- this.messageProducer = (JMSProducer)context.getBean("jmsProducer");
- } catch(NoSuchBeanDefinitionException ex){
- logger.error("Currently using the dmaap profile but still not able to find bean so check DmaapConfig", ex);
- }
- } else {
- this.messageProducer = new AAIDmaapEventJMSProducer();
- }
- }
+ this.messageProducer = new AAIDmaapEventJMSProducer();
this.transactionId = transactionId;
this.sourceOfTruth = sourceOfTruth;
}
diff --git a/pom.xml b/pom.xml
index e217e7ac..e8c2548b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,6 @@
<module>aai-core</module>
<module>aai-auth</module>
<module>aai-utils</module>
- <module>aai-client-loadbalancer</module>
</modules>
<properties>