2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.util;
24 import java.io.FileNotFoundException;
25 import java.io.FileReader;
26 import java.util.ArrayList;
27 import java.util.HashMap;
30 import org.json.simple.JSONArray;
31 import org.json.simple.JSONObject;
32 import org.json.simple.parser.JSONParser;
34 import org.openecomp.aai.logging.ErrorLogHelper;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
38 public class AAIMechIdConfig {
39 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIMechIdConfig.class);
40 private static final String mechIdConfigFileName = AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "mechid-config.json";
42 public static final String SYSTEM_GFP_IP = "GFP";
43 public static final String SYSTEM_GCP = "GCP";
44 public static final String SYSTEM_DCAE = "DCAE";
45 public static final String SYSTEM_RUBY = "RUBY";
46 public static final String SYSTEM_ACTION = "ACTION";
47 public static final String SYSTEM_INSTAR = "INSTAR-LPP-AMS";
48 public static final String FILE_CLASS_GFP_IP = "GFP-IP";
49 public static final String FILE_CLASS_INSTAR = "INSTAR-LPP-AMS";
51 public static HashMap<String, String> mechIdtoSystem = new HashMap<String, String>();
52 public static HashMap<String, ArrayList<String>> fileClassToMechId = new HashMap<String, ArrayList<String>>();
58 * @param appId the app id
59 * @param logger the logger
61 public static void init() {
62 LOGGER.debug("Initializing AAIMechIdConfig");
64 String systemMechId = "";
65 JSONParser parser = new JSONParser();
68 Object obj = parser.parse(new FileReader(mechIdConfigFileName));
69 JSONObject jsonObject = (JSONObject) obj;
70 JSONObject mechIds = (JSONObject) jsonObject.get("mech-ids");
72 @SuppressWarnings("unchecked")
73 Set<String> systemSet = mechIds.keySet();
74 for (String system : systemSet) {
75 JSONObject systemJsonObj = (JSONObject) mechIds.get(system);
76 systemMechId = (String) systemJsonObj.get("mechid");
77 enable = (Boolean) systemJsonObj.get("enable");
78 if (systemMechId != null && !systemMechId.isEmpty() && enable != null && enable == true) {
79 mechIdtoSystem.put(systemMechId, system);
80 JSONArray fileClasses = (JSONArray) systemJsonObj.get("file-classes");
81 if (fileClasses != null ) {
82 String fileClass = "";
83 for (Object fileClassObj : fileClasses) {
84 fileClass = (String) fileClassObj;
86 if (!fileClassToMechId.containsKey(fileClass)) {
87 fileClassToMechId.put(fileClass, new ArrayList<String>());
88 fileClassToMechId.get(fileClass).add(systemMechId);
90 if(!fileClassToMechId.get(fileClass).contains(systemMechId)){
91 fileClassToMechId.get(fileClass).add(systemMechId);
100 } catch (FileNotFoundException fnfe) {
101 ErrorLogHelper.logError("AAI_4001",
102 " " + mechIdConfigFileName + ". Exception: " + fnfe.getMessage());
103 } catch (Exception e) {
104 ErrorLogHelper.logError("AAI_4004",
105 " " + mechIdConfigFileName + ". Exception: " + e.getMessage());
111 * Transform mech id to pickup dir.
113 * @param systemMechId the system mech id
116 public static String transformMechIdToPickupDir(String systemMechId) {
117 String pickupDir = "";
118 if (systemMechId != null && !systemMechId.isEmpty()) {
119 pickupDir = "/opt/aaihome/" + systemMechId + "/pickup";
121 if (pickupDir != null && !pickupDir.isEmpty() && new File(pickupDir).isDirectory()) {