Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangdavidliu committed May 31, 2017
2 parents 15f5235 + 1ac04e1 commit 9c88b5c
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ The build requires java8 because of some required libraries that are java8 (serv

Support
----------
[Eureka Google Group] (https://groups.google.com/forum/?fromgroups#!forum/eureka_netflix)
[Eureka Google Group](https://groups.google.com/forum/?fromgroups#!forum/eureka_netflix)


Documentation
--------------
Please see [wiki] (https://github.com/Netflix/eureka/wiki) for detailed documentation.
Please see [wiki](https://github.com/Netflix/eureka/wiki) for detailed documentation.
2 changes: 1 addition & 1 deletion eureka-client-archaius2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ dependencies {
testCompile "org.mockito:mockito-core:${mockitoVersion}"
testCompile "org.mock-server:mockserver-netty:${mockserverVersion}"
testCompile "com.netflix.archaius:archaius2-guice:${archaius2Version}"

testCompile "com.netflix.governator:governator:${governatorVersion}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected void configureArchaius() {
.put("eureka.registration.enabled", "false")
.put("eureka.serviceUrl.default", "http://localhost:8080/eureka/v2")
.put("eureka.shouldInitAsEc2", "false")
.put("eureka.instanceDeploymentEnvironment", "non-ec2")
.build()
);
}
Expand Down
1 change: 1 addition & 0 deletions eureka-client-jersey2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ dependencies {

testCompile "junit:junit:${junit_version}"
testCompile "org.mockito:mockito-core:${mockitoVersion}"
testCompile "com.netflix.governator:governator:${governatorVersion}"
}
1 change: 1 addition & 0 deletions eureka-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ dependencies {
testCompile 'org.mortbay.jetty:jetty:6.1H.22'
testCompile "org.mockito:mockito-core:${mockitoVersion}"
testCompile "org.mock-server:mockserver-netty:${mockserverVersion}"
testCompile "com.netflix.governator:governator:${governatorVersion}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public List<InstanceInfo> getInstances() {
*/
@JsonIgnore
public List<InstanceInfo> getInstancesAsIsFromEureka() {
return new ArrayList<InstanceInfo>(this.instances);
synchronized (instances) {
return new ArrayList<InstanceInfo>(this.instances);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public void shutdown() {
if(Monitors.isObjectRegistered(name, this)) {
Monitors.unregisterObject(name, this);
}
executorService.shutdown();
threadPoolExecutor.shutdown();
executorService.shutdownNow();
threadPoolExecutor.shutdownNow();
backgroundTask.cancel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private List<AwsEndpoint> createEurekaEndpointsFromConfig() {
myZone
));
} catch (URISyntaxException ignore) {
logger.warn("Invalid eureka server URI: ; removing from the server pool", serviceUrl);
logger.warn("Invalid eureka server URI: {}; removing from the server pool", serviceUrl);
}
}
return endpoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -79,11 +77,11 @@ private List<AwsEndpoint> getClusterEndpointsFromConfig() {

List<AwsEndpoint> endpoints = new ArrayList<>();
for (String zone : serviceUrls.keySet()) {
for(String url : serviceUrls.get(zone)) {
for (String url : serviceUrls.get(zone)) {
try {
endpoints.add(new AwsEndpoint(url, getRegion(), zone));
} catch (Exception ignore) {
logger.warn("Invalid eureka server URI: ; removing from the server pool", url);
logger.warn("Invalid eureka server URI: {}; removing from the server pool", url);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
import com.sun.jersey.client.apache4.config.ApacheHttpClient4Config;
import com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.conn.SchemeRegistryFactory;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
Expand Down Expand Up @@ -89,6 +93,7 @@ public static class EurekaJerseyClientBuilder {
private int connectionIdleTimeout;
private EncoderWrapper encoderWrapper;
private DecoderWrapper decoderWrapper;
private SSLContext sslContext;

public EurekaJerseyClientBuilder withClientName(String clientName) {
this.clientName = clientName;
Expand Down Expand Up @@ -161,6 +166,11 @@ public EurekaJerseyClientBuilder withDecoderWrapper(DecoderWrapper decoderWrappe
this.decoderWrapper = decoderWrapper;
return this;
}

public EurekaJerseyClientBuilder withCustomSSL(SSLContext sslContext) {
this.sslContext = sslContext;
return this;
}

public EurekaJerseyClient build() {
MyDefaultApacheHttpClient4Config config = new MyDefaultApacheHttpClient4Config();
Expand All @@ -177,10 +187,10 @@ class MyDefaultApacheHttpClient4Config extends DefaultApacheHttpClient4Config {

if (systemSSL) {
cm = createSystemSslCM();
} else if (trustStoreFileName != null) {
} else if (sslContext != null || trustStoreFileName != null) {
cm = createCustomSslCM();
} else {
cm = new MonitoredConnectionManager(clientName);
cm = createDefaultSslCM();
}

if (proxyHost != null) {
Expand Down Expand Up @@ -219,7 +229,8 @@ private void addProxyConfiguration(MonitoredConnectionManager cm) {

private MonitoredConnectionManager createSystemSslCM() {
MonitoredConnectionManager cm;
SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSystemSocketFactory();
SSLConnectionSocketFactory systemSocketFactory = SSLConnectionSocketFactory.getSystemSocketFactory();
SSLSocketFactory sslSocketFactory = new SSLSocketFactoryAdapter(systemSocketFactory);
SchemeRegistry sslSchemeRegistry = new SchemeRegistry();
sslSchemeRegistry.register(new Scheme(PROTOCOL, HTTPS_PORT, sslSocketFactory));
cm = new MonitoredConnectionManager(clientName, sslSchemeRegistry);
Expand All @@ -229,20 +240,23 @@ private MonitoredConnectionManager createSystemSslCM() {
private MonitoredConnectionManager createCustomSslCM() {
FileInputStream fin = null;
try {
SSLContext sslContext = SSLContext.getInstance(PROTOCOL_SCHEME);
KeyStore sslKeyStore = KeyStore.getInstance(KEYSTORE_TYPE);
if (sslContext == null) {
sslContext = SSLContext.getInstance(PROTOCOL_SCHEME);
KeyStore sslKeyStore = KeyStore.getInstance(KEYSTORE_TYPE);

fin = new FileInputStream(trustStoreFileName);
sslKeyStore.load(fin, trustStorePassword.toCharArray());
fin = new FileInputStream(trustStoreFileName);
sslKeyStore.load(fin, trustStorePassword.toCharArray());

TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init(sslKeyStore);
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init(sslKeyStore);

TrustManager[] trustManagers = factory.getTrustManagers();
TrustManager[] trustManagers = factory.getTrustManagers();

sslContext.init(null, trustManagers, null);
SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext);
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
sslContext.init(null, trustManagers, null);
}
X509HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SSLConnectionSocketFactory customSslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
SSLSocketFactory sslSocketFactory = new SSLSocketFactoryAdapter(customSslSocketFactory);
SchemeRegistry sslSchemeRegistry = new SchemeRegistry();
sslSchemeRegistry.register(new Scheme(PROTOCOL, HTTPS_PORT, sslSocketFactory));

Expand All @@ -258,6 +272,18 @@ private MonitoredConnectionManager createCustomSslCM() {
}
}
}

/**
* @see SchemeRegistryFactory#createDefault()
*/
private MonitoredConnectionManager createDefaultSslCM() {
final SchemeRegistry registry = new SchemeRegistry();
registry.register(
new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(
new Scheme("https", 443, new SSLSocketFactoryAdapter(SSLConnectionSocketFactory.getSocketFactory())));
return new MonitoredConnectionManager(clientName, registry);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.netflix.discovery.shared.transport.jersey;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.protocol.HttpContext;

/**
* Adapts a version 4.3+ {@link SSLConnectionSocketFactory} to a pre 4.3
* {@link SSLSocketFactory}. This allows {@link HttpClient}s built using the
* deprecated pre 4.3 APIs to use SSL improvements from 4.3, e.g. SNI.
*
* @author William Tran
*
*/
public class SSLSocketFactoryAdapter extends SSLSocketFactory {

private final SSLConnectionSocketFactory factory;

public SSLSocketFactoryAdapter(SSLConnectionSocketFactory factory) {
// super's dependencies are dummies, and will delegate all calls to the
// to the overridden methods
super(DummySSLSocketFactory.INSTANCE, DummyX509HostnameVerifier.INSTANCE);
this.factory = factory;
}

@Override
public Socket createSocket(final HttpContext context) throws IOException {
return factory.createSocket(context);
}

@Override
public Socket connectSocket(
final int connectTimeout,
final Socket socket,
final HttpHost host,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpContext context) throws IOException {
return factory.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
}

@Override
public Socket createLayeredSocket(
final Socket socket,
final String target,
final int port,
final HttpContext context) throws IOException {
return factory.createLayeredSocket(socket, target, port, context);
}

private static class DummySSLSocketFactory extends javax.net.ssl.SSLSocketFactory {
private static final DummySSLSocketFactory INSTANCE = new DummySSLSocketFactory();

@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public String[] getDefaultCipherSuites() {
throw new UnsupportedOperationException();
}

@Override
public String[] getSupportedCipherSuites() {
throw new UnsupportedOperationException();
}

@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
throw new UnsupportedOperationException();
}

@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
throws IOException, UnknownHostException {
throw new UnsupportedOperationException();
}

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
throws IOException {
throw new UnsupportedOperationException();
}
}

private static class DummyX509HostnameVerifier implements X509HostnameVerifier {
private static final DummyX509HostnameVerifier INSTANCE = new DummyX509HostnameVerifier();

@Override
public boolean verify(String hostname, SSLSession session) {
throw new UnsupportedOperationException();
}

@Override
public void verify(String host, SSLSocket ssl) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public void verify(String host, X509Certificate cert) throws SSLException {
throw new UnsupportedOperationException();
}

@Override
public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
throw new UnsupportedOperationException();
}

}

}
1 change: 0 additions & 1 deletion eureka-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ dependencies {
compile "com.amazonaws:aws-java-sdk-sts:${awsVersion}"
compile "com.amazonaws:aws-java-sdk-route53:${awsVersion}"
compile "javax.servlet:servlet-api:${servletVersion}"
compile "com.netflix.governator:governator:${governatorVersion}"
compile 'com.thoughtworks.xstream:xstream:1.4.9'
compile 'javax.ws.rs:jsr311-api:1.1.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public synchronized void initializedResponseCache() {

protected void initRemoteRegionRegistry() throws MalformedURLException {
Map<String, String> remoteRegionUrlsWithName = serverConfig.getRemoteRegionUrlsWithName();
if (remoteRegionUrlsWithName != null) {
if (remoteRegionUrlsWithName.size() > 0) {
allKnownRemoteRegions = new String[remoteRegionUrlsWithName.size()];
int remoteRegionArrayIndex = 0;
for (Map.Entry<String, String> remoteRegionUrlWithName : remoteRegionUrlsWithName.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public StatusInfo build() {
String.valueOf(totalMem - freeMem) + "mb" + " ("
+ usedPercent + "%)");

result.instanceInfo = ApplicationInfoManager.getInstance()
.getInfo();

return result;
}
}
Expand Down

0 comments on commit 9c88b5c

Please sign in to comment.