Open Kilda Java Documentation
HealthCheckImpl.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.northbound.service.impl;
17 
27 
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Value;
32 import org.springframework.stereotype.Service;
33 
34 import java.util.Arrays;
35 import java.util.HashMap;
36 import java.util.Map;
37 
41 @Service
42 public class HealthCheckImpl implements HealthCheckService {
46  private static final Logger logger = LoggerFactory.getLogger(HealthCheckImpl.class);
47 
51  @Value("#{kafkaTopicsConfig.getHealthCheckTopic()}")
52  private String topic;
53 
57  private static final HealthCheckCommandData NORTHBOUND_REQUESTER =
59 
63  @Value("${service.name}")
64  private String serviceName;
65 
69  @Value("${service.version}")
70  private String serviceVersion;
71 
75  @Value("${service.description}")
76  private String serviceDescription;
77 
81  @Autowired
82  private HealthCheckMessageConsumer healthCheckMessageConsumer;
83 
87  @Autowired
88  private MessageProducer messageProducer;
89 
95  @Override
97  final String correlationId = RequestCorrelationId.getId();
98 
99  // FIXME(surabujin): restore health check operation
100  /*
101  healthCheckMessageConsumer.clear();
102 
103  messageProducer.send(topic, new CommandMessage(
104  NORTHBOUND_REQUESTER, System.currentTimeMillis(), correlationId, null));
105 
106  Map<String, String> status = healthCheckMessageConsumer.poll(correlationId);
107 
108  Arrays.stream(ServiceType.values())
109  .forEach(service -> status.putIfAbsent(service.getSwitchId(), Utils.HEALTH_CHECK_NON_OPERATIONAL_STATUS));
110  */
111 
112  // FIXME(surabujin): hack to restore "operational" despite actual state of services
113  // hack start
114  Map<String, String> status = new HashMap<>();
115 
116  Arrays.stream(ServiceType.values())
117  .forEach(service -> status.putIfAbsent(service.getId(), Utils.HEALTH_CHECK_OPERATIONAL_STATUS));
118  // hack end
119 
120  HealthCheck healthCheck = new HealthCheck(serviceName, serviceVersion, serviceDescription, status);
121 
122  logger.info("Health-Check Status: {}", healthCheck);
123 
124  return healthCheck;
125  }
126 }
def status()
Definition: rest.py:593
static final String HEALTH_CHECK_OPERATIONAL_STATUS
Definition: Utils.java:77