From 6489bbca90237d869669dbf2e2e677f2e360b72b Mon Sep 17 00:00:00 2001 From: amshegokar Date: Thu, 21 Feb 2019 18:38:35 +0530 Subject: starts threads each for every supported collector Make code changes so that mapper starts one thread each for every supported collector as per configuration Change-Id: I90d3b9d27d0d64107b1b33c6752dc2f0c49344de Issue-ID: DCAEGEN2-1174 Signed-off-by: amshegokar --- .../adapter/GenericAdapter.java | 2 +- .../adapter/UniversalEventAdapter.java | 63 ++-- .../configs/DMaaPMRSubscriberConfig.java | 10 +- .../controller/VesController.java | 6 +- .../onap/universalvesadapter/dmaap/Creator.java | 26 +- .../service/AdapterService.java | 53 --- .../universalvesadapter/service/DMaapService.java | 120 ------- .../service/VESAdapterInitializer.java | 176 +++++----- .../universalvesadapter/service/VesService.java | 112 +++++-- .../utils/CollectorConfigPropertyRetrival.java | 84 +++++ .../universalvesadapter/utils/DmaapConfig.java | 80 ++--- .../utils/FetchDynamicConfig.java | 204 ++++++++++++ .../utils/MapperConfigUtils.java | 361 --------------------- .../src/main/resources/DMaapMR.properties | 45 --- .../src/main/resources/application.properties | 13 - UniversalVesAdapter/src/main/resources/kv.json | 21 ++ UniversalVesAdapter/src/main/resources/logback.xml | 3 + .../src/main/resources/mapper.properties | 41 +++ 18 files changed, 619 insertions(+), 801 deletions(-) delete mode 100644 UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/AdapterService.java delete mode 100644 UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java create mode 100644 UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/CollectorConfigPropertyRetrival.java create mode 100644 UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/FetchDynamicConfig.java delete mode 100644 UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java delete mode 100644 UniversalVesAdapter/src/main/resources/DMaapMR.properties create mode 100644 UniversalVesAdapter/src/main/resources/kv.json create mode 100644 UniversalVesAdapter/src/main/resources/mapper.properties (limited to 'UniversalVesAdapter/src/main') diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java index 95b31fb..7b649a4 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java @@ -44,6 +44,6 @@ public interface GenericAdapter { * @throws ConfigFileSmooksConversionException if unable to convert config file data to smooks object * */ - String transform(String incomingJsonString, String eventType) throws ConfigFileSmooksConversionException, VesException; + String transform(String incomingJsonString) throws ConfigFileSmooksConversionException, VesException; } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java index b922b45..c161977 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java @@ -24,18 +24,21 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; + import javax.annotation.PreDestroy; + import org.milyn.Smooks; import org.onap.dcaegen2.ves.domain.VesEvent; import org.onap.universalvesadapter.exception.ConfigFileSmooksConversionException; import org.onap.universalvesadapter.exception.VesException; import org.onap.universalvesadapter.service.VESAdapterInitializer; +import org.onap.universalvesadapter.utils.CollectorConfigPropertyRetrival; import org.onap.universalvesadapter.utils.SmooksUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.xml.sax.SAXException; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; @@ -53,14 +56,11 @@ import com.google.gson.JsonSyntaxException; @Component public class UniversalEventAdapter implements GenericAdapter { - - private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); - private String enterpriseId; - @Value("${defaultEnterpriseId}") - private String defaultEnterpriseId; + private String collectorIdentifierValue; + private String collectorIdentifierKey; private Map eventToSmooksMapping = new ConcurrentHashMap<>(); public UniversalEventAdapter() { @@ -74,34 +74,53 @@ public class UniversalEventAdapter implements GenericAdapter { * @return ves Event */ @Override - public String transform(String incomingJsonString, String eventType) + public String transform(String incomingJsonString) throws ConfigFileSmooksConversionException, VesException { String result = ""; String configFileData; + + String identifier[]= CollectorConfigPropertyRetrival.getProperyArray("identifier"); + String defaultMappingFile="defaultMappingFile-"+Thread.currentThread().getName(); try { Gson gson = new Gson(); JsonObject body = gson.fromJson(incomingJsonString, JsonObject.class); - JsonElement results = body.get("notify OID"); - String notifyOid = results.getAsString(); - - // extracting enterprise id from notify OID of SNMP trap. - enterpriseId = notifyOid.substring(0, notifyOid.length() - 4); + + JsonElement results; + for(int i=0;i list = new LinkedList(); - @Autowired - private UniversalEventAdapter eventAdapter; - @Autowired - private DmaapConfig dmaapConfig; - - /** - * It fetches events from DMaap in JSON, transforms JSON to VES format and - * publishes it to outgoing DMaap MR Topic - * - * @param DMaaPMRSubscriber,DMaaPMRPublisher - * @return - */ - public void fetchAndPublishInDMaaP(DMaaPMRSubscriber dMaaPMRSubscriber, DMaaPMRPublisher publisher, Creator creater) - throws InterruptedException { - metricsLogger.info("fetch and publish from and to Dmaap started"); - int pollingInternalInt=dmaapConfig.getPollingInterval(); - debugLogger.info("The Polling Interval in Milli Second is :{}" +pollingInternalInt); - while (true) { - synchronized (this) { - for (String incomingJsonString : dMaaPMRSubscriber.fetchMessages().getFetchedMessages()) { - list.add(incomingJsonString); - - } - - if (list.isEmpty()) { - Thread.sleep(pollingInternalInt); - } - debugLogger.debug("number of messages to be converted :{}", list.size()); - - if (!list.isEmpty()) { - String val = ((LinkedList) list).removeFirst(); - List messages = new ArrayList<>(); - String vesEvent = processReceivedJson(val); - if (vesEvent!=null && (!(vesEvent.isEmpty() || vesEvent.equals("")))) { - messages.add(vesEvent); - publisher.publish(messages); - metricsLogger.info("Message successfully published to DMaaP Topic"); - } - - } - - } - } - } - - /** - * It finds mapping file for received json, transforms json to VES format - * - * @param incomingJsonString - * @return - */ - private String processReceivedJson(String incomingJsonString) { - String outgoingJsonString = null; - if (!"".equals(incomingJsonString)) { - - try { - /* - * For Future events String eventType = - * adapterService.identifyEventTypeFromIncomingJson(incomingJsonString); - * - * LOGGER.debug("Event identified as " + eventType); - */ - - outgoingJsonString = eventAdapter.transform(incomingJsonString, "snmp"); - - } catch (VesException exception) { - errorLogger.error("Received exception : {},{}" + exception.getMessage(), exception); - debugLogger.warn("APPLICATION WILL BE SHUTDOWN UNTIL ABOVE ISSUE IS RESOLVED."); - } catch (DMaapException e) { - errorLogger.error("Received exception : {}", e.getMessage()); - } - } - return outgoingJsonString; - } - -} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java index dbf451d..220c5e0 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VESAdapterInitializer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : DCAE * ================================================================================ -* Copyright 2018 TechMahindra +* Copyright 2018-2019 TechMahindra *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +20,18 @@ package org.onap.universalvesadapter.service; import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.apache.commons.codec.binary.Hex; +import java.util.Map.Entry; +import java.util.Set; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; import org.onap.universalvesadapter.dmaap.Creator; +import org.onap.universalvesadapter.utils.CollectorConfigPropertyRetrival; import org.onap.universalvesadapter.utils.DmaapConfig; +import org.onap.universalvesadapter.utils.FetchDynamicConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -48,7 +45,6 @@ import org.springframework.stereotype.Component; //AdapterInitializer @Component public class VESAdapterInitializer implements CommandLineRunner, Ordered { - private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); @@ -56,29 +52,16 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { private Creator creator; @Autowired private DmaapConfig dmaapConfig; - @Value("${spring.datasource.url}") - String dBurl; - @Value("${spring.datasource.username}") - String user; - @Value("${spring.datasource.password}") - String pwd; - @Value("${defaultMappingFilelocation}") - String defaultMappingFileLocation; - @Value("${MappingFileTableName}") - String MappingFileTableName; - @Value("${defaultEnterpriseId}") - String defaultEnterpriseId; @Value("${server.port}") String serverPort; private static Map mappingFiles = new HashMap(); private static Map env; - private static String url; - public static String retString; - public static String retCBSString; - public static String configFile = "/opt/app/KV-Configuration.json"; - byte[] bytesArray = null; - @Autowired private ApplicationContext applicationContext; + public static String configFile = "/opt/app/VESAdapter/conf/kv.json"; + //public static String configFile = "src\\main\\resources\\kv.json"; + + @Autowired + private ApplicationContext applicationContext; @Override public void run(String... args) throws Exception { @@ -86,64 +69,36 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { for (Map.Entry entry : env.entrySet()) { debugLogger.debug(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 - - debugLogger.info(">>>Dynamic configuration to be used"); + + //checks for DMaaP Host and Port No + if( (env.get("DMAAPHOST")==null ||(env.get("MR_DEFAULT_PORT_NUMBER")==null))) { - if( (env.get("DMAAPHOST")==null || - (env.get("MR_DEFAULT_PORT_NUMBER")==null || - (env.get("URL_JDBC")==null || - (env.get("JDBC_USERNAME")==null || - (env.get("JDBC_PASSWORD")==null )))))) { - - - errorLogger.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, () -> {errorLogger.error("Application stoped due to missing default mapping file");return-1;})); - - }else { - - - - dmaapConfig.setDmaaphost(env.get("DMAAPHOST")); - dmaapConfig.setDEFAULT_PORT_NUMBER(Integer.parseInt(env.get("MR_DEFAULT_PORT_NUMBER"))); - creator.setDmaapConfig(dmaapConfig); - - dBurl=env.get("URL_JDBC"); - user=env.get("JDBC_USERNAME"); - pwd=env.get("JDBC_PASSWORD"); - } + errorLogger.error("Some docker environment parameter is missing. Sample Usage is -\n sudo docker run -d -p 8085:8085/tcp --env MR_DEFAULT_PORT_NUMBER=3904 --env CONSUL_HOST=10.53.172.109 --env HOSTNAME=mvp-dcaegen2-service-mua --env CONFIG_BINDING_SERVICE=config_binding_service --env DMAAPHOST='10.53.172.156' onap/org.onap.dcaegen2.services.mapper.vesadapter.universalvesadaptor:latest"); + System.exit(SpringApplication.exit(applicationContext, () -> {errorLogger.error("Application stoped due missing DMAAPHOST or MR_DEFAULT_PORT_NUMBER environment varibales.Please refer above example for environment varibales to pass ");return-1;})); + } - + dmaapConfig.setDmaaphost(env.get("DMAAPHOST")); + dmaapConfig.setDEFAULT_PORT_NUMBER(Integer.parseInt(env.get("MR_DEFAULT_PORT_NUMBER"))); + creator.setDmaapConfig(dmaapConfig); + //check for consul details + if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE") && env.containsKey("HOSTNAME")) { + debugLogger.info(">>>Dynamic configuration to be used"); + FetchDynamicConfig.cbsCall(); + } else { debugLogger.info(">>>Static configuration to be used"); + } - prepareDatabase(); - fetchMappingFile(); + readJsonToMap(configFile); + + //prepareDatabase(); + //fetchMappingFile(); debugLogger.info("Triggering controller's start url "); executecurl("http://localhost:"+serverPort+"/start"); } - private void getconsul() { - - //TODO - } - - public static boolean verifyConfigChange() { - //TODO - return false; - } - - public static void getCBS() { - //TODO - } - - public static void writefile(String retCBSString) { - //TODO - } private static String executecurl(String url) { @@ -172,31 +127,38 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { } - public void fetchMappingFile() { + private void readJsonToMap(String configFile) { + try { + JSONArray collectorArray=CollectorConfigPropertyRetrival.collectorConfigArray(configFile); - try (Connection con = DriverManager.getConnection(dBurl, user, pwd);PreparedStatement pstmt = con.prepareStatement("SELECT * FROM mapping_file");ResultSet rs = pstmt.executeQuery()) { - debugLogger.info("Retrieving data from DB"); - // parsing the column each time is a linear search - int column1Pos = rs.findColumn("enterpriseid"); - int column2Pos = rs.findColumn("mappingfilecontents"); - String hexString; - while (rs.next()) { - String column1 = rs.getString(column1Pos); - String column2 = rs.getString(column2Pos); - hexString = column2.substring(2); - byte[] bytes = Hex.decodeHex(hexString.toCharArray()); - String data = new String(bytes, "UTF-8"); - mappingFiles.put(column1, data); + for (int i = 0; i < collectorArray.size(); i++) { + JSONObject obj2 = (JSONObject) collectorArray.get(i); + + if (obj2.containsKey("mapping-files")) { + + JSONArray a1 = (JSONArray) obj2.get("mapping-files"); + + for (int j = 0; j < a1.size(); j++) { + JSONObject obj3 = (JSONObject) a1.get(j); + Set> set = obj3.entrySet(); + + for (Entry entry : set) { + + mappingFiles.put(entry.getKey(), entry.getValue()); + } + } + + } } - debugLogger.info("DB Initialization Completed, Total # Mappingfiles are:{}" , mappingFiles.size()); + } catch (Exception e) { - errorLogger.error("Error occured due to :{}", e.getMessage()); + errorLogger.error("Exception occured while reading Collector config file cause: ",e.getCause()); } } - private void prepareDatabase() throws IOException { + /* private void prepareDatabase() throws IOException { debugLogger.info("The Default Mapping file Location:" + defaultMappingFileLocation.trim()); @@ -277,7 +239,33 @@ public class VESAdapterInitializer implements CommandLineRunner, Ordered { })); } - } + }*/ + /*public void fetchMappingFile() { + + try (Connection con = DriverManager.getConnection(dBurl, user, pwd)) { + debugLogger.info("Retrieving data from DB"); + PreparedStatement pstmt = con.prepareStatement("SELECT * FROM mapping_file"); + ResultSet rs = pstmt.executeQuery(); + // parsing the column each time is a linear search + int column1Pos = rs.findColumn("enterpriseid"); + int column2Pos = rs.findColumn("mappingfilecontents"); + String hexString; + while (rs.next()) { + String column1 = rs.getString(column1Pos); + String column2 = rs.getString(column2Pos); + hexString = column2.substring(2); + byte[] bytes = Hex.decodeHex(hexString.toCharArray()); + String data = new String(bytes, "UTF-8"); + mappingFiles.put(column1, data); + } + debugLogger.info("DB Initialization Completed, Total # Mappingfiles are" + mappingFiles.size()); + } catch (Exception e) { + errorLogger.error("Error occured due to :" + e.getMessage()); + e.printStackTrace(); + } + + }*/ + public static Map getMappingFiles() { return mappingFiles; } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java index 06ef080..79317ea 100644 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java @@ -19,10 +19,24 @@ */ package org.onap.universalvesadapter.service; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.onap.universalvesadapter.adapter.UniversalEventAdapter; import org.onap.universalvesadapter.dmaap.Creator; import org.onap.universalvesadapter.dmaap.MRPublisher.DMaaPMRPublisher; import org.onap.universalvesadapter.dmaap.MRSubcriber.DMaaPMRSubscriber; +import org.onap.universalvesadapter.exception.DMaapException; import org.onap.universalvesadapter.exception.MapperConfigException; +import org.onap.universalvesadapter.exception.VesException; +import org.onap.universalvesadapter.utils.CollectorConfigPropertyRetrival; +import org.onap.universalvesadapter.utils.DmaapConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,12 +56,13 @@ public class VesService { private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); private boolean isRunning = true; - - @Autowired - private DMaapService dmaapService; - @Autowired private Creator creator; + @Autowired + private UniversalEventAdapter eventAdapter; + @Autowired + private DmaapConfig dmaapConfig; + private static List list = new LinkedList(); /** @@ -55,27 +70,66 @@ public class VesService { */ public void start() throws MapperConfigException { debugLogger.info("Creating Subcriber and Publisher with creator............."); - DMaaPMRSubscriber subcriber = creator.getDMaaPMRSubscriber(); + DMaaPMRPublisher publisher = creator.getDMaaPMRPublisher(); - // Create subscriber & publisher thread - Thread t1 = new Thread(new Runnable() { - @Override - public void run() { - try { + String topicArray[]= CollectorConfigPropertyRetrival.getProperyArray("subscriberTopic"); + + + ExecutorService executorService=Executors.newFixedThreadPool(topicArray.length); + for(int i=0;i) list).removeFirst(); + List messages = new ArrayList<>(); + String vesEvent = processReceivedJson(val); + if (vesEvent!=null && (!(vesEvent.isEmpty() || vesEvent.equals("")))) { + messages.add(vesEvent); + publisher.publish(messages); + metricsLogger.info("Message successfully published to DMaaP Topic"); + } + + } + + } + } + + + + } + }); + } + + } @@ -85,5 +139,23 @@ public class VesService { public void stop() { isRunning = false; } + + private String processReceivedJson(String incomingJsonString) { + String outgoingJsonString = null; + if (!"".equals(incomingJsonString)) { + + try { + + outgoingJsonString = eventAdapter.transform(incomingJsonString); + + } catch (VesException exception) { + errorLogger.error("Received exception : {},{}" + exception.getMessage(), exception); + debugLogger.warn("APPLICATION WILL BE SHUTDOWN UNTIL ABOVE ISSUE IS RESOLVED."); + } catch (DMaapException e) { + errorLogger.error("Received exception : {}", e.getMessage()); + } + } + return outgoingJsonString; + } } diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/CollectorConfigPropertyRetrival.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/CollectorConfigPropertyRetrival.java new file mode 100644 index 0000000..9de7e63 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/CollectorConfigPropertyRetrival.java @@ -0,0 +1,84 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2019 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.universalvesadapter.utils; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class CollectorConfigPropertyRetrival { + + + public static String configFile = "/opt/app/VESAdapter/conf/kv.json"; + //public static String configFile = "src\\main\\resources\\kv.json"; + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); + private static JSONArray array; + + public static JSONArray collectorConfigArray(String configFile){ + try { + JSONParser parser = new JSONParser(); + FileReader fileReader = new FileReader(configFile); + JSONObject obj = (JSONObject) parser.parse(fileReader); + JSONObject appobj = (JSONObject) obj.get("app_preferences"); + array =(JSONArray) appobj.get("collectors"); + + debugLogger.info("Retrieved JsonArray from Collector Config File"); + } catch (ParseException e) { + errorLogger.error("ParseException occured at position:",e.getPosition()); + } catch (FileNotFoundException e) { + + errorLogger.error("Collector Config File is not found..",e.getMessage()); + } catch (IOException e) { + + errorLogger.error("Error occured due to :",e.getMessage()); + } + + + return array; + + } + + + public static String [] getProperyArray(String properyName) { + JSONArray jsonArray =collectorConfigArray(configFile); + + String [] propertyArray=new String[jsonArray.size()]; + + for (int k=0;k env; + + public FetchDynamicConfig() { + } + + public static void cbsCall() { + + env = System.getenv(); + Boolean areEqual; + // Call consul api and identify the CBS Service address and port + getconsul(); + // Construct and invoke CBS API to get application Configuration + getCBS(); + // Verify if data has changed + areEqual = verifyConfigChange(); + + if (!areEqual) { + FetchDynamicConfig fc = new FetchDynamicConfig(); + fc.writefile(retCBSString); + } else { + debugLogger.info("New config pull results identical - " + configFile + " NOT refreshed"); + } + } + + + private static void getconsul() { + url = env.get("CONSUL_HOST") + ":8500/v1/catalog/service/" + env.get("CONFIG_BINDING_SERVICE"); + + // for testing :url="10.12.6.50:8500/v1/catalog/service/config_binding_service"; + //http://10.12.6.44:8500/v1/catlog/service/config_binding_service + + retString = executecurl(url); + debugLogger.info("CBS details fetched from Consul"); + + } + + public static boolean verifyConfigChange() { + + boolean areEqual = false; + // Read current data + try { + File f = new File(configFile); + if (f.exists() && !f.isDirectory()) { + + String jsonData = readFile(configFile); + JSONObject jsonObject = new JSONObject(jsonData); + + ObjectMapper mapper = new ObjectMapper(); + + JsonNode tree1 = mapper.readTree(jsonObject.toString()); + JsonNode tree2 = mapper.readTree(retCBSString); + areEqual = tree1.equals(tree2); + debugLogger.info("Comparison value:" + areEqual); + } else { + debugLogger.info("First time config file read: " + configFile); + } + + } catch (IOException e) { + errorLogger.error("Comparison with new fetched data failed" + e.getMessage()); + + } + + return areEqual; + + } + + public static void getCBS() { + + // consul return as array + JSONTokener temp = new JSONTokener(retString); + JSONObject cbsjobj = (JSONObject) new JSONArray(temp).get(0); + + String urlPart1 = null; + if (cbsjobj.has("ServiceAddress") && cbsjobj.has("ServicePort")) { + + urlPart1 = cbsjobj.getString("ServiceAddress") + ":" + cbsjobj.getInt("ServicePort"); + + } + debugLogger.info("CONFIG_BINDING_SERVICE DNS RESOLVED:" + urlPart1); + + if (env.containsKey("HOSTNAME")) { + url = urlPart1 + "/service_component/" + env.get("HOSTNAME"); + retCBSString = executecurl(url); + } else if (env.containsKey("SERVICE_NAME")) { + url = urlPart1 + "/service_component/" + env.get("SERVICE_NAME"); + retCBSString = executecurl(url); + } else { + errorLogger.error("Service name environment variable - HOSTNAME/SERVICE_NAME not found within container "); + } + + } + + public void writefile(String retCBSString) { + debugLogger.info("URL to fetch configuration:" + url); + + String indentedretstring = (new JSONObject(retCBSString)).toString(4); + + try (FileWriter file = new FileWriter(FetchDynamicConfig.configFile)) { + file.write(indentedretstring); + + debugLogger.info("Successfully Copied JSON Object to file " + configFile); + } catch (IOException e) { + errorLogger.error("Error in writing configuration into file " + configFile + retString + e.getMessage()); + e.printStackTrace(); + } + + } + + public static String readFile(String filename) { + String result = ""; + try (BufferedReader br = new BufferedReader(new FileReader(filename))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null) { + sb.append(line); + line = br.readLine(); + } + result = sb.toString(); + } catch (FileNotFoundException e) { + errorLogger.error("colud not find file :",filename); + + } catch (Exception e) { + errorLogger.error("unable to read the file , reason:",e.getCause()); + } + return result; + } + private static String executecurl(String url) { + + String[] command = { "curl", "-v", url }; + ProcessBuilder process = new ProcessBuilder(command); + Process p; + String result = null; + try { + p = process.start(); + InputStreamReader ipr = new InputStreamReader(p.getInputStream()); + BufferedReader reader = new BufferedReader(ipr); + StringBuilder builder = new StringBuilder(); + String line; + + while ((line = reader.readLine()) != null) { + builder.append(line); + } + result = builder.toString(); + debugLogger.info(result); + + reader.close(); + ipr.close(); + } catch (IOException e) { + errorLogger.error("error", e); + e.printStackTrace(); + } + return result; + + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java deleted file mode 100644 index fb7ed26..0000000 --- a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java +++ /dev/null @@ -1,361 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : DCAE -* ================================================================================ -* 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.universalvesadapter.utils; - -import java.io.IOException; -import java.util.Set; -import java.util.TreeSet; - -import org.onap.universalvesadapter.exception.MapperConfigException; -import org.onap.universalvesadapter.mappingconfig.Entry; -import org.onap.universalvesadapter.mappingconfig.Evaluation; -import org.onap.universalvesadapter.mappingconfig.MapperConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * This class will be used in Future for different telemetry data: - * This class will be utility class to read the mapper config file and parse the - * config to prepare the grammar to detect the incoming json's event type. - * - * @author kmalbari - * - */ -public class MapperConfigUtils { - - private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); - private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); - private static Set entries = new TreeSet<>((o1, o2) -> o1.getPriority().compareTo(o2.getPriority())); - - private enum JoinOperator { - AND("AND"), OR("OR"); - - private final String value; - - private JoinOperator(final String value) { - this.value = value; - } - - public String getValue() { - return value; - } - } - - private enum ExpressionOperator { - EQUALS("EQUALS"), STARTSWITH("STARTSWITH"), ENDSWITH("ENDSWITH"), CONTAINS("CONTAINS"); - - private final String value; - - private ExpressionOperator(final String value) { - this.value = value; - } - - public String getValue() { - return value; - } - } - - private enum DataType { - STRING("STRING"), DOUBLE("DOUBLE"); - - private final String value; - - private DataType(final String value) { - this.value = value; - } - - public String getValue() { - return value; - } - } - - /** - * main method. - * - * @param args - * arguments - */ - public static void main(String[] args) { - - String mappingFile = " { " + " \"entries\": [{ " + " \"priority\": 4, " + " \"evaluation\": { " - + " \"operand\": \"AND\", " + " \"field\": null, " + " \"value\": null, " - + " \"datatype\": null, " + " \"lhs\": { " + " \"operand\": \"OR\", " - + " \"field\": null, " + " \"value\": null, " - + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " - + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " - + " \"lhs\": null, " + " \"rhs\": null " + " }, " - + " \"rhs\": { " + " \"operand\": \"EQUALS\", " - + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " - + " \"datatype\": \"string\", " + " \"lhs\": null, " - + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " - + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " - + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " - + " \"result\": \"smooks.config\" " + " }, { " + " \"priority\": 1, " - + " \"evaluation\": { " + " \"operand\": \"AND\", " + " \"field\": null, " - + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"OR\", " + " \"field\": null, " - + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " - + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " - + " \"lhs\": null, " + " \"rhs\": null " + " }, " - + " \"rhs\": { " + " \"operand\": \"EQUALS\", " - + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " - + " \"datatype\": \"string\", " + " \"lhs\": null, " - + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " - + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " - + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " - + " \"result\": \"smooks.config\" " + " }, { " + " \"priority\": 3, " - + " \"evaluation\": { " + " \"operand\": \"AND\", " + " \"field\": null, " - + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"OR\", " + " \"field\": null, " - + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " - + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " - + " \"lhs\": null, " + " \"rhs\": null " + " }, " - + " \"rhs\": { " + " \"operand\": \"EQUALS\", " - + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " - + " \"datatype\": \"string\", " + " \"lhs\": null, " - + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " - + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " - + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " - + " \"result\": \"smooks.config\" " + " }, { " + " \"priority\": 2, " - + " \"evaluation\": { " + " \"operand\": \"AND\", " + " \"field\": null, " - + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"OR\", " + " \"field\": null, " - + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " - + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " - + " \"lhs\": null, " + " \"rhs\": null " + " }, " - + " \"rhs\": { " + " \"operand\": \"EQUALS\", " - + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " - + " \"datatype\": \"string\", " + " \"lhs\": null, " - + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " - + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " - + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " - + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " - + " \"result\": \"smooks.config\" " + " }] " + "}"; - String incomingJsonString = "{\"domain\":\"snmp-heartbeat\",\"trap version\":1.2}"; - - try { - readMapperConfigFile(mappingFile); - checkIncomingJsonForMatchingDomain(incomingJsonString); - } catch (MapperConfigException e) { - errorLogger.error("Exception in mapperConfigFile reading:{}",e); - } - - } - - /** - * Checks incoming json to see which of the domain it mathces as per mapper - * config entries. If nothing matches, a default mapping will be used. - * - * @param incomingJsonString - * incoming json - * @throws MapperConfigException - * if error occurs in operation - */ - public static String checkIncomingJsonForMatchingDomain(String incomingJsonString) throws MapperConfigException { - ObjectMapper mapper = new ObjectMapper(); - JsonNode actualObj = null; - try { - actualObj = mapper.readTree(incomingJsonString); - } catch (IOException exception) { - throw new MapperConfigException("Unable to read incoming json in a tree " + exception.getMessage(), - exception); - } - for (Entry entry : entries) { - - boolean result = false; - result = evaluateEntryMatch(entry.getEvaluation(), actualObj); - if (result) { - return entry.getResult(); - } - } - return "default"; - } - - /** - * Reads the mapper config file. - * - * @param mappingFileData - * string json for mapper config - * @throws MapperConfigException - * if error in mapper config - */ - public static void readMapperConfigFile(String mappingFileData) throws MapperConfigException { - - ObjectMapper name = new ObjectMapper(); - MapperConfig config = null; - try { - config = name.readValue(mappingFileData, MapperConfig.class); - } catch (IOException exception) { - throw new MapperConfigException("Unable to read config file for reason...\n " + exception.getMessage(), - exception); - } - debugLogger.debug("Read config file content into :{}",config); - - if (null != config) { - entries.addAll(config.getEntries()); - } else { - throw new MapperConfigException("Unable to generate configuration for different domains."); - } - } - - /** - * Evaluates the passed in {@code Evaluation} instance and return boolean - * result. - * - * @param evaluation - * evaluation instance - * @param actualObj - * Json node with values to compare with - * @return true if matches evaluation else false - * @throws MapperConfigException - * error in evaluation - */ - public static boolean evaluateEntryMatch(Evaluation evaluation, JsonNode actualObj) throws MapperConfigException { - if (null == evaluation) { - throw new MapperConfigException("Cannot have null evaluation"); - } - if (null != evaluation.getOperand()) { - - if (MapperConfigUtils.isValidEnum(JoinOperator.class, evaluation.getOperand())) { - // if(JOIN_OPERATOR.contains(evaluation.getOperand())){ - switch (JoinOperator.valueOf(evaluation.getOperand())) { - case AND: - return evaluateEntryMatch(evaluation.getLhs(), actualObj) - && evaluateEntryMatch(evaluation.getRhs(), actualObj); - case OR: - return evaluateEntryMatch(evaluation.getLhs(), actualObj) - || evaluateEntryMatch(evaluation.getRhs(), actualObj); - default: - break; - } - } - - if (MapperConfigUtils.isValidEnum(ExpressionOperator.class, evaluation.getOperand())) { - // if(EXPR_OPERATOR.contains(evaluation.getOperand())){ - - // currently it is assumed field being compared is first level - // child of incoming JSON structure. - // If needed, can write a JsonPath implementation later - String field = evaluation.getField(); - if (null != field && null != evaluation.getDatatype() && actualObj.has(field)) { - switch (ExpressionOperator.valueOf(evaluation.getOperand())) { - case EQUALS: - if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { - switch (DataType.valueOf(evaluation.getDatatype())) { - case STRING: - if (null != actualObj.get(field)) - return actualObj.get(field).asText().equals(evaluation.getValue()); - break; - case DOUBLE: - if (null != actualObj.get(field)) - return actualObj.get(field).asDouble() == Double - .valueOf(evaluation.getValue()); - break; - default: - return false; - } - } else - return false; - break; - case STARTSWITH: - if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { - switch (DataType.valueOf(evaluation.getDatatype())) { - case STRING: - if (null != actualObj.get(field)) - return actualObj.get(field).asText().startsWith(evaluation.getValue()); - break; - default: - return false; - } - } else - return false; - break; - case ENDSWITH: - if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { - switch (DataType.valueOf(evaluation.getDatatype())) { - case STRING: - if (null != actualObj.get(field)) - return actualObj.get(field).asText().endsWith(evaluation.getValue()); - break; - default: - return false; - } - } else - return false; - break; - case CONTAINS: - if (MapperConfigUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { - switch (DataType.valueOf(evaluation.getDatatype())) { - case STRING: - if (null != actualObj.get(field)) - return actualObj.get(field).asText().contains(evaluation.getValue()); - break; - default: - return false; - } - } else - return false; - break; - default: - return false; - } - } - } - } else - throw new MapperConfigException("Not an expected operand as per config for " + evaluation.getField()); - - return false; - } - /** - *

Checks if the specified name is a valid enum for the class.

- * - *

This method differs from {@link Enum#valueOf} in that checks if the name is - * a valid enum without needing to catch the exception.

- * - * @param the type of the enumeration - * @param enumClass the class of the enum to query, not null - * @param enumName the enum name, null returns false - * @return true if the enum name is valid, otherwise false - */ - - public static > boolean isValidEnum(final Class enumClass, final String enumName) { - if (enumName == null) { - return false; - } - try { - Enum.valueOf(enumClass, enumName); - return true; - } catch (final IllegalArgumentException ex) { - return false; - } - } - - -} diff --git a/UniversalVesAdapter/src/main/resources/DMaapMR.properties b/UniversalVesAdapter/src/main/resources/DMaapMR.properties deleted file mode 100644 index dfb8167..0000000 --- a/UniversalVesAdapter/src/main/resources/DMaapMR.properties +++ /dev/null @@ -1,45 +0,0 @@ - # ///////////////// DMaaP Config Constants - - #default hostname - mr.dmaaphost=10.53.172.156 - # default port number - mr.DEFAULT_PORT_NUMBER=3904 - # defaults to no username - mr.DEFAULT_USER_NAME=null - # defaults to no userPassword - mr.DEFAULT_USER_PASSWORD=null - #d efaults to using https protocol - mr.DEFAULT_PROTOCOL=http - # defaults to json content type - mr.DEFAULT_CONTENT_TYPE=application/json - - mr.DMAAP_URI_PATH_PREFIX=/events/ - mr.DMAAP_DEFAULT_CONSUMER_ID=con2 - mr.DMAAP_GROUP_PREFIX=grp2 - -#DMaaP MR subscriber thread's polling interval in milli second -mr.POLLING_INTERVAL=10000 - -# ///////////////// Publisher Constants - -#Dmaap Publisher Topic -mr.publisher.topic=unauthenticated.SEC_FAULT_OUTPUT -#disable batching by default -mr.publisher.DEFAULT_PUBLISHER_MAX_BATCH_SIZE=1 -# default recovery messages size -mr.publisher.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE=100000 -#number of retries when flushing messages -mr.publisher.PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE=5 -#delay in retrying for flushing messages -mr.publisher.PUBLISHER_DELAY_MS_ON_RETRIES_ON_CLOSE=5000 - - -#////////////////// Subscriber Constants - -#Dmaap Subcriber Topic -mr.subscriber.topic=ONAP-COLLECTOR-SNMPTRAP -mr.subcriber.DEFAULT_SUBSCRIBER_TIMEOUT_MS=-1 -mr.subcriber.DEFAULT_SUBSCRIBER_MESSAGE_LIMIT=-1 -mr.subcriber.DEFAULT_SUBSCRIBER_GROUP_PREFIX=grp2 -mr.subcriber.SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME=timeout -mr.subcriber.SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME=limit \ No newline at end of file diff --git a/UniversalVesAdapter/src/main/resources/application.properties b/UniversalVesAdapter/src/main/resources/application.properties index 8d83595..cd2d02b 100644 --- a/UniversalVesAdapter/src/main/resources/application.properties +++ b/UniversalVesAdapter/src/main/resources/application.properties @@ -1,14 +1 @@ server.port=8085 -logging.level.org.springframework.web=ERROR -dmaap.mr_props=DMaapMR.properties - -#Lab Details -spring.datasource.url=jdbc:postgresql://10.53.172.138:5432/postgres -spring.datasource.username=postgres -spring.datasource.password=root - -#MappingFileDetails -defaultMappingFilelocation=defaultSnmpMappingFile.xml -defaultEnterpriseId=default - -MappingFileTableName=mapping_file \ No newline at end of file diff --git a/UniversalVesAdapter/src/main/resources/kv.json b/UniversalVesAdapter/src/main/resources/kv.json new file mode 100644 index 0000000..065ac64 --- /dev/null +++ b/UniversalVesAdapter/src/main/resources/kv.json @@ -0,0 +1,21 @@ +{"collectors": [ + { + "identifier": "notify OID", + "subscriberTopic": "ONAP-COLLECTOR-SNMPTRAP", + "mapping-files": [{ + "1.3.6.1.6.3.1.1.5.3": " <\/json:keyMap> <\/json:reader> <\/jb:bean> <\/jb:bean> '3.0'<\/jb:expression> 'XXXX'<\/jb:expression> 'VesAdapter'<\/jb:expression> 'fault'<\/jb:expression> commonEventHeader.domain+'_'+'_'+ faultFields.alarmCondition;<\/jb:expression> 'Medium'<\/jb:expression> <\/jb:bean> 'MINOR'<\/jb:expression> 'SNMP Agent'<\/jb:expression> 'SNMP Fault'<\/jb:expression> 'Active'<\/jb:expression> <\/jb:bean> <\/jb:bean> <\/jb:bean> <\/smooks-resource-list>", + ".1.3.6.1.4.1.74.2.46.12.1.1": " <\/json:keyMap> <\/json:reader> <\/jb:bean> <\/jb:bean> '3.0'<\/jb:expression> 'XXXX'<\/jb:expression> 'VesAdapter'<\/jb:expression> 'fault'<\/jb:expression> commonEventHeader.domain+'_'+'_'+ faultFields.alarmCondition;<\/jb:expression> 'Medium'<\/jb:expression> 'VesAdapter'<\/jb:expression> <\/jb:bean> 'MINOR'<\/jb:expression> 'SNMP Agent'<\/jb:expression> 'SNMP Fault'<\/jb:expression> 'Active'<\/jb:expression> <\/jb:bean> <\/jb:bean> <\/jb:bean> <\/smooks-resource-list>", + "eventname1": "SNMP xml mapping string", + "defaultMappingFile-ONAP-COLLECTOR-SNMPTRAP": " <\/json:keyMap> <\/json:reader> <\/jb:bean> <\/jb:bean> '3.0'<\/jb:expression> 'XXXsnmp'<\/jb:expression> 'VesAdapter'<\/jb:expression> 'fault'<\/jb:expression> commonEventHeader.domain+'_'+'_'+ faultFields.alarmCondition;<\/jb:expression> 'Medium'<\/jb:expression> <\/jb:bean> 'MINOR'<\/jb:expression> 'SNMP Agent'<\/jb:expression> 'SNMP Fault'<\/jb:expression> 'Active'<\/jb:expression> <\/jb:bean> <\/jb:bean> <\/jb:bean> <\/smooks-resource-list>" + }] + }, + { + "identifier": "notification1-id", + "subscriberTopic": "ONAP-COLLECTOR-RESTCONFTRAP", + "mapping-files": [{ + "defaultMappingFile-ONAP-COLLECTOR-RESTCONFTRAP": " <\/json:keyMap> <\/json:reader> <\/jb:bean> <\/jb:bean> '3.0'<\/jb:expression> 'XXXRestConf'<\/jb:expression> 'VesAdapter'<\/jb:expression> 'fault'<\/jb:expression> commonEventHeader.domain+'_'+'_'+ faultFields.alarmCondition;<\/jb:expression> 'Medium'<\/jb:expression> <\/jb:bean> 'MINOR'<\/jb:expression> 'SNMP Agent'<\/jb:expression> 'SNMP Fault'<\/jb:expression> 'Active'<\/jb:expression> <\/jb:bean> <\/jb:bean> <\/jb:bean> <\/smooks-resource-list>", + "eventname2": "rest conf xml mapping string", + "2541256": " <\/core:namespaces> notification<\/json:key> push-change-update<\/json:key> yang-patch<\/json:key> termination-point<\/json:key> <\/json:keyMap> <\/json:reader> <\/jb:bean> <\/jb:bean> 'fault'<\/jb:expression> 'fault_Status_Change'<\/jb:expression> 'High'<\/jb:expression> '3.0'<\/jb:expression> 'Domain_Contorller'<\/jb:expression> <\/jb:bean> 'CRITICAL'<\/jb:expression> 'Route_Status'<\/jb:expression> 'Fault_SOTN_Service_Status'<\/jb:expression> 'other'<\/jb:expression> 'Active'<\/jb:expression> <\/jb:bean> <\/jb:bean> <\/jb:bean> <\/smooks-resource-list>" + }] + } +]} \ No newline at end of file diff --git a/UniversalVesAdapter/src/main/resources/logback.xml b/UniversalVesAdapter/src/main/resources/logback.xml index d704962..83f5ba1 100644 --- a/UniversalVesAdapter/src/main/resources/logback.xml +++ b/UniversalVesAdapter/src/main/resources/logback.xml @@ -76,10 +76,12 @@ + + @@ -92,6 +94,7 @@ + \ No newline at end of file diff --git a/UniversalVesAdapter/src/main/resources/mapper.properties b/UniversalVesAdapter/src/main/resources/mapper.properties new file mode 100644 index 0000000..d85010f --- /dev/null +++ b/UniversalVesAdapter/src/main/resources/mapper.properties @@ -0,0 +1,41 @@ + # ///////////////// DMaaP Config Constants + + # defaults to no username +mr.DEFAULT_USER_NAME=null + # defaults to no userPassword +mr.DEFAULT_USER_PASSWORD=null + #d efaults to using https protocol +mr.DEFAULT_PROTOCOL=http + # defaults to json content type +mr.DEFAULT_CONTENT_TYPE=application/json + +mr.DMAAP_URI_PATH_PREFIX=/events/ +mr.DMAAP_DEFAULT_CONSUMER_ID=con2 +mr.DMAAP_GROUP_PREFIX=grp2 + +#DMaaP MR subscriber thread's polling interval in milli second +mr.POLLING_INTERVAL=10000 + +# ///////////////// Publisher Constants + +#Dmaap Publisher Topic +mr.publisher.topic=unauthenticated.SEC_FAULT_OUTPUT +#disable batching by default +mr.publisher.DEFAULT_PUBLISHER_MAX_BATCH_SIZE=1 +# default recovery messages size +mr.publisher.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE=100000 +#number of retries when flushing messages +mr.publisher.PUBLISHER_MAX_FLUSH_RETRIES_ON_CLOSE=5 +#delay in retrying for flushing messages +mr.publisher.PUBLISHER_DELAY_MS_ON_RETRIES_ON_CLOSE=5000 + + +#////////////////// Subscriber Constants +mr.subscriber.DEFAULT_SUBSCRIBER_TIMEOUT_MS=-1 +mr.subscriber.DEFAULT_SUBSCRIBER_MESSAGE_LIMIT=-1 +mr.subscriber.DEFAULT_SUBSCRIBER_GROUP_PREFIX=grp2 +mr.subscriber.SUBSCRIBER_TIMEOUT_QUERY_PARAM_NAME=timeout +mr.subscriber.SUBSCRIBER_MSG_LIMIT_QUERY_PARAM_NAME=limit +mr.mr_URI_PATH_PREFIX = /events/ +mr.mr_GROUP_PREFIX = grp2 +mr.mr_DEFAULT_CONSUMER_ID = con2 -- cgit 1.2.3-korg