aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/training-core/hdfs-writer-source-code/hdfs-writer/src/main/java/Orchestrator.java
blob: b4daf2d150f792029e927328109c26f77fd65b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import config.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;


public class Orchestrator {

    private static Logger logger = LoggerFactory.getLogger(Orchestrator.class);

    public void init(String configYamlFile){

        parseConfigYaml(configYamlFile);
    }

    private void parseConfigYaml(String configYaml) {

        URL fileUrl = getClass().getResource(configYaml);
        if(fileUrl==null)
            System.out.println("::: Config file missing!!! :::");

        else{
            Configuration conf = new Configuration();
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            String realConfigYaml = configYaml;

            if (!realConfigYaml.startsWith("/")) {
                realConfigYaml = "/" + configYaml;
            }
            Map<String, Object> configs;
            try (InputStream is = getClass().getResourceAsStream(realConfigYaml)) {
                TypeReference<HashMap<String, Object>> typeRef
                        = new TypeReference<HashMap<String, Object>>() {
                };
                configs = mapper.readValue(is, typeRef);
                conf.init(configs);

            } catch (Exception e) {
                logger.error(e.getMessage());
            }
        }
    }
}