1 package org.onap.sdc.dcae.composition.controller.health;
3 import java.util.ArrayList;
6 import org.onap.sdc.common.onaplog.OnapLoggerDebug;
7 import org.onap.sdc.common.onaplog.OnapLoggerError;
8 import org.onap.sdc.common.onaplog.Enums.LogLevel;
9 import org.onap.sdc.dcae.composition.restmodels.health.ComponentsInfo;
10 import org.onap.sdc.dcae.composition.restmodels.health.HealthResponse;
11 import org.onap.sdc.dcae.composition.CompositionEngine;
12 import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
15 import org.springframework.http.HttpStatus;
16 import org.springframework.http.ResponseEntity;
17 import org.springframework.web.bind.annotation.CrossOrigin;
18 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.bind.annotation.RequestMethod;
20 import org.springframework.web.bind.annotation.RestController;
22 import com.google.gson.Gson;
25 @EnableAutoConfiguration
27 public class HealthController {
28 private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
29 private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
30 Gson gson = new Gson();
33 ToscaLabHealthState toscaLabHealthState;
35 @RequestMapping(value = "/healthCheck", method = RequestMethod.GET)
36 public ResponseEntity<String> healthCheck() {
37 HttpStatus httpSts = HttpStatus.OK;
39 HealthResponse healthResponse = new HealthResponse();
40 healthResponse.setHealthCheckComponent(DcaeBeConstants.Health.APP_NAME);
41 healthResponse.setHealthCheckStatus(DcaeBeConstants.Health.UP);
42 healthResponse.setSdcVersion(CompositionEngine.getDcaeVersion());
43 healthResponse.setDescription(DcaeBeConstants.Health.OK);
45 List<ComponentsInfo> componentsInfoList = new ArrayList<ComponentsInfo>();
46 ComponentsInfo componentsInfo = new ComponentsInfo();
47 componentsInfo.setHealthCheckComponent(DcaeBeConstants.Health.BE);
48 componentsInfo.setHealthCheckStatus(DcaeBeConstants.Health.UP);
49 componentsInfo.setVersion(CompositionEngine.getDcaeVersion());
50 componentsInfo.setDescription(DcaeBeConstants.Health.OK);
51 componentsInfoList.add(componentsInfo);
53 ComponentsInfo toscaLab = new ComponentsInfo();
54 ComponentsInfo toscaLabHealthRes = toscaLabHealthState.getToscaLabHealthResponse();
55 if(toscaLabHealthRes.getHealthCheckStatus().equals(DcaeBeConstants.Health.DOWN)){
56 healthResponse.setHealthCheckStatus(DcaeBeConstants.Health.DOWN);
57 healthResponse.setDescription(toscaLabHealthRes.getHealthCheckComponent()+" is down");
58 httpSts = HttpStatus.INTERNAL_SERVER_ERROR;
60 toscaLab.setHealthCheckComponent(toscaLabHealthRes.getHealthCheckComponent());
61 toscaLab.setHealthCheckStatus(toscaLabHealthRes.getHealthCheckStatus());
62 toscaLab.setVersion(toscaLabHealthRes.getVersion());
63 toscaLab.setDescription(toscaLabHealthRes.getDescription());
64 componentsInfoList.add(toscaLab);
66 healthResponse.setComponentsInfo(componentsInfoList);
67 String json = gson.toJson(healthResponse, HealthResponse.class);
69 return new ResponseEntity<String>(json, httpSts);
72 errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error occured while performing HealthCheck: {}", e.getLocalizedMessage());
73 return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);