Skip to content

feat: ConsoleService strategy pattern POC for zowex SSH and z/OSMF REST - #627

Open
chaitanyakatore wants to merge 1 commit into
zowe:mainfrom
chaitanyakatore:poc-console-strategy-pattern
Open

chaitanyakatore wants to merge 1 commit into
zowe:mainfrom
chaitanyakatore:poc-console-strategy-pattern

Conversation

@chaitanyakatore

Copy link
Copy Markdown
Contributor
  • Extract ConsoleService strategy interface for z/OS console operations
  • Update ConsoleCmd to implement ConsoleService for z/OSMF REST transport
  • Add ZowexConsoleService strategy implementation for zowex SSH transport
  • Add ConsoleServiceFactory for connection-based strategy selection
  • Add ConsoleServiceTest validating polymorphic execution and strategy switching

@frankgiordano
frankgiordano self-requested a review August 24, 2026 01:34
@frankgiordano frankgiordano added the enhancement New feature or request label Aug 24, 2026
@frankgiordano

Copy link
Copy Markdown
Collaborator

Do you have the ability to convert this to a draft PR. This is not something to merge in the near future, but experimental for now not be merged until further notice.

@frankgiordano
frankgiordano marked this pull request as draft August 24, 2026 01:37
@frankgiordano

Copy link
Copy Markdown
Collaborator

I was able to convert to DRAFT PR status. Thanks for the PR. I will review soon. Let's discussed on discord further.

@frankgiordano

Copy link
Copy Markdown
Collaborator

I reviewed the code, see my comments. Can you try to implement the actual ssh connection and command execution? I can test it. You can create a RemoteClient.java and add it to the console class like:

private final RemoteSshClient remoteSshClient;

and call it in the issueCommon method. Initialize the remoteSshClient if null and reuse it.

BTW zowex naming convention has changed.

See:

https://medium.com/zowe/technical-preview-zowe-remote-ssh-zrs-507a405fbc05
https://github.com/zowe/zo

@frankgiordano
frankgiordano marked this pull request as ready for review October 19, 2026 04:43

@frankgiordano frankgiordano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments, can you tweak the PR further thanks.

@frankgiordano

Copy link
Copy Markdown
Collaborator

model the SSH setup/error handling after UssCmd, but not reuse its "wait until remote process exits" execution model.

try (ManagedSession session =
             new ManagedSession(connection, timeout);
     ManagedRemoteChannel channel =
             new ManagedRemoteChannel(session.get(), timeout)) {

    BufferedReader reader = channel.getReader();
    OutputStream writer = channel.getWriter();

    // 1. Wait for zo server ready banner
    final String readyLine = reader.readLine();
    
    if (readyLine == null) {
        throw new IllegalStateException(
                "Zowe Remote SSH server closed before becoming ready"
        );
    }
    
    final JsonNode ready = mapper.readTree(readyLine);
    
    if (!"ready".equals(ready.path("status").asText())) {
        throw new IllegalStateException(
                "Unexpected Zowe Remote SSH startup response: " + readyLine
        );
    }

    // 2. Send JSON-RPC request
    writer.write((payload + "\n").getBytes(StandardCharsets.UTF_8));
    writer.flush();

    // 3. Read matching response
    String response = reader.readLine();

    // 4. Parse result.data
}

@chaitanyakatore

Copy link
Copy Markdown
Contributor Author

Hi @frankgiordano I have made the changes please review and let me know if it looks good or any changes require

@frankgiordano

Copy link
Copy Markdown
Collaborator

Nice updates to summarize:

  • Keep the existing ConsoleCmd.java for z/OSMF REST.
  • Use RemoteConsoleCmd.java for the Zowe Remote SSH implementation.
  • Rename ConsoleService to ConsoleCmdProvider.
  • Do not use the old Zowex... naming because the current feature name is Zowe Remote SSH; RemoteConsoleCmd is clearer.
  • Remove ConsoleServiceFactory; it is unnecessary because the constructors already identify the transport: ConsoleCmd(ZosConnection) RemoteConsoleCmd(SshConnection)

I would like to make one additional structural change before we move this POC further.

Please extract the common Zowe Remote SSH communication logic from RemoteConsoleCmd into a reusable RemoteSshClient class.

RemoteConsoleCmd should remain focused on console-specific behavior:

  • build the consoleCommand JSON-RPC request
  • pass the request to RemoteSshClient
  • process the returned JSON-RPC response
  • map result.data into ConsoleCmdResponse

RemoteSshClient should own the SSH transport details:

  • create and configure the JSch session from SshConnection
  • connect the SSH session and exec channel
  • start zo server
  • obtain stdin/stdout streams
  • wait for and validate the initial zo server ready response before sending a request
  • write the JSON-RPC request followed by a newline
  • read the corresponding JSON-RPC response
  • handle SSH/channel timeout and cleanup
  • close/disconnect the channel and session

The intended flow should look roughly like:

RemoteConsoleCmd -> RemoteSshClient -> SSH -> zo server -> JSON-RPC request/response

I also recommend that RemoteSshClient return the parsed JSON response, such as a JsonNode, rather than making it aware of ConsoleCmdResponse. That will keep the SSH client generic so we can reuse it later for other Zowe Remote SSH APIs.

Please also make sure the zo server startup response is explicitly read and validated before the consoleCommand request is sent. We should not assume the server is ready immediately after the exec channel connects.

For now, it is fine for RemoteSshClient to create and close the SSH session and zo server process for each request. We can optimize session reuse later once the basic implementation is working and tested.

Add the new class in the core package.

Seeing that this PR is getting cluttered with tweaks/changes. Can you open a new PR request with the latest changes and then close this PR. Make sure to rebase your fork with the latest from mainline.

- Add ConsoleCmdProvider interface defining console command execution contract
- Update ConsoleCmd to implement ConsoleCmdProvider for z/OSMF REST transport
- Add generic RemoteSshClient in core package for JSON-RPC communication with zo server over SSH
- Add RemoteConsoleCmd implementing ConsoleCmdProvider via RemoteSshClient
- Add comprehensive unit tests in RemoteSshClientTest and RemoteConsoleCmdTest

Signed-off-by: chaitanya <chaitanyakatore@gmail.com>
@chaitanyakatore
chaitanyakatore force-pushed the poc-console-strategy-pattern branch from 3c83391 to 540e643 Compare October 25, 2026 16:43
@chaitanyakatore

Copy link
Copy Markdown
Contributor Author

Hi @frankgiordano,

I have updated this PR based on your feedback:

  • Extracted RemoteSshClient into zowe.client.sdk.core to manage the JSch SSH session, start the remote zo server, validate the startup {"status":"ready"} banner, and return generic JsonNode responses.
  • Refactored RemoteConsoleCmd to focus solely on console logic (building consoleCommand JSON-RPC payloads and mapping result.data to ConsoleCmdResponse), delegating transport to RemoteSshClient.
  • Added unit tests for both RemoteSshClientTest and RemoteConsoleCmdTest.
  • Rebased the branch directly on top of latest main with a clean commit history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants