use logging interceptor in SDC client
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / WebConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 - 2019 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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.onap.vid.controller;
23
24 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
25
26 import com.fasterxml.jackson.module.kotlin.KotlinModule;
27 import io.joshworks.restclient.http.mapper.ObjectMapper;
28 import java.io.File;
29 import java.util.concurrent.ExecutorService;
30 import java.util.concurrent.Executors;
31 import javax.servlet.ServletContext;
32 import org.onap.portalsdk.core.util.SystemProperties;
33 import org.onap.vid.aai.AaiClient;
34 import org.onap.vid.aai.AaiClientInterface;
35 import org.onap.vid.aai.AaiOverTLSClient;
36 import org.onap.vid.aai.AaiOverTLSClientInterface;
37 import org.onap.vid.aai.AaiOverTLSPropertySupplier;
38 import org.onap.vid.aai.AaiResponseTranslator;
39 import org.onap.vid.aai.PombaClientImpl;
40 import org.onap.vid.aai.PombaClientInterface;
41 import org.onap.vid.aai.PombaRestInterface;
42 import org.onap.vid.aai.model.PortDetailsTranslator;
43 import org.onap.vid.aai.util.AAIRestInterface;
44 import org.onap.vid.aai.util.CacheProvider;
45 import org.onap.vid.aai.util.HttpsAuthClient;
46 import org.onap.vid.aai.util.SSLContextProvider;
47 import org.onap.vid.aai.util.ServiceInstanceStandardQuery;
48 import org.onap.vid.aai.util.ServletRequestHelper;
49 import org.onap.vid.aai.util.SystemPropertyHelper;
50 import org.onap.vid.asdc.AsdcClient;
51 import org.onap.vid.asdc.parser.ToscaParserImpl2;
52 import org.onap.vid.asdc.parser.VidNotionsBuilder;
53 import org.onap.vid.asdc.rest.SdcRestClient;
54 import org.onap.vid.client.SyncRestClient;
55 import org.onap.vid.properties.AsdcClientConfiguration;
56 import org.onap.vid.properties.VidProperties;
57 import org.onap.vid.scheduler.SchedulerService;
58 import org.onap.vid.scheduler.SchedulerServiceImpl;
59 import org.onap.vid.services.AAIServiceTree;
60 import org.onap.vid.services.AAITreeNodeBuilder;
61 import org.onap.vid.services.AaiService;
62 import org.onap.vid.services.AaiServiceImpl;
63 import org.onap.vid.services.ChangeManagementService;
64 import org.onap.vid.services.PombaService;
65 import org.onap.vid.services.PombaServiceImpl;
66 import org.onap.vid.utils.JoshworksJacksonObjectMapper;
67 import org.onap.vid.utils.Logging;
68 import org.springframework.beans.factory.annotation.Qualifier;
69 import org.springframework.context.annotation.Bean;
70 import org.springframework.context.annotation.Configuration;
71 import org.togglz.core.manager.FeatureManager;
72 import springfox.documentation.builders.PathSelectors;
73 import springfox.documentation.builders.RequestHandlerSelectors;
74 import springfox.documentation.spi.DocumentationType;
75 import springfox.documentation.spring.web.plugins.Docket;
76 import springfox.documentation.swagger2.annotations.EnableSwagger2;
77
78 @EnableSwagger2
79 @Configuration
80 public class WebConfig {
81
82     /**
83      * Gets the object mapper.
84      *
85      * @return the object mapper
86      */
87     @Bean
88     public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
89         return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
90     }
91
92
93     @Bean
94     public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
95         return new SchedulerServiceImpl(changeManagementService);
96     }
97
98     @Bean
99     public AaiService getAaiService(AaiClientInterface aaiClient, AaiResponseTranslator aaiResponseTranslator,
100         AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) {
101         return new AaiServiceImpl(aaiClient, aaiResponseTranslator, aaiServiceTree, executorService);
102     }
103
104     @Bean
105     public AaiResponseTranslator aaiResponseTranslator() {
106         return new AaiResponseTranslator();
107     }
108
109     @Bean
110     public PortDetailsTranslator portDetailsTranslator() {
111         return new PortDetailsTranslator();
112     }
113
114     @Bean
115     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
116         return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
117     }
118
119     @Bean(name = "aaiRestInterface")
120     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory,
121         ServletRequestHelper servletRequestHelper,
122         SystemPropertyHelper systemPropertyHelper,
123         Logging loggingService) {
124         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper, loggingService);
125     }
126
127     @Bean
128     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory,
129         ServletRequestHelper servletRequestHelper,
130         SystemPropertyHelper systemPropertyHelper,
131         Logging loggingService) {
132         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper, loggingService);
133     }
134
135     @Bean
136     public SSLContextProvider sslContextProvider() {
137         return new SSLContextProvider();
138     }
139
140     @Bean
141     public SystemPropertyHelper systemPropertyHelper() {
142         return new SystemPropertyHelper();
143     }
144
145     @Bean
146     public ServletRequestHelper servletRequestHelper() {
147         return new ServletRequestHelper();
148     }
149
150     @Bean
151     public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
152         final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
153         return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
154     }
155
156     @Bean
157     public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, Logging loggingService) {
158         String auth = asdcClientConfiguration.getAsdcClientAuth();
159         String host = asdcClientConfiguration.getAsdcClientHost();
160         String protocol = asdcClientConfiguration.getAsdcClientProtocol();
161         int port = asdcClientConfiguration.getAsdcClientPort();
162
163         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth,
164             new SyncRestClient( loggingService, true),
165             loggingService);
166     }
167
168     @Bean
169     public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
170         return new VidNotionsBuilder(featureManager);
171     }
172
173     @Bean
174     public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
175         return new ToscaParserImpl2(vidNotionsBuilder);
176     }
177
178     @Bean
179     public PombaService getVerifyServiceInstanceService() {
180         return new PombaServiceImpl();
181     }
182
183     @Bean
184     public PombaClientInterface getVerifyServiceInstanceClientInterface() {
185         return new PombaClientImpl();
186     }
187
188     @Bean
189     public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
190         return new ServiceInstanceStandardQuery(aaiClient);
191     }
192
193     @Bean
194     public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties, Logging loggingService){
195         return new AaiOverTLSClient(
196             new SyncRestClient(unirestObjectMapper,  loggingService),
197             new AaiOverTLSPropertySupplier());
198     }
199
200     @Bean
201     public ObjectMapper unirestFasterxmlObjectMapper() {
202         return new JoshworksJacksonObjectMapper();
203     }
204
205     @Bean
206     public Docket api(){
207         return new Docket(DocumentationType.SWAGGER_2)
208                 .select()
209                 .apis(RequestHandlerSelectors.basePackage("org.onap.vid.controller.open"))
210                 .paths(PathSelectors.any())
211                 .build();
212     }
213
214     @Bean
215     public ExecutorService executorService() {
216         int threadsCount = defaultIfNull(Integer.parseInt(SystemProperties.getProperty(VidProperties.VID_THREAD_COUNT)), 1);
217         return Executors.newFixedThreadPool(threadsCount);
218     }
219 }