Format Java code with respect to ONAP Code Style
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / status / OnapClient.java
1 /**
2  * Copyright (c) 2018 Orange
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11  * specific language governing permissions and limitations under the License.
12  */
13
14 package org.onap.nbi.apis.status;
15
16 import java.text.MessageFormat;
17 import org.onap.nbi.apis.hub.service.dmaap.CheckDMaaPEventsManager;
18 import org.onap.nbi.apis.servicecatalog.SdcClient;
19 import org.onap.nbi.apis.serviceinventory.AaiClient;
20 import org.onap.nbi.apis.serviceorder.SoClient;
21 import org.onap.nbi.apis.status.model.ApplicationStatus;
22 import org.onap.nbi.apis.status.model.OnapModuleType;
23 import org.onap.nbi.apis.status.model.StatusType;
24 import org.onap.nbi.exceptions.BackendFunctionalException;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service;
29 import org.springframework.web.client.ResourceAccessException;
30
31 @Service
32 public class OnapClient {
33
34     @Autowired
35     private SdcClient sdcClient;
36
37     @Autowired
38     private AaiClient aaiClient;
39
40     @Autowired
41     private SoClient soClient;
42
43     @Autowired
44     private CheckDMaaPEventsManager checkDMaaPEventsManager;
45
46     private static final Logger LOGGER = LoggerFactory.getLogger(OnapClient.class);
47
48     public ApplicationStatus checkConnectivity(OnapModuleType onapModuleType) {
49         try {
50
51             switch (onapModuleType) {
52                 case SDC:
53                     sdcClient.callCheckConnectivity();
54                     break;
55                 case AAI:
56                     aaiClient.callCheckConnectivity();
57                     break;
58                 case SO:
59                     soClient.callCheckConnectivity();
60                     break;
61                 case DMAAP:
62                     checkDMaaPEventsManager.callCheckConnectivity();
63                     break;
64             }
65         } catch (BackendFunctionalException e) {
66             String message = MessageFormat.format("backend exception for {0}, status code {1}, body response {2}",
67                     onapModuleType, e.getHttpStatus(), e.getBodyResponse());
68             LOGGER.error(message);
69             return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.KO, null);
70         } catch (ResourceAccessException e) {
71             String message = MessageFormat.format("resource access exception for {0}, response {1}", onapModuleType,
72                     e.getMessage());
73             LOGGER.error(message);
74             return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.KO, null);
75         }
76         return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.OK, null);
77     }
78
79 }