2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
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.aai.util;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.util.ArrayList;
26 import java.util.HashMap;
29 import org.json.simple.JSONArray;
30 import org.json.simple.JSONObject;
31 import org.json.simple.parser.JSONParser;
33 import org.onap.aai.logging.ErrorLogHelper;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
37 public class AAIMechIdConfig {
38 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIMechIdConfig.class);
39 private static final String mechIdConfigFileName = AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "mechid-config.json";
41 public static final String SYSTEM_GFP_IP = "GFP";
42 public static final String SYSTEM_GCP = "GCP";
43 public static final String SYSTEM_DCAE = "DCAE";
44 public static final String SYSTEM_RUBY = "RUBY";
45 public static final String SYSTEM_ACTION = "ACTION";
46 public static final String SYSTEM_INSTAR = "INSTAR-LPP-AMS";
47 public static final String FILE_CLASS_GFP_IP = "GFP-IP";
48 public static final String FILE_CLASS_INSTAR = "INSTAR-LPP-AMS";
50 public static HashMap<String, String> mechIdtoSystem = new HashMap<String, String>();
51 public static HashMap<String, ArrayList<String>> fileClassToMechId = new HashMap<String, ArrayList<String>>();
57 * @param appId the app id
58 * @param logger the logger
60 public static void init() {
61 LOGGER.debug("Initializing AAIMechIdConfig");
63 String systemMechId = "";
64 JSONParser parser = new JSONParser();
67 Object obj = parser.parse(new FileReader(mechIdConfigFileName));
68 JSONObject jsonObject = (JSONObject) obj;
69 JSONObject mechIds = (JSONObject) jsonObject.get("mech-ids");
71 @SuppressWarnings("unchecked")
72 Set<String> systemSet = mechIds.keySet();
73 for (String system : systemSet) {
74 JSONObject systemJsonObj = (JSONObject) mechIds.get(system);
75 systemMechId = (String) systemJsonObj.get("mechid");
76 enable = (Boolean) systemJsonObj.get("enable");
77 if (systemMechId != null && !systemMechId.isEmpty() && enable != null && enable == true) {
78 mechIdtoSystem.put(systemMechId, system);
79 JSONArray fileClasses = (JSONArray) systemJsonObj.get("file-classes");
80 if (fileClasses != null ) {
81 String fileClass = "";
82 for (Object fileClassObj : fileClasses) {
83 fileClass = (String) fileClassObj;
85 if (!fileClassToMechId.containsKey(fileClass)) {
86 fileClassToMechId.put(fileClass, new ArrayList<String>());
87 fileClassToMechId.get(fileClass).add(systemMechId);
89 if(!fileClassToMechId.get(fileClass).contains(systemMechId)){
90 fileClassToMechId.get(fileClass).add(systemMechId);
99 } catch (FileNotFoundException fnfe) {
100 ErrorLogHelper.logError("AAI_4001",
101 " " + mechIdConfigFileName + ". Exception: " + fnfe.getMessage());
102 } catch (Exception e) {
103 ErrorLogHelper.logError("AAI_4004",
104 " " + mechIdConfigFileName + ". Exception: " + e.getMessage());
110 * Transform mech id to pickup dir.
112 * @param systemMechId the system mech id
115 public static String transformMechIdToPickupDir(String systemMechId) {
116 String pickupDir = "";
117 if (systemMechId != null && !systemMechId.isEmpty()) {
118 pickupDir = "/opt/aaihome/" + systemMechId + "/pickup";
120 if (pickupDir != null && !pickupDir.isEmpty() && new File(pickupDir).isDirectory()) {