org.apache.twill.zookeeper.ZKClient Java Examples
The following examples show how to use
org.apache.twill.zookeeper.ZKClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ControllerTest.java From twill with Apache License 2.0 | 6 votes |
private Service createService(ZKClient zkClient, RunId runId) { return new AbstractTwillService(zkClient, runId) { private final CountDownLatch stopLatch = new CountDownLatch(1); @Override protected void doStart() throws Exception { LOG.info("Start"); } @Override protected void doRun() throws Exception { stopLatch.await(); } @Override protected void doStop() throws Exception { LOG.info("Stop"); } @Override protected void triggerShutdown() { stopLatch.countDown(); } }; }
Example #2
Source File: ZKDiscoveryService.java From twill with Apache License 2.0 | 6 votes |
/** * Constructs ZKDiscoveryService using the provided zookeeper client for storing service registry under namespace. * @param zkClient of zookeeper quorum * @param namespace under which the service registered would be stored in zookeeper. * If namespace is {@code null}, no namespace will be used. */ public ZKDiscoveryService(ZKClient zkClient, String namespace) { this.closed = new AtomicBoolean(); this.discoverables = HashMultimap.create(); this.lock = new ReentrantLock(); this.retryExecutor = Executors.newSingleThreadScheduledExecutor( Threads.createDaemonThreadFactory("zk-discovery-retry")); this.zkClient = namespace == null ? zkClient : ZKClients.namespace(zkClient, namespace); this.services = CacheBuilder.newBuilder() .removalListener(new RemovalListener<String, ServiceDiscoveredCacheEntry>() { @Override public void onRemoval(RemovalNotification<String, ServiceDiscoveredCacheEntry> notification) { ServiceDiscoveredCacheEntry entry = notification.getValue(); if (entry != null) { entry.cancel(); } } }) .build(createServiceLoader()); this.watcherCancellable = this.zkClient.addConnectionWatcher(createConnectionWatcher()); }
Example #3
Source File: BasicTwillContext.java From twill with Apache License 2.0 | 6 votes |
public BasicTwillContext(RunId runId, RunId appRunId, InetAddress host, String[] args, String[] appArgs, TwillRunnableSpecification spec, int instanceId, DiscoveryService discoveryService, DiscoveryServiceClient discoveryServiceClient, ZKClient zkClient, int instanceCount, int allowedMemoryMB, int virtualCores) { this.runId = runId; this.appRunId = appRunId; this.host = host; this.args = args; this.appArgs = appArgs; this.spec = spec; this.instanceId = instanceId; this.discoveryService = discoveryService; this.discoveryServiceClient = discoveryServiceClient; this.zkClient = zkClient; this.elections = new ElectionRegistry(zkClient); this.instanceCount = instanceCount; this.allowedMemoryMB = allowedMemoryMB; this.virtualCores = virtualCores; }
Example #4
Source File: AbstractTwillController.java From twill with Apache License 2.0 | 6 votes |
public AbstractTwillController(String appName, RunId runId, ZKClient zkClient, boolean logCollectionEnabled, Iterable<LogHandler> logHandlers) { super(runId, zkClient); this.appName = appName; this.runId = runId; this.logHandlers = new ConcurrentLinkedQueue<>(); // When addressing TWILL-147, need to check if the given ZKClient is // actually used by the Kafka used for log collection if (logCollectionEnabled) { this.kafkaClient = new ZKKafkaClientService(ZKClients.namespace(zkClient, "/" + runId.getId() + "/kafka")); Iterables.addAll(this.logHandlers, logHandlers); } else { this.kafkaClient = null; if (!Iterables.isEmpty(logHandlers)) { LOG.warn("Log collection is disabled for application {} with runId {}. " + "Adding log handler won't get any logs.", appName, runId); } } }
Example #5
Source File: RunningContainers.java From twill with Apache License 2.0 | 6 votes |
RunningContainers(TwillRuntimeSpecification twillRuntimeSpec, String appId, TwillRunResources appMasterResources, ZKClient zookeeperClient, Location applicationLocation, Map<String, RuntimeSpecification> runnables, EventHandler eventHandler) { containers = HashBasedTable.create(); runnableInstances = Maps.newHashMap(); completedContainerCount = Maps.newHashMap(); startSequence = Lists.newLinkedList(); containerLock = new ReentrantLock(); containerChange = containerLock.newCondition(); resourceReport = new DefaultResourceReport(appId, appMasterResources); zkClient = zookeeperClient; containerStats = HashMultimap.create(); this.applicationLocation = applicationLocation; this.runnableNames = runnables.keySet(); this.logLevels = new TreeMap<>(); this.maxRetries = Maps.newHashMap(twillRuntimeSpec.getMaxRetries()); this.numRetries = Maps.newHashMap(); this.eventHandler = eventHandler; }
Example #6
Source File: ApplicationMasterService.java From twill with Apache License 2.0 | 6 votes |
public ApplicationMasterService(RunId runId, ZKClient zkClient, TwillRuntimeSpecification twillRuntimeSpec, YarnAMClient amClient, Configuration config, Location applicationLocation) throws Exception { super(zkClient, runId, config, applicationLocation); this.runId = runId; this.twillRuntimeSpec = twillRuntimeSpec; this.zkClient = zkClient; this.applicationLocation = applicationLocation; this.amClient = amClient; this.credentials = createCredentials(); this.jvmOpts = loadJvmOptions(); this.twillSpec = twillRuntimeSpec.getTwillSpecification(); this.placementPolicyManager = new PlacementPolicyManager(twillSpec.getPlacementPolicies()); this.environments = getEnvironments(); this.amLiveNode = new ApplicationMasterLiveNodeData(Integer.parseInt(System.getenv(EnvKeys.YARN_APP_ID)), Long.parseLong(System.getenv(EnvKeys.YARN_APP_ID_CLUSTER_TIME)), amClient.getContainerId().toString(), getLocalizeFiles(), twillRuntimeSpec.getKafkaZKConnect()); this.expectedContainers = new ExpectedContainers(twillSpec); this.eventHandler = createEventHandler(twillSpec); this.runningContainers = createRunningContainers(amClient.getContainerId(), amClient.getHost()); }
Example #7
Source File: TransactionService.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Inject public TransactionService(Configuration conf, ZKClient zkClient, DiscoveryService discoveryService, Provider<TransactionManager> txManagerProvider) { super(conf, discoveryService, txManagerProvider); this.conf = conf; this.zkClient = zkClient; }
Example #8
Source File: UpdateStatisticsTool.java From phoenix with Apache License 2.0 | 5 votes |
private void configureJob() throws Exception { job = Job.getInstance(getConf(), "UpdateStatistics-" + tableName + "-" + snapshotName); PhoenixMapReduceUtil.setInput(job, NullDBWritable.class, snapshotName, tableName, restoreDir); PhoenixConfigurationUtil.setMRJobType(job.getConfiguration(), MRJobType.UPDATE_STATS); // DO NOT allow mapper splits using statistics since it may result into many smaller chunks PhoenixConfigurationUtil.setSplitByStats(job.getConfiguration(), false); job.setJarByClass(UpdateStatisticsTool.class); job.setMapperClass(TableSnapshotMapper.class); job.setMapOutputKeyClass(NullWritable.class); job.setMapOutputValueClass(NullWritable.class); job.setOutputFormatClass(NullOutputFormat.class); job.setNumReduceTasks(0); job.setPriority(this.jobPriority); TableMapReduceUtil.addDependencyJars(job); TableMapReduceUtil.addDependencyJarsForClasses(job.getConfiguration(), PhoenixConnection.class, Chronology.class, CharStream.class, TransactionSystemClient.class, TransactionNotInProgressException.class, ZKClient.class, DiscoveryServiceClient.class, ZKDiscoveryService.class, Cancellable.class, TTransportException.class, SpanReceiver.class, TransactionProcessor.class, Gauge.class, MetricRegistriesImpl.class); LOGGER.info("UpdateStatisticsTool running for: " + tableName + " on snapshot: " + snapshotName + " with restore dir: " + restoreDir); }
Example #9
Source File: ControllerTest.java From twill with Apache License 2.0 | 5 votes |
private TwillController getController(ZKClient zkClient, String appName, RunId runId) { AbstractTwillController controller = new AbstractTwillController(appName, runId, zkClient, false, ImmutableList.<LogHandler>of()) { @Override public void kill() { // No-op } @Override protected void instanceNodeUpdated(NodeData nodeData) { // No-op } @Override protected void instanceNodeFailed(Throwable cause) { // Shutdown if the instance node goes away if (cause instanceof KeeperException.NoNodeException) { forceShutDown(); } } @Override public ResourceReport getResourceReport() { return null; } }; controller.startAndWait(); return controller; }
Example #10
Source File: TwillContainerLauncher.java From twill with Apache License 2.0 | 5 votes |
protected TwillContainerControllerImpl(ZKClient zkClient, RunId runId, String runnable, int instanceId, ProcessController<Void> processController) { super(runId, zkClient); this.runnable = runnable; this.instanceId = instanceId; this.processController = processController; this.shutdownLatch = new CountDownLatch(1); }
Example #11
Source File: TwillContainerLauncher.java From twill with Apache License 2.0 | 5 votes |
public TwillContainerLauncher(RuntimeSpecification runtimeSpec, ContainerInfo containerInfo, ProcessLauncher.PrepareLaunchContext launchContext, ZKClient zkClient, int instanceCount, JvmOptions jvmOpts, int reservedMemory, double minHeapRatio, Location secureStoreLocation) { this.runtimeSpec = runtimeSpec; this.containerInfo = containerInfo; this.launchContext = launchContext; this.zkClient = zkClient; this.instanceCount = instanceCount; this.jvmOpts = jvmOpts; this.reservedMemory = reservedMemory; this.minHeapRatio = minHeapRatio; this.secureStoreLocation = secureStoreLocation; }
Example #12
Source File: YarnTwillController.java From twill with Apache License 2.0 | 5 votes |
YarnTwillController(String appName, RunId runId, ZKClient zkClient, boolean logCollectionEnabled, Iterable<LogHandler> logHandlers, Callable<ProcessController<YarnApplicationReport>> startUp, long startTimeout, TimeUnit startTimeoutUnit) { super(appName, runId, zkClient, logCollectionEnabled, logHandlers); this.appName = appName; this.startUp = startUp; this.startTimeout = startTimeout; this.startTimeoutUnit = startTimeoutUnit; }
Example #13
Source File: YarnTwillController.java From twill with Apache License 2.0 | 5 votes |
/** * Creates an instance with an existing {@link ApplicationMasterLiveNodeData}. */ YarnTwillController(String appName, RunId runId, ZKClient zkClient, final ApplicationMasterLiveNodeData amLiveNodeData, final YarnAppClient yarnAppClient) { super(appName, runId, zkClient, amLiveNodeData.getKafkaZKConnect() != null, Collections.<LogHandler>emptyList()); this.appName = appName; this.amLiveNodeData = amLiveNodeData; this.startUp = () -> yarnAppClient.createProcessController( ApplicationId.newInstance(amLiveNodeData.getAppIdClusterTime(), amLiveNodeData.getAppId())); this.startTimeout = Constants.APPLICATION_MAX_START_SECONDS; this.startTimeoutUnit = TimeUnit.SECONDS; }
Example #14
Source File: YarnTwillRunnerService.java From twill with Apache License 2.0 | 5 votes |
private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) { String instancePath = String.format("/%s/instances/%s", appName, runId.getId()); // Fetch the content node. Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() { @Override public void onSuccess(NodeData result) { if (cancelled.get()) { return; } ApplicationMasterLiveNodeData amLiveNodeData = ApplicationMasterLiveNodeDecoder.decode(result); if (amLiveNodeData == null) { return; } synchronized (YarnTwillRunnerService.this) { if (!controllers.contains(appName, runId)) { ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName); YarnAppClient yarnAppClient = new VersionDetectYarnAppClientFactory().create(new Configuration(yarnConfig)); YarnTwillController controller = listenController( new YarnTwillController(appName, runId, zkClient, amLiveNodeData, yarnAppClient)); controllers.put(appName, runId, controller); controller.start(); } } } @Override public void onFailure(Throwable t) { LOG.warn("Failed in fetching application instance node.", t); } }, Threads.SAME_THREAD_EXECUTOR); }
Example #15
Source File: TwillContainerService.java From twill with Apache License 2.0 | 5 votes |
TwillContainerService(BasicTwillContext context, ContainerInfo containerInfo, ZKClient zkClient, RunId runId, TwillRunnableSpecification specification, ClassLoader classLoader, Configuration config, Location applicationLocation, Map<String, String> defaultLogLevels, Map<String, String> logLevels) { super(zkClient, runId, config, applicationLocation); this.specification = specification; this.classLoader = classLoader; this.defaultLogLevels = ImmutableMap.copyOf(defaultLogLevels); this.oldLogLevels = new HashMap<>(defaultLogLevels); this.containerLiveNodeData = createLiveNodeData( containerInfo, isLoggerContext() ? logLevels : Collections.<String, String>emptyMap()); this.context = context; }
Example #16
Source File: ZKModule.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override protected void configure() { /** * ZKClientService is provided by the provider method * {@link #provideZKClientService(org.apache.hadoop.conf.Configuration)}. */ bind(ZKClient.class).to(ZKClientService.class); }
Example #17
Source File: ReentrantDistributedLock.java From twill with Apache License 2.0 | 5 votes |
/** * Creates a distributed lock instance. * * @param zkClient the {@link ZKClient} to interact with the ZooKeeper used for the lock coordination * @param path the path in ZooKeeper where the lock coordination happens */ public ReentrantDistributedLock(ZKClient zkClient, String path) { this.zkClient = zkClient; this.path = path.startsWith("/") ? path : "/" + path; this.localLockNode = new ThreadLocal<String>(); this.lock = new ReentrantLock(); }
Example #18
Source File: RewatchOnExpireWatcher.java From twill with Apache License 2.0 | 5 votes |
RewatchOnExpireWatcher(ZKClient client, ActionType actionType, String path, Watcher delegate) { this.client = client; this.actionType = actionType; this.path = path; this.delegate = delegate; this.lastResult = new AtomicMarkableReference<Object>(null, false); }
Example #19
Source File: ElectionRegistry.java From twill with Apache License 2.0 | 4 votes |
public ElectionRegistry(ZKClient zkClient) { this.zkClient = zkClient; Multimap<String, LeaderElection> multimap = HashMultimap.create(); this.registry = Multimaps.synchronizedMultimap(multimap); }
Example #20
Source File: ThriftTransactionSystemTest.java From phoenix-tephra with Apache License 2.0 | 4 votes |
@Inject public TestTransactionService(Configuration conf, ZKClient zkClient, DiscoveryService discoveryService, Provider<TransactionManager> txManagerProvider) { super(conf, zkClient, discoveryService, txManagerProvider); }
Example #21
Source File: ZKKafkaClientService.java From twill with Apache License 2.0 | 4 votes |
public ZKKafkaClientService(ZKClient zkClient) { this.brokerService = new ZKBrokerService(zkClient); this.publishers = Collections.synchronizedMap(new IdentityHashMap<WeakReference<KafkaPublisher>, Cancellable>()); this.referenceQueue = new ReferenceQueue<KafkaPublisher>(); this.consumer = new SimpleKafkaConsumer(brokerService); }
Example #22
Source File: RewatchOnExpireZKClient.java From twill with Apache License 2.0 | 4 votes |
public RewatchOnExpireZKClient(ZKClient delegate) { super(delegate); }
Example #23
Source File: NamespaceZKClient.java From twill with Apache License 2.0 | 4 votes |
public NamespaceZKClient(ZKClient delegate, String namespace) { super(delegate); this.namespace = namespace; this.delegate = delegate; this.connectString = delegate.getConnectString() + namespace; }
Example #24
Source File: FailureRetryZKClient.java From twill with Apache License 2.0 | 4 votes |
public FailureRetryZKClient(ZKClient delegate, RetryStrategy retryStrategy) { super(delegate); this.retryStrategy = retryStrategy; }
Example #25
Source File: AbstractZKServiceController.java From twill with Apache License 2.0 | 4 votes |
protected AbstractZKServiceController(RunId runId, ZKClient zkClient) { super(runId); this.zkClient = zkClient; this.instanceNodeDataCallback = new InstanceNodeDataCallback(); this.messageFutures = Lists.newLinkedList(); }
Example #26
Source File: AbstractTwillService.java From twill with Apache License 2.0 | 4 votes |
protected AbstractTwillService(final ZKClient zkClient, RunId runId) { this.zkClient = zkClient; this.runId = runId; }
Example #27
Source File: ApplicationMasterMain.java From twill with Apache License 2.0 | 4 votes |
AppMasterTwillZKPathService(ZKClient zkClient, RunId runId) { super(zkClient, runId); this.zkClient = zkClient; }
Example #28
Source File: LeaderElection.java From twill with Apache License 2.0 | 4 votes |
public LeaderElection(ZKClient zkClient, String prefix, ElectionHandler handler) { this.guid = UUID.randomUUID().toString(); this.zkClient = zkClient; this.zkFolderPath = prefix.startsWith("/") ? prefix : "/" + prefix; this.handler = handler; }
Example #29
Source File: ServiceMain.java From twill with Apache License 2.0 | 4 votes |
public TwillZKPathService(ZKClient zkClient, RunId runId) { this.zkClient = zkClient; this.path = "/" + runId.getId(); }
Example #30
Source File: AbstractYarnTwillService.java From twill with Apache License 2.0 | 4 votes |
protected AbstractYarnTwillService(ZKClient zkClient, RunId runId, Configuration config, Location applicationLocation) { super(zkClient, runId); this.config = config; this.applicationLocation = applicationLocation; }