Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.model.enumeration.ErrorCode;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.indices.ExistsRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ActuatorConfig {

@Bean
public HealthIndicator ogcApiHealth(
@Value("${elasticsearch.vocabs_index.name}") String vocabIndexName,
@Value("${elasticsearch.index.name}") String indexName,
@Value("${elasticsearch.cloud_optimized_index.name}") String coIndexName,
ElasticsearchClient client) {
return () -> {
try {
// Is elastic up and run?
String status = client.cluster().health(r -> r).status().toString();
if ("yellow".equalsIgnoreCase(status) || "red".equalsIgnoreCase(status)) {
return Health.status(ErrorCode.ELASTICSEARCH_UNAVAILABLE.getStatus())
.withDetail("reason", ErrorCode.ELASTICSEARCH_UNAVAILABLE.getMessage())
.withDetail("code", ErrorCode.ELASTICSEARCH_UNAVAILABLE.getCode())
.build();
}

// Now if our target index exist?
if(!client.indices().exists(ExistsRequest.of(b -> b.index(indexName))).value()) {
return Health.status(ErrorCode.MISSING_CORE_INDEX.getStatus())
.withDetail("reason", ErrorCode.MISSING_CORE_INDEX.getMessage())
.withDetail("code", ErrorCode.MISSING_CORE_INDEX.getCode())
.build();
}

if(!client.indices().exists(ExistsRequest.of(b -> b.index(coIndexName))).value()) {
return Health.status(ErrorCode.MISSING_CO_CORE_INDEX.getStatus())
.withDetail("reason", ErrorCode.MISSING_CO_CORE_INDEX.getMessage())
.withDetail("code", ErrorCode.MISSING_CO_CORE_INDEX.getCode())
.build();
}

if(!client.indices().exists(ExistsRequest.of(b -> b.index(vocabIndexName))).value()) {
return Health.status(ErrorCode.MISSING_VOCAB_INDEX.getStatus())
.withDetail("reason", ErrorCode.MISSING_VOCAB_INDEX.getMessage())
.withDetail("code", ErrorCode.MISSING_VOCAB_INDEX.getCode())
.build();
}

return Health.up().build();
} catch (Exception e) {
return Health.status(ErrorCode.ELASTICSEARCH_UNAVAILABLE.getStatus())
.withDetail("reason", ErrorCode.ELASTICSEARCH_UNAVAILABLE.getMessage())
.withDetail("code", ErrorCode.ELASTICSEARCH_UNAVAILABLE.getCode())
.withException(e)
.build();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Config {
ObjectMapper mapper;

@Autowired
public void initConstrucUtils(ObjectMapper mapper) {
public void initConstructUtils(ObjectMapper mapper) {
ConstructUtils.setObjectMapper(mapper);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ElasticsearchClient geoNetworkElasticsearchClient(RestClientTransport tra
* @param indexName - The elastic index name that store the STAC from es-indexer
* @param pageSize - Do not set this value too high, say 5000 will crash elastic search
* @param searchAsYouTypeSize - The number of search result return for search as you type
* @return
* @return The search object
*/
@Bean
public Search createElasticSearch(ElasticsearchClient client,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package au.org.aodn.ogcapi.server.core.model.enumeration;

import lombok.Getter;

@Getter
public enum ErrorCode {
ELASTICSEARCH_UNAVAILABLE("DOWN", "E1000", "Dependency unavailable"),
MISSING_CO_CORE_INDEX("DEGRADED", "E1001","Missing cloud optimized index"),
MISSING_VOCAB_INDEX("DEGRADED", "E1002","Missing vocab index"),
MISSING_CORE_INDEX("DOWN", "E1003","Missing core index");

private final String status;
private final String code;
private final String message;

ErrorCode(String status, String code, String message) {
this.status = status;
this.code = code;
this.message = message;
}
}
4 changes: 4 additions & 0 deletions server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,16 @@ management:
health:
elasticsearch:
enabled: false
diskspace:
enabled: false
endpoints:
web:
base-path: /api/v1/ogc/manage
exposure:
include: "health,info"
endpoint:
health:
show-details: always
logfile:
external-file: /tmp/logs/ogcapi.log
# Actuator info point
Expand Down
Loading