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.
13 package org.onap.nbi.apis.status;
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;
31 public class OnapClient {
34 private SdcClient sdcClient;
37 private AaiClient aaiClient;
40 private SoClient soClient;
43 private CheckDMaaPEventsManager checkDMaaPEventsManager;
45 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
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);
77 return new ApplicationStatus(onapModuleType.getValue() + " connectivity", StatusType.OK, null);