2 * ============LICENSE_START=======================================================
3 * org.onap.dcaegen2.collectors.ves
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2020 Nokia. All rights reserved.
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=========================================================
21 package org.onap.dcae.configuration;
23 import static io.vavr.API.Try;
24 import static io.vavr.API.Tuple;
25 import static org.onap.dcae.common.publishing.VavrUtils.f;
26 import static org.onap.dcae.configuration.Conversions.toList;
28 import io.vavr.collection.Map;
29 import io.vavr.control.Option;
30 import org.json.JSONObject;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 interface ConfigParsing {
36 Logger log = LoggerFactory.getLogger(ConfigParsing.class);
38 static Option<JSONObject> getDMaaPConfig(JSONObject configuration) {
39 log.info(f("Getting DMaaP configuration from app configuration: '%s'", configuration));
40 return toList(configuration.toMap().entrySet().iterator())
41 .filter(t -> t.getKey().startsWith("streams_publishes"))
43 .flatMap(e -> Try(() -> configuration.getJSONObject(e.getKey())).toOption())
44 .onEmpty(() -> log.warn(f("App configuration '%s' is missing DMaaP configuration ('streams_publishes' key) "
45 + "or DMaaP configuration is not a valid json document", configuration)))
46 .peek(dMaaPConf -> log.info(f("Found following DMaaP configuration: '%s'", dMaaPConf)));
49 static Map<String, String> getProperties(JSONObject configuration) {
50 log.info(f("Getting properties configuration from app configuration: '%s'", configuration));
51 Map<String, String> confEntries = toList(configuration.toMap().entrySet().iterator())
52 .toMap(e -> Tuple(e.getKey(), String.valueOf(e.getValue())))
53 .filterKeys(e -> !e.startsWith("streams_publishes"));
54 log.info(f("Found following app properties: '%s'", confEntries));