use of com.netflix.client.config.DefaultClientConfigImpl in project zuul by Netflix.
the class StartServer method initNIWS.
private void initNIWS() throws ClientException {
String stack = ConfigurationManager.getDeploymentContext().getDeploymentStack();
if (stack != null && !stack.trim().isEmpty() && RibbonConfig.isAutodetectingBackendVips()) {
RibbonConfig.setupDefaultRibbonConfig();
ZuulApplicationInfo.setApplicationName(RibbonConfig.getApplicationName());
} else {
DynamicStringProperty DEFAULT_CLIENT = DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_NIWS_DEFAULTCLIENT, null);
if (DEFAULT_CLIENT.get() != null) {
ZuulApplicationInfo.setApplicationName(DEFAULT_CLIENT.get());
} else {
ZuulApplicationInfo.setApplicationName(stack);
}
}
String clientPropertyList = DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_NIWS_CLIENTLIST, "").get();
String[] aClientList = clientPropertyList.split("\\|");
String namespace = DynamicPropertyFactory.getInstance().getStringProperty(ZUUL_RIBBON_NAMESPACE, "ribbon").get();
for (String client : aClientList) {
DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(client, namespace);
ClientFactory.registerClientFromProperties(client, clientConfig);
}
}
use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.
the class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest method testTwoInstancesDontStepOnEachOther.
/**
* Tests case where two different clients want to use the same instance, one with overriden ports and one without
*
* @throws Exception for anything unexpected
*/
@Test
public void testTwoInstancesDontStepOnEachOther() throws Exception {
// setup override client
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.DeploymentContextBasedVipAddresses", "dummy");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.IsSecure", "false");
// override from 8001
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.Port", "6001");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.TargetRegion", "region");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1.ribbon.ForceClientPortConfiguration", "true");
// setup non override client
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.DeploymentContextBasedVipAddresses", "dummy");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.IsSecure", "false");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.Port", "6001");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.TargetRegion", "region");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2.ribbon.ForceClientPortConfiguration", "false");
// check override client
DiscoveryEnabledNIWSServerList deList1 = new DiscoveryEnabledNIWSServerList();
DefaultClientConfigImpl clientConfig1 = DefaultClientConfigImpl.class.newInstance();
clientConfig1.loadProperties("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther1");
deList1.initWithNiwsConfig(clientConfig1);
List<DiscoveryEnabledServer> serverList1 = deList1.getInitialListOfServers();
Assert.assertEquals(1, serverList1.size());
// client property overridden
Assert.assertEquals(6001, serverList1.get(0).getPort());
// client property overridden
Assert.assertEquals(6001, serverList1.get(0).getInstanceInfo().getPort());
// 7002 is the secure default
Assert.assertEquals(7002, serverList1.get(0).getInstanceInfo().getSecurePort());
// check non-override client
DiscoveryEnabledNIWSServerList deList2 = new DiscoveryEnabledNIWSServerList();
DefaultClientConfigImpl clientConfig2 = DefaultClientConfigImpl.class.newInstance();
clientConfig2.loadProperties("DiscoveryEnabled.testTwoInstancesDontStepOnEachOther2");
deList2.initWithNiwsConfig(clientConfig2);
List<DiscoveryEnabledServer> serverList2 = deList2.getInitialListOfServers();
Assert.assertEquals(1, serverList2.size());
// client property indicated in ii
Assert.assertEquals(8001, serverList2.get(0).getPort());
// client property indicated in ii
Assert.assertEquals(8001, serverList2.get(0).getInstanceInfo().getPort());
// 7002 is the secure default
Assert.assertEquals(7002, serverList2.get(0).getInstanceInfo().getSecurePort());
}
use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.
the class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest method testDefaultHonorsVipPortDefinition.
@Test
public void testDefaultHonorsVipPortDefinition() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.DeploymentContextBasedVipAddresses", "dummy");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.IsSecure", "false");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.Port", "6999");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.TargetRegion", "region");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipPortDefinition.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList();
DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance();
clientConfig.loadProperties("DiscoveryEnabled.testDefaultHonorsVipPortDefinition");
deList.initWithNiwsConfig(clientConfig);
List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers();
Assert.assertEquals(1, serverList.size());
// vip indicated
Assert.assertEquals(8001, serverList.get(0).getPort());
// vip indicated
Assert.assertEquals(8001, serverList.get(0).getInstanceInfo().getPort());
// 7002 is the secure default
Assert.assertEquals(7002, serverList.get(0).getInstanceInfo().getSecurePort());
}
use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.
the class ClientConfigTest method testresolveDeploymentContextbasedVipAddresses.
@Test
public void testresolveDeploymentContextbasedVipAddresses() throws Exception {
DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
clientConfig.loadDefaultValues();
Properties props = new Properties();
final String restClientName = "testRestClient2";
clientConfig.setProperty(props, restClientName, CommonClientConfigKey.AppName.key(), "movieservice");
clientConfig.setProperty(props, restClientName, CommonClientConfigKey.DeploymentContextBasedVipAddresses.key(), "${<appname>}-${netflix.appinfo.stack}-${netflix.environment}:${<port>},${<appname>}--${netflix.environment}:${<port>}");
clientConfig.setProperty(props, restClientName, CommonClientConfigKey.Port.key(), "7001");
clientConfig.setProperty(props, restClientName, CommonClientConfigKey.EnableZoneAffinity.key(), "true");
ConfigurationManager.loadProperties(props);
clientConfig.loadProperties(restClientName);
Assert.assertEquals("movieservice", clientConfig.getProperty(CommonClientConfigKey.AppName));
Assert.assertEquals("true", clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
ConfigurationManager.getConfigInstance().setProperty("testRestClient2.ribbon.DeploymentContextBasedVipAddresses", "movieservice-xbox-test:7001");
assertEquals("movieservice-xbox-test:7001", clientConfig.getProperty(CommonClientConfigKey.DeploymentContextBasedVipAddresses));
ConfigurationManager.getConfigInstance().clearProperty("testRestClient2.ribbon.EnableZoneAffinity");
assertNull(clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
}
use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.
the class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest method testVipPortCanBeOverriden.
@Test
public void testVipPortCanBeOverriden() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.DeploymentContextBasedVipAddresses", "dummy");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.IsSecure", "false");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.Port", "6001");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.TargetRegion", "region");
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testVipPortCanBeOverriden.ribbon.ForceClientPortConfiguration", "true");
DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList();
DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance();
clientConfig.loadProperties("DiscoveryEnabled.testVipPortCanBeOverriden");
deList.initWithNiwsConfig(clientConfig);
List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers();
Assert.assertEquals(1, serverList.size());
// client property indicated
Assert.assertEquals(6001, serverList.get(0).getPort());
// client property indicated
Assert.assertEquals(6001, serverList.get(0).getInstanceInfo().getPort());
// 7002 is the secure default
Assert.assertEquals(7002, serverList.get(0).getInstanceInfo().getSecurePort());
}
Aggregations