Search in sources :

Example 1 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallConfigurationTest method testDefaultConfigurationFromRegistryWithDefaultName.

@Test
public void testDefaultConfigurationFromRegistryWithDefaultName() throws Exception {
    StaticServiceDiscovery sd = new StaticServiceDiscovery();
    sd.addServer("127.0.0.1:8080");
    sd.addServer("127.0.0.1:8081");
    BlacklistServiceFilter sf = new BlacklistServiceFilter();
    sf.addServer("127.0.0.1:8080");
    ServiceCallConfigurationDefinition conf = new ServiceCallConfigurationDefinition();
    conf.setServiceDiscovery(sd);
    conf.serviceFilter(sf);
    SimpleRegistry reg = new SimpleRegistry();
    reg.put(org.apache.camel.model.cloud.ServiceCallConstants.DEFAULT_SERVICE_CALL_CONFIG_ID, conf);
    CamelContext context = new DefaultCamelContext(reg);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").routeId("default").serviceCall().name("scall").component("file").end();
        }
    });
    context.start();
    DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
    Assert.assertNotNull(proc);
    Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
    DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
    Assert.assertEquals(sd, loadBalancer.getServiceDiscovery());
    Assert.assertEquals(sf, loadBalancer.getServiceFilter());
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallConfigurationTest method testDefaultConfigurationFromCamelContext.

// ****************************************
// test default resolution
// ****************************************
@Test
public void testDefaultConfigurationFromCamelContext() throws Exception {
    StaticServiceDiscovery sd = new StaticServiceDiscovery();
    sd.addServer("127.0.0.1:8080");
    sd.addServer("127.0.0.1:8081");
    BlacklistServiceFilter sf = new BlacklistServiceFilter();
    sf.addServer("127.0.0.1:8080");
    ServiceCallConfigurationDefinition conf = new ServiceCallConfigurationDefinition();
    conf.setServiceDiscovery(sd);
    conf.setServiceFilter(sf);
    CamelContext context = new DefaultCamelContext();
    context.setServiceCallConfiguration(conf);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").routeId("default").serviceCall().name("scall").component("file").end();
        }
    });
    context.start();
    DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
    Assert.assertNotNull(proc);
    Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
    DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
    Assert.assertEquals(sd, loadBalancer.getServiceDiscovery());
    Assert.assertEquals(sf, loadBalancer.getServiceFilter());
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallConfigurationTest method testMixedConfiguration.

// ****************************************
// test mixed resolution
// ****************************************
@Test
public void testMixedConfiguration() throws Exception {
    // Default
    StaticServiceDiscovery defaultServiceDiscovery = new StaticServiceDiscovery();
    defaultServiceDiscovery.addServer("127.0.0.1:8080");
    defaultServiceDiscovery.addServer("127.0.0.1:8081");
    defaultServiceDiscovery.addServer("127.0.0.1:8082");
    BlacklistServiceFilter defaultServiceFilter = new BlacklistServiceFilter();
    defaultServiceFilter.addServer("127.0.0.1:8080");
    ServiceCallConfigurationDefinition defaultConfiguration = new ServiceCallConfigurationDefinition();
    defaultConfiguration.setServiceDiscovery(defaultServiceDiscovery);
    defaultConfiguration.serviceFilter(defaultServiceFilter);
    // Named
    BlacklistServiceFilter namedServiceFilter = new BlacklistServiceFilter();
    namedServiceFilter.addServer("127.0.0.1:8081");
    ServiceCallConfigurationDefinition namedConfiguration = new ServiceCallConfigurationDefinition();
    namedConfiguration.serviceFilter(namedServiceFilter);
    // Local
    StaticServiceDiscovery localServiceDiscovery = new StaticServiceDiscovery();
    localServiceDiscovery.addServer("127.0.0.1:8080");
    localServiceDiscovery.addServer("127.0.0.1:8081");
    localServiceDiscovery.addServer("127.0.0.1:8082");
    localServiceDiscovery.addServer("127.0.0.1:8084");
    // Camel context
    CamelContext context = new DefaultCamelContext();
    context.setServiceCallConfiguration(defaultConfiguration);
    context.addServiceCallConfiguration("named", namedConfiguration);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:default").id("default").serviceCall().name("default-scall").component("file").end();
            from("direct:named").id("named").serviceCall().serviceCallConfiguration("named").name("named-scall").component("file").end();
            from("direct:local").id("local").serviceCall().serviceCallConfiguration("named").name("local-scall").component("file").serviceDiscovery(localServiceDiscovery).end();
        }
    });
    context.start();
    {
        // Default
        DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
        Assert.assertNotNull(proc);
        Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
        DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
        Assert.assertEquals(defaultServiceDiscovery, loadBalancer.getServiceDiscovery());
        Assert.assertEquals(defaultServiceFilter, loadBalancer.getServiceFilter());
    }
    {
        // Named
        DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("named"));
        Assert.assertNotNull(proc);
        Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
        DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
        Assert.assertEquals(defaultServiceDiscovery, loadBalancer.getServiceDiscovery());
        Assert.assertEquals(namedServiceFilter, loadBalancer.getServiceFilter());
    }
    {
        // Local
        DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("local"));
        Assert.assertNotNull(proc);
        Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
        DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
        Assert.assertEquals(localServiceDiscovery, loadBalancer.getServiceDiscovery());
        Assert.assertEquals(namedServiceFilter, loadBalancer.getServiceFilter());
    }
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 4 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallClientRouteTest method createRouteBuilder.

@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            KubernetesConfiguration kubernetesConfiguration = new KubernetesConfiguration();
            kubernetesConfiguration.setMasterUrl("http://172.28.128.80:8080");
            kubernetesConfiguration.setUsername("admin");
            kubernetesConfiguration.setPassword("admin");
            kubernetesConfiguration.setNamespace("default");
            ServiceCallConfigurationDefinition config = new ServiceCallConfigurationDefinition();
            config.setServiceDiscovery(new KubernetesEnvServiceDiscovery(kubernetesConfiguration));
            // register configuration
            context.setServiceCallConfiguration(config);
            from("direct:start").serviceCall("cdi-camel-jetty").serviceCall("cdi-camel-jetty").to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) KubernetesConfiguration(org.apache.camel.component.kubernetes.KubernetesConfiguration) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)

Example 5 with ServiceCallConfigurationDefinition

use of org.apache.camel.model.cloud.ServiceCallConfigurationDefinition in project camel by apache.

the class ServiceCallConfigurationTest method testServiceDiscoveryConfiguration.

@Test
public void testServiceDiscoveryConfiguration() {
    ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1");
    assertNotNull("No ServiceCallConfiguration (1)", conf1);
    assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration());
    StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration) conf1.getServiceDiscoveryConfiguration();
    assertEquals(1, discovery1.getServers().size());
    assertEquals("localhost:9091", discovery1.getServers().get(0));
    ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2");
    assertNotNull("No ServiceCallConfiguration (2)", conf2);
    assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration());
    StaticServiceCallServiceDiscoveryConfiguration discovery2 = (StaticServiceCallServiceDiscoveryConfiguration) conf2.getServiceDiscoveryConfiguration();
    assertEquals(2, discovery2.getServers().size());
    assertEquals("localhost:9092", discovery2.getServers().get(0));
    assertEquals("localhost:9093,localhost:9094", discovery2.getServers().get(1));
}
Also used : ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) StaticServiceCallServiceDiscoveryConfiguration(org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration) Test(org.junit.Test)

Aggregations

ServiceCallConfigurationDefinition (org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)7 Test (org.junit.Test)7 CamelContext (org.apache.camel.CamelContext)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 StaticServiceCallServiceDiscoveryConfiguration (org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration)3 KubernetesConfiguration (org.apache.camel.component.kubernetes.KubernetesConfiguration)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 RibbonConfiguration (org.apache.camel.component.ribbon.RibbonConfiguration)1 StaticServiceDiscovery (org.apache.camel.impl.cloud.StaticServiceDiscovery)1 BlacklistServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.BlacklistServiceCallServiceFilterConfiguration)1 ChainedServiceCallServiceDiscoveryConfiguration (org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration)1 ChainedServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration)1 DefaultServiceCallLoadBalancerConfiguration (org.apache.camel.model.cloud.DefaultServiceCallLoadBalancerConfiguration)1 HealthyServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.HealthyServiceCallServiceFilterConfiguration)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1