Hi Caleb,

The Iterable returned by the lookupLive() call is a live iterable that
reflects the current ZK states known by the given TwillRunner. There can be
delay between connecting to ZK to TwillRunner has all the states sync and
has watches added, hence the first call to the lookup may return `null` (or
an empty Iterable if you call lookupLive). If you try to insert a short
delay, say, 3 seconds after calling twillRunner.start(), you should be able
to get the twill controller as well as live info even on the first call.

The https://issues.apache.org/jira/browse/TWILL-183 is targeted to improve
this situation by having a way to tap into the state changes inside twill
runner.

Terence

On Mon, Feb 13, 2017 at 11:32 AM, Martin Serrano <[email protected]> wrote:

> Caleb,
>
> I tend to use the version of lookup that does not take a RunId. That will
> return all Controllers.  I think your understanding of lookupLive is
> correct.  Looking at the code, it seems like the liveInfo is not populated
> until there is some type of change in the application.  This is a bug.  I
> will file a ticket.
>
> -Martin
>
> Hey Martin,
>
> Thanks for the reply.  I am trying to use the simple class name to do a
> lookup.  Here's an excerpt from client A:
>
>         String zkStr = args[0];
>         YarnConfiguration yarnConfiguration = new YarnConfiguration();
>         TwillRunnerService runner = new 
> YarnTwillRunnerService(yarnConfiguration,
> zkStr);
>         runner.start();
>
>         runner.prepare(new NotificationRunnable())
>                 .addLogHandler(new PrinterLogHandler(new
> PrintWriter(System.out)))
>                 .start();
>
> Here's an excerpt from client B:
>
>         String zkStr = args[0];
>         YarnConfiguration yarnConfiguration = new YarnConfiguration();
>         TwillRunnerService runner = new 
> YarnTwillRunnerService(yarnConfiguration,
> zkStr);
>         runner.start();
>
>         TwillController controller = 
> runner.lookup(NotificationRunnable.class.getSimpleName(),
> RunIds.fromString("yarn_applicationId"));
>         Iterable<LiveInfo> info = runner.lookupLive();
>         for(LiveInfo i: info) {
>                 System.out.println("LiveInfo is " +
> i.getApplicationName());
>         }
>         if(controller == null) {
>                 System.out.println("No instances of NotificationRunnable
> are running.  Please start an instance of NotificationRunnable"
>                                 + " before attempting to add or delete
> notifications");
>         }
>
> The runnable is pretty simple.  It's implementing AbstractTwillRunnable,
> so the application name should be the simple class name.  When I run client
> A,
> the main terminates and the runnable continues to run--I verify this by
> looking at the running applications in Yarn.  When I run client B, I use
> the "yarn_applicationId"
> that I see in Yarn to discover the controller.  However, the controller
> that gets returned is null and no LiveInfo gets returned, which is
> indicated by the System.out.println().
> Am I using the incorrect Id, or am I misinterpreting  the use of
> runner.lookupLive()?
>
> Caleb A. Meier, Ph.D.
> Software Engineer II ♦ Analyst
> Parsons Corporation
> 1911 N. Fort Myer Drive, Suite 800 ♦ Arlington, VA 22209
> Office:  (703)797-3066
> [email protected] ♦ www.parsons.com
>
>
> -----Original Message-----
> From: Martin Serrano [mailto:[email protected]]
> Sent: Friday, February 10, 2017 2:10 PM
> To: [email protected]
> Cc: Meier, Caleb
> Subject: Re: Gaining Control of Runnable after client terminates
>
> Caleb,
>
> Sorry, made a mistake there.  In the simple case the application has the
> simple classname, not the full one.
>
> -Martin
>
> On 02/10/2017 02:02 PM, Martin Serrano wrote:
>
>> Caleb,
>>
>> The TwillRunnerService handles the ZK registration of applications for
>> you.  When TwillClient B starts the service it can get the controllers
>> for the application via the TwillRunnerService.lookup method.  If you
>> did not explicitly name your application, then your are probably using
>> the prepare method that names the application to the full classname of
>> your runnable.
>>
>> -Martin
>>
>> On 02/09/2017 10:53 AM, Meier, Caleb wrote:
>>
>>> Hello,
>>>
>>> Suppose that I start an instance of NotificationRunnable with
>>> TwillClient A.  NotificationRunnable continues to run after
>>> TwillClient A terminates (I no longer have a handle on the
>>> YarnTwillRunner that prepared it), but I want to send a command to
>>> NotificatonRunnable using an instance of TwillController that I
>>> create in TwillClient B.  Is this possible?  It seems like I would
>>> still need access to the YarnTwillRunner that started the
>>> NotificationRunnable.  I’m basing this on the source code for
>>> YarnTwillRunner.lookup(…) – it seems like this method only returns
>>> controllers for runnables that the enclosing instance of
>>> YarnTwillRunner has prepared.  Am I mistaken about this?  If not, do
>>> I need to explicitly register my application with a
>>> ZkDiscoveryService and then look it up later through the same
>>> service?  Is there a better way to go about this?
>>>
>>> Thanks,
>>>
>>> Caleb A. Meier, Ph.D.
>>> Software Engineer II ♦ Analyst
>>> Parsons Corporation
>>> 1911 N. Fort Myer Drive, Suite 800 ♦ Arlington, VA 22209
>>> Office:  (703)797-3066
>>> [email protected]<mailto:[email protected]> ♦
>>> www.parsons.com<https://webportal.parsons.com/,DanaInfo=www.parsons.c
>>> om+>
>>>
>>>
>>>
>>
>

Reply via email to