bed0aaecc109a50f64985064639639994185617a
[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 org.openecomp.sdc.common.log.wrappers.Logger;
24
25 import java.util.concurrent.Callable;
26
27 public class UebHealthCheckCall implements Callable<Boolean> {
28
29     CambriaHandler cambriaHandler = new CambriaHandler();
30
31     String server;
32     String publicApiKey;
33
34     private static final Logger healthLogger = Logger.getLogger(DistributionEngineClusterHealth.UEB_HEALTH_LOG_CONTEXT);
35
36     private static final Logger logger = Logger.getLogger(UebHealthCheckCall.class.getName());
37
38     public UebHealthCheckCall(String server, String publicApiKey) {
39         super();
40         this.server = server;
41         this.publicApiKey = publicApiKey;
42     }
43
44     @Override
45     public Boolean call() {
46
47         healthLogger.trace("Going to run health check towards ueb server {}", server);
48
49         boolean result = false;
50         CambriaErrorResponse cambriaErrorResponse = cambriaHandler.getApiKey(server, publicApiKey);
51
52         logger.debug("After running Health check towards ueb server {}. Result is {}", server, cambriaErrorResponse);
53
54         if (cambriaErrorResponse.httpCode < CambriaErrorResponse.HTTP_INTERNAL_SERVER_ERROR) {
55             logger.debug("After running Health check towards ueb server {}. Error code is {}. Set result to true", server, cambriaErrorResponse.httpCode);
56             result = true;
57         }
58         else {
59             logger.debug("After running Health check towards ueb server {}. Error code is {}. Set result to false", server, cambriaErrorResponse.httpCode);
60         }
61
62         healthLogger.trace("Result after running health check towards ueb server {} is {}. Returned result is {} ", server, cambriaErrorResponse, result);
63
64         return result;
65     }
66
67     public String getServer() {
68         return server;
69     }
70
71     public CambriaHandler getCambriaHandler() {
72         return cambriaHandler;
73     }
74
75     public void setCambriaHandler(CambriaHandler cambriaHandler) {
76         this.cambriaHandler = cambriaHandler;
77     }
78
79 }