[ 
https://issues.apache.org/jira/browse/YARN-679?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13734135#comment-13734135
 ] 

Steve Loughran commented on YARN-679:
-------------------------------------

I've been evolving this driven by the Hoya application; code is up online at 
[https://github.com/hortonworks/hoya/tree/master/src/main/java/org/apache/hadoop/yarn/service/launcher]

Some observations
I added an interface {{GetExceptionExitCode}} to get an exception code off any 
Exception. 

{code}
public interface GetExceptionExitCode {

  int  getExitCode();
}
{code}

It'd be nice to have this interface implemented by {{Shell.ExitCodeException}} 
and {{ExitUtil.ExitException}} so that we have a consistent way to get exit 
codes from any exception willing to provide them.

ps. we could do with a more standardised set of error codes for YARN 
applications -convention rather than mandatory.

To make services executable, rather than just deployable, I added another 
interface.

{code}
public interface RunService {

  /**
   * Propagate the command line arguments
   * 
   * @param args argument list
   * @throws IOException any problem
   */
  void setArgs(String...args) throws Exception;
  
  /**
   * Run a service
   * @return the exit code
   * @throws Throwable any exception to report
   */
  int runService() throws Throwable ;
}
{code}

Here {{setArgs}} passes down all the arguments *before {{Service.init(Config)}} 
is called. This lets me tune the config passed to the superclass based on the 
supplied arguments.

{{runService()}} is called after {{Service.start()}}. 

The model here is that the main() thread goes
# create service class
# {{setArgs(...)}}
# {{init(config}}
# {{start()}}
# {{int exit=runService()}}
# {{stop}}

The service doesn't need to start its own worker thread, and the exit code from 
runService becomes the exit code of the app. Any of the service methods are 
also free to throw an exception; it implements {{getExitCode()}} that becomes 
the exit code of the app.

The code seems a bit over-complex, but it's evolved to also be the entry point 
for tests too

                
> add an entry point that can start any Yarn service
> --------------------------------------------------
>
>                 Key: YARN-679
>                 URL: https://issues.apache.org/jira/browse/YARN-679
>             Project: Hadoop YARN
>          Issue Type: Sub-task
>          Components: api
>            Reporter: Steve Loughran
>            Priority: Minor
>         Attachments: YARN-679-001.patch
>
>
> There's no need to write separate .main classes for every Yarn service, given 
> that the startup mechanism should be identical: create, init, start, wait for 
> stopped -with an interrupt handler to trigger a clean shutdown on a control-c 
> interrrupt.
> Provide one that takes any classname, and a list of config files/options

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to