@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(); }
/** * The provider must be started before use * * @throws Exception any errors */ @Override public void start() throws Exception { cache.start(); discovery.providerOpened(this); }
@Override public void clearDependencyRegistrationHooks() throws IOException { for (ServiceCache<?> cache : this.dependencyRegistry.values()) { cache.close(); } }
/** * Returns a list of the metadata provided by all of the Oozie Servers. Note that the metadata is cached so it may be a second * or two stale. * * @return a List of the metadata provided by all of the Oozie Servers. */ public List<ServiceInstance<Map>> getAllMetaData() { List<ServiceInstance<Map>> instances = null; if (sCache != null) { instances = sCache.getInstances(); } return instances; }
.build(); serviceProvider.start(); serviceProvider.serviceCache().addListener(new ServiceCacheListener<NodeStatus>() { @Override public void cacheChanged() {
@Override public ServiceInstance<T> getInstance(String id) { return cache.getInstance(id); }
/** * The provider must be started before use * * @throws Exception any errors */ @Override public void start() throws Exception { cache.start(); discovery.providerOpened(this); }
@Override public void close() throws Exception { // might be redundant, as serviceCache clears them upon closure clearListeners(); serviceCache.close(); } }
/** * Returns a list of the metadata provided by all of the Oozie Servers. Note that the metadata is cached so it may be a second * or two stale. * * @return a List of the metadata provided by all of the Oozie Servers. */ public List<ServiceInstance<Map>> getAllMetaData() { List<ServiceInstance<Map>> instances = null; if (sCache != null) { instances = sCache.getInstances(); } return instances; }
@Override public void start() throws Exception { serviceCache.start(); serviceCache.addListener(new EndpointListener()); updateEndpoints(); }
@Override public void start() throws Exception { cache.start(); discovery.providerOpened(this); }
/** * {@inheritDoc} */ @Override public void close() throws IOException { discovery.providerClosed(this); cache.close(); }
@Override public Collection<NodeEndpoint> getAvailableEndpoints() { return transform(serviceCache.getInstances(), new Function<ServiceInstance<NodeEndpoint>, NodeEndpoint>() { @Override public NodeEndpoint apply(ServiceInstance<NodeEndpoint> input) { return input.getPayload(); } }); }
@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(); }
private void advertiseService() throws Exception { // Advertise on the service discovery new EnsurePath(ZK_BASE_SERVICES_PATH).ensure(client.getZookeeperClient()); InstanceSerializer<Map> instanceSerializer = new FixedJsonInstanceSerializer<Map>(Map.class); sDiscovery = ServiceDiscoveryBuilder.builder(Map.class) .basePath(ZK_BASE_SERVICES_PATH) .client(client) .serializer(instanceSerializer) .build(); sDiscovery.start(); sDiscovery.registerService(getMetadataInstance()); // Create the service discovery cache sCache = sDiscovery.serviceCacheBuilder().name(ZK_OOZIE_SERVICE).build(); sCache.start(); zkRegTime = sDiscovery.queryForInstance(ZK_OOZIE_SERVICE, zkId).getRegistrationTimeUTC(); }
/** * {@inheritDoc} */ @Override public void close() throws IOException { discovery.providerClosed(this); cache.close(); }
@SuppressWarnings("unchecked") public void verifyDependencyPresence(String dependencyName, @SuppressWarnings("rawtypes") ServiceCache serviceCache, boolean required) { if (required) { MANDATORY_DEPENDENCY_CHECKER.checkPresence(dependencyName, serviceCache.getInstances()); } else { this.optionalDependencyChecker.checkPresence(dependencyName, serviceCache.getInstances()); } } }
@Override public void registerDependencyRegistrationHooks() { for (ZookeeperDependency zookeeperDependency : this.zookeeperDependencies.getDependencyConfigurations()) { String dependencyPath = zookeeperDependency.getPath(); ServiceCache<?> serviceCache = getServiceDiscovery() .serviceCacheBuilder().name(dependencyPath).build(); try { serviceCache.start(); } catch (Exception e) { ReflectionUtils.rethrowRuntimeException(e); } this.dependencyPresenceOnStartupVerifier.verifyDependencyPresence(dependencyPath, serviceCache, zookeeperDependency.isRequired()); this.dependencyRegistry.put(dependencyPath, serviceCache); serviceCache.addListener(new DependencyStateChangeListenerRegistry(this.listeners, dependencyPath, serviceCache)); } }
private void advertiseService() throws Exception { // Advertise on the service discovery new EnsurePath(ZK_BASE_SERVICES_PATH).ensure(client.getZookeeperClient()); InstanceSerializer<Map> instanceSerializer = new FixedJsonInstanceSerializer<Map>(Map.class); sDiscovery = ServiceDiscoveryBuilder.builder(Map.class) .basePath(ZK_BASE_SERVICES_PATH) .client(client) .serializer(instanceSerializer) .build(); sDiscovery.start(); sDiscovery.registerService(getMetadataInstance()); // Create the service discovery cache sCache = sDiscovery.serviceCacheBuilder().name(ZK_OOZIE_SERVICE).build(); sCache.start(); zkRegTime = sDiscovery.queryForInstance(ZK_OOZIE_SERVICE, zkId).getRegistrationTimeUTC(); }
@Override public void close() throws IOException { discovery.providerClosed(this); cache.close(); } }