Search in sources :

Example 1 with DefaultClientConfigImpl

use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.

the class DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest method testUsesIpAddr.

/**
     * Generic method to help with various tests
     * @param globalspecified if false, will clear property DiscoveryEnabledNIWSServerList.useIpAddr
     * @param global value of DiscoveryEnabledNIWSServerList.useIpAddr
     * @param clientspecified if false, will not set property on client config
     * @param client value of client.namespace.ribbon.UseIPAddrForServer
     */
private List<Server> testUsesIpAddr(boolean globalSpecified, boolean global, boolean clientSpecified, boolean client) throws Exception {
    if (globalSpecified) {
        ConfigurationManager.getConfigInstance().setProperty("ribbon.UseIPAddrForServer", global);
    } else {
        ConfigurationManager.getConfigInstance().clearProperty("ribbon.UseIPAddrForServer");
    }
    if (clientSpecified) {
        ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.UseIPAddrForServer", client);
    } else {
        ConfigurationManager.getConfigInstance().clearProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.UseIPAddrForServer");
    }
    System.out.println("r = " + ConfigurationManager.getConfigInstance().getProperty("ribbon.UseIPAddrForServer"));
    System.out.println("d = " + ConfigurationManager.getConfigInstance().getProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.UseIPAddrForServer"));
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.DeploymentContextBasedVipAddresses", "dummy");
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testUsesIpAddr.ribbon.TargetRegion", "region");
    DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList("TESTVIP:8080");
    DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance();
    clientConfig.loadProperties("DiscoveryEnabled.testUsesIpAddr");
    deList.initWithNiwsConfig(clientConfig);
    List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers();
    Assert.assertEquals(2, serverList.size());
    List<Server> servers = new ArrayList<Server>();
    for (DiscoveryEnabledServer server : serverList) {
        servers.add((Server) server);
    }
    return servers;
}
Also used : Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl)

Example 2 with DefaultClientConfigImpl

use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.

the class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest method testDefaultHonorsVipSecurePortDefinition.

@Test
public void testDefaultHonorsVipSecurePortDefinition() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.DeploymentContextBasedVipAddresses", "secureDummy");
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.IsSecure", "true");
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.SecurePort", "6002");
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.TargetRegion", "region");
    ConfigurationManager.getConfigInstance().setProperty("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    DiscoveryEnabledNIWSServerList deList = new DiscoveryEnabledNIWSServerList();
    DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.class.newInstance();
    clientConfig.loadProperties("DiscoveryEnabled.testDefaultHonorsVipSecurePortDefinition");
    deList.initWithNiwsConfig(clientConfig);
    List<DiscoveryEnabledServer> serverList = deList.getInitialListOfServers();
    Assert.assertEquals(1, serverList.size());
    // vip indicated
    Assert.assertEquals(8002, serverList.get(0).getPort());
    // vip indicated
    Assert.assertEquals(8002, serverList.get(0).getInstanceInfo().getPort());
    // 7002 is the secure default
    Assert.assertEquals(7002, serverList.get(0).getInstanceInfo().getSecurePort());
}
Also used : DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with DefaultClientConfigImpl

use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.

the class ClientConfigTest method testNiwsConfigViaProperties.

@Test
public void testNiwsConfigViaProperties() throws Exception {
    DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    DefaultClientConfigImpl override = new DefaultClientConfigImpl();
    clientConfig.loadDefaultValues();
    Properties props = new Properties();
    final String restClientName = "testRestClient";
    props.setProperty("netflix.appinfo.stack", "xbox");
    props.setProperty("netflix.environment", "test");
    props.setProperty("appname", "movieservice");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.AppName.key(), "movieservice");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.DeploymentContextBasedVipAddresses.key(), "${appname}-${netflix.appinfo.stack}-${netflix.environment},movieservice--${netflix.environment}");
    clientConfig.setProperty(props, restClientName, CommonClientConfigKey.EnableZoneAffinity.key(), "false");
    ConfigurationManager.loadProperties(props);
    ConfigurationManager.getConfigInstance().setProperty("testRestClient.ribbon.customProperty", "abc");
    clientConfig.loadProperties(restClientName);
    clientConfig.setProperty(CommonClientConfigKey.ConnectTimeout, "1000");
    override.setProperty(CommonClientConfigKey.Port, "8000");
    override.setProperty(CommonClientConfigKey.ConnectTimeout, "5000");
    clientConfig.applyOverride(override);
    Assert.assertEquals("movieservice", clientConfig.getProperty(CommonClientConfigKey.AppName));
    Assert.assertEquals("false", clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
    Assert.assertEquals("movieservice-xbox-test,movieservice--test", clientConfig.resolveDeploymentContextbasedVipAddresses());
    Assert.assertEquals("5000", clientConfig.getProperty(CommonClientConfigKey.ConnectTimeout));
    Assert.assertEquals("8000", clientConfig.getProperty(CommonClientConfigKey.Port));
    assertEquals("abc", clientConfig.getProperties().get("customProperty"));
    System.out.println("AutoVipAddress:" + clientConfig.resolveDeploymentContextbasedVipAddresses());
    ConfigurationManager.getConfigInstance().setProperty("testRestClient.ribbon.EnableZoneAffinity", "true");
    ConfigurationManager.getConfigInstance().setProperty("testRestClient.ribbon.customProperty", "xyz");
    assertEquals("true", clientConfig.getProperty(CommonClientConfigKey.EnableZoneAffinity));
    assertEquals("xyz", clientConfig.getProperties().get("customProperty"));
}
Also used : Properties(java.util.Properties) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 4 with DefaultClientConfigImpl

use of com.netflix.client.config.DefaultClientConfigImpl in project ribbon by Netflix.

the class ConfigurationBasedServerListTest method testList.

@Test
public void testList() {
    ConfigurationBasedServerList list = new ConfigurationBasedServerList();
    DefaultClientConfigImpl config = DefaultClientConfigImpl.getClientConfigWithDefaultValues("junit1");
    list.initWithNiwsConfig(config);
    assertTrue(list.getInitialListOfServers().isEmpty());
    ConfigurationManager.getConfigInstance().setProperty("junit1.ribbon.listOfServers", "abc.com:80,microsoft.com,1.2.3.4:8080");
    List<Server> servers = list.getUpdatedListOfServers();
    List<Server> expected = new ArrayList<Server>();
    expected.add(new Server("abc.com:80"));
    expected.add(new Server("microsoft.com:80"));
    expected.add(new Server("1.2.3.4:8080"));
    assertEquals(expected, servers);
    ConfigurationManager.getConfigInstance().setProperty("junit1.ribbon.listOfServers", "");
    assertTrue(list.getUpdatedListOfServers().isEmpty());
    ConfigurationManager.getConfigInstance().clearProperty("junit1.ribbon.listOfServers");
    assertTrue(list.getUpdatedListOfServers().isEmpty());
}
Also used : ArrayList(java.util.ArrayList) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 5 with DefaultClientConfigImpl

use of com.netflix.client.config.DefaultClientConfigImpl in project zuul by Netflix.

the class RibbonConfig method setupDefaultRibbonConfig.

/**
     * This method attempts to set up the default Ribbon origin VIP from properties and environment.
     * One method is through autoscale name convention. The Autoscaling group name can be set up as follow : zuul-origin_stack.
     * Zuul will derive the origin VIP  as origin-stack.{zuul.ribbon.vipAddress.template}
     * <p/>
     * the client may also be specified by the property ZuulConstants.ZUUL_NIWS_DEFAULTCLIENT
     *
     * @throws ClientException
     */
public static void setupDefaultRibbonConfig() throws ClientException {
    final DeploymentContext config = ConfigurationManager.getDeploymentContext();
    String stack = config.getDeploymentStack();
    if (stack != null && stack.contains("_")) {
        //use stack for client and stack  client_stack
        setAppInfoFromZuulStack(stack);
    } else {
        String env = config.getDeploymentEnvironment();
        if (stack != null) {
            setApplicationName(stack);
        } else {
            if (DEFAULT_CLIENT.get() == null)
                throw new RuntimeException("Can't figure out default origin vips. Set stack as appName_stack of set zuul.niws.defaultClient param");
            setApplicationName(DEFAULT_CLIENT.get());
        }
        setApplicationStack(env);
    }
    String vip = RibbonConfig.getDefaultVipName();
    String vipAddr = RibbonConfig.getDefaultVipAddress(getApplicationStack());
    String namespace = DynamicPropertyFactory.getInstance().getStringProperty(ZuulConstants.ZUUL_RIBBON_NAMESPACE, "ribbon").get();
    setIfNotDefined(vip, vipAddr);
    setIfNotDefined(getApplicationName() + "." + namespace + ".Port", "7001");
    setIfNotDefined(getApplicationName() + "." + namespace + ".AppName", getApplicationName());
    setIfNotDefined(getApplicationName() + "." + namespace + ".ReadTimeout", "2000");
    setIfNotDefined(getApplicationName() + "." + namespace + ".ConnectTimeout", "2000");
    setIfNotDefined(getApplicationName() + "." + namespace + ".MaxAutoRetriesNextServer", "1");
    setIfNotDefined(getApplicationName() + "." + namespace + ".FollowRedirects", "false");
    setIfNotDefined(getApplicationName() + "." + namespace + ".ConnIdleEvictTimeMilliSeconds", "3600000");
    setIfNotDefined(getApplicationName() + "." + namespace + ".EnableZoneAffinity", "true");
    DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(getApplicationName(), namespace);
    ClientFactory.registerClientFromProperties(getApplicationName(), clientConfig);
}
Also used : DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl)

Aggregations

DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)12 Test (org.junit.Test)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 MockHttpServer (com.netflix.client.testutil.MockHttpServer)1 DynamicStringProperty (com.netflix.config.DynamicStringProperty)1 Server (com.netflix.loadbalancer.Server)1