Refine search
@Override public void start() throws Exception { serviceDiscovery.start(); }
if (!allowDuplicateRegistrations) { try { for (ServiceInstance<IgniteInstanceDetails> sd : discovery.queryForInstances(serviceName)) registrationsToIgnore.add(new InetSocketAddress(sd.getAddress(), sd.getPort())); ServiceInstance<IgniteInstanceDetails> si = ServiceInstance.<IgniteInstanceDetails>builder() .name(serviceName) .uriSpec(URI_SPEC) discovery.registerService(si);
@Override public void unregister(RegistrationHandle handle) { if (!(handle instanceof ZKRegistrationHandle)) { throw new UnsupportedOperationException( "Unknown handle type: " + handle.getClass().getName()); } // when Drillbit is unregistered, clean all the listeners registered in CC. this.listeners.clear(); ZKRegistrationHandle h = (ZKRegistrationHandle) handle; try { ServiceInstance<DrillbitEndpoint> serviceInstance = ServiceInstance .<DrillbitEndpoint> builder().address("").port(0).id(h.id) .name(serviceName).build(); discovery.unregisterService(serviceInstance); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } }
@Override public void start(long millisToWait) throws Exception { logger.debug("Starting ZKClusterCoordination."); discovery.start(); if (millisToWait != 0) { boolean success = this.initialConnection.await(millisToWait, TimeUnit.MILLISECONDS); if (!success) { throw new IOException(String.format( "Failure to connect to the zookeeper cluster service within the allotted time of %d milliseconds.", millisToWait)); } } else { this.initialConnection.await(); } serviceCache = discovery.serviceCacheBuilder().name(serviceName).build(); serviceCache.addListener(new EndpointListener()); serviceCache.start(); updateEndpoints(); }
} else { try { instance = ServiceInstance.<Void>builder() .name(serviceName) .address(service.getHost()) discovery.registerService(instance);
@Override public List<ComponentInfo> getComponents(ComponentCategory category) { try { Collection<ServiceInstance<ComponentInfo>> instances = serviceDiscovery.queryForInstances(category.toString()); List<ComponentInfo> result = new ArrayList<>(instances.size()); instances.forEach(i -> result.add(i.getPayload())); return result; } catch (Exception e) { e.printStackTrace(); } return new ArrayList<ComponentInfo>(); }
serviceDiscovery.start(); endpoint.setVersion(version); }; ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint> builder() .address(endpointUrl.getHost()) .id(containerId) try { LOG.info("Installing service instance: " + instance + " at " + serviceDiscovery); serviceDiscovery.registerService(instance); LOG.info("Installed instance " + name + ":" + version + "@" + endpointUrl);
@Override protected void doStop() throws Exception { if (serviceDiscovery != null) { try { if (configuration.isDeregisterServicesOnStop()) { for (String serviceName: serviceDiscovery.queryForNames()) { for (ServiceInstance<MetaData> serviceInstance: serviceDiscovery.queryForInstances(serviceName)) { if (serviceList.contains(serviceInstance.getId())) { serviceDiscovery.unregisterService(serviceInstance); // remove the serviceId to the list of known server serviceList.remove(serviceInstance.getId()); } } } } serviceDiscovery.close(); } catch (Exception e) { LOGGER.warn("Error closing Curator ServiceDiscovery", e); } } if (curator != null && managedInstance) { curator.close(); } }
Map<String, ServiceInstance<ModelEndpoint>> containerToEndpoint = new HashMap<>(); try { for(String name : serviceDiscovery.queryForNames()) { for(ServiceInstance<ModelEndpoint> endpoint: serviceDiscovery.queryForInstances(name)) { ModelEndpoint ep = endpoint.getPayload(); if(LOG.isDebugEnabled()) { LOG.debug("Found model endpoint " + ep);
@Override public void start() throws Exception { discovery.start(); if ( soaInfo.isRegisterInDiscovery() ) { discovery.registerService(us.get()); } }
/** {@inheritDoc} */ @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException { init(); if (log.isDebugEnabled()) log.debug("Getting registered addresses from ZooKeeper IP Finder."); Collection<ServiceInstance<IgniteInstanceDetails>> serviceInstances; try { serviceInstances = discovery.queryForInstances(serviceName); } catch (Exception e) { log.warning("Error while getting registered addresses from ZooKeeper IP Finder.", e); return Collections.emptyList(); } Set<InetSocketAddress> answer = new HashSet<>(); for (ServiceInstance<IgniteInstanceDetails> si : serviceInstances) answer.add(new InetSocketAddress(si.getAddress(), si.getPort())); if (log.isInfoEnabled()) log.info("ZooKeeper IP Finder resolved addresses: " + answer); return answer; }
private void registerService(ModelEndpoint ep) throws Exception { discoverer.getServiceDiscovery().registerService(createInstance(ep)); } private void registerService(String name, String version, AtomicInteger containerId) throws Exception {
@Override public void unannounce(DruidNode service) { final String serviceName = CuratorServiceUtils.makeCanonicalServiceName(service.getServiceName()); final ServiceInstance<Void> instance; synchronized (monitor) { instance = instanceMap.get(serviceName); if (instance == null) { log.warn("Ignoring request to unannounce service[%s]", service); return; } } log.info("Unannouncing service[%s]", service); try { discovery.unregisterService(instance); } catch (Exception e) { log.makeAlert(e, "Failed to unannounce service[%s], zombie znode perhaps in existence.", serviceName) .addData("service", service) .emit(); } finally { synchronized (monitor) { instanceMap.remove(serviceName); } } } }
private void unadvertiseService() throws Exception { // Stop the service discovery cache sCache.close(); // Unadvertise on the service discovery sDiscovery.unregisterService(getMetadataInstance()); sDiscovery.close(); }
public void listInstances(ServiceDiscovery<MetaData> serviceDiscovery) throws Exception { // This shows how to query all the instances in service discovery try { Collection<String> serviceNames = serviceDiscovery.queryForNames(); for (String serviceName : serviceNames) { Collection<ServiceInstance<MetaData>> instances = serviceDiscovery.queryForInstances(serviceName); log.info("serviceName: " + serviceName); for (ServiceInstance<MetaData> instance : instances) { outputInstance(instance); } } } catch (Exception e) { /* * Something bad did happen, but carry on */ log.error(e.getMessage(), e); } }
@Override public RegistrationHandle register(DrillbitEndpoint data) { try { ServiceInstance<DrillbitEndpoint> serviceInstance = newServiceInstance( data); discovery.registerService(serviceInstance); return new ZKRegistrationHandle(serviceInstance.getId(), data); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } }
@Override public boolean apply(String input) { try { return serviceDiscovery.queryForInstances(input.replace('/', ':')).size() == 1; } catch (Exception e) { throw new ISE( "Something went wrong while finding instance with name [%s] in Service Discovery", input ); } } }
@Override public void stop() { try { serviceDiscovery.close(); } catch (Exception e) { throw Throwables.propagate(e); } } }
/** * Reset the state to empty. */ public void resetState() { rwLock.readLock().lock(); ServiceInstance<ModelEndpoint> ep = null; try { for(Map.Entry<String, ServiceInstance<ModelEndpoint>> kv : containerToEndpoint.entrySet()) { ep = kv.getValue(); serviceDiscovery.unregisterService(ep); } } catch (Exception e) { LOG.error("Unable to unregister endpoint " + ep.getPayload(), e); } finally { rwLock.readLock().unlock(); } }
public ServerDiscoverySelector createSelector(String serviceName) { if (serviceName == null) { return new ServerDiscoverySelector(new NoopServiceProvider(), serviceName); } final ServiceProvider serviceProvider = serviceDiscovery .serviceProviderBuilder() .serviceName(CuratorServiceUtils.makeCanonicalServiceName(serviceName)) .build(); return new ServerDiscoverySelector(serviceProvider, serviceName); }