c522ca91b527d0cae1a70ae8146dbb7f6ddec707
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.distribution.engine;
22
23 import java.util.concurrent.Callable;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class UebHealthCheckCall implements Callable<Boolean> {
29
30         CambriaHandler cambriaHandler = new CambriaHandler();
31
32         String server;
33         String publicApiKey;
34
35         private static Logger healthLogger = LoggerFactory.getLogger(DistributionEngineClusterHealth.UEB_HEALTH_LOG_CONTEXT);
36
37         private static Logger logger = LoggerFactory.getLogger(UebHealthCheckCall.class.getName());
38
39         public UebHealthCheckCall(String server, String publicApiKey) {
40                 super();
41                 this.server = server;
42                 this.publicApiKey = publicApiKey;
43         }
44
45         @Override
46         public Boolean call() {
47
48                 healthLogger.trace("Going to run health check towards ueb server {}", server);
49
50                 boolean result = false;
51                 CambriaErrorResponse cambriaErrorResponse = cambriaHandler.getApiKey(server, publicApiKey);
52
53                 logger.debug("After running Health check towards ueb server {}. Result is {}", server, cambriaErrorResponse);
54
55                 if (cambriaErrorResponse.httpCode < CambriaErrorResponse.HTTP_INTERNAL_SERVER_ERROR) {
56                         logger.debug("After running Health check towards ueb server {}. Error code is {}. Set result to true", server, cambriaErrorResponse.httpCode);
57                         result = true;
58                 }
59
60                 healthLogger.trace("Result after running health check towards ueb server {} is {}. Returned result is {} ", server, cambriaErrorResponse, result);
61
62                 return result;
63         }
64
65         public String getServer() {
66                 return server;
67         }
68
69         public CambriaHandler getCambriaHandler() {
70                 return cambriaHandler;
71         }
72
73         public void setCambriaHandler(CambriaHandler cambriaHandler) {
74                 this.cambriaHandler = cambriaHandler;
75         }
76
77 }