2 * Copyright (c) 2018 Orange
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
14 package org.onap.nbi.apis.status;
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;
32 public class OnapClient {
35 private SdcClient sdcClient;
38 private AaiClient aaiClient;
41 private SoClient soClient;
44 private CheckDMaaPEventsManager checkDMaaPEventsManager;
46 private static final Logger LOGGER = LoggerFactory.getLogger(OnapClient.class);
48 public ApplicationStatus checkConnectivity(OnapModuleType onapModuleType) {
51 switch (onapModuleType) {
53 sdcClient.callCheckConnectivity();
56 aaiClient.callCheckConnectivity();
59 soClient.callCheckConnectivity();
62 checkDMaaPEventsManager.callCheckConnectivity();
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,
73 LOGGER.error(message);
74 return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.KO, null);
76 return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.OK, null);