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();
}
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();
}
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();
}
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");
}
};
}
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));
}
Aggregations