-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App Service Manage task review comments (#6143)
* resolved review comments #1 * resolved review comments #2 * addressed review comments #3 * comment mock tests * addressed review comments #4 * addressed review comments #5 * resolve build failures * remove inherit * remove unreachable codes & Fix few tests * Fix L0 Tests * addressed review comments * changed case * change source to target * removed xml2js dependency
- Loading branch information
1 parent
ceaf37f
commit 3001125
Showing
26 changed files
with
667 additions
and
582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Tasks/AzureAppServiceManage/operations/AzureAppServiceUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import tl = require('vsts-task-lib/task'); | ||
import { AzureAppService } from 'azure-arm-rest/azure-arm-app-service'; | ||
import webClient = require('azure-arm-rest/webClient'); | ||
var parseString = require('xml2js').parseString; | ||
import Q = require('q'); | ||
import { Kudu } from 'azure-arm-rest/azure-arm-app-service-kudu'; | ||
|
||
export class AzureAppServiceUtils { | ||
private _appService: AzureAppService; | ||
constructor(appService: AzureAppService) { | ||
this._appService = appService; | ||
} | ||
|
||
public async monitorApplicationState(state: string): Promise<void> { | ||
state = state.toLowerCase(); | ||
if(["running", "stopped"].indexOf(state) == -1) { | ||
throw new Error(tl.loc('InvalidMonitorAppState', state)); | ||
} | ||
|
||
while(true) { | ||
var appDetails = await this._appService.get(true); | ||
if(appDetails && appDetails.properties && appDetails.properties["state"]) { | ||
tl.debug(`App Service state: ${appDetails.properties["state"]}`) | ||
if(appDetails.properties["state"].toLowerCase() == state) { | ||
tl.debug(`App Service state '${appDetails.properties["state"]}' matched with expected state '${state}'.`); | ||
console.log(tl.loc('AppServiceState', appDetails.properties["state"])); | ||
break; | ||
} | ||
await webClient.sleepFor(5); | ||
} | ||
else { | ||
tl.debug('Unable to monitor app service details as the state is unknown.'); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public async getWebDeployPublishingProfile(): Promise<any> { | ||
var publishingProfile = await this._appService.getPublishingProfileWithSecrets(); | ||
var defer = Q.defer<any>(); | ||
parseString(publishingProfile, (error, result) => { | ||
for (var index in result.publishData.publishProfile) { | ||
if (result.publishData.publishProfile[index].$.publishMethod === "MSDeploy") { | ||
defer.resolve(result.publishData.publishProfile[index].$); | ||
} | ||
} | ||
defer.reject(tl.loc('ErrorNoSuchDeployingMethodExists')); | ||
}); | ||
|
||
return defer.promise; | ||
} | ||
|
||
public async pingApplication(): Promise<void> { | ||
try { | ||
var applicationUrl: string = (await this.getWebDeployPublishingProfile()).destinationAppUrl; | ||
|
||
if(!applicationUrl) { | ||
tl.debug('Application Url not found.'); | ||
return; | ||
} | ||
var webRequest = new webClient.WebRequest(); | ||
webRequest.method = 'GET'; | ||
webRequest.uri = applicationUrl; | ||
tl.debug('pausing for 5 seconds before request'); | ||
await webClient.sleepFor(5); | ||
var response = await webClient.sendRequest(webRequest); | ||
tl.debug(`App Service status Code: '${response.statusCode}'. Status Message: '${response.statusMessage}'`); | ||
} | ||
catch(error) { | ||
tl.debug(`Unable to ping App Service. Error: ${error}`); | ||
} | ||
} | ||
|
||
public async getKuduService(): Promise<Kudu> { | ||
var publishingCredentials = await this._appService.getPublishingCredentials(); | ||
if(publishingCredentials.properties["scmUri"]) { | ||
tl.setVariable(`AZURE_APP_SERVICE_KUDU_${this._appService.getSlot()}_PASSWORD`, publishingCredentials.properties["publishingPassword"], true); | ||
return new Kudu(publishingCredentials.properties["scmUri"], publishingCredentials.properties["publishingUserName"], publishingCredentials.properties["publishingPassword"]); | ||
} | ||
|
||
throw Error(tl.loc('KuduSCMDetailsAreEmpty')); | ||
} | ||
} |
Oops, something went wrong.