summaryrefslogtreecommitdiffstats
path: root/dcae-analytics/dcae-analytics-tca-web
diff options
context:
space:
mode:
authorKai <lukai@chinamobile.com>2021-03-29 11:48:10 +0800
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2021-05-12 17:11:08 +0200
commit9bb841d5faa995c2170057f93cd65303fba7979c (patch)
treeb3fe5deaa60844546984d74adb82b9217a6f4705 /dcae-analytics/dcae-analytics-tca-web
parent6302edb304f69068b108a69001d69bc6213b6a6a (diff)
Fix mongodb errors on application startup1.3.0-tca-gen2
Revert Dockerfile refactor due to permissions issues Issue-ID: DCAEGEN2-2747 Issue-ID: DCAEGEN2-2590 Signed-off-by: Kai Lu <lukai@chinamobile.com> Change-Id: I84075575cc75090876416cb13e0ac197a8e0f6e3 Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Diffstat (limited to 'dcae-analytics/dcae-analytics-tca-web')
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/Dockerfile28
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/pom.xml102
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java15
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java4
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java5
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandlerTest.java12
6 files changed, 81 insertions, 85 deletions
diff --git a/dcae-analytics/dcae-analytics-tca-web/Dockerfile b/dcae-analytics/dcae-analytics-tca-web/Dockerfile
index 2791e03..a2c59c4 100644
--- a/dcae-analytics/dcae-analytics-tca-web/Dockerfile
+++ b/dcae-analytics/dcae-analytics-tca-web/Dockerfile
@@ -9,23 +9,23 @@ ARG DOCKER_ARTIFACT_DIR
ARG user=tca-gen2
ARG group=tca-gen2
-WORKDIR ${DOCKER_ARTIFACT_DIR}
-#Copy dependencies and executable jar
-COPY ${PROJECT_BUILD_DIR_NAME}/${FINAL_JAR} .
-
USER root
-#Symlink to overcome Docker limitation to put ARG inside ENTRYPOINT
-RUN mkdir -p /var/log/ONAP/dcaegen2/analytics/tca-gen2 && \
- addgroup $group && adduser --system --disabled-password --no-create-home --ingroup $group $user && \
- chmod g+rwx /opt; \
- chmod u+rw /var/log/ONAP/dcaegen2/analytics/tca-gen2 && \
- chown -R $user /opt && \
- chown -R $user /var/log/ONAP/dcaegen2/analytics/tca-gen2 && \
- ln -s ${FINAL_JAR} tca-gen2.jar && \
- chown $user ${FINAL_JAR} tca-gen2.jar
+RUN mkdir -p /var/log/ONAP/dcaegen2/analytics/tca-gen2
+#Add a new user and group to allow container to be run as non-root
+RUN addgroup $group && adduser --system --disabled-password --no-create-home --ingroup $group $user && \
+ chmod 775 /opt && \
+ chmod 775 /var/log/ONAP/dcaegen2/analytics/tca-gen2 && \
+ chown -R $user:$group /opt && \
+ chown -R $user:$group /var/log/ONAP/dcaegen2/analytics/tca-gen2
+
+#Copy dependencies and executable jar
+WORKDIR ${DOCKER_ARTIFACT_DIR}
+COPY ${PROJECT_BUILD_DIR_NAME}/${FINAL_JAR} .
+#Overcome Docker limitation to put ARG inside ENTRYPOINT
+RUN ln -s ${FINAL_JAR} tca-gen2.jar
EXPOSE 8100
-USER $user
+USER $user:$group
ENTRYPOINT ["java", "-Dspring.profiles.active=configBindingService,dmaap,mongo", "-jar", "tca-gen2.jar"]
diff --git a/dcae-analytics/dcae-analytics-tca-web/pom.xml b/dcae-analytics/dcae-analytics-tca-web/pom.xml
index 86d332f..7c81f4f 100644
--- a/dcae-analytics/dcae-analytics-tca-web/pom.xml
+++ b/dcae-analytics/dcae-analytics-tca-web/pom.xml
@@ -3,6 +3,7 @@
~ ================================================================================
~ Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
~ Copyright (c) 2021 Samsung Electronics. All rights reserved.
+ ~ Copyright (c) 2021 Nokia Intellectual Property. All rights reserved.
~ ================================================================================
~ Modifications Copyright (C) 2019 IBM
~ ================================================================================
@@ -43,7 +44,7 @@
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
<docker.image.name>onap/${project.groupId}.${project.artifactId}</docker.image.name>
- <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
</properties>
<dependencies>
@@ -69,7 +70,6 @@
<artifactId>undertow-core</artifactId>
</exclusion>
</exclusions>
-
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
@@ -107,6 +107,10 @@
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework.plugin</groupId>
+ <artifactId>spring-plugin-core</artifactId>
+ </dependency>
+ <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
@@ -117,33 +121,13 @@
<artifactId>dcae-analytics-test</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.undertow/undertow-core -->
- <dependency>
- <groupId>io.undertow</groupId>
- <artifactId>undertow-core</artifactId>
- </dependency>
<dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-handler</artifactId>
- <version>4.1.54.Final</version>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-handler-proxy</artifactId>
- <version>4.1.54.Final</version>
+ <groupId>io.undertow</groupId>
+ <artifactId>undertow-core</artifactId>
</dependency>
</dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>5.1.12.RELEASE</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<build>
<resources>
<resource>
@@ -165,39 +149,39 @@
</plugin>
<!-- DOCKER PLUGIN -->
<plugin>
- <groupId>com.spotify</groupId>
- <artifactId>dockerfile-maven-plugin</artifactId>
- <version>1.4.10</version>
- <configuration>
- <contextDirectory>${project.basedir}</contextDirectory>
- <repository>${docker.repository}/${docker.image.name}</repository>
- <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
- <buildArgs>
- <PROJECT_BUILD_DIR_NAME>target</PROJECT_BUILD_DIR_NAME>
- <DEPENDENCIES_DIR>${dependency.dir.name}</DEPENDENCIES_DIR>
- <DOCKER_ARTIFACT_DIR>/opt</DOCKER_ARTIFACT_DIR>
- <FINAL_JAR>${project.build.finalName}.jar</FINAL_JAR>
- </buildArgs>
- </configuration>
- <executions>
- <execution>
- <id>build-image</id>
- <phase>install</phase>
- <goals>
- <goal>build</goal>
- </goals>
- </execution>
- <execution>
- <id>tag-version</id>
- <phase>install</phase>
- <goals>
- <goal>tag</goal>
- <goal>push</goal>
- </goals>
- <configuration>
- <tag>${project.version}</tag>
- </configuration>
- </execution>
+ <groupId>com.spotify</groupId>
+ <artifactId>dockerfile-maven-plugin</artifactId>
+ <version>1.4.10</version>
+ <configuration>
+ <contextDirectory>${project.basedir}</contextDirectory>
+ <repository>${docker.repository}/${docker.image.name}</repository>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+ <buildArgs>
+ <PROJECT_BUILD_DIR_NAME>target</PROJECT_BUILD_DIR_NAME>
+ <DEPENDENCIES_DIR>${dependency.dir.name}</DEPENDENCIES_DIR>
+ <DOCKER_ARTIFACT_DIR>/opt</DOCKER_ARTIFACT_DIR>
+ <FINAL_JAR>${project.build.finalName}.jar</FINAL_JAR>
+ </buildArgs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>build-image</id>
+ <phase>install</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>tag-version</id>
+ <phase>install</phase>
+ <goals>
+ <goal>tag</goal>
+ <goal>push</goal>
+ </goals>
+ <configuration>
+ <tag>${project.version}</tag>
+ </configuration>
+ </execution>
<execution>
<id>tag-version-ts</id>
<phase>install</phase>
@@ -206,10 +190,10 @@
<goal>push</goal>
</goals>
<configuration>
- <tag>${project.version}-${maven.build.timestamp}Z</tag>
+ <tag>${project.version}-${maven.build.timestamp}Z</tag>
</configuration>
</execution>
- </executions>
+ </executions>
</plugin>
</plugins>
</build>
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java
index 3579d3e..ed8e7ea 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java
@@ -1,6 +1,8 @@
/*
* ================================================================================
* Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2021 China Mobile Property. All rights reserved.
+ * Copyright (c) 2021 Nokia Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +25,6 @@ import static org.onap.dcae.analytics.model.AnalyticsHttpConstants.REQUEST_ID_HE
import static org.onap.dcae.analytics.model.AnalyticsHttpConstants.REQUEST_TRANSACTION_ID_HEADER_KEY;
import java.util.List;
-import java.util.Map;
-
import org.onap.dcae.analytics.model.AnalyticsProfile;
import org.onap.dcae.analytics.model.DmaapMrConstants;
import org.onap.dcae.analytics.tca.web.TcaAppProperties;
@@ -44,6 +44,7 @@ import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
+import org.springframework.integration.handler.GenericHandler;
import org.springframework.messaging.MessageHeaders;
/**
@@ -82,11 +83,15 @@ public class TcaMrConfig {
// get messages from dmaap subscriber channel
return IntegrationFlows.from(mrSubscriberOutputChannel)
// handle incoming message from dmaap
- .handle((List<String> cefMessages, Map<String, Object> headers) ->
- tcaProcessingService.getTcaExecutionResults(
+ .handle(new GenericHandler<List<String>>() {
+ @Override
+ public Object handle(List<String> cefMessages, MessageHeaders headers) {
+ return tcaProcessingService.getTcaExecutionResults(
headers.getOrDefault(REQUEST_ID_HEADER_KEY, headers.get(MessageHeaders.ID)).toString(),
headers.getOrDefault(REQUEST_TRANSACTION_ID_HEADER_KEY, "").toString(),
- tcaPolicyWrapper, cefMessages))
+ tcaPolicyWrapper, cefMessages);
+ }
+ })
// transform tca execution results to alerts - if not alerts are detected terminate further processing
.transform(tcaAlertTransformer, c -> c.requiresReply(false))
// post messages to dmaap publisher input channel
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java
index 9bade85..ff086ed 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaAlertTransformer.java
@@ -1,6 +1,7 @@
/*
* ================================================================================
* Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2021 China Mobile Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,7 +72,7 @@ public class TcaAlertTransformer extends AbstractTransformer {
@Override
@SuppressWarnings("unchecked")
- protected Object doTransform(final Message<?> message) throws Exception {
+ protected Object doTransform(final Message<?> message) {
final Object messagePayload = message.getPayload();
@@ -158,3 +159,4 @@ public class TcaAlertTransformer extends AbstractTransformer {
Integer.toString(abatedExecutionContexts.size()), Integer.toString(tcaAlerts.size()));
}
}
+
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java
index 7cd542c..024e4bf 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandler.java
@@ -1,6 +1,7 @@
/*
* ================================================================================
* Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (c) 2021 China Mobile Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +25,6 @@ import static org.onap.dcae.analytics.model.AnalyticsHttpConstants.REQUEST_BEGIN
import static org.onap.dcae.analytics.model.AnalyticsHttpConstants.REQUEST_END_TS_HEADER_KEY;
import java.util.Date;
-import java.util.Map;
import org.onap.dcae.analytics.model.ecomplogger.AnalyticsErrorType;
import org.onap.dcae.analytics.tca.core.util.TcaUtils;
@@ -60,7 +60,7 @@ public class TcaPublisherResponseHandler implements GenericHandler<String> {
}
@Override
- public Object handle(final String payload, final Map<String, Object> headers) {
+ public Object handle(final String payload, MessageHeaders headers) {
final MessageHeaders messageHeaders = new MessageHeaders(headers);
final String requestId = AnalyticsHttpUtils.getRequestId(messageHeaders);
@@ -99,3 +99,4 @@ public class TcaPublisherResponseHandler implements GenericHandler<String> {
}
}
+
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandlerTest.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandlerTest.java
index 66043aa..2637a39 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandlerTest.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/integration/TcaPublisherResponseHandlerTest.java
@@ -1,6 +1,7 @@
/*
* ================================================================================
* Copyright (c) 2019 IBM Intellectual Property. All rights reserved.
+ * Copyright (c) 2021 China Mobile Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,17 +27,19 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcae.analytics.tca.web.TcaAppProperties;
import org.onap.dcae.analytics.tca.web.TcaAppProperties.Tca;
+import org.springframework.messaging.MessageHeaders;
public class TcaPublisherResponseHandlerTest {
- static Map<String, Object> headers;
+ static MessageHeaders messageHeaders;
@BeforeAll
static void initialize() {
- headers = new HashMap<>();
+ Map headers = new HashMap<>();
headers.put("X-ECOMP-RequestID", "TestRequestID");
headers.put("X-ECOMP-TransactionID", "TestTransactionID");
headers.put("X-ECOMP-FromAppID", "TestFromAppID");
+ messageHeaders = new MessageHeaders(headers);
}
@@ -49,7 +52,7 @@ public class TcaPublisherResponseHandlerTest {
Mockito.when(tcaAppProperties.getTca().getEnableEcompLogging()).thenReturn(true);
TcaPublisherResponseHandler responseHandler = new TcaPublisherResponseHandler(tcaAppProperties);
- responseHandler.handle("testpayload", headers);
+ responseHandler.handle("testpayload", messageHeaders);
}
@@ -62,8 +65,9 @@ public class TcaPublisherResponseHandlerTest {
Mockito.when(tcaAppProperties.getTca().getEnableEcompLogging()).thenReturn(false);
TcaPublisherResponseHandler responseHandler = new TcaPublisherResponseHandler(tcaAppProperties);
- responseHandler.handle("testpayload", headers);
+ responseHandler.handle("testpayload", messageHeaders);
}
}
+