diff --git a/appservice/src/TunnelProxy.ts b/appservice/src/TunnelProxy.ts index 3910afddb0..4e10dda7ba 100644 --- a/appservice/src/TunnelProxy.ts +++ b/appservice/src/TunnelProxy.ts @@ -120,7 +120,7 @@ class TunnelSocket extends EventEmitter { /** * Interface for tunnel GetStatus API */ -enum WebAppState { +enum AppState { STARTED = 'STARTED', STARTING = 'STARTING', STOPPED = 'STOPPED' @@ -129,7 +129,7 @@ enum WebAppState { interface ITunnelStatus { port: number; canReachPort: boolean; - state: WebAppState; + state: AppState; msg: string; } @@ -171,26 +171,16 @@ export class TunnelProxy { this._server.unref(); } - // Starts up an app when it is found to be in the STOPPED state - // Apps can be in the STOPPED state for different reasons: - // 1. A stop request was sent through the Azure API (using the portal, using the extension, etc) - // - In this case it will respond with 403 until a start request is sent to the Azure API - // 2. The app is inactive, or was recently started - // - In this case it will stay stopped until a request is made to the app itself, waking it up - // - // To cover both cases, we send a start request followed by a ping to the app url + // Starts up an app by pinging it when it is found to be in the STOPPED state private async startupApp(): Promise { - ext.outputChannel.appendLine('[WebApp Tunnel] Sending start request...'); - await this._client.start(); - - ext.outputChannel.appendLine('[WebApp Tunnel] Pinging app default url...'); + ext.outputChannel.appendLine('[Tunnel] Pinging app default url...'); // tslint:disable-next-line:no-unsafe-any const pingResponse: IncomingMessage = await requestP.get({ uri: this._client.defaultHostUrl, simple: false, // allows the call to succeed without exception, even when status code is not 2XX resolveWithFullResponse: true // allows access to the status code from the response }); - ext.outputChannel.appendLine(`[WebApp Tunnel] Ping responded with status code: ${pingResponse.statusCode}`); + ext.outputChannel.appendLine(`[Tunnel] Ping responded with status code: ${pingResponse.statusCode}`); } private async checkTunnelStatus(): Promise { @@ -209,32 +199,32 @@ export class TunnelProxy { try { // tslint:disable-next-line:no-unsafe-any const responseBody: string = await requestP.get(statusOptions); - ext.outputChannel.appendLine(`[WebApp Tunnel] Checking status, body: ${responseBody}`); + ext.outputChannel.appendLine(`[Tunnel] Checking status, body: ${responseBody}`); // tslint:disable-next-line:no-unsafe-any tunnelStatus = JSON.parse(responseBody); } catch (error) { const parsedError: IParsedError = parseError(error); - ext.outputChannel.appendLine(`[WebApp Tunnel] Checking status, error: ${parsedError.message}`); + ext.outputChannel.appendLine(`[Tunnel] Checking status, error: ${parsedError.message}`); throw new Error(`Error getting tunnel status: ${parsedError.errorType}`); } - if (tunnelStatus.state === WebAppState.STARTED) { + if (tunnelStatus.state === AppState.STARTED) { if ((tunnelStatus.port === 2222 && !this._isSsh) || (tunnelStatus.port !== 2222 && this._isSsh)) { // Tunnel is pointed to default SSH port and still needs time to restart - throw new RetryableTunnelStatusError('WebApp is waiting for restart'); + throw new RetryableTunnelStatusError('App is waiting for restart'); } else if (tunnelStatus.canReachPort) { return; } else { - throw new Error('WebApp is started, but port is unreachable'); + throw new Error('App is started, but port is unreachable'); } - } else if (tunnelStatus.state === WebAppState.STARTING) { - throw new RetryableTunnelStatusError('WebApp is starting'); - } else if (tunnelStatus.state === WebAppState.STOPPED) { + } else if (tunnelStatus.state === AppState.STARTING) { + throw new RetryableTunnelStatusError('App is starting'); + } else if (tunnelStatus.state === AppState.STOPPED) { await this.startupApp(); - throw new RetryableTunnelStatusError('WebApp is starting from STOPPED state'); + throw new RetryableTunnelStatusError('App is starting from STOPPED state'); } else { - throw new Error(`Unexpected WebApp state: ${tunnelStatus.state}`); + throw new Error(`Unexpected app state: ${tunnelStatus.state}`); } } diff --git a/appservice/src/index.ts b/appservice/src/index.ts index c7d197cdf4..0feab0662f 100644 --- a/appservice/src/index.ts +++ b/appservice/src/index.ts @@ -15,7 +15,6 @@ export * from './createAppService/SiteOSStep'; export * from './createAppService/SiteRuntimeStep'; export * from './remoteDebug/remoteDebugCommon'; export * from './remoteDebug/startRemoteDebug'; -export * from './remoteDebug/stopRemoteDebug'; export * from './createSlot'; export * from './deploy/deploy'; export * from './deploy/runPreDeployTask'; diff --git a/appservice/src/remoteDebug/remoteDebugCommon.ts b/appservice/src/remoteDebug/remoteDebugCommon.ts index aa5e28177d..5cbf1d75db 100644 --- a/appservice/src/remoteDebug/remoteDebugCommon.ts +++ b/appservice/src/remoteDebug/remoteDebugCommon.ts @@ -9,14 +9,17 @@ import { callWithTelemetryAndErrorHandling, DialogResponses, IActionContext } fr import { ext } from '../extensionVariables'; import { SiteClient } from '../SiteClient'; -export const remoteDebugLink: string = 'https://aka.ms/appsvc-remotedebug'; - export function reportMessage(message: string, progress: vscode.Progress<{}>): void { ext.outputChannel.appendLine(message); progress.report({ message: message }); } export async function setRemoteDebug(isRemoteDebuggingToBeEnabled: boolean, confirmMessage: string, noopMessage: string | undefined, siteClient: SiteClient, siteConfig: SiteConfigResource, progress?: vscode.Progress<{}>, learnMoreLink?: string): Promise { + const state: string | undefined = await siteClient.getState(); + if (state && state.toLowerCase() === 'stopped') { + throw new Error('The app must be running, but is currently in state "Stopped". Start the app to continue.'); + } + if (isRemoteDebuggingToBeEnabled !== siteConfig.remoteDebuggingEnabled) { const confirmButton: vscode.MessageItem = isRemoteDebuggingToBeEnabled ? { title: 'Enable' } : { title: 'Disable' }; diff --git a/appservice/src/remoteDebug/startRemoteDebug.ts b/appservice/src/remoteDebug/startRemoteDebug.ts index 00c7cc4628..a2565c5264 100644 --- a/appservice/src/remoteDebug/startRemoteDebug.ts +++ b/appservice/src/remoteDebug/startRemoteDebug.ts @@ -10,7 +10,9 @@ import { callWithTelemetryAndErrorHandling, IActionContext } from 'vscode-azuree import { ext } from '../extensionVariables'; import { SiteClient } from '../SiteClient'; import { TunnelProxy } from '../TunnelProxy'; -import { remoteDebugLink, reportMessage, setRemoteDebug } from './remoteDebugCommon'; +import { reportMessage, setRemoteDebug } from './remoteDebugCommon'; + +const remoteDebugLink: string = 'https://aka.ms/appsvc-remotedebug'; let isRemoteDebugging: boolean = false; @@ -34,9 +36,7 @@ async function startRemoteDebugInternal(siteClient: SiteClient, siteConfig: Site // tslint:disable-next-line:no-unsafe-any const localHostPortNumber: number = debugConfig.port; - reportMessage('Checking app settings...', progress); - - const confirmEnableMessage: string = 'The app configuration will be updated to enable remote debugging and restarted. Would you like to continue?'; + const confirmEnableMessage: string = 'The configuration will be updated to enable remote debugging. Would you like to continue? This will restart the app.'; await setRemoteDebug(true, confirmEnableMessage, undefined, siteClient, siteConfig, progress, remoteDebugLink); reportMessage('Starting tunnel proxy...', progress); @@ -68,7 +68,7 @@ async function startRemoteDebugInternal(siteClient: SiteClient, siteConfig: Site } terminateDebugListener.dispose(); - const confirmDisableMessage: string = 'Leaving the app in debugging mode may cause performance issues. Would you like to disable debugging for this app? The app will be restarted.'; + const confirmDisableMessage: string = 'Remaining in debugging mode may cause performance issues. Would you like to disable debugging? This will restart the app.'; await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (innerProgress: vscode.Progress<{}>): Promise => { await setRemoteDebug(false, confirmDisableMessage, undefined, siteClient, siteConfig, innerProgress, remoteDebugLink); }); diff --git a/appservice/src/remoteDebug/stopRemoteDebug.ts b/appservice/src/remoteDebug/stopRemoteDebug.ts deleted file mode 100644 index e741f40fe9..0000000000 --- a/appservice/src/remoteDebug/stopRemoteDebug.ts +++ /dev/null @@ -1,18 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { SiteConfigResource } from 'azure-arm-website/lib/models'; -import * as vscode from 'vscode'; -import { SiteClient } from '../SiteClient'; -import { remoteDebugLink, setRemoteDebug } from './remoteDebugCommon'; - -export async function stopRemoteDebug(siteClient: SiteClient, siteConfig: SiteConfigResource): Promise { - const confirmMessage: string = 'The app configuration will be updated to disable remote debugging and restarted. Would you like to continue?'; - const noopMessage: string = 'The app is not configured for debugging.'; - - await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress: vscode.Progress<{}>): Promise => { - await setRemoteDebug(false, confirmMessage, noopMessage, siteClient, siteConfig, progress, remoteDebugLink); - }); -}