Skip to content

Commit 04aa6c1

Browse files
committed
pull out server path detection into util, use in both deploy code paths
Signed-off-by: CBforZ <chris.boehm@broadcom.com>
1 parent be4bcef commit 04aa6c1

4 files changed

Lines changed: 34 additions & 21 deletions

File tree

packages/zowe-explorer/__tests__/__e2e__/step_definitions/jobs/JobFavorites.steps.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,7 @@ Given("a sleep job has been submitted for polling", async function () {
243243

244244
await browser.waitUntil((): Promise<boolean> => quickPick.isClickable());
245245
if (await quickPick.hasOptions()) {
246-
const createFilter = await quickPick.findItem(
247-
"$(plus) Create a new filter. For example: HLQ.*, HLQ.aaa.bbb, HLQ.ccc.ddd(member)"
248-
);
246+
const createFilter = await quickPick.findItem("$(plus) Create a new filter. For example: HLQ.*, HLQ.aaa.bbb, HLQ.ccc.ddd(member)");
249247
await expect(createFilter).toBeClickable();
250248
await createFilter.click();
251249
}
@@ -360,9 +358,7 @@ Given("the Jobs tree has a favorited job search filter for the active job", asyn
360358

361359
// The newly added filter is the last child under the favorited profile
362360
const favProfileChildren = await (await this.favProfileNode.find()).getChildren();
363-
const activeFilterNode = favProfileChildren.length > 0
364-
? (favProfileChildren[favProfileChildren.length - 1] as TreeItem)
365-
: undefined;
361+
const activeFilterNode = favProfileChildren.length > 0 ? (favProfileChildren[favProfileChildren.length - 1] as TreeItem) : undefined;
366362
await expect(activeFilterNode).toBeDefined();
367363

368364
// Click once to initialize collapsible state, then expand

packages/zowex-for-zowe-explorer/src/ServerDeployment.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
import type { SshSession } from "@zowe/zos-uss-for-zowe-sdk";
2-
import { Gui, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
2+
import { Gui, imperative, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
33
import * as vscode from "vscode";
44
import { SshErrorHandler } from "./SshErrorHandler";
55
import { ZSshUtils } from "@zowe/zowex-for-zowe-sdk";
6+
import path from "path/posix";
7+
import { SshClientCache } from "./SshClientCache";
8+
9+
/**
10+
* Detect if a usable instance of our server binary exists on the user's USS environment.
11+
* @param session - established SSH session used to detect the server
12+
* @param profile - the SSH profile used to connect
13+
* @returns true if a usable version of the SSH backend server is detected on the user's path
14+
*/
15+
export async function isServerDetectedOnPath(session: SshSession, profile: imperative.IProfileLoaded): Promise<boolean> {
16+
try {
17+
const pathServer = await ZSshUtils.detectServerOnPath(session);
18+
imperative.Logger.getAppLogger().trace("detectServerOnPath return value: %s", JSON.stringify(pathServer));
19+
if (pathServer.serverPath && pathServer.hasExecutePermission && pathServer.writeAccessToParent) {
20+
imperative.Logger.getAppLogger().debug("Skipping deploy, since a usable instance of the server exists on the user's PATH");
21+
// remove binary from the full path to set serverPath to the parent directory,
22+
// the same as a user would configure the path manually
23+
SshClientCache.inst.setOnPathServer(profile, path.resolve(pathServer.serverPath, ".."));
24+
return true;
25+
}
26+
} catch (e) {
27+
imperative.Logger.getAppLogger().error("Error detecting server on user's $PATH: %s", e);
28+
await SshErrorHandler.getInstance().handleError(e as Error, ZoweExplorerApiType.All, "Detecting server on $PATH");
29+
}
30+
return false;
31+
}
632

733
export function deployWithProgress(session: SshSession, serverPath: string): Thenable<boolean> {
834
return Gui.withProgress(

packages/zowex-for-zowe-explorer/src/SshClientCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { imperative, ProfilesCache } from "@zowe/zowe-explorer-api";
1414
import * as vscode from "vscode";
1515
import { type ClientOptions, type ExistingClientRequest, ZSshClient, ZSshUtils } from "@zowe/zowex-for-zowe-sdk";
1616
import { ConfigUtils } from "./ConfigUtils";
17-
import { deployWithProgress } from "./ServerDeployment";
17+
import { deployWithProgress, isServerDetectedOnPath } from "./ServerDeployment";
1818

1919
class AsyncMutex extends imperative.DeferredPromise<void> implements Disposable {
2020
public constructor(private onDispose?: () => void) {
@@ -109,8 +109,8 @@ export class SshClientCache extends vscode.Disposable {
109109
if (!this.mClientSessionMap.has(clientId)) {
110110
using _lock = this.acquireProfileLock(clientId);
111111
const session = ZSshUtils.buildSession(profile.profile!);
112-
const serverPath = this.mClientOnPathServerMap.get(clientId) ??
113-
ConfigUtils.getServerPath(profile.profile);
112+
await isServerDetectedOnPath(session, profile);
113+
const serverPath = this.mClientOnPathServerMap.get(clientId) ?? ConfigUtils.getServerPath(profile.profile);
114114
const vsceConfig = vscode.workspace.getConfiguration("zowe");
115115
const keepAliveInterval = vsceConfig.get<number>("zowex.keepAliveInterval");
116116
const numWorkers = vsceConfig.get<number>("zowex.workerCount");

packages/zowex-for-zowe-explorer/src/Utilities.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import { ConfigUtils } from "./ConfigUtils";
1616
import { VscePromptApi } from "./VscePromptApi";
1717
import { SshClientCache } from "./SshClientCache";
1818
import { SshErrorHandler } from "./SshErrorHandler";
19-
import { deployWithProgress } from "./ServerDeployment";
20-
import path from "path/posix";
19+
import { deployWithProgress, isServerDetectedOnPath } from "./ServerDeployment";
2120

2221
export function registerCommands(context: vscode.ExtensionContext, zoweExplorerApi: IApiExplorerExtender): vscode.Disposable[] {
2322
const profCache = zoweExplorerApi.getProfilesCache();
@@ -31,14 +30,7 @@ export function registerCommands(context: vscode.ExtensionContext, zoweExplorerA
3130
}
3231

3332
const sshSession = ZSshUtils.buildSession(profile.profile);
34-
const pathServer = await ZSshUtils.detectServerOnPath(sshSession);
35-
imperative.Logger.getAppLogger().trace("detectServerOnPath return value: %s", JSON.stringify(pathServer));
36-
if (pathServer.serverPath
37-
&& pathServer.hasExecutePermission
38-
&& pathServer.writeAccessToParent) {
39-
imperative.Logger.getAppLogger().debug("Skipping deploy as an instance of the server exists on the user's PATH");
40-
SshClientCache.inst.setOnPathServer(profile, path.resolve(pathServer.serverPath, '..'));
41-
} else {
33+
if (!(await isServerDetectedOnPath(sshSession, profile))) {
4234
const defaultServerPath = ConfigUtils.getServerPath(profile.profile);
4335
const deployDirectory = await vscePromptApi.promptForDeployDirectory(profile.profile.host, defaultServerPath);
4436
if (!deployDirectory) {
@@ -55,7 +47,6 @@ export function registerCommands(context: vscode.ExtensionContext, zoweExplorerA
5547
}
5648

5749
await ConfigUtils.showSessionInTree(profile.name!, true, zoweExplorerApi);
58-
5950
}),
6051
vscode.commands.registerCommand(`zowe.zowex.restart`, async (profName?: string) => {
6152
imperative.Logger.getAppLogger().trace("Running restart command for profile %s", profName);

0 commit comments

Comments
 (0)