aboutsummaryrefslogtreecommitdiffstats
path: root/snmpmapper/src
diff options
context:
space:
mode:
authorPooja03 <pm00501616@techmahindra.com>2018-09-25 11:16:04 +0530
committerPooja03 <pm00501616@techmahindra.com>2018-09-25 11:16:04 +0530
commit7f9114df5c5ea043906f05df6fd5734955d8685a (patch)
treef705343ef1dd001809f3482a23394a29df38cf77 /snmpmapper/src
parentd6680d72e53df89e607f3aa2f84e4b1a28c74a88 (diff)
Config from docker env params
Taking Config from docker env parameters if CONSUL_HOST flag is present Change-Id: Ice897f9414186409bdbc3db79eee7b5a971f1cdc Issue-ID: DCAEGEN2-338 Signed-off-by: Pooja03 <pm00501616@techmahindra.com>
Diffstat (limited to 'snmpmapper/src')
-rw-r--r--snmpmapper/src/assembly/dep.xml57
-rw-r--r--snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java46
-rw-r--r--snmpmapper/src/main/resources/application.properties2
-rw-r--r--snmpmapper/src/main/resources/logback.xml79
-rw-r--r--snmpmapper/src/main/scripts/run.sh2
5 files changed, 183 insertions, 3 deletions
diff --git a/snmpmapper/src/assembly/dep.xml b/snmpmapper/src/assembly/dep.xml
new file mode 100644
index 0000000..2859272
--- /dev/null
+++ b/snmpmapper/src/assembly/dep.xml
@@ -0,0 +1,57 @@
+<!--
+================================================================================
+Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+Copyright (c) 2018 Nokia. 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=========================================================
+-->
+
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+
+ <id>bundle</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>dir</format>
+ </formats>
+
+ <fileSets>
+ <fileSet>
+ <directory>src/main/scripts</directory>
+ <outputDirectory>bin</outputDirectory>
+ <includes>
+ <include>**/*.sh</include>
+ </includes>
+ <fileMode>0755</fileMode>
+ <lineEnding>unix</lineEnding>
+ </fileSet>
+
+ <fileSet>
+ <directory>src/main/resources</directory>
+ <outputDirectory>conf</outputDirectory>
+ <includes>
+ <include>**/defaultSnmpMappingFile.xml</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <scope>runtime</scope>
+ <useProjectArtifact>true</useProjectArtifact>
+ <unpack>false</unpack>
+ <outputDirectory>lib</outputDirectory>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java
index 93fd1a5..3d18d1d 100644
--- a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java
+++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java
@@ -24,11 +24,13 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-
-import org.onap.dcaegen2.services.mapper.snmpmapper.exception.SnmpMapperException;
+import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.SpringApplication;
+import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;
import org.springframework.web.multipart.MultipartFile;
@@ -46,9 +48,46 @@ public class MappingFileDAOImpl implements MappingFileDAO {
String user;
@Value("${spring.datasource.password}")
String pwd;
+ @Autowired private ApplicationContext applicationContext;
+ private static Map<String, String> env;
@Override
public String uploadMappingFile(MultipartFile mappingFile, String enterpriseid) throws SQLException, IOException {
+
+ env = System.getenv();
+ for (Map.Entry<String, String> entry : env.entrySet()) {
+ LOGGER.info(entry.getKey() + ":" + entry.getValue());
+ }
+
+ if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE") && env.containsKey("HOSTNAME")) {
+ //TODO - Add logic to talk to Consul and CBS to get the configuration. For now, we will refer to configuration coming from docker env parameters
+
+ LOGGER.info(">>>Dynamic configuration to be used");
+
+ if( (env.get("MR_DMAAPHOST")==null ||
+ (env.get("MR_DMAAPHOST")==null ||
+ (env.get("MR_DEFAULT_PORT_NUMBER")==null ||
+ (env.get("URL_JDBC")==null ||
+ (env.get("JDBC_USERNAME")==null ||
+ (env.get("JDBC_PASSWORD")==null ))))))) {
+
+
+ LOGGER.error("Some docker environment parameter is missing. Sample Usage is -\n sudo docker run -d -p 8085:8085/tcp --env URL_JDBC=jdbc:postgresql://10.53.172.129:5432/dummy --env JDBC_USERNAME=ngpuser --env JDBC_PASSWORD=root --env MR_DMAAPHOST=10.10.10.10 --env MR_DEFAULT_PORT_NUMBER=3904 --env CONSUL_HOST=10.53.172.109 --env HOSTNAME=mvp-dcaegen2-collectors-ves --env CONFIG_BINDING_SERVICE=config_binding_service -e DMAAPHOST='10.53.172.156' onap/org.onap.dcaegen2.services.mapper.vesadapter.universalvesadaptor:latest");
+ System.exit(SpringApplication.exit(applicationContext, () -> {LOGGER.error("Application is stoped please provide the above environment parameter during docker run");return-1;}));
+
+ }else {
+
+ url=env.get("URL_JDBC");
+ user=env.get("JDBC_USERNAME");
+ pwd=env.get("JDBC_PASSWORD");
+ }
+
+ } else {
+ LOGGER.info(">>>Static configuration to be used");
+ }
+
+
+
try (Connection con = DriverManager.getConnection(url, user, pwd)) {
LOGGER.debug("Connection established successfully");
PreparedStatement pstmt = con.prepareStatement(
@@ -61,6 +100,9 @@ public class MappingFileDAOImpl implements MappingFileDAO {
pstmt.executeUpdate();
+ }catch (Exception e) {
+ LOGGER.error("Error occured due to :" + e.getMessage());
+ e.printStackTrace();
}
return "Uploaded successfully";
diff --git a/snmpmapper/src/main/resources/application.properties b/snmpmapper/src/main/resources/application.properties
index 2121542..c9d1255 100644
--- a/snmpmapper/src/main/resources/application.properties
+++ b/snmpmapper/src/main/resources/application.properties
@@ -1,4 +1,4 @@
-server.port=9090
+server.port=8080
#spring.datasource.url=jdbc:postgresql://10.49.16.19:5432/dummy
#spring.datasource.username=postgres
#spring.datasource.password=root
diff --git a/snmpmapper/src/main/resources/logback.xml b/snmpmapper/src/main/resources/logback.xml
new file mode 100644
index 0000000..e979ca2
--- /dev/null
+++ b/snmpmapper/src/main/resources/logback.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <property name="DEV_HOME" value="logs" />
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
+ </Pattern>
+ </layout>
+ </appender>
+
+ <appender name="FILE-AUDIT"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${DEV_HOME}/debug.log</file>
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
+ </Pattern>
+ </encoder>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <!-- rollover daily -->
+ <fileNamePattern>${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log
+ </fileNamePattern>
+ <timeBasedFileNamingAndTriggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+ <maxFileSize>10MB</maxFileSize>
+ </timeBasedFileNamingAndTriggeringPolicy>
+ </rollingPolicy>
+
+ </appender>
+
+ <appender name="FILE-ERROR"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <filter class="ch.qos.logback.classic.filter.LevelFilter">
+ <level>ERROR</level>
+ <onMatch>ACCEPT</onMatch>
+ <onMismatch>DENY</onMismatch>
+ </filter>
+ <file>${DEV_HOME}/error.log</file>
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <Pattern>
+ %d{yyyy-MM-dd HH:mm:ss} %logger{36} - %msg%n
+ </Pattern>
+ </encoder>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <!-- rollover daily -->
+ <fileNamePattern>${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log
+ </fileNamePattern>
+ <timeBasedFileNamingAndTriggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
+ <maxFileSize>10MB</maxFileSize>
+ </timeBasedFileNamingAndTriggeringPolicy>
+ </rollingPolicy>
+
+ </appender>
+
+ <!-- Send logs to both console and file audit -->
+ <logger name="org.onap.dcaegen2.services.mapper.snmpmapper" level="debug" additivity="false">
+ <appender-ref ref="FILE-AUDIT" />
+ <appender-ref ref="STDOUT" />
+ </logger>
+ <logger name="org.onap.dcaegen2.services.mapper.snmpmapper" level="debug" additivity="false">
+ <appender-ref ref="FILE-AUDIT" />
+ <appender-ref ref="FILE-ERROR" />
+ <appender-ref ref="STDOUT" />
+ </logger> -
+ <!-- <logger name="org.onap.universalvesadapter.adapter" level="error" additivity="false">
+ <appender-ref ref="FILE-ERROR" />
+ </logger> -->
+
+
+
+
+
+</configuration> \ No newline at end of file
diff --git a/snmpmapper/src/main/scripts/run.sh b/snmpmapper/src/main/scripts/run.sh
new file mode 100644
index 0000000..e85fe59
--- /dev/null
+++ b/snmpmapper/src/main/scripts/run.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+java -cp "./conf:./lib/*" org.onap.dcaegen2.services.mapper.snmpmapper.SnmpmapperApplication \ No newline at end of file