From 7f9114df5c5ea043906f05df6fd5734955d8685a Mon Sep 17 00:00:00 2001 From: Pooja03 Date: Tue, 25 Sep 2018 11:16:04 +0530 Subject: 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 --- snmpmapper/src/assembly/dep.xml | 57 ++++++++++++++++ .../mapper/snmpmapper/DAO/MappingFileDAOImpl.java | 46 ++++++++++++- .../src/main/resources/application.properties | 2 +- snmpmapper/src/main/resources/logback.xml | 79 ++++++++++++++++++++++ snmpmapper/src/main/scripts/run.sh | 2 + 5 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 snmpmapper/src/assembly/dep.xml create mode 100644 snmpmapper/src/main/resources/logback.xml create mode 100644 snmpmapper/src/main/scripts/run.sh (limited to 'snmpmapper/src') 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 @@ + + + + + bundle + false + + dir + + + + + src/main/scripts + bin + + **/*.sh + + 0755 + unix + + + + src/main/resources + conf + + **/defaultSnmpMappingFile.xml + + + + + + runtime + true + false + lib + + + 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 env; @Override public String uploadMappingFile(MultipartFile mappingFile, String enterpriseid) throws SQLException, IOException { + + env = System.getenv(); + for (Map.Entry 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 @@ + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + ${DEV_HOME}/debug.log + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + ${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log + + + 10MB + + + + + + + + ERROR + ACCEPT + DENY + + ${DEV_HOME}/error.log + + + %d{yyyy-MM-dd HH:mm:ss} %logger{36} - %msg%n + + + + + + ${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log + + + 10MB + + + + + + + + + + + + + + + - + + + + + + + \ 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 -- cgit 1.2.3-korg