Skip to content

Commit

Permalink
Send AffinityCookie with ZipDeploy Polling Request (#8822)
Browse files Browse the repository at this point in the history
* changes

* incrememted task version

* make explicit check for affinityCookie
  • Loading branch information
vincent1173 authored Nov 19, 2018
1 parent 5c8d37b commit 5deb0c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 3,
"Minor": 4,
"Patch": 16
"Patch": 17
},
"releaseNotes": "What's new in Version 3.0: <br/>&nbsp;&nbsp;Supports File Transformations (XDT) <br/>&nbsp;&nbsp;Supports Variable Substitutions(XML, JSON) <br/>Click [here](https://aka.ms/azurermwebdeployreadme) for more information.",
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureRmWebAppDeploymentV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 3,
"Minor": 4,
"Patch": 16
"Patch": 17
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"minimumAgentVersion": "2.104.1",
Expand Down
27 changes: 21 additions & 6 deletions Tasks/Common/azure-arm-rest/azure-arm-app-service-kudu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export class KuduServiceManagementClient {
this._scmUri = scmUri;
}

public async beginRequest(request: webClient.WebRequest, reqOptions?: webClient.WebRequestOptions, contentType?: string): Promise<webClient.WebResponse> {
public async beginRequest(request: webClient.WebRequest, reqOptions?: webClient.WebRequestOptions): Promise<webClient.WebResponse> {
request.headers = request.headers || {};
request.headers["Authorization"] = "Basic " + this._accesssToken;
request.headers['Content-Type'] = contentType || 'application/json; charset=utf-8';
if(!request.headers['Content-Type']) {
request.headers['Content-Type'] = 'application/json; charset=utf-8';
}

let retryCount = reqOptions && util.isNumber(reqOptions.retryCount) ? reqOptions.retryCount : 5;

Expand Down Expand Up @@ -445,19 +447,23 @@ export class Kudu {
httpRequest.method = 'POST';
httpRequest.uri = this._client.getRequestUri(`/api/zipdeploy`, queryParameters);
httpRequest.body = fs.createReadStream(webPackage);
httpRequest.headers = {
'Content-Type': 'application/octet-stream'
};

try {
let response = await this._client.beginRequest(httpRequest, null, 'application/octet-stream');
let response = await this._client.beginRequest(httpRequest);
tl.debug(`ZIP Deploy response: ${JSON.stringify(response)}`);
if(response.statusCode == 200) {
tl.debug('Deployment passed');
return null;
}
else if(response.statusCode == 202) {
let pollableURL: string = response.headers.location;
let affinityCookie: string [] = response.headers['set-cookie'];
if(!!pollableURL) {
tl.debug(`Polling for ZIP Deploy URL: ${pollableURL}`);
return await this._getDeploymentDetailsFromPollURL(pollableURL);
return await this._getDeploymentDetailsFromPollURL(pollableURL, affinityCookie);
}
else {
tl.debug('zip deploy returned 202 without pollable URL.');
Expand All @@ -478,6 +484,9 @@ export class Kudu {
httpRequest.method = 'POST';
httpRequest.uri = this._client.getRequestUri(`/api/wardeploy`, queryParameters);
httpRequest.body = fs.createReadStream(webPackage);
httpRequest.headers = {
'Content-Type': 'application/octet-stream'
};

try {
let response = await this._client.beginRequest(httpRequest);
Expand All @@ -488,9 +497,10 @@ export class Kudu {
}
else if(response.statusCode == 202) {
let pollableURL: string = response.headers.location;
let affinityCookie: string [] = response.headers['set-cookie'];
if(!!pollableURL) {
tl.debug(`Polling for War Deploy URL: ${pollableURL}`);
return await this._getDeploymentDetailsFromPollURL(pollableURL);
return await this._getDeploymentDetailsFromPollURL(pollableURL, affinityCookie);
}
else {
tl.debug('war deploy returned 202 without pollable URL.');
Expand Down Expand Up @@ -593,10 +603,15 @@ export class Kudu {
}
}

private async _getDeploymentDetailsFromPollURL(pollURL: string):Promise<any> {
private async _getDeploymentDetailsFromPollURL(pollURL: string, affinityCookie?: string[]): Promise<any> {
let httpRequest = new webClient.WebRequest();
httpRequest.method = 'GET';
httpRequest.uri = pollURL;
httpRequest.headers = {};

if(!!affinityCookie) {
httpRequest['set-cookie'] = affinityCookie;
}

while(true) {
let response = await this._client.beginRequest(httpRequest);
Expand Down

0 comments on commit 5deb0c0

Please sign in to comment.