Skip to content

Commit

Permalink
Merge pull request #117 from Netflix/simplenodelistprovider_with_tls
Browse files Browse the repository at this point in the history
Changed SimpleNodeListProvider to use the secure port when TLS is enabled
  • Loading branch information
tharanga authored Sep 16, 2021
2 parents 21f699a + 50a88f2 commit d834747
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Application;
import com.netflix.evcache.metrics.EVCacheMetricsFactory;
import com.netflix.evcache.pool.EVCacheClientPool;
import com.netflix.evcache.pool.EVCacheNodeList;
import com.netflix.evcache.pool.EVCacheServerGroupConfig;
import com.netflix.evcache.pool.ServerGroup;
import com.netflix.evcache.util.EVCacheConfig;
import com.netflix.spectator.api.BasicTag;
import com.netflix.spectator.api.Tag;
import org.slf4j.Logger;
Expand All @@ -32,8 +32,6 @@
import java.util.Set;

public class EurekaNodeListProvider implements EVCacheNodeList {
public static final String DEFAULT_PORT = "11211";
public static final String DEFAULT_SECURE_PORT = "11443";

private static final Logger log = LoggerFactory.getLogger(EurekaNodeListProvider.class);
private final EurekaClient _eurekaClient;
Expand Down Expand Up @@ -116,7 +114,8 @@ public Map<ServerGroup, EVCacheServerGroupConfig> discoverInstances(String _appN
}

final Map<String, String> metaInfo = iInfo.getMetadata();
final int evcachePort = Integer.parseInt((metaInfo != null && metaInfo.containsKey("evcache.port")) ? metaInfo.get("evcache.port") : DEFAULT_PORT);
final int evcachePort = Integer.parseInt((metaInfo != null && metaInfo.containsKey("evcache.port")) ?
metaInfo.get("evcache.port") : EVCacheClientPool.DEFAULT_PORT);
final int rendPort = (metaInfo != null && metaInfo.containsKey("rend.port")) ? Integer.parseInt(metaInfo.get("rend.port")) : 0;
final int rendBatchPort = (metaInfo != null && metaInfo.containsKey("rend.batch.port")) ? Integer.parseInt(metaInfo.get("rend.batch.port")) : 0;
final int udsproxyMemcachedPort = (metaInfo != null && metaInfo.containsKey("udsproxy.memcached.port")) ? Integer.parseInt(metaInfo.get("udsproxy.memcached.port")) : 0;
Expand All @@ -130,7 +129,8 @@ public Map<ServerGroup, EVCacheServerGroupConfig> discoverInstances(String _appN
int port = rendPort == 0 ? evcachePort : ((useBatchPort.get().booleanValue()) ? rendBatchPort : rendPort);
final Property<Boolean> isSecure = props.get(asgName + ".use.secure", Boolean.class).orElseGet(_appName + ".use.secure").orElse(false);
if(isSecure.get()) {
port = Integer.parseInt((metaInfo != null && metaInfo.containsKey("evcache.secure.port")) ? metaInfo.get("evcache.secure.port") : DEFAULT_SECURE_PORT);
port = Integer.parseInt((metaInfo != null && metaInfo.containsKey("evcache.secure.port")) ?
metaInfo.get("evcache.secure.port") : EVCacheClientPool.DEFAULT_SECURE_PORT);
}

final ServerGroup serverGroup = new ServerGroup(zone, asgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class EVCacheClientPool implements Runnable, EVCacheClientPoolMBean {
private final Property<Integer> _readTimeout; // Timeout for readOperation
private final Property<Integer> _bulkReadTimeout; // Timeout for readOperation
public static final String DEFAULT_PORT = "11211";
public static final String DEFAULT_SECURE_PORT = "11443";

private final Property<Boolean> _retryAcrossAllReplicas;
private long lastReconcileTime = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Set;
import java.util.StringTokenizer;

import com.netflix.archaius.api.PropertyRepository;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand All @@ -26,6 +27,7 @@
import com.google.common.net.InetAddresses;
import com.netflix.archaius.api.Property;
import com.netflix.evcache.util.EVCacheConfig;
import com.netflix.evcache.pool.EVCacheClientPool;

public class SimpleNodeListProvider implements EVCacheNodeList {

Expand Down Expand Up @@ -95,10 +97,11 @@ public Map<ServerGroup, EVCacheServerGroupConfig> discoverInstances(String appNa
private Map<ServerGroup, EVCacheServerGroupConfig> bootstrapFromEureka(String appName) throws IOException {

if(env == null || region == null) return Collections.<ServerGroup, EVCacheServerGroupConfig> emptyMap();

final String url = "http://discoveryreadonly." + region + ".dyn" + env + ".netflix.net:7001/v2/apps/" + appName;
final CloseableHttpClient httpclient = HttpClients.createDefault();
final long start = System.currentTimeMillis();
PropertyRepository props = EVCacheConfig.getInstance().getPropertyRepository();
CloseableHttpResponse httpResponse = null;
try {
final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).build();
Expand All @@ -118,13 +121,20 @@ private Map<ServerGroup, EVCacheServerGroupConfig> bootstrapFromEureka(String ap
final JSONObject application = jsonObj.getJSONObject("application");
final JSONArray instances = application.getJSONArray("instance");
final Map<ServerGroup, EVCacheServerGroupConfig> serverGroupMap = new HashMap<ServerGroup, EVCacheServerGroupConfig>();
final Property<Boolean> useBatchPort = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".use.batch.port", Boolean.class).orElseGet("evcache.use.batch.port").orElse(false);
final Property<Boolean> useBatchPort = props.get(appName + ".use.batch.port", Boolean.class)
.orElseGet("evcache.use.batch.port").orElse(false);
final int securePort = Integer.parseInt(props.get("evcache.secure.port", String.class)
.orElse(EVCacheClientPool.DEFAULT_SECURE_PORT).get());

for(int i = 0; i < instances.length(); i++) {
final JSONObject instanceObj = instances.getJSONObject(i);
final JSONObject metadataObj = instanceObj.getJSONObject("dataCenterInfo").getJSONObject("metadata");

final String asgName = instanceObj.getString("asgName");
final Property<Boolean> asgEnabled = EVCacheConfig.getInstance().getPropertyRepository().get(asgName + ".enabled", Boolean.class).orElse(true);
final Property<Boolean> asgEnabled = props.get(asgName + ".enabled", Boolean.class).orElse(true);
final boolean isSecure = props.get(asgName + ".use.secure", Boolean.class)
.orElseGet(appName + ".use.secure").orElse(false).get();

if (!asgEnabled.get()) {
if(log.isDebugEnabled()) log.debug("ASG " + asgName + " is disabled so ignoring it");
continue;
Expand All @@ -134,15 +144,18 @@ private Map<ServerGroup, EVCacheServerGroupConfig> bootstrapFromEureka(String ap
final ServerGroup rSet = new ServerGroup(zone, asgName);
final String localIp = metadataObj.getString("local-ipv4");
final JSONObject instanceMetadataObj = instanceObj.getJSONObject("metadata");
final String evcachePortString = instanceMetadataObj.optString("evcache.port", "11211");
final String evcachePortString = instanceMetadataObj.optString("evcache.port",
EVCacheClientPool.DEFAULT_PORT);
final String rendPortString = instanceMetadataObj.optString("rend.port", "0");
final String rendBatchPortString = instanceMetadataObj.optString("rend.batch.port", "0");
final int rendPort = Integer.parseInt(rendPortString);
final int rendBatchPort = Integer.parseInt(rendBatchPortString);
final String rendMemcachedPortString = instanceMetadataObj.optString("rend.memcached.port", "0");
final String rendMementoPortString = instanceMetadataObj.optString("rend.memento.port", "0");
final int evcachePort = Integer.parseInt(evcachePortString);
final int port = rendPort == 0 ? evcachePort : ((useBatchPort.get().booleanValue()) ? rendBatchPort : rendPort);
final int port = isSecure ? securePort : rendPort == 0 ?
evcachePort : ((useBatchPort.get().booleanValue()) ?
rendBatchPort : rendPort);

EVCacheServerGroupConfig config = serverGroupMap.get(rSet);
if(config == null) {
Expand Down

0 comments on commit d834747

Please sign in to comment.