Collectd operator utilties
[demo.git] / vnfs / DAaaS / training-core / hdfs-writer-source-code / hdfs-writer / src / main / java / Orchestrator.java
1 import com.fasterxml.jackson.core.type.TypeReference;
2 import com.fasterxml.jackson.databind.ObjectMapper;
3 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
4 import config.Configuration;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import java.io.InputStream;
9 import java.net.URL;
10 import java.util.HashMap;
11 import java.util.Map;
12
13
14 public class Orchestrator {
15
16     private static Logger logger = LoggerFactory.getLogger(Orchestrator.class);
17
18     public void init(String configYamlFile){
19
20         parseConfigYaml(configYamlFile);
21     }
22
23     private void parseConfigYaml(String configYaml) {
24
25         URL fileUrl = getClass().getResource(configYaml);
26         if(fileUrl==null)
27             System.out.println("::: Config file missing!!! :::");
28
29         else{
30             Configuration conf = new Configuration();
31             ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
32             String realConfigYaml = configYaml;
33
34             if (!realConfigYaml.startsWith("/")) {
35                 realConfigYaml = "/" + configYaml;
36             }
37             Map<String, Object> configs;
38             try (InputStream is = getClass().getResourceAsStream(realConfigYaml)) {
39                 TypeReference<HashMap<String, Object>> typeRef
40                         = new TypeReference<HashMap<String, Object>>() {
41                 };
42                 configs = mapper.readValue(is, typeRef);
43                 conf.init(configs);
44
45             } catch (Exception e) {
46                 logger.error(e.getMessage());
47             }
48         }
49     }
50 }
51