2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dcae;
23 import io.vavr.collection.Map;
24 import org.json.JSONObject;
25 import org.onap.dcae.commonFunction.EventProcessor;
26 import org.onap.dcae.commonFunction.event.publishing.DMaaPConfigurationParser;
27 import org.onap.dcae.commonFunction.event.publishing.EventPublisher;
28 import org.onap.dcae.commonFunction.event.publishing.PublisherConfig;
29 import org.onap.dcae.controller.ConfigLoader;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Qualifier;
33 import org.springframework.boot.Banner;
34 import org.springframework.boot.SpringApplication;
35 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
36 import org.springframework.boot.autoconfigure.SpringBootApplication;
37 import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
38 import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.Lazy;
42 import java.nio.file.Paths;
43 import java.util.concurrent.*;
45 @SpringBootApplication(exclude = {GsonAutoConfiguration.class, SecurityAutoConfiguration.class})
46 public class VesApplication {
48 private static final Logger metriclog = LoggerFactory.getLogger("com.att.ecomp.metrics");
49 private static final Logger incomingRequestsLogger = LoggerFactory.getLogger("org.onap.dcae.commonFunction.input");
50 private static final Logger oplog = LoggerFactory.getLogger("org.onap.dcae.commonFunction.output");
51 private static final Logger errorLog = LoggerFactory.getLogger("org.onap.dcae.commonFunction.error");
52 private static final int MAX_THREADS = 20;
53 public static LinkedBlockingQueue<JSONObject> fProcessingInputQueue;
54 private static ApplicationSettings properties;
56 public static void main(String[] args) {
57 SpringApplication app = new SpringApplication(VesApplication.class);
59 properties = new ApplicationSettings(args, CLIUtils::processCmdLine);
61 fProcessingInputQueue = new LinkedBlockingQueue<>(properties.maximumAllowedQueuedEvents());
63 EventPublisher publisher = EventPublisher.createPublisher(oplog,
64 DMaaPConfigurationParser
65 .parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation()))
67 spawnDynamicConfigUpdateThread(publisher, properties);
68 EventProcessor ep = new EventProcessor(EventPublisher.createPublisher(oplog, getDmapConfig()), properties);
70 ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS);
71 for (int i = 0; i < MAX_THREADS; ++i) {
75 app.setBannerMode(Banner.Mode.OFF);
76 app.setAddCommandLineProperties(true);
80 private static void spawnDynamicConfigUpdateThread(EventPublisher eventPublisher, ApplicationSettings properties) {
81 ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
82 ConfigLoader configLoader = ConfigLoader
83 .create(eventPublisher::reconfigure,
84 Paths.get(properties.dMaaPConfigurationFileLocation()),
85 properties.configurationFileLocation());
86 scheduledThreadPoolExecutor
87 .scheduleAtFixedRate(() -> configLoader.updateConfig(),
88 properties.configurationUpdateFrequency(),
89 properties.configurationUpdateFrequency(),
93 private static Map<String, PublisherConfig> getDmapConfig() {
94 return DMaaPConfigurationParser.
95 parseToDomainMapping(Paths.get(properties.dMaaPConfigurationFileLocation())).get();
100 public ApplicationSettings applicationSettings() {
105 @Qualifier("incomingRequestsLogger")
106 public Logger incomingRequestsLogger() {
107 return incomingRequestsLogger;
111 @Qualifier("metricsLog")
112 public Logger incomingRequestsMetricsLogger() {
117 @Qualifier("errorLog")
118 public Logger errorLogger() {
123 public LinkedBlockingQueue<JSONObject> inputQueue() {
124 return fProcessingInputQueue;