import * as vscode from "vscode" ; import { Kubectl } from "../kubectl" ; import { Dictionary } from "../utils/dictionary" ; import { ExecResult } from "../binutilplusplus" ; async function promptForPort ( promptMessage , defaultPort ) { const input = await vscode . window . showInputBox ( { prompt : promptMessage , placeHolder : defaultPort , value : defaultPort } ) ; return input && input . trim ( ) ; } export async function promptForDebugPort ( defaultPort ) { return await promptForPort ( "Please specify debug port exposed for debugging" , defaultPort ) ; } export async function promptForAppPort ( ports , defaultPort , env ) { let rawAppPortInfo ; if ( ports . length === 0 ) { return await promptForPort ( "What port does your application listen on?" , defaultPort ) ; } if ( ports . length === 1 ) { rawAppPortInfo = ports [ 0 ] ; } else if ( ports . length > 1 ) { rawAppPortInfo = await vscode . window . showQuickPick ( ports , { placeHolder : "Choose the port your app listens on." } ) ; } if ( ! rawAppPortInfo ) { return undefined ; } const portRegExp = /\$\{?(\w+)\}?/ ; const portRegExpMatch = rawAppPortInfo . match ( portRegExp ) ; if ( portRegExpMatch && portRegExpMatch . length > 0 ) { const varName = portRegExpMatch [ 1 ] ; if ( rawAppPortInfo . trim ( ) === `$${ varName }` || rawAppPortInfo . trim ( ) === `\${${ varName }}` ) { const defaultAppPort = "50006" ; env [ varName ] = defaultAppPort ; rawAppPortInfo = defaultAppPort ; } else { vscode . window . showErrorMessage ( `Invalid port variable ${ rawAppPortInfo } in the docker file.` ) ; return undefined ; } } return rawAppPortInfo ; } param kubectl param pod param container return export async function getProcesses ( kubectl , pod , podNamespace , container ) { const processes = [ ] ; const nsarg = podNamespace ? `--namespace ${ podNamespace }` : '' ; const containerCommand = container ? `-c ${ container }` : '' ; const execCmd = `exec ${ pod } ${ nsarg } ${ containerCommand } -- ps -o pid,command -e -w -w` ; const execResult = await kubectl . invokeCommand ( execCmd ) ; if ( ExecResult . succeeded ( execResult ) ) { /**
         * PID   COMMAND
         *  1    java -Djava.security.egd=file:/dev/./urandom -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044,quiet=y -jar target/app.jar
         * 44    sh
         * 48    ps  -o pid,comm -e -w -w
         */ const outputRegEx = /^\s*(\d+)\s*(.*)$/gm ; let match = outputRegEx . exec ( execResult . stdout ) ; while ( match ) { processes . push ( { pid : + match [ 1 ] , command : match [ 2 ] } ) ; match = outputRegEx . exec ( execResult . stdout ) ; } return processes ; } return undefined ; } /**
 * Represents information about a running process.
 */ export interface ProcessInfo { /** The process ID */ readonly pid : number ; /** The full command that launched the process */ readonly command : string ; }