admin@glassfish.java.net

Re: Invoking a command from a command

From: Bill Shannon <bill.shannon_at_oracle.com>
Date: Thu, 03 Jun 2010 13:51:48 -0700

As Tim described, one option is always to refactor the commands so that
the common code is in a non-command shared class.

But, really, there should be a straightforward way to invoke one command
from another, both local commands and remote commands. Some of the
challenges are... how do you want to supply the parameters, and what
do you want to do with the results?

For a remote command executing a remote command, I believe you should
be able to use the CommandRunner API.

For a local command executing either a local or remote command, you
should be able to do this:

        @Inject
        Habitat habitat;
        ...
        CLICommand cmd = CLICommand.getCommand(habitat, "command-name");
        String[] argv = ...; // just like asadmin command line
        int rc = cmd.execute(argv); // argv[0] is command-name
        // note that output goes to System.out

If a local command needs to execute a command that is know to be a
remote command, you can construct a RemoteCommand object directly.
There are a variety of constructors and execute methods that offer
more control over the arguments and output.

If a remote command wants to call a local command on another node,
well, I believe that's the "remote command execution facility" that
*you* are building! :-)


Joe Di Pol wrote on 06/03/2010 01:00 PM:
>
> I'm looking for a little push in the right direction.
> If there are existing commands that do this feel free
> to point me at them.
>
> Case 1
> ------
> I have a remote command that as part of it's processing
> wants to invoke another remote command. For example
> start-cluster will likely loop through the instances
> and call start-instance on each instance.
>
> What is the suggested way to have a remote command
> execute another remote command locally? Seems like I
> want a variation of enterprise.admin.cli.remote.RemoteCommand
> that operates directly on the command class (instead
> of remotely over HTTP).
>
> Case 2
> -------
> Same as Case 1 except I want to call a local command.
> For example start-instance may want to call
> start-local-instance if the instance is local to the DAS.
>
> Thanks,
>
> Joe
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: admin-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: admin-help_at_glassfish.dev.java.net
>