Hi, From your code, I believe you are using it correctly. You mentioned that you sometimes see the newly launched app, sometimes not. But is the change eventually consistent or is it keeps flipping back and forth?
Terence > On Aug 15, 2016, at 9:40 PM, ...the end <549198...@qq.com> wrote: > > hi Terence, > > Here is my code. > > My http server extends the AbstractService of Hadoop. When the service init, > I start the runner: > @Override > > protected void serviceInit(Configuration conf) throws Exception { > > super.serviceInit(conf); > > LOG.info("service init"); > > injector = Guice.createInjector(new TwillServiceModule()); > > TwillRunnerService runner = > injector.getInstance(TwillRunnerService.class); > > runner.start(); > > } > > > > When the service stop, I stop the runner: > > @Override > > protected void serviceStop() throws Exception { > > LOG.info("service stop"); > > TwillRunnerService runner = > injector.getInstance(TwillRunnerService.class); > > runner.stop(); > > context.clearAttributes(); > > context.stop(); > > server.stop(); > > super.serviceStop(); > > > } > > > > And here is how I look up all the live applications: > > @GET > > @Path("recover") > > public String recover() { > > LOG.info("service discover"); > > Iterable<LiveInfo> iterable = twillRunner.lookupLive(); > > Iterator<LiveInfo> iterator = iterable.iterator(); > > JsonArray jsonArray = new JsonArray(); > > while (iterator.hasNext()) { > > LiveInfo info = iterator.next(); > > for (TwillController controller : info.getControllers()) { > > LOG.info("application {}, controller runid {}", > info.getApplicationName(), controller.getRunId()); > > jsonArray.add(new JsonPrimitive(String.format("application > %s, controller runid %s", > > info.getApplicationName(), controller.getRunId()))); > > } > > } > > twillRunner.stop(); > > return jsonArray.toString(); > > > } > > > > My zookeeper version is 3.4.6, thanks! > > > > Haosu Guo > > > > ------------------ Original ------------------ > From: "Terence Yim";<cht...@gmail.com>; > Date: Tue, Aug 16, 2016 12:02 PM > To: "...the end"<549198...@qq.com>; > Cc: "dev"<dev@twill.apache.org>; > Subject: Re: A question about lookupLive of TwillRunner > > Hi, > > The ZK watches reflect the changes from ZK asynchronously, so there can be > some delay. Would you mind attach your code to show how you use it? > > Terence > > Sent from my iPhone > > > On Aug 15, 2016, at 8:07 PM, ...the end <549198...@qq.com> wrote: > > > > hi, all: > > > > I'm using Twill and it's a very helpful project to write yarn applications. > > And now I've run into a problem. > > > > I want to start a http server to accept user's request and control the > > user's application in the server. I start the TwillRunner when the server > > starts, the runner can recover the applications started before the runner > > start. But when I start some new applications or kill some applications, > > using the lookupLive api or lookup api cannot see any change sometimes. > > > > I've read the source codes of YarnTwillRunnerService.java. I saw that you > > used watchers to listen the changes of zookeeper, but I've no idea why it > > doesn't work sometimes. Is there something wrong about the way I use the > > TwillRunner? > > > > Hoping to hear from you soon. > > Thanks! > > > > Haosu Guo