Add consul hints (#792)

This commit is contained in:
Olga Maciaszek-Sharma
2022-08-08 18:20:40 +02:00
committed by GitHub
parent b76d500bca
commit 702c330b54
3 changed files with 139 additions and 1 deletions

View File

@@ -18,12 +18,51 @@ package org.springframework.cloud.consul;
import java.util.function.Supplier;
import com.ecwid.consul.transport.AbstractHttpTransport;
import com.ecwid.consul.transport.HttpResponse;
import com.ecwid.consul.transport.TLSConfig;
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.ConsulRawClient;
import com.ecwid.consul.v1.ConsulRawClient.Builder;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.acl.AclClient;
import com.ecwid.consul.v1.acl.model.NewAcl;
import com.ecwid.consul.v1.acl.model.UpdateAcl;
import com.ecwid.consul.v1.agent.AgentClient;
import com.ecwid.consul.v1.agent.AgentConsulClient;
import com.ecwid.consul.v1.agent.model.Check;
import com.ecwid.consul.v1.agent.model.NewCheck;
import com.ecwid.consul.v1.agent.model.NewService;
import com.ecwid.consul.v1.catalog.CatalogClient;
import com.ecwid.consul.v1.catalog.CatalogConsulClient;
import com.ecwid.consul.v1.catalog.CatalogNodesRequest;
import com.ecwid.consul.v1.catalog.CatalogServiceRequest;
import com.ecwid.consul.v1.catalog.model.CatalogDeregistration;
import com.ecwid.consul.v1.catalog.model.CatalogRegistration;
import com.ecwid.consul.v1.coordinate.CoordinateClient;
import com.ecwid.consul.v1.event.EventClient;
import com.ecwid.consul.v1.event.EventListRequest;
import com.ecwid.consul.v1.event.model.Event;
import com.ecwid.consul.v1.event.model.EventParams;
import com.ecwid.consul.v1.health.HealthChecksForServiceRequest;
import com.ecwid.consul.v1.health.HealthClient;
import com.ecwid.consul.v1.health.HealthServicesRequest;
import com.ecwid.consul.v1.health.model.HealthService;
import com.ecwid.consul.v1.kv.KeyValueClient;
import com.ecwid.consul.v1.kv.model.GetBinaryValue;
import com.ecwid.consul.v1.kv.model.GetValue;
import com.ecwid.consul.v1.kv.model.PutParams;
import com.ecwid.consul.v1.query.QueryClient;
import com.ecwid.consul.v1.session.SessionClient;
import com.ecwid.consul.v1.session.model.Session;
import com.ecwid.consul.v1.status.StatusClient;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -39,6 +78,7 @@ import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.annotation.Retryable;
import org.springframework.retry.interceptor.RetryInterceptorBuilder;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
@@ -138,3 +178,99 @@ public class ConsulAutoConfiguration {
}
}
// TODO: remove hints after merging GraalVM metadata PR
class ConsulHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
if (!ClassUtils.isPresent("com.ecwid.consul.v1.ConsulClient", classLoader)) {
return;
}
hints.reflection().registerType(TypeReference.of(NewService.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(NewAcl.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(UpdateAcl.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(NewCheck.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(CatalogDeregistration.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(CatalogRegistration.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(CatalogRegistration.Service.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(QueryParams.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(EventParams.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(EventListRequest.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(CatalogNodesRequest.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(CatalogServiceRequest.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(HealthChecksForServiceRequest.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(HealthServicesRequest.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(PutParams.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(AbstractHttpTransport.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(ConsulClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(ConsulRawClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(AgentConsulClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(CatalogConsulClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(AclClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(AgentClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(CatalogClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(CoordinateClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(EventClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(HealthClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(KeyValueClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(QueryClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(SessionClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(StatusClient.class),
hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS));
hints.reflection().registerType(TypeReference.of(HttpResponse.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(HealthService.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(HealthService.Node.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(HealthService.Service.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(Response.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(Session.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(GetBinaryValue.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(GetValue.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(Check.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(Check.CheckStatus.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(com.ecwid.consul.v1.health.model.Check.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
hints.reflection().registerType(TypeReference.of(Event.class),
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
}
}

View File

@@ -0,0 +1,2 @@
org.springframework.aot.hint.RuntimeHintsRegistrar=\
org.springframework.cloud.consul.ConsulHints

View File

@@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ConditionalOnProperty(value = "spring.cloud.consul.discovery.test.enabled", matchIfMissing = false)
@ConditionalOnProperty("spring.cloud.consul.discovery.test.enabled")
@Configuration(proxyBeanMethods = false)
public class TestConsulDiscoveryClientBootstrapConfiguration {