Skip to content
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<dependency>
<groupId>au.org.aodn</groupId>
<artifactId>stacmodel</artifactId>
<version>0.0.60</version>
<version>0.0.63</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.model.enumeration.ErrorCode;
import au.org.aodn.ogcapi.server.core.service.das.DasService;
import au.org.aodn.ogcapi.server.core.service.dda.DdaService;
import au.org.aodn.ogcapi.server.core.service.geonetwork.Geonetwork;
import au.org.aodn.ogcapi.server.core.service.indexer.EsIndexer;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.HealthStatus;
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.boot.actuate.info.InfoContributor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class ActuatorConfig {

private static final String DEP_SERVICE = "depService";

// Define the InfoContributor bean to fill in the missing info in /manage/info endpoint
@Bean
public InfoContributor externalApiInfoContributor(
DasService das,
DdaService dda,
EsIndexer esIndexer,
Geonetwork geonetwork
) {
return builder -> {
try {
Map<String, Map<?,?>> versions = new HashMap<>();
versions.put(das.getName(),
Map.of("version", das.getVersion(), "description", das.getDescription()));
versions.put(dda.getName(),
Map.of("version", dda.getVersion(), "description", dda.getDescription()));
versions.put(esIndexer.getName(),
Map.of("version", esIndexer.getVersion(), "description", esIndexer.getDescription()));
versions.put(geonetwork.getName(),
Map.of("version", geonetwork.getVersion(), "description", geonetwork.getDescription()));

builder.withDetail(DEP_SERVICE, versions);
} catch (Exception e) {
builder.withDetail(DEP_SERVICE, Map.of(
"status", "ERROR Query",
"error", e.getMessage()
));
}
};
}

@Bean
public HealthIndicator ogcApiHealth(
@Value("${elasticsearch.vocabs_index.name}") String vocabIndexName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.service.das.DasProperties;
import au.org.aodn.ogcapi.server.core.service.dda.DdaProperties;
import au.org.aodn.ogcapi.server.core.service.geonetwork.GNProperties;
import au.org.aodn.ogcapi.server.core.service.indexer.IndexerProperties;
import au.org.aodn.ogcapi.server.core.util.ConstructUtils;
import au.org.aodn.ogcapi.server.core.util.GeometryUtils;
import au.org.aodn.ogcapi.server.core.util.RestTemplateUtils;
Expand All @@ -18,7 +22,12 @@

@Configuration
@EnableScheduling
@EnableConfigurationProperties(DasProperties.class)
@EnableConfigurationProperties({
DdaProperties.class,
IndexerProperties.class,
GNProperties.class,
DasProperties.class
})
public class Config {

public static final String DAS_REST_TEMPLATE = "dasRestTemplate";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.service.dda.DdaProperties;
import au.org.aodn.ogcapi.server.core.service.dda.DdaService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class DdaConfig {

@Bean
public DdaService createDdaServer(DdaProperties properties, RestTemplate template) {
return new DdaService(properties,template);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.service.geonetwork.GNProperties;
import au.org.aodn.ogcapi.server.core.service.geonetwork.Geonetwork;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class GeoNetworkConfig {

@Bean
public Geonetwork createGeonetwork(GNProperties properties, RestTemplate template) {
return new Geonetwork(properties, template);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package au.org.aodn.ogcapi.server.core.configuration;

import au.org.aodn.ogcapi.server.core.service.indexer.EsIndexer;
import au.org.aodn.ogcapi.server.core.service.indexer.IndexerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class IndexerConfig {

@Bean
public EsIndexer createEsIndexer(IndexerProperties properties, RestTemplate template) {
return new EsIndexer(properties, template);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package au.org.aodn.ogcapi.server.core.service;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.Map;

public interface ApplicationInfo {
/**
* Query this is repeat code to query the info path
* @param restTemplate - The template of the service
* @param host - Host
* @param path - query path
* @return - Map of value
*/
default Map<String, Map<?,?>> queryInfo(RestTemplate restTemplate, String host, String path) {
if(path != null) {
try {
String das = String.format("%s/%s", host, path);
ResponseEntity<Map<String, Map<?, ?>>> response = restTemplate.exchange(
das,
HttpMethod.GET,
null,
new ParameterizedTypeReference<>() {
}
);

if (response.getStatusCode().is2xxSuccessful()) {
return response.getBody();
}
} catch (Exception e) {
// Do not throw exception that impacts start, UI will use health endpoint to decide level of
// service, for example if geonetwork is not work, we can still provide service
}
}
return Collections.emptyMap();
}

String getName();
String getVersion();
String getDescription();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package au.org.aodn.ogcapi.server.core.configuration;
package au.org.aodn.ogcapi.server.core.service.das;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
Expand All @@ -8,6 +8,7 @@
@ConfigurationProperties(prefix = "data-access-service")
public record DasProperties(
String host,
@DefaultValue("api/v1/das/manage/info") String infoPath,
String secret,
String internal,
@DefaultValue("5s") Duration connectTimeout,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package au.org.aodn.ogcapi.server.core.service.das;

import au.org.aodn.ogcapi.server.core.configuration.Config;
import au.org.aodn.ogcapi.server.core.configuration.DasProperties;
import au.org.aodn.ogcapi.server.core.model.DatasetMetadata;
import au.org.aodn.ogcapi.server.core.service.ApplicationInfo;
import au.org.aodn.ogcapi.server.core.util.SseResponseParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -11,18 +11,18 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("DataAccessService")
public class DasService {
public class DasService implements ApplicationInfo {

protected final DasProperties dasProperties;

protected final RestTemplate httpClient;

protected final ObjectMapper objectMapper;
protected final Map<String, Map<?,?>> appInfo;

public DasService(
DasProperties dasProperties,
Expand All @@ -31,6 +31,7 @@ public DasService(
this.dasProperties = dasProperties;
this.httpClient = httpClient;
this.objectMapper = objectMapper;
this.appInfo = queryInfo(httpClient, dasProperties.host(), dasProperties.infoPath());
}

/**
Expand Down Expand Up @@ -130,4 +131,19 @@ public ResponseEntity<DatasetMetadata> getDatasetMetadata(String datasetId) {
.contentType(MediaType.APPLICATION_JSON)
.body(response.getBody());
}

@Override
public String getName() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("name").toString();
}

@Override
public String getVersion() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("version").toString();
}

@Override
public String getDescription() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("description").toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package au.org.aodn.ogcapi.server.core.service.das;

import au.org.aodn.ogcapi.server.core.configuration.DasProperties;
import au.org.aodn.ogcapi.server.core.configuration.Config;
import au.org.aodn.ogcapi.server.core.exception.DasUpstreamException;
import au.org.aodn.ogcapi.server.core.service.Search;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package au.org.aodn.ogcapi.server.core.service.dda;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;

@ConfigurationProperties(prefix = "data-discovery-ai")
public record DdaProperties(
String host,
@DefaultValue("api/v1/ml/manage/info") String infoPath
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package au.org.aodn.ogcapi.server.core.service.dda;

import au.org.aodn.ogcapi.server.core.service.ApplicationInfo;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
import java.util.Map;

public class DdaService implements ApplicationInfo {
protected final Map<String, Map<?,?>> appInfo;

public DdaService(DdaProperties properties, RestTemplate template) {
this.appInfo = queryInfo(template, properties.host(), properties.infoPath());
}

@Override
public String getName() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("name").toString();
}

@Override
public String getVersion() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("version").toString();
}

@Override
public String getDescription() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("description").toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package au.org.aodn.ogcapi.server.core.service.geonetwork;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;

@ConfigurationProperties(prefix = "geonetwork4")
public record GNProperties (
String host,
@DefaultValue("geonetwork/srv/api/manage/info") String infoPath
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package au.org.aodn.ogcapi.server.core.service.geonetwork;

import au.org.aodn.ogcapi.server.core.service.ApplicationInfo;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.Map;

/**
* This Geonetwork is use by portal to store data catalog, it is not use to remotely access external geonetwork
*/
public class Geonetwork implements ApplicationInfo {

protected final Map<String, Map<?,?>> appInfo;

public Geonetwork(GNProperties properties, RestTemplate template) {
this.appInfo = queryInfo(template, properties.host(), properties.infoPath());
}

@Override
public String getName() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("name").toString();
}

@Override
public String getVersion() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("version").toString();
}

@Override
public String getDescription() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("description").toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package au.org.aodn.ogcapi.server.core.service.indexer;

import au.org.aodn.ogcapi.server.core.service.ApplicationInfo;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.Map;

public class EsIndexer implements ApplicationInfo {

protected final Map<String, Map<?,?>> appInfo;

public EsIndexer(IndexerProperties properties, RestTemplate template) {
this.appInfo = queryInfo(template, properties.host(), properties.infoPath());
}

@Override
public String getName() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("name").toString();
}

@Override
public String getVersion() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("version").toString();
}

@Override
public String getDescription() {
return this.appInfo.getOrDefault("application", Collections.emptyMap()).get("description").toString();
}
}
Loading
Loading