2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.util;
25 import java.io.FileNotFoundException;
26 import java.io.FileReader;
27 import java.util.ArrayList;
28 import java.util.HashMap;
31 import org.json.simple.JSONArray;
32 import org.json.simple.JSONObject;
33 import org.json.simple.parser.JSONParser;
35 import org.onap.aai.logging.ErrorLogHelper;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
39 public class AAIMechIdConfig {
40 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIMechIdConfig.class);
41 private static final String mechIdConfigFileName = AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "mechid-config.json";
43 public static final String SYSTEM_GFP_IP = "GFP";
44 public static final String SYSTEM_GCP = "GCP";
45 public static final String SYSTEM_DCAE = "DCAE";
46 public static final String SYSTEM_RUBY = "RUBY";
47 public static final String SYSTEM_ACTION = "ACTION";
48 public static final String SYSTEM_INSTAR = "INSTAR-LPP-AMS";
49 public static final String FILE_CLASS_GFP_IP = "GFP-IP";
50 public static final String FILE_CLASS_INSTAR = "INSTAR-LPP-AMS";
52 public static HashMap<String, String> mechIdtoSystem = new HashMap<String, String>();
53 public static HashMap<String, ArrayList<String>> fileClassToMechId = new HashMap<String, ArrayList<String>>();
59 * @param appId the app id
60 * @param logger the logger
62 public static void init() {
63 LOGGER.debug("Initializing AAIMechIdConfig");
65 String systemMechId = "";
66 JSONParser parser = new JSONParser();
69 Object obj = parser.parse(new FileReader(mechIdConfigFileName));
70 JSONObject jsonObject = (JSONObject) obj;
71 JSONObject mechIds = (JSONObject) jsonObject.get("mech-ids");
73 @SuppressWarnings("unchecked")
74 Set<String> systemSet = mechIds.keySet();
75 for (String system : systemSet) {
76 JSONObject systemJsonObj = (JSONObject) mechIds.get(system);
77 systemMechId = (String) systemJsonObj.get("mechid");
78 enable = (Boolean) systemJsonObj.get("enable");
79 if (systemMechId != null && !systemMechId.isEmpty() && enable != null && enable == true) {
80 mechIdtoSystem.put(systemMechId, system);
81 JSONArray fileClasses = (JSONArray) systemJsonObj.get("file-classes");
82 if (fileClasses != null ) {
83 String fileClass = "";
84 for (Object fileClassObj : fileClasses) {
85 fileClass = (String) fileClassObj;
87 if (!fileClassToMechId.containsKey(fileClass)) {
88 fileClassToMechId.put(fileClass, new ArrayList<String>());
89 fileClassToMechId.get(fileClass).add(systemMechId);
91 if(!fileClassToMechId.get(fileClass).contains(systemMechId)){
92 fileClassToMechId.get(fileClass).add(systemMechId);
101 } catch (FileNotFoundException fnfe) {
102 ErrorLogHelper.logError("AAI_4001",
103 " " + mechIdConfigFileName + ". Exception: " + fnfe.getMessage());
104 } catch (Exception e) {
105 ErrorLogHelper.logError("AAI_4004",
106 " " + mechIdConfigFileName + ". Exception: " + e.getMessage());
112 * Transform mech id to pickup dir.
114 * @param systemMechId the system mech id
117 public static String transformMechIdToPickupDir(String systemMechId) {
118 String pickupDir = "";
119 if (systemMechId != null && !systemMechId.isEmpty()) {
120 pickupDir = "/opt/aaihome/" + systemMechId + "/pickup";
122 if (pickupDir != null && !pickupDir.isEmpty() && new File(pickupDir).isDirectory()) {