/** Initializes this IP Finder by creating the appropriate Curator objects. */ private void init() { if (!initGuard.compareAndSet(false, true)) return; String sysPropZkConnString = System.getProperty(PROP_ZK_CONNECTION_STRING); if (sysPropZkConnString != null && !sysPropZkConnString.trim().isEmpty()) zkConnectionString = sysPropZkConnString; if (log.isInfoEnabled()) log.info("Initializing ZooKeeper IP Finder."); if (curator == null) { A.notNullOrEmpty(zkConnectionString, String.format("ZooKeeper URL (or system property %s) cannot be null " + "or empty if a CuratorFramework object is not provided explicitly", PROP_ZK_CONNECTION_STRING)); curator = CuratorFrameworkFactory.newClient(zkConnectionString, retryPolicy); } if (curator.getState() == CuratorFrameworkState.LATENT) curator.start(); A.ensure(curator.getState() == CuratorFrameworkState.STARTED, "CuratorFramework can't be started."); discovery = ServiceDiscoveryBuilder.builder(IgniteInstanceDetails.class) .client(curator) .basePath(basePath) .serializer(new JsonInstanceSerializer<>(IgniteInstanceDetails.class)) .build(); }
/** * Pretend to be a Drillbit creating its ZK entry. Real Drillbits use a GUID * as the key, but we just use the host name, which is good enough for our * purposes here. * * @param zk * @param host * @throws Exception */ private void addDrillbit(CuratorFramework zk, String host) throws Exception { DrillbitEndpoint dbe = makeEndpoint(host); ServiceInstance<DrillbitEndpoint> si = ServiceInstance .<DrillbitEndpoint> builder().name(CLUSTER_ID).payload(dbe).build(); byte data[] = DrillServiceInstanceHelper.SERIALIZER.serialize(si); zk.create().forPath("/" + host, data); }
/** * Return the current available set of instances <b>IMPORTANT: </b> users * should not hold on to the instance returned. They should always get a fresh list. * * @return all known instances * @throws Exception any errors */ @Override public Collection<ServiceInstance<T>> getAllInstances() throws Exception { return instanceProvider.getInstances(); }
@Override public void noteError(ServiceInstance<T> instance) { downInstanceManager.add(instance); } }
@Override public ServiceInstance<T> getInstance(String id) { return instanceProvider.getInstance(id); } }
@Override public Void apply(ServiceCacheListener<T> listener) { listener.cacheChanged(); listener.cacheChanged(event, fServiceInstance); return null; } }
/** * Return all known instances for the given service * * @param name name of the service * @return list of instances (or an empty list) * @throws Exception errors */ @Override public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception { return queryForInstances(name, null); }
public ServiceProvider<T> build() { return new ServiceProviderImpl<T>(discovery, serviceName, providerStrategy, threadFactory, filters, downInstancePolicy); }
ServiceCacheImpl(ServiceDiscoveryImpl<T> discovery, String name, ThreadFactory threadFactory) { this(discovery, name, convertThreadFactory(threadFactory)); }
ServiceCacheImplExt(ServiceDiscoveryImpl<T> discovery, String name, ThreadFactory threadFactory) { this(discovery, name, convertThreadFactory(threadFactory)); }
LOG.error("Unable to create path: " + e.getMessage(), e); JsonInstanceSerializer<ModelEndpoint> serializer = new JsonInstanceSerializer<>(ModelEndpoint.class); serviceDiscovery = ServiceDiscoveryBuilder.builder(ModelEndpoint.class) .client(client)
@Override public Collection<ServiceInstance<T>> getAllInstances() throws Exception { return instanceProvider.getInstances(); }
@Override public void noteError(ServiceInstance<T> instance) { downInstanceManager.add(instance); }
@Override public ServiceInstance<T> getInstance(String id) { return instanceProvider.getInstance(id); } }
@Override public Void apply(ServiceCacheListener listener) { listener.cacheChanged(); return null; } }
/** * Return all known instances for the given group * * @param name name of the group * @return list of instances (or an empty list) * @throws Exception errors */ @Override public Collection<ServiceInstance<T>> queryForInstances(String name) throws Exception { return queryForInstances(name, null); }
public ServiceProvider<T> build() { return new ServiceProviderImpl<T>(discovery, serviceName, providerStrategy, threadFactory, filters, downInstancePolicy); }
ServiceCacheImpl(ServiceDiscoveryImpl<T> discovery, String name, ThreadFactory threadFactory) { this(discovery, name, convertThreadFactory(threadFactory)); }
client.start(); MaaSConfig config = ConfigUtil.INSTANCE.read(client, zkRoot, new MaaSConfig(), MaaSConfig.class); JsonInstanceSerializer<ModelEndpoint> serializer = new JsonInstanceSerializer<>(ModelEndpoint.class); try { serviceDiscovery = ServiceDiscoveryBuilder.builder(ModelEndpoint.class)
/** * Return the current available set of instances <b>IMPORTANT: </b> users * should not hold on to the instance returned. They should always get a fresh list. * * @return all known instances * @throws Exception any errors */ @Override public List<ServiceInstance<T>> getAllInstances() throws Exception { return instanceProvider.getInstances(); }