Commit 2cb07dfe authored by Mingyang Zhu's avatar Mingyang Zhu
Browse files

implement spi interface for the customized health check api

parent 35fc1e1d
......@@ -14,27 +14,25 @@
package org.opengroup.osdu.partition.api;
import java.util.Collections;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
@RestController
@RequestMapping(path= "/_ah", produces = "application/json")
@RequestMapping(path = "/_ah", produces = "application/json")
public class HealthCheck {
@Autowired
private AuditLogger auditLogger;
@Autowired
@Qualifier("partitionServiceCache")
private IPartitionServiceCache<String, PartitionInfo> dummyCache;
private IHealthCheckService healthCheckService;
@GetMapping("/liveness_check")
public ResponseEntity<String> livenessCheck() {
......@@ -45,14 +43,7 @@ public class HealthCheck {
@GetMapping("/readiness_check")
public ResponseEntity<String> readinessCheck() {
customReadinessCheckList();
healthCheckService.performReadinessCheck();
return new ResponseEntity<>("Partition service is ready", HttpStatus.OK);
}
/**
* Cache layer must be ready before the pod can serve the traffic
*/
private void customReadinessCheckList() {
dummyCache.get("dummy-key");
}
}
package org.opengroup.osdu.partition.provider.interfaces;
public interface IHealthCheckService {
void performReadinessCheck();
}
......@@ -20,8 +20,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.partition.logging.AuditLogger;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService;
import org.springframework.http.HttpStatus;
import static org.junit.jupiter.api.Assertions.assertEquals;
......@@ -33,7 +32,7 @@ public class HealthCheckTest {
@Mock
private AuditLogger auditLogger;
@Mock
private IPartitionServiceCache<String, PartitionInfo> dummyCache;
private IHealthCheckService healthCheckService;
@InjectMocks
private HealthCheck sut;
......@@ -46,6 +45,6 @@ public class HealthCheckTest {
@Test
public void should_returnHttp200_when_checkReadiness() {
assertEquals(HttpStatus.OK, this.sut.readinessCheck().getStatusCode());
verify(dummyCache).get("dummy-key");
verify(healthCheckService).performReadinessCheck();
}
}
\ No newline at end of file
package org.opengroup.osdu.partition.provider.aws.service;
import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService;
public class HealthCheckServiceImpl implements IHealthCheckService {
@Override
public void performReadinessCheck() {
}
}
package org.opengroup.osdu.partition.provider.azure.service;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
public class HealthCheckServiceImpl implements IHealthCheckService {
@Autowired
@Qualifier("partitionServiceCache")
private IPartitionServiceCache<String, PartitionInfo> partitionServiceCache;
/**
* Cache layer must be ready before the pod can serve the traffic
*/
@Override
public void performReadinessCheck() {
partitionServiceCache.get("dummy-key");
}
}
package org.opengroup.osdu.partition.provider.gcp.service;
import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService;
public class HealthCheckServiceImpl implements IHealthCheckService {
@Override
public void performReadinessCheck() {
}
}
package org.opengroup.osdu.partition.provider.ibm.service;
import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService;
public class HealthCheckServiceImpl implements IHealthCheckService {
@Override
public void performReadinessCheck() {
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment