admin@glassfish.java.net

Re: Invoking a command from a command

From: Bill Shannon <bill.shannon_at_oracle.com>
Date: Fri, 04 Jun 2010 13:37:07 -0700

If a remote command wants to execute a local command on the same
machine that the remote command is running on, use Runtime.exec.
I think there's some helper classes that make it easier to use
Runtime.exec.

It was a goal to *not* load the local asadmin commands in the server
JVM, they're not designed to work in that environment.


Joe Di Pol wrote on 06/ 4/10 12:20 PM:
>
> Bill,
>
> The one case not mentioned below is a remote command executing
> a local command. After talking with Vijay we are thinking this
> is probably not supported since the local command won't be in
> the DAS's habitat.
>
> Does that sound right?
>
> This then brings us back to refactoring the command to
> share code between the CLI and the DAS.
>
> Joe
>
>
> Bill Shannon wrote:
>> 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
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: admin-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: admin-help_at_glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: admin-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: admin-help_at_glassfish.dev.java.net
>