2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.config.sdc;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
30 import java.io.IOException;
31 import java.util.HashMap;
34 import javax.annotation.PostConstruct;
36 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
37 import org.onap.clamp.clds.util.JacksonUtils;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.beans.factory.annotation.Value;
40 import org.springframework.context.ApplicationContext;
41 import org.springframework.core.io.Resource;
44 * This class maps the SDC config JSON file. This JSON can have multiple
45 * sdc-controller config. So the json is loaded in a static way and the instance
46 * must specify the controller name that it represents.
48 public class SdcControllersConfiguration {
50 private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcControllersConfiguration.class);
51 public static final String CONTROLLER_SUBTREE_KEY = "sdc-connections";
53 protected ApplicationContext appContext;
55 * The file name that will be loaded by Spring.
57 @Value("${clamp.config.files.sdcController:'classpath:/clds/sdc-controllers-config.json'}")
58 protected String sdcControllerFile;
60 * The root of the JSON.
62 private JsonNode jsonRootNode;
65 public void loadConfiguration() throws IOException {
66 Resource resource = appContext.getResource(sdcControllerFile);
67 // Try to load json tree
68 jsonRootNode = JacksonUtils.getObjectMapperInstance().readValue(resource.getInputStream(), JsonNode.class);
71 public SdcSingleControllerConfiguration getSdcSingleControllerConfiguration(String controllerName) {
72 return getAllDefinedControllers().get(controllerName);
76 * This method reads all Controllers configurations and returns them.
78 * @return A list of controller Names defined in the config
80 public Map<String, SdcSingleControllerConfiguration> getAllDefinedControllers() {
81 Map<String, SdcSingleControllerConfiguration> result = new HashMap<>();
82 if (jsonRootNode.get(CONTROLLER_SUBTREE_KEY) != null) {
83 jsonRootNode.get(CONTROLLER_SUBTREE_KEY).fields().forEachRemaining(entry -> result.put(entry.getKey(),
84 new SdcSingleControllerConfiguration(entry.getValue(), entry.getKey())));
86 throw new SdcParametersException(
87 CONTROLLER_SUBTREE_KEY + " key not found in the file: " + sdcControllerFile);