Skip to content

Commit c742db5

Browse files
committed
Added more info to debugger panel + actions to start/stop server and service
Signed-off-by: Seb Julliand <[email protected]>
1 parent 5a62fcc commit c742db5

File tree

4 files changed

+273
-88
lines changed

4 files changed

+273
-88
lines changed

src/api/debug/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,24 +363,15 @@ export async function initialize(context: ExtensionContext) {
363363

364364
if (confirmEndServer === `End service`) {
365365
progress.report({ increment: 33, message: `Ending currently running service.` });
366-
try {
367-
await server.end(connection);
368-
startupService = true;
369-
} catch (e: any) {
370-
vscode.window.showErrorMessage(`Failed to end existing debug service (${e.message})`);
371-
}
366+
startupService = await server.stopService(connection);
372367
}
373368
} else {
374369
startupService = true;
375370
}
376371

377372
if (startupService) {
378373
progress.report({ increment: 34, message: `Starting service up.` });
379-
try {
380-
await server.startup(connection);
381-
} catch (e: any) {
382-
vscode.window.showErrorMessage(`Failed to start debug service (${e.message})`);
383-
}
374+
await server.startService(connection);
384375
} else {
385376
vscode.window.showInformationMessage(`Cancelled startup of debug service.`);
386377
}
@@ -402,7 +393,7 @@ export async function initialize(context: ExtensionContext) {
402393
if (ptfInstalled) {
403394
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
404395
progress.report({ message: `Ending Debug Service` });
405-
await server.stop(connection);
396+
await server.stopService(connection);
406397
});
407398
}
408399
}

src/api/debug/server.ts

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import path from "path";
2-
import { window } from "vscode";
2+
import { commands, window } from "vscode";
33

44
import { instance } from "../../instantiate";
5+
import { t } from "../../locale";
56
import IBMi from "../IBMi";
67
import IBMiContent from "../IBMiContent";
78
import { Tools } from "../Tools";
@@ -11,15 +12,19 @@ const serverDirectory = `/QIBM/ProdData/IBMiDebugService/bin/`;
1112
const MY_JAVA_HOME = `MY_JAVA_HOME="/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit"`;
1213

1314
export type DebugJob = {
14-
job: string
15+
name: string
1516
port: number
1617
}
1718

18-
export async function startup(connection: IBMi) {
19+
export async function startService(connection: IBMi) {
1920
const host = connection.currentHost;
2021

2122
const encryptResult = await connection.sendCommand({
22-
command: `${MY_JAVA_HOME} DEBUG_SERVICE_KEYSTORE_PASSWORD="${host}" ${path.posix.join(serverDirectory, `encryptKeystorePassword.sh`)} | /usr/bin/tail -n 1`
23+
command: `${path.posix.join(serverDirectory, `encryptKeystorePassword.sh`)} | /usr/bin/tail -n 1`,
24+
env: {
25+
DEBUG_SERVICE_KEYSTORE_PASSWORD: host,
26+
MY_JAVA_HOME: "/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit"
27+
}
2328
});
2429

2530
if ((encryptResult.code || 0) >= 1) {
@@ -34,26 +39,44 @@ export async function startup(connection: IBMi) {
3439

3540
const keystorePath = certificates.getRemoteServerCertificatePath(connection);
3641

42+
let didNotStart = false;
3743
connection.sendCommand({
3844
command: `${MY_JAVA_HOME} DEBUG_SERVICE_KEYSTORE_PASSWORD="${password}" DEBUG_SERVICE_KEYSTORE_FILE="${keystorePath}" /QOpenSys/usr/bin/nohup "${path.posix.join(serverDirectory, `startDebugService.sh`)}"`
3945
}).then(startResult => {
40-
if ((startResult.code || 0) >= 1) {
41-
window.showErrorMessage(startResult.stdout || startResult.stderr);
46+
if (startResult.code) {
47+
window.showErrorMessage(t("start.debug.service.failed", startResult.stdout || startResult.stderr));
48+
didNotStart = true;
4249
}
4350
});
4451

45-
return;
52+
let tries = 0;
53+
while (!didNotStart && tries < 20) {
54+
if (await getDebugServiceJob()) {
55+
window.showInformationMessage(t("start.debug.service.succeeded"));
56+
commands.executeCommand("code-for-ibmi.updateConnectedBar");
57+
return true;
58+
}
59+
else {
60+
await Tools.sleep(500);
61+
tries++;
62+
}
63+
}
64+
65+
return false;
4666
}
4767

48-
export async function stop(connection: IBMi) {
68+
export async function stopService(connection: IBMi) {
4969
const endResult = await connection.sendCommand({
50-
command: `${path.posix.join(serverDirectory, `stopDebugService.sh`)}`
70+
command: `${MY_JAVA_HOME} ${path.posix.join(serverDirectory, `stopDebugService.sh`)}`
5171
});
5272

53-
if (endResult.code === 0) {
54-
window.showInformationMessage(`Ended Debug Service.`);
73+
if (!endResult.code) {
74+
window.showInformationMessage(t("stop.debug.service.succeeded"));
75+
commands.executeCommand("code-for-ibmi.updateConnectedBar");
76+
return true;
5577
} else {
56-
window.showErrorMessage(endResult.stdout || endResult.stderr);
78+
window.showErrorMessage(t("stop.debug.service.failed", endResult.stdout || endResult.stderr));
79+
return false;
5780
}
5881
}
5982

@@ -76,17 +99,7 @@ export async function getDebugServerJob() {
7699
}
77100

78101
function rowToDebugJob(row?: Tools.DB2Row): DebugJob | undefined {
79-
return row?.JOB_NAME ? { job: String(row.JOB_NAME), port: Number(row.LOCAL_PORT) } : undefined;
80-
}
81-
82-
export async function end(connection: IBMi): Promise<void> {
83-
const endResult = await connection.sendCommand({
84-
command: `${MY_JAVA_HOME} ${path.posix.join(serverDirectory, `stopDebugService.sh`)}`
85-
});
86-
87-
if (endResult.code && endResult.code >= 0) {
88-
throw new Error(endResult.stdout || endResult.stderr);
89-
}
102+
return row?.JOB_NAME ? { name: String(row.JOB_NAME), port: Number(row.LOCAL_PORT) } : undefined;
90103
}
91104

92105
/**
@@ -113,4 +126,34 @@ export function endJobs(jobIds: string[], connection: IBMi) {
113126

114127
export async function isDebugEngineRunning() {
115128
return Boolean(await getDebugServerJob()) && Boolean(await getDebugServiceJob());
129+
}
130+
131+
export async function startServer() {
132+
const result = await instance.getConnection()?.runCommand({ command: "STRDBGSVR", noLibList: true });
133+
if (result) {
134+
if (result.code) {
135+
window.showErrorMessage(t("strdbgsvr.failed"), result.stderr);
136+
return false;
137+
}
138+
else {
139+
commands.executeCommand("code-for-ibmi.updateConnectedBar");
140+
window.showInformationMessage(t("strdbgsvr.succeeded"));
141+
}
142+
}
143+
return true;
144+
}
145+
146+
export async function stopServer() {
147+
const result = await instance.getConnection()?.runCommand({ command: "ENDDBGSVR", noLibList: true });
148+
if (result) {
149+
if (result.code) {
150+
window.showErrorMessage(t("enddbgsvr.failed"), result.stderr);
151+
return false;
152+
}
153+
else {
154+
commands.executeCommand("code-for-ibmi.updateConnectedBar");
155+
window.showInformationMessage(t("enddbgsvr.succeeded"));
156+
}
157+
}
158+
return true;
116159
}

src/locale/ids/en.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export const en: Locale = {
4747
'online': 'Online',
4848
'status': 'Status',
4949
'job': 'Job',
50-
'listening.on.port': 'Listening on port',
50+
'start':'Start',
51+
'restart':'Restart',
52+
'stop':'Stop',
53+
'listening.on.port': 'Listening on port',
5154
'overview': 'Overview',
5255
'JOB_NAME_SHORT':'Job name',
5356
'JOB_USER':'Job user',
@@ -362,5 +365,22 @@ export const en: Locale = {
362365
'debug.server': 'Debug Server',
363366
'debug.service': 'Debug Service',
364367
'active.job':'Active job',
365-
'jvm.info':'JVM information'
368+
'jvm.info':'JVM information',
369+
'debug.service.certificate':'Debug Service Certificate',
370+
'service.certificate.exists':'Remote service certificate exists',
371+
'local.certificate':'Local certificate',
372+
'certificates.match':'Local certificate matches remote',
373+
'generate.certificate':'Generate service certificate',
374+
'download.certificate':'Download certificate',
375+
'not.found.in':'Not found in <code>{0}</code>',
376+
'strdbgsvr.succeeded':'Debug server started.',
377+
'strdbgsvr.failed':'Failed to start debug server: {0}',
378+
'enddbgsvr.succeeded':'Debug server stopped.',
379+
'enddbgsvr.failed':'Failed to stop debug server: {0}',
380+
'start.debug.service.task':'Starting debug service...',
381+
'start.debug.service.succeeded':'Debug service started.',
382+
'start.debug.service.failed':'Failed to start debug service: {0}',
383+
'stop.debug.service.task':'Stopping debug service...',
384+
'stop.debug.service.succeeded':'Debug service stopped.',
385+
'stop.debug.service.failed':'Failed to stop debug service: {0}'
366386
};

0 commit comments

Comments
 (0)