2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.asdc.healthcheck;
24 import javax.ws.rs.GET;
25 import javax.ws.rs.HEAD;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.Produces;
28 import javax.ws.rs.QueryParam;
29 import javax.ws.rs.core.Response;
31 import org.apache.http.HttpStatus;
32 import org.openecomp.mso.HealthCheckUtils;
33 import org.openecomp.mso.logger.MessageEnum;
34 import org.openecomp.mso.logger.MsoLogger;
35 import org.openecomp.mso.properties.MsoJsonProperties;
36 import org.openecomp.mso.properties.MsoPropertiesFactory;
37 import org.openecomp.mso.utils.UUIDChecker;
41 public class HealthCheckHandler {
43 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.ASDC);
44 private static final String MSO_PROP_ASDC = "MSO_PROP_ASDC";
45 private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
47 private static final String SUC_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
48 private static final String NOT_FOUND = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Application Not Ready</title></head><body>Application Not Ready. Properties file missing or invalid or database Connection failed</body></html>";
50 private static final Response OK_RESPONSE = Response.status (HttpStatus.SC_OK).entity (SUC_HTML).build ();
51 private static final Response NOK_RESPONSE = Response.status (HttpStatus.SC_SERVICE_UNAVAILABLE).entity (NOT_FOUND).build ();
56 @Produces("text/html")
57 public Response healthcheck (@QueryParam("requestId") String requestId) {
58 long startTime = System.currentTimeMillis ();
59 MsoLogger.setServiceName ("Healthcheck");
60 UUIDChecker.verifyOldUUID(requestId, msoLogger);
61 HealthCheckUtils healthCheck = new HealthCheckUtils ();
62 if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
63 return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
66 MsoJsonProperties props = loadMsoProperties ();
68 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Application Not Ready");
69 return HealthCheckUtils.NOT_STARTED_RESPONSE;
72 if (!healthCheck.catalogDBCheck (msoLogger, startTime)) {
73 return HealthCheckUtils.NOT_STARTED_RESPONSE;
75 msoLogger.debug("healthcheck - Successful");
76 return HealthCheckUtils.HEALTH_CHECK_RESPONSE;
79 private MsoJsonProperties loadMsoProperties () {
80 MsoJsonProperties msoProperties;
82 msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_PROP_ASDC);
83 } catch (Exception e) {
84 msoLogger.error (MessageEnum.ASDC_PROPERTIES_NOT_FOUND, MSO_PROP_ASDC, "", "", MsoLogger.ErrorCode.DataError, "Exception - getMsoJsonProperties", e);
88 if (msoProperties !=null && msoProperties.getJsonRootNode().elements().hasNext()) {
91 msoLogger.error (MessageEnum.ASDC_PROPERTIES_NOT_FOUND , MSO_PROP_ASDC, "", "", MsoLogger.ErrorCode.DataError, "ASDC properties not found");