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 org.openecomp.mso.MsoStatusUtil;
25 import org.openecomp.mso.db.catalog.CatalogDatabase;
26 import org.openecomp.mso.logger.MessageEnum;
27 import org.openecomp.mso.logger.MsoLogger;
28 import org.openecomp.mso.properties.MsoJsonProperties;
29 import org.openecomp.mso.properties.MsoPropertiesFactory;
30 import org.openecomp.mso.HealthCheckUtils;
31 import org.openecomp.mso.utils.UUIDChecker;
32 import org.apache.http.HttpStatus;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.HEAD;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.QueryParam;
39 import javax.ws.rs.core.Response;
43 public class HealthCheckHandler {
45 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.ASDC);
46 private static final String MSO_PROP_ASDC = "MSO_PROP_ASDC";
47 private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
49 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>";
50 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>";
52 private static final Response OK_RESPONSE = Response.status (HttpStatus.SC_OK).entity (SUC_HTML).build ();
53 private static final Response NOK_RESPONSE = Response.status (HttpStatus.SC_SERVICE_UNAVAILABLE).entity (NOT_FOUND).build ();
58 @Produces("text/html")
59 public Response healthcheck (@QueryParam("requestId") String requestId) {
60 long startTime = System.currentTimeMillis ();
61 MsoLogger.setServiceName ("Healthcheck");
62 UUIDChecker.verifyOldUUID(requestId, msoLogger);
63 HealthCheckUtils healthCheck = new HealthCheckUtils ();
64 if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
65 return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
68 MsoJsonProperties props = loadMsoProperties ();
70 msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Application Not Ready");
71 return HealthCheckUtils.NOT_STARTED_RESPONSE;
74 if (!healthCheck.catalogDBCheck (msoLogger, startTime)) {
75 return HealthCheckUtils.NOT_STARTED_RESPONSE;
77 msoLogger.debug("healthcheck - Successful");
78 return HealthCheckUtils.HEALTH_CHECK_RESPONSE;
81 private MsoJsonProperties loadMsoProperties () {
82 MsoJsonProperties msoProperties;
84 msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_PROP_ASDC);
85 } catch (Exception e) {
86 msoLogger.error (MessageEnum.ASDC_PROPERTIES_NOT_FOUND, MSO_PROP_ASDC, "", "", MsoLogger.ErrorCode.DataError, "Exception - getMsoJsonProperties", e);
90 if (msoProperties !=null && msoProperties.getJsonRootNode().getElements().hasNext()) {
93 msoLogger.error (MessageEnum.ASDC_PROPERTIES_NOT_FOUND , MSO_PROP_ASDC, "", "", MsoLogger.ErrorCode.DataError, "ASDC properties not found");