Skip to content

Commit

Permalink
Added more info to debugger panel + actions to start/stop server and …
Browse files Browse the repository at this point in the history
…service

Signed-off-by: Seb Julliand <[email protected]>
  • Loading branch information
sebjulliand committed Mar 25, 2024
1 parent 5a62fcc commit c742db5
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 88 deletions.
15 changes: 3 additions & 12 deletions src/api/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,15 @@ export async function initialize(context: ExtensionContext) {

if (confirmEndServer === `End service`) {
progress.report({ increment: 33, message: `Ending currently running service.` });
try {
await server.end(connection);
startupService = true;
} catch (e: any) {
vscode.window.showErrorMessage(`Failed to end existing debug service (${e.message})`);
}
startupService = await server.stopService(connection);
}
} else {
startupService = true;
}

if (startupService) {
progress.report({ increment: 34, message: `Starting service up.` });
try {
await server.startup(connection);
} catch (e: any) {
vscode.window.showErrorMessage(`Failed to start debug service (${e.message})`);
}
await server.startService(connection);
} else {
vscode.window.showInformationMessage(`Cancelled startup of debug service.`);
}
Expand All @@ -402,7 +393,7 @@ export async function initialize(context: ExtensionContext) {
if (ptfInstalled) {
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
progress.report({ message: `Ending Debug Service` });
await server.stop(connection);
await server.stopService(connection);
});
}
}
Expand Down
89 changes: 66 additions & 23 deletions src/api/debug/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from "path";
import { window } from "vscode";
import { commands, window } from "vscode";

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

export type DebugJob = {
job: string
name: string
port: number
}

export async function startup(connection: IBMi) {
export async function startService(connection: IBMi) {
const host = connection.currentHost;

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

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

const keystorePath = certificates.getRemoteServerCertificatePath(connection);

let didNotStart = false;
connection.sendCommand({
command: `${MY_JAVA_HOME} DEBUG_SERVICE_KEYSTORE_PASSWORD="${password}" DEBUG_SERVICE_KEYSTORE_FILE="${keystorePath}" /QOpenSys/usr/bin/nohup "${path.posix.join(serverDirectory, `startDebugService.sh`)}"`
}).then(startResult => {
if ((startResult.code || 0) >= 1) {
window.showErrorMessage(startResult.stdout || startResult.stderr);
if (startResult.code) {
window.showErrorMessage(t("start.debug.service.failed", startResult.stdout || startResult.stderr));
didNotStart = true;
}
});

return;
let tries = 0;
while (!didNotStart && tries < 20) {
if (await getDebugServiceJob()) {
window.showInformationMessage(t("start.debug.service.succeeded"));
commands.executeCommand("code-for-ibmi.updateConnectedBar");
return true;
}
else {
await Tools.sleep(500);
tries++;
}
}

return false;
}

export async function stop(connection: IBMi) {
export async function stopService(connection: IBMi) {
const endResult = await connection.sendCommand({
command: `${path.posix.join(serverDirectory, `stopDebugService.sh`)}`
command: `${MY_JAVA_HOME} ${path.posix.join(serverDirectory, `stopDebugService.sh`)}`
});

if (endResult.code === 0) {
window.showInformationMessage(`Ended Debug Service.`);
if (!endResult.code) {
window.showInformationMessage(t("stop.debug.service.succeeded"));
commands.executeCommand("code-for-ibmi.updateConnectedBar");
return true;
} else {
window.showErrorMessage(endResult.stdout || endResult.stderr);
window.showErrorMessage(t("stop.debug.service.failed", endResult.stdout || endResult.stderr));
return false;
}
}

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

function rowToDebugJob(row?: Tools.DB2Row): DebugJob | undefined {
return row?.JOB_NAME ? { job: String(row.JOB_NAME), port: Number(row.LOCAL_PORT) } : undefined;
}

export async function end(connection: IBMi): Promise<void> {
const endResult = await connection.sendCommand({
command: `${MY_JAVA_HOME} ${path.posix.join(serverDirectory, `stopDebugService.sh`)}`
});

if (endResult.code && endResult.code >= 0) {
throw new Error(endResult.stdout || endResult.stderr);
}
return row?.JOB_NAME ? { name: String(row.JOB_NAME), port: Number(row.LOCAL_PORT) } : undefined;
}

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

export async function isDebugEngineRunning() {
return Boolean(await getDebugServerJob()) && Boolean(await getDebugServiceJob());
}

export async function startServer() {
const result = await instance.getConnection()?.runCommand({ command: "STRDBGSVR", noLibList: true });
if (result) {
if (result.code) {
window.showErrorMessage(t("strdbgsvr.failed"), result.stderr);
return false;
}
else {
commands.executeCommand("code-for-ibmi.updateConnectedBar");
window.showInformationMessage(t("strdbgsvr.succeeded"));
}
}
return true;
}

export async function stopServer() {
const result = await instance.getConnection()?.runCommand({ command: "ENDDBGSVR", noLibList: true });
if (result) {
if (result.code) {
window.showErrorMessage(t("enddbgsvr.failed"), result.stderr);
return false;
}
else {
commands.executeCommand("code-for-ibmi.updateConnectedBar");
window.showInformationMessage(t("enddbgsvr.succeeded"));
}
}
return true;
}
24 changes: 22 additions & 2 deletions src/locale/ids/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const en: Locale = {
'online': 'Online',
'status': 'Status',
'job': 'Job',
'listening.on.port': 'Listening on port',
'start':'Start',
'restart':'Restart',
'stop':'Stop',
'listening.on.port': 'Listening on port',
'overview': 'Overview',
'JOB_NAME_SHORT':'Job name',
'JOB_USER':'Job user',
Expand Down Expand Up @@ -362,5 +365,22 @@ export const en: Locale = {
'debug.server': 'Debug Server',
'debug.service': 'Debug Service',
'active.job':'Active job',
'jvm.info':'JVM information'
'jvm.info':'JVM information',
'debug.service.certificate':'Debug Service Certificate',
'service.certificate.exists':'Remote service certificate exists',
'local.certificate':'Local certificate',
'certificates.match':'Local certificate matches remote',
'generate.certificate':'Generate service certificate',
'download.certificate':'Download certificate',
'not.found.in':'Not found in <code>{0}</code>',
'strdbgsvr.succeeded':'Debug server started.',
'strdbgsvr.failed':'Failed to start debug server: {0}',
'enddbgsvr.succeeded':'Debug server stopped.',
'enddbgsvr.failed':'Failed to stop debug server: {0}',
'start.debug.service.task':'Starting debug service...',
'start.debug.service.succeeded':'Debug service started.',
'start.debug.service.failed':'Failed to start debug service: {0}',
'stop.debug.service.task':'Stopping debug service...',
'stop.debug.service.succeeded':'Debug service stopped.',
'stop.debug.service.failed':'Failed to stop debug service: {0}'
};
Loading

0 comments on commit c742db5

Please sign in to comment.