Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions src/debug/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Tools } from "../api/Tools";
import { DebugConfiguration, getDebugServiceDetails, getJavaHome } from "../api/configuration/DebugConfiguration";
import { instance } from "../instantiate";
import { CustomUI } from "../webviews/CustomUI";
export type DebugJob = {
name: string
ports: number[]
export type DebugJobs = {
server?: string
service?: string
}

export const MIN_DEBUG_VERSION = 3;
Expand Down Expand Up @@ -86,9 +86,9 @@ export async function startService(connection: IBMi) {
let tries = 0;
const checkJob = async (done: (started: boolean) => void) => {
if (tries++ < 30) {
const jobDetail = await readActiveJob(connection, { name: job, ports: [] });
const jobDetail = await readActiveJob(connection, job);
if (jobDetail && typeof jobDetail === "object" && !["HLD", "MSGW", "END"].includes(String(jobDetail.JOB_STATUS))) {
if (await getDebugServiceJob()) {
if ((await getDebugEngineJobs()).service) {
window.showInformationMessage(l10n.t(`Debug service started.`));
refreshDebugSensitiveItems();
done(true);
Expand Down Expand Up @@ -145,30 +145,22 @@ export async function stopService(connection: IBMi) {
}
}

export async function getDebugServiceJob() {
const connection = instance.getConnection();
if (connection) {
const rows = await connection.runSQL(`select job_name, local_port from qsys2.netstat_job_info j where job_name = (select job_name from qsys2.netstat_job_info j where local_port = ${connection.getConfig().debugPort || 8005} and remote_address = '0.0.0.0' fetch first row only) and remote_address = '0.0.0.0'`);
if (rows && rows.length) {
return {
name: String(rows[0].JOB_NAME),
ports: rows.map(row => Number(row.LOCAL_PORT)).sort()
} as DebugJob;
}
export async function getDebugEngineJobs(): Promise<DebugJobs> {
const rows = await instance.getConnection()?.runSQL([
"select 'SERVER' as TYPE, JOB_NAME from table(QSYS2.ACTIVE_JOB_INFO(JOB_NAME_FILTER => 'QB5ROUTER'))",
"Union",
"select 'SERVICE' as TYPE, JOB_NAME from table(QSYS2.ACTIVE_JOB_INFO(JOB_NAME_FILTER => 'QDBGSRV'))"
].join(" "));

return {
server: rows?.find(row => row.TYPE === 'SERVER')?.JOB_NAME as string,
service: rows?.find(row => row.TYPE === 'SERVICE')?.JOB_NAME as string
}
}

export async function getDebugServerJob() {
const connection = instance.getConnection();
if (connection) {
const [row] = await connection.runSQL(`select job_name, local_port from qsys2.netstat_job_info where cast(local_port_name as VarChar(14) CCSID 37) = 'is-debug-ile' fetch first row only`);
if (row) {
return {
name: String(row.JOB_NAME),
ports: [Number(row.LOCAL_PORT)]
} as DebugJob;
}
}
export async function isDebugEngineRunning() {
const debugJobs = await getDebugEngineJobs();
return Boolean(debugJobs.server) && Boolean(debugJobs.service);
}

/**
Expand All @@ -193,10 +185,6 @@ export function endJobs(jobIds: string[], connection: IBMi) {
return Promise.all(promises);
}

export async function isDebugEngineRunning() {
return (await Promise.all([getDebugServerJob(), getDebugServiceJob()])).every(Boolean);
}

export async function startServer() {
const result = await instance.getConnection()?.runCommand({ command: "STRDBGSVR", noLibList: true });
if (result) {
Expand Down Expand Up @@ -232,22 +220,22 @@ export function refreshDebugSensitiveItems() {
commands.executeCommand("code-for-ibmi.debug.refresh");
}

export async function readActiveJob(connection: IBMi, job: DebugJob) {
export async function readActiveJob(connection: IBMi, job: string) {
try {
return (await connection.runSQL(
`select job_name_short "Job name", job_user "Job user", job_number "Job number", subsystem_library_name concat '/' concat subsystem as "Subsystem", authorization_name "Current user", job_status "Job status", memory_pool "Memory pool" from table(qsys2.active_job_info(job_name_filter => '${job.name.substring(job.name.lastIndexOf('/') + 1)}')) where job_name = '${job.name}' fetch first row only`
`select job_name_short "Job name", job_user "Job user", job_number "Job number", subsystem_library_name concat '/' concat subsystem as "Subsystem", authorization_name "Current user", job_status "Job status", memory_pool "Memory pool" from table(qsys2.active_job_info(job_name_filter => '${job.substring(job.lastIndexOf('/') + 1)}')) where job_name = '${job}' fetch first row only`
)).at(0);
} catch (error) {
return String(error);
}
}

export async function readJVMInfo(connection: IBMi, job: DebugJob) {
export async function readJVMInfo(connection: IBMi, job: string) {
try {
return (await connection.runSQL(`
select START_TIME "Start time", JAVA_HOME "Java Home", USER_DIRECTORY "User directory", CURRENT_HEAP_SIZE "Current memory", MAX_HEAP_SIZE "Maximum allowed memory"
from QSYS2.JVM_INFO
where job_name = '${job.name}'
where job_name = '${job}'
fetch first row only`)).at(0);
} catch (error) {
return String(error);
Expand Down
2 changes: 0 additions & 2 deletions src/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ async function onConnected() {
connectedBarItem,
disconnectBarItem,
].forEach(barItem => barItem.show());

updateConnectedBar();
}

async function onDisconnected() {
Expand Down
44 changes: 21 additions & 23 deletions src/ui/views/debugView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import vscode from "vscode";
import { DebugConfiguration, getDebugServiceDetails, SERVICE_CERTIFICATE } from "../../api/configuration/DebugConfiguration";
import { Tools } from "../../api/Tools";
import { checkClientCertificate, remoteCertificatesExists } from "../../debug/certificates";
import { DebugJob, getDebugServerJob, getDebugServiceJob, isDebugEngineRunning, readActiveJob, readJVMInfo, startServer, startService, stopServer, stopService } from "../../debug/server";
import { getDebugEngineJobs, isDebugEngineRunning, readActiveJob, readJVMInfo, startServer, startService, stopServer, stopService } from "../../debug/server";
import { instance } from "../../instantiate";
import { VscodeTools } from "../Tools";
import { BrowserItem } from "../types";
Expand Down Expand Up @@ -90,27 +90,25 @@ class DebugBrowser implements vscode.TreeDataProvider<BrowserItem> {
}
}

return Promise.all([
getDebugServerJob().then(debugJob =>
new DebugJobItem("server",
vscode.l10n.t(`Debug Server`),
{
startFunction: startServer,
stopFunction: stopServer,
debugJob
})
),
getDebugServiceJob().then(debugJob =>
new DebugJobItem("service",
vscode.l10n.t(`Debug Service`), {
const debugJobs = await getDebugEngineJobs();

return [
new DebugJobItem("server",
vscode.l10n.t(`Debug Server`),
{
startFunction: startServer,
stopFunction: stopServer,
debugJob: debugJobs.server
}),
new DebugJobItem("service",
vscode.l10n.t(`Debug Service`), {
startFunction: () => startService(connection),
stopFunction: () => stopService(connection),
debugJob,
debugConfig,
certificates
})
)
]);
debugJob: debugJobs.service,
debugConfig,
certificates
})
];
}
else {
return [];
Expand All @@ -120,7 +118,7 @@ class DebugBrowser implements vscode.TreeDataProvider<BrowserItem> {
async resolveTreeItem(item: vscode.TreeItem, element: BrowserItem, token: vscode.CancellationToken) {
const connection = instance.getConnection();
if (connection && element.tooltip === undefined && element instanceof DebugJobItem && element.parameters.debugJob) {
element.tooltip = new vscode.MarkdownString(`${vscode.l10n.t("Listening on port(s)")} ${element.parameters.debugJob.ports.join(", ")}\n\n`);
element.tooltip = new vscode.MarkdownString();
const activeJob = await readActiveJob(connection, element.parameters.debugJob);
if (activeJob) {
const jobToMarkDown = (job: Tools.DB2Row | string) => typeof job === "string" ? job : Object.entries(job).filter(([key, value]) => value !== null).map(([key, value]) => `- ${vscode.l10n.t(key)}: ${value}`).join("\n");
Expand Down Expand Up @@ -151,7 +149,7 @@ class DebugJobItem extends DebugItem {
constructor(readonly type: "server" | "service", label: string, readonly parameters: {
startFunction: () => Promise<boolean>,
stopFunction: () => Promise<boolean>,
debugJob?: DebugJob,
debugJob?: string,
certificates?: Certificates,
debugConfig?: DebugConfiguration
}) {
Expand Down Expand Up @@ -184,7 +182,7 @@ class DebugJobItem extends DebugItem {
this.problem = problem;

if (running) {
this.description = this.parameters.debugJob!.name;
this.description = this.parameters.debugJob;
}
else {
this.description = vscode.l10n.t(`Offline`);
Expand Down
Loading