2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.universalvesadapter.utils;
22 import java.io.FileNotFoundException;
23 import java.io.FileReader;
24 import java.io.IOException;
26 import org.json.simple.JSONArray;
27 import org.json.simple.JSONObject;
28 import org.json.simple.parser.JSONParser;
29 import org.json.simple.parser.ParseException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 public class CollectorConfigPropertyRetrival {
37 public static String configFile = "/opt/app/VESAdapter/conf/kv.json";
38 //public static String configFile = "src\\main\\resources\\kv.json";
39 private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger");
40 private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger");
41 private static JSONArray array;
43 public static JSONArray collectorConfigArray(String configFile){
45 JSONParser parser = new JSONParser();
46 FileReader fileReader = new FileReader(configFile);
47 JSONObject obj = (JSONObject) parser.parse(fileReader);
48 JSONObject appobj = (JSONObject) obj.get("app_preferences");
49 array =(JSONArray) appobj.get("collectors");
51 debugLogger.info("Retrieved JsonArray from Collector Config File");
52 } catch (ParseException e) {
53 errorLogger.error("ParseException occured at position:",e.getPosition());
54 } catch (FileNotFoundException e) {
56 errorLogger.error("Collector Config File is not found..",e.getMessage());
57 } catch (IOException e) {
59 errorLogger.error("Error occured due to :",e.getMessage());
68 public static String [] getProperyArray(String properyName) {
69 JSONArray jsonArray =collectorConfigArray(configFile);
71 String [] propertyArray=new String[jsonArray.size()];
73 for (int k=0;k<jsonArray.size();k++) {
75 JSONObject collJson= (JSONObject) jsonArray.get(k);
77 propertyArray[k]=(String) collJson.get(properyName);
79 debugLogger.info("returning "+properyName+" array from Collector Config");