@Override public List<ServiceDefinition> getServices(String name) { return delegate.getServices(name); } }
public RibbonServiceDefinition(ServiceDefinition definition) { this( definition.getName(), definition.getHost(), definition.getPort(), definition.getMetadata(), definition.getHealth() ); }
@Override public List<RibbonServiceDefinition> getInitialListOfServers() { List<ServiceDefinition> services = serviceDiscovery.getServices(serviceName); if (serviceFilter != null) { services = serviceFilter.apply(services); } return asRibbonServerList(services); }
@Override public ZookeeperRegistration convert(ServiceDefinition source) { ZookeeperInstance instance = new ZookeeperInstance( source.getId(), source.getName(), source.getMetadata() ); return ServiceInstanceRegistration.builder() .address(properties.getServiceRegistry().getServiceHost()) .port(source.getPort()) .name(source.getName()) .payload(instance) .uriSpec(ZookeeperDiscoveryProperties.DEFAULT_URI_SPEC) .build(); } }
@Override public void deregister(ServiceDefinition definition) { if (definition.getId() == null) { throw new IllegalArgumentException("Service ID must be defined (definition=" + definition + ")"); } if (definition.getName() == null) { throw new IllegalArgumentException("Service Name must be defined (definition=" + definition + ")"); } try { for (ServiceInstance<MetaData> serviceInstance: serviceDiscovery.queryForInstances(definition.getName())) { if (Objects.equals(serviceInstance.getId(), definition.getId())) { serviceDiscovery.unregisterService(serviceInstance); // remove the serviceId to the list of known server serviceList.remove(serviceInstance.getId()); } } } catch (Exception e) { LOGGER.warn("", e); } }
@Override public List<ServiceDefinition> getServices(String name) { List<ServiceDefinition> servers = serversRef.get(); if (servers == null) { serversRef.set(getServices()); watch(); } return serversRef.get().stream() .filter(s -> name.equalsIgnoreCase(s.getName())) .collect(Collectors.toList()); }
private String computeServiceHost(ServiceDefinition definition) { String host = definition.getHost(); if (configuration.isOverrideServiceHost() && configuration.getServiceHost() != null) { host = configuration.getServiceHost(); } return ObjectHelper.notNull(host, "service host"); }
@Override public void deregister(ServiceDefinition definition) { if (definition.getId() == null) { throw new IllegalArgumentException("ServiceID must be defined (definition=" + definition + ")"); } client.agentClient().deregister(definition.getId()); //remove the serviceId to the list of known server serviceList.remove(definition.getId()); }
private Registration.RegCheck computeCheck(ServiceDefinition definition) { if (definition.getHealth() == null) { return ImmutableRegCheck.builder() .ttl(String.format("%ss", configuration.getCheckInterval())) return definition.getHealth().getEndpoint().flatMap( uri -> { if (Objects.equals("http", uri.getScheme())) {
@Override public <T> T process(String serviceName, ServiceLoadBalancerFunction<T> request) throws Exception { ILoadBalancer loadBalancer = loadBalancers.computeIfAbsent(serviceName, key -> createLoadBalancer(key)); Server server = loadBalancer.chooseServer(serviceName); if (server == null) { throw new RejectedExecutionException("No active services with name " + serviceName); } ServiceDefinition definition; if (server instanceof ServiceDefinition) { // If the service discovery is one of camel provides, the definition // is already of the expected type. definition = (ServiceDefinition)server; } else { // If ribbon server list is configured through client config properties // i.e. with listOfServers property the instance provided by the load // balancer is of type Server so a conversion is needed definition = new RibbonServiceDefinition( serviceName, server.getHost(), server.getPort() ); String zone = server.getZone(); if (zone != null) { server.setZone(zone); } } return request.apply(definition); }
@Override protected void doSuspend() throws Exception { if (delegatedConsumer instanceof SuspendableService) { final ServiceEndpoint endpoint = (ServiceEndpoint)getEndpoint(); final ServiceDefinition definition = endpoint.getServiceDefinition(); // de-register service serviceRegistry.deregister(definition); ((SuspendableService)delegatedConsumer).suspend(); } super.doSuspend(); } }
private ServiceDefinition computeServiceDefinition(CamelContext context, Endpoint delegateEndpoint) { Map<String, String> parameters = new HashMap<>(); if (delegateEndpoint instanceof DiscoverableService) { parameters.putAll(((DiscoverableService)delegateEndpoint).getServiceProperties()); } parameters.putAll(serviceParameters); parameters.computeIfAbsent(ServiceDefinition.SERVICE_META_ID, k -> context.getUuidGenerator().generateUuid()); return DefaultServiceDefinition.builder().from(parameters).build(); } }
@Override protected void doResume() throws Exception { if (delegatedConsumer instanceof SuspendableService) { final ServiceEndpoint endpoint = (ServiceEndpoint)getEndpoint(); final ServiceDefinition definition = endpoint.getServiceDefinition(); // register service serviceRegistry.register(definition); ((SuspendableService)delegatedConsumer).resume(); } super.doResume(); }
private List<RibbonServiceDefinition> asRibbonServerList(List<ServiceDefinition> services) { List<RibbonServiceDefinition> ribbonServers = new ArrayList<>(); for (ServiceDefinition service : services) { if (service instanceof RibbonServiceDefinition) { ribbonServers.add((RibbonServiceDefinition)service); } else { RibbonServiceDefinition serviceDef = new RibbonServiceDefinition( serviceName, service.getHost(), service.getPort(), service.getMetadata(), service.getHealth() ); String zone = serviceDef.getMetadata().get("zone"); if (zone != null) { serviceDef.setZone(zone); } ribbonServers.add(serviceDef); } } return ribbonServers; } }
@Override public void register(ServiceDefinition definition) { if (definition.getId() == null) { throw new IllegalArgumentException("Service ID must be defined (definition=" + definition + ")"); } if (definition.getName() == null) { throw new IllegalArgumentException("Service Name must be defined (definition=" + definition + ")"); } try { ServiceInstance<MetaData> instance = ServiceInstance.<MetaData>builder() .address(computeServiceHost(definition)) .port(definition.getPort()) .name(definition.getName()) .id(definition.getId()) .payload(new MetaData(definition.getMetadata())) .build(); serviceDiscovery.registerService(instance); // add the serviceId to the list of known server serviceList.add(definition.getId()); } catch (Exception e) { LOGGER.warn("", e); } }
@Override public List<RibbonServiceDefinition> getUpdatedListOfServers() { List<ServiceDefinition> services = serviceDiscovery.getServices(serviceName); if (serviceFilter != null) { services = serviceFilter.apply(services); } return asRibbonServerList(services); }
private String computeServiceHost(ServiceDefinition definition) { String host = definition.getHost(); if (configuration.isOverrideServiceHost() && configuration.getServiceHost() != null) { host = configuration.getServiceHost(); } return ObjectHelper.notNull(host, "service host"); }
@Override protected void doStop() throws Exception { super.doStop(); final ServiceEndpoint endpoint = (ServiceEndpoint)getEndpoint(); final ServiceDefinition definition = endpoint.getServiceDefinition(); // de-register service serviceRegistry.deregister(definition); // stop delegate ServiceHelper.stopAndShutdownServices(delegatedConsumer); ServiceHelper.stopAndShutdownServices(delegatedEndpoint); delegatedConsumer = null; }
@Override public List<RibbonServiceDefinition> getUpdatedListOfServers() { if (serviceId == null) { return Collections.emptyList(); } List<ServiceDefinition> services = serviceDiscovery.getServices(serviceId); if (serviceFilter != null) { services = serviceFilter.apply(services); } return convert(services); }
@Override public List<RibbonServiceDefinition> getInitialListOfServers() { if (serviceId == null) { return Collections.emptyList(); } List<ServiceDefinition> services = serviceDiscovery.getServices(serviceId); if (serviceFilter != null) { services = serviceFilter.apply(services); } return convert(services); }