Skip to content

Commit

Permalink
Merge pull request #1473 from spencergibb/fixme-2-0-patch1
Browse files Browse the repository at this point in the history
Fixme 2.0 patch1. LGTM
  • Loading branch information
howardyuan authored Nov 15, 2022
2 parents eb14927 + 3b73bdb commit 03dc7c7
Show file tree
Hide file tree
Showing 34 changed files with 330 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class MyDefaultApacheHttpClient4Config extends ClientConfig {

if (systemSSL) {
cm = createSystemSslCM();
} else if (trustStoreFileName != null) {
} else if (trustStoreFileName != null && !trustStoreFileName.trim().isEmpty()) {
cm = createCustomSslCM();
} else {
cm = new PoolingHttpClientConnectionManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.netflix.eureka.cluster.PeerEurekaNodes;
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
import com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl;
import com.netflix.eureka.transport.EurekaServerHttpClientFactory;
import com.netflix.eureka.transport.Jersey3EurekaServerHttpClientFactory;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -138,8 +140,8 @@ public MockServer(String appName, PeerEurekaNodes peerEurekaNodes) throws Except

Mockito.doReturn("true").when(serverConfig).getExperimental("registry.registration.ignoreIfDirtyTimestampIsOlder");

EurekaHttpClient eurekaHttpClient = null; // FIXME 2.0
this.registry = new PeerAwareInstanceRegistryImpl(serverConfig, clientConfig, serverCodecs, eurekaClient, eurekaHttpClient);
EurekaServerHttpClientFactory eurekaServerHttpClientFactory = new Jersey3EurekaServerHttpClientFactory();
this.registry = new PeerAwareInstanceRegistryImpl(serverConfig, clientConfig, serverCodecs, eurekaClient, eurekaServerHttpClientFactory);
this.registry.init(peerEurekaNodes);

this.applicationResource = new ApplicationResource(appName, serverConfig, registry);
Expand Down
1 change: 1 addition & 0 deletions eureka-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ dependencies {
testImplementation "com.github.tomakehurst:wiremock-jre8:2.25.1"
testImplementation "org.assertj:assertj-core:3.11.1"
testImplementation "jakarta.servlet:jakarta.servlet-api:5.0.0"
testRuntimeOnly 'org.slf4j:slf4j-simple:2.0.0-beta1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public abstract class AbstractDiscoveryClientOptionalArgs<T> {

TransportClientFactory transportClientFactory;

TransportClientFactories transportClientFactories;

private Set<EurekaEventListener> eventListeners;

private Optional<SSLContext> sslContext = Optional.empty();
Expand Down Expand Up @@ -82,16 +80,6 @@ public void setAdditionalFilters(Collection<T> additionalFilters) {
this.additionalFilters = additionalFilters;
}

public TransportClientFactories getTransportClientFactories() {
return transportClientFactories;
}

// @Inject
public void setTransportClientFactories(TransportClientFactories transportClientFactories) {
this.transportClientFactories = transportClientFactories;
}


public TransportClientFactory getTransportClientFactory() {
return transportClientFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,16 @@ public class DiscoveryClient implements EurekaClient {
protected final EurekaClientConfig clientConfig;
protected final EurekaTransportConfig transportConfig;

@SuppressWarnings("rawtypes")
protected final TransportClientFactories transportClientFactories;

private final long initTimestampMs;
private final int initRegistrySize;

private final Stats stats = new Stats();

private static final class EurekaTransport {
@SuppressWarnings("rawtypes")
private ClosableResolver bootstrapResolver;
private TransportClientFactory transportClientFactory;

Expand Down Expand Up @@ -228,34 +232,19 @@ void shutdown() {
}
}

/**
* Assumes applicationInfoManager is already initialized
*
* @deprecated use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
*/
@Deprecated
public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config) {
this(myInfo, config, null);
}

/**
* @deprecated use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
*/
@Deprecated
public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args) {
this(ApplicationInfoManager.getInstance(), config, args);
}

public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config) {
this(applicationInfoManager, config, null);
@SuppressWarnings("rawtypes")
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, TransportClientFactories transportClientFactories) {
this(applicationInfoManager, config, transportClientFactories, null);
}

public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args) {
this(applicationInfoManager, config, args, ResolverUtils::randomize);
@SuppressWarnings("rawtypes")
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args) {
this(applicationInfoManager, config, transportClientFactories, args, ResolverUtils::randomize);
}

public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args, EndpointRandomizer randomizer) {
this(applicationInfoManager, config, args, new Provider<BackupRegistry>() {
@SuppressWarnings("rawtypes")
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, final EurekaClientConfig config, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args, EndpointRandomizer randomizer) {
this(applicationInfoManager, config, transportClientFactories, args, new Provider<BackupRegistry>() {
private volatile BackupRegistry backupRegistryInstance;

@Override
Expand Down Expand Up @@ -286,17 +275,8 @@ public synchronized BackupRegistry get() {
}, randomizer);
}

/**
* @deprecated Use {@link #DiscoveryClient(ApplicationInfoManager, EurekaClientConfig, AbstractDiscoveryClientOptionalArgs, Provider<BackupRegistry>, EndpointRandomizer)}
*/
@Deprecated
DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args,
Provider<BackupRegistry> backupRegistryProvider) {
this(applicationInfoManager, config, args, backupRegistryProvider, ResolverUtils::randomize);
}

@Inject
DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args,
DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args,
Provider<BackupRegistry> backupRegistryProvider, EndpointRandomizer endpointRandomizer) {
if (args != null) {
this.healthCheckHandlerProvider = args.healthCheckHandlerProvider;
Expand All @@ -308,7 +288,7 @@ public synchronized BackupRegistry get() {
this.healthCheckHandlerProvider = null;
this.preRegistrationHandler = null;
}

this.transportClientFactories = transportClientFactories;
this.applicationInfoManager = applicationInfoManager;
InstanceInfo myInfo = applicationInfoManager.getInfo();

Expand Down Expand Up @@ -468,6 +448,7 @@ public synchronized BackupRegistry get() {
initTimestampMs, initRegistrySize);
}

@SuppressWarnings("unchecked")
private void scheduleServerEndpointTask(EurekaTransport eurekaTransport,
AbstractDiscoveryClientOptionalArgs args) {

Expand All @@ -476,13 +457,6 @@ private void scheduleServerEndpointTask(EurekaTransport eurekaTransport,
? Collections.emptyList()
: args.additionalFilters;

@SuppressWarnings("rawtypes")
// Ignore the raw types warnings since the client filter interface changed between jersey 1/2
TransportClientFactories transportClientFactories = null;
if (args != null && args.getTransportClientFactories() != null) {
transportClientFactories = args.getTransportClientFactories();
}

if (transportClientFactories == null) {
throw new IllegalArgumentException("transportClientFactories may not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.LookupService;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -80,20 +80,14 @@ public void setEurekaInstanceConfig(EurekaInstanceConfig eurekaInstanceConfig) {
* @param eurekaConfig the eureka client configuration of the instance.
*/
public void initComponent(EurekaInstanceConfig config,
EurekaClientConfig eurekaConfig, AbstractDiscoveryClientOptionalArgs args) {
EurekaClientConfig eurekaConfig, TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs args) {
this.eurekaInstanceConfig = config;
this.eurekaClientConfig = eurekaConfig;
if (ApplicationInfoManager.getInstance().getInfo() == null) {
// Initialize application info
ApplicationInfoManager.getInstance().initComponent(config);
}
InstanceInfo info = ApplicationInfoManager.getInstance().getInfo();
discoveryClient = new DiscoveryClient(info, eurekaConfig, args);
}

public void initComponent(EurekaInstanceConfig config,
EurekaClientConfig eurekaConfig) {
initComponent(config, eurekaConfig, null);
discoveryClient = new DiscoveryClient(ApplicationInfoManager.getInstance(), eurekaConfig, transportClientFactories, args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ public Name getName() {

backupRegistry = new MockBackupRegistry();
setupBackupMock();
Jersey3DiscoveryClientOptionalArgs args = new Jersey3DiscoveryClientOptionalArgs();
args.setTransportClientFactories(Jersey3TransportClientFactories.getInstance());
client = new DiscoveryClient(
applicationInfoManager,
new DefaultEurekaClientConfig(),
args,
Jersey3TransportClientFactories.getInstance(),
null,
() -> backupRegistry,
ResolverUtils::randomize
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.MyDataCenterInstanceConfig;
import com.netflix.config.ConfigurationManager;
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -42,7 +43,7 @@ public Name getName() {
});

ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig());
client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig(), Jersey3TransportClientFactories.getInstance());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public void testDoNotUnregisterOnShutdown() throws Exception {

private Jersey3DiscoveryClientOptionalArgs getOptionalArgs() {
Jersey3DiscoveryClientOptionalArgs optionalArgs = new Jersey3DiscoveryClientOptionalArgs();
optionalArgs.setTransportClientFactories(Jersey3TransportClientFactories.getInstance());
return optionalArgs;
}

Expand All @@ -171,7 +170,7 @@ private static <T> T getLast(List<T> list) {
private static class TestClient extends DiscoveryClient {

public TestClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs optionalArgs) {
super(applicationInfoManager, config, optionalArgs);
super(applicationInfoManager, config, Jersey3TransportClientFactories.getInstance(), optionalArgs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package com.netflix.eureka;

import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.Jersey3DiscoveryClientOptionalArgs;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;
import com.netflix.eureka.cluster.Jersey3PeerEurekaNodes;
import com.netflix.eureka.cluster.PeerEurekaNodes;
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
import com.netflix.eureka.resources.ServerCodecs;
import com.netflix.eureka.transport.EurekaServerHttpClientFactory;
import com.netflix.eureka.transport.Jersey3EurekaServerHttpClientFactory;

/**
* Jersey3 eureka server bootstrapper
* @author Matt Nelson
*/
public class Jersey3EurekaBootStrap extends EurekaBootStrap {


// for servlet based deployments
public Jersey3EurekaBootStrap() {
super(null);
}

public Jersey3EurekaBootStrap(DiscoveryClient discoveryClient) {
super(discoveryClient);
}
Expand All @@ -33,8 +43,19 @@ protected PeerEurekaNodes getPeerEurekaNodes(PeerAwareInstanceRegistry registry,
}

@Override
protected EurekaHttpClient getEurekaHttpClient() {
// FIXME 2.0
return null;
protected AbstractDiscoveryClientOptionalArgs<?> getDiscoveryClientOptionalArgs() {
Jersey3DiscoveryClientOptionalArgs jersey3DiscoveryClientOptionalArgs = new Jersey3DiscoveryClientOptionalArgs();
return jersey3DiscoveryClientOptionalArgs;
}

@Override
protected TransportClientFactories getTransportClientFactories() {
return Jersey3TransportClientFactories.getInstance();
}

@Override
protected EurekaServerHttpClientFactory getEurekaServerHttpClientFactory() {
return new Jersey3EurekaServerHttpClientFactory();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.netflix.eureka.transport;

import com.netflix.discovery.shared.dns.DnsServiceImpl;
import com.netflix.discovery.shared.resolver.ClusterResolver;
import com.netflix.discovery.shared.resolver.EurekaEndpoint;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
import com.netflix.discovery.shared.transport.TransportClientFactory;
import com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient;
import com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient;
import com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient;
import com.netflix.discovery.shared.transport.decorator.ServerStatusEvaluators;
import com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient;
import com.netflix.eureka.EurekaServerConfig;
import com.netflix.eureka.Names;
import com.netflix.eureka.resources.ServerCodecs;

public class Jersey3EurekaServerHttpClientFactory implements EurekaServerHttpClientFactory {

public static final long RECONNECT_INTERVAL_MINUTES = 30;

@Override
public EurekaHttpClient createRemoteRegionClient(EurekaServerConfig serverConfig, EurekaTransportConfig transportConfig, ServerCodecs serverCodecs, ClusterResolver<EurekaEndpoint> clusterResolver) {
Jersey3RemoteRegionClientFactory jersey3RemoteRegionClientFactory = new Jersey3RemoteRegionClientFactory(serverConfig, serverCodecs, clusterResolver.getRegion());
TransportClientFactory metricsFactory = MetricsCollectingEurekaHttpClient.createFactory(jersey3RemoteRegionClientFactory);

SessionedEurekaHttpClient client = new SessionedEurekaHttpClient(
Names.REMOTE,
RetryableEurekaHttpClient.createFactory(
Names.REMOTE,
transportConfig,
clusterResolver,
createFactory(metricsFactory),
ServerStatusEvaluators.legacyEvaluator()),
RECONNECT_INTERVAL_MINUTES * 60 * 1000
);
return client;
}

public static TransportClientFactory createFactory(final TransportClientFactory delegateFactory) {
final DnsServiceImpl dnsService = new DnsServiceImpl();
return new TransportClientFactory() {
@Override
public EurekaHttpClient newClient(EurekaEndpoint endpoint) {
return new RedirectingEurekaHttpClient(endpoint.getServiceUrl(), delegateFactory, dnsService);
}

@Override
public void shutdown() {
delegateFactory.shutdown();
}
};
}
}
Loading

0 comments on commit 03dc7c7

Please sign in to comment.