Implement second part of dynamic DMaaP config
[dcaegen2/collectors/ves.git] / src / main / java / org / onap / dcae / controller / PreAppStartupConfigUpdater.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dcaegen2.collectors.ves
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.controller;
21
22 import io.vavr.collection.Map;
23 import java.nio.file.Path;
24 import java.nio.file.Paths;
25 import java.util.function.Consumer;
26 import org.onap.dcae.commonFunction.event.publishing.PublisherConfig;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * On the first application launch, the configuration update thread that application spawns, has no chance to run yet
32  * and prepare initial application configuration. In this case, it needs to be fetched from outside of the application,
33  * so this is run from the .sh script.
34  * Later on, once application is already started it will take care of the configuration update itself
35  * @author Pawel Szalapski (pawel.szalapski@nokia.com)
36  */
37 public class PreAppStartupConfigUpdater {
38     private final static Logger log = LoggerFactory.getLogger(PreAppStartupConfigUpdater.class);
39
40     private static final Path DEFAULT_CONFIGURATION_FILE_PATH = Paths.get("etc/collector.properties");
41     private static final Path DEFAULT_DMAAP_FILE_PATH = Paths.get("etc/DmaapConfig.json");
42     private static final Consumer<Map<String, PublisherConfig>> NO_OP_CONSUMER = c -> { };
43
44     public static void main(String[] args) {
45         log.info("Running initial configuration update, before the application gets started.");
46         ConfigLoader.create(NO_OP_CONSUMER, DEFAULT_DMAAP_FILE_PATH, DEFAULT_CONFIGURATION_FILE_PATH)
47             .updateConfig();
48     }
49 }