Integrate sdc notification
[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 package org.onap.nbi.apis.status;
14
15 import java.text.MessageFormat;
16 import org.onap.nbi.apis.hub.service.dmaap.CheckDMaaPEventsManager;
17 import org.onap.nbi.apis.servicecatalog.SdcClient;
18 import org.onap.nbi.apis.serviceinventory.AaiClient;
19 import org.onap.nbi.apis.serviceorder.SoClient;
20 import org.onap.nbi.apis.status.model.ApplicationStatus;
21 import org.onap.nbi.apis.status.model.OnapModuleType;
22 import org.onap.nbi.apis.status.model.StatusType;
23 import org.onap.nbi.exceptions.BackendFunctionalException;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service;
28 import org.springframework.web.client.ResourceAccessException;
29
30 @Service
31 public class OnapClient {
32
33     @Autowired
34     private SdcClient sdcClient;
35
36     @Autowired
37     private AaiClient aaiClient;
38
39     @Autowired
40     private SoClient soClient;
41
42     @Autowired
43     private CheckDMaaPEventsManager checkDMaaPEventsManager;
44
45     private static final Logger LOGGER = LoggerFactory.getLogger(OnapClient.class);
46
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
67                 .format("backend exception for {0}, status code {1}, body response {2}", onapModuleType,
68                     e.getHttpStatus(), e.getBodyResponse());
69             LOGGER.error(message);
70             return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.KO, null);
71         } catch (ResourceAccessException e) {
72             String message = MessageFormat
73                 .format("resource access exception for {0}, response {1}", onapModuleType, e.getMessage());
74             LOGGER.error(message);
75             return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.KO, null);
76         }
77         return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.OK, null);
78     }
79
80
81 }