Skip to content

Commit

Permalink
Users/ajya/create physical path for va (#3294)
Browse files Browse the repository at this point in the history
* Create Physical path for a virtual application

* Creation logic moved to different function

* review comment corrections
  • Loading branch information
Ajay Kumar Yadav authored Dec 22, 2016
1 parent 8b58524 commit 0b0e605
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,11 @@
"loc.messages.UnknownFileEncodeError": "Unable to detect encoding of the file %s (typeCode: %s). Supported encodings are UTF-8 and UTF-16 LE.",
"loc.messages.ShortFileBufferError": "File buffer is too short to detect encoding type : %s",
"loc.messages.FailedToUpdateAzureRMWebAppConfigDetails": "Failed to update Web App config details. Error: %s",
"loc.messages.SuccessfullyUpdatedAzureRMWebAppConfigDetails": "Successfully updated Web App config details"
"loc.messages.SuccessfullyUpdatedAzureRMWebAppConfigDetails": "Successfully updated Web App service configuration details",
"loc.messages.RequestedURLforkuduphysicalpath": "Requested URL for kudu physical path : %s",
"loc.messages.Physicalpathalreadyexists": "Physical path '%s' already exists",
"loc.messages.KuduPhysicalpathCreatedSuccessfully": "Kudu physical path created successfully : %s",
"loc.messages.FailedtocreateKuduPhysicalPath": "Failed to create kudu physical path. %s: %s",
"loc.messages.FailedtocheckphysicalPath": "Failed to check kudu physical path. %s: %s",
"loc.messages.VirtualApplicationDoesNotExist": "Virtual application doesn't exists : %s"
}
9 changes: 9 additions & 0 deletions Tasks/AzureRmWebAppDeployment/Tests/L0WindowsAllInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ tr.registerMock('./msdeployutility.js', {
}
});

tr.registerMock('webdeployment-common/kuduutility.js', {
getVirtualAndPhysicalPaths : function() {
return ["/virtualApp", "/test/path"]
},
ensurePhysicalPathExists: function() {
return true;
}
});

tr.registerMock('azurerest-common/azurerestutility.js', {
getAzureRMWebAppPublishProfile: function(SPN, webAppName, resourceGroupName, deployToSlotFlag, slotName) {
var mockPublishProfile = {
Expand Down
30 changes: 27 additions & 3 deletions Tasks/AzureRmWebAppDeployment/azurermwebappdeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ async function run() {
tl.setVariable(webAppUri, publishingProfile.destinationAppUrl);
}

var azureWebAppDetails = null;
if(virtualApplication) {
azureWebAppDetails = await azureRESTUtility.getAzureRMWebAppConfigDetails(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName);
var virtualApplicationMappings = azureWebAppDetails.properties.virtualApplications;
var pathMappings = kuduUtility.getVirtualAndPhysicalPaths(virtualApplication, virtualApplicationMappings);
if(pathMappings[1] != null) {
await kuduUtility.ensurePhysicalPathExists(publishingProfile, pathMappings[1]);
} else {
throw Error(tl.loc("VirtualApplicationDoesNotExist", virtualApplication));
}
}

if(utility.canUseWebDeploy(useWebDeploy)) {
if(!tl.osType().match(/^Win/)){
throw Error(tl.loc("PublishusingwebdeployoptionsaresupportedonlywhenusingWindowsagent"));
Expand All @@ -137,7 +149,9 @@ async function run() {
additionalArguments, isFolderBasedDeployment, useWebDeploy);
} else {
tl.debug("Initiated deployment via kudu service for webapp package : " + webDeployPkg);
var azureWebAppDetails = await azureRESTUtility.getAzureRMWebAppConfigDetails(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName);
if(azureWebAppDetails == null) {
azureWebAppDetails = await azureRESTUtility.getAzureRMWebAppConfigDetails(endPoint, webAppName, resourceGroupName, deployToSlotFlag, slotName);
}
await DeployUsingKuduDeploy(webDeployPkg, azureWebAppDetails, publishingProfile, virtualApplication, isFolderBasedDeployment, takeAppOfflineFlag);

}
Expand Down Expand Up @@ -186,8 +200,18 @@ async function DeployUsingKuduDeploy(webDeployPkg, azureWebAppDetails, publishin
throw new Error(tl.loc("MSDeploygeneratedpackageareonlysupportedforWindowsplatform"));
}
}
var pathMappings = kuduUtility.getVirtualAndPhysicalPaths(virtualApplication, virtualApplicationMappings);
await kuduUtility.deployWebAppPackage(webAppZipFile, publishingProfile, pathMappings[0], pathMappings[1], takeAppOfflineFlag);
var physicalPath = "/site/wwwroot";
var virtualPath = "/";
if(virtualApplication) {
var pathMappings = kuduUtility.getVirtualAndPhysicalPaths(virtualApplication, virtualApplicationMappings);
if(pathMappings[1] != null) {
virtualPath = pathMappings[0];
physicalPath = pathMappings[1];
} else {
throw Error(tl.loc("VirtualApplicationDoesNotExist", virtualApplication));
}
}
await kuduUtility.deployWebAppPackage(webAppZipFile, publishingProfile, virtualPath, physicalPath, takeAppOfflineFlag);
tl._writeLine(tl.loc('WebappsuccessfullypublishedatUrl0', publishingProfile.destinationAppUrl));
}
catch(error) {
Expand Down
8 changes: 7 additions & 1 deletion Tasks/AzureRmWebAppDeployment/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@
"UnknownFileEncodeError": "Unable to detect encoding of the file %s (typeCode: %s). Supported encodings are UTF-8 and UTF-16 LE.",
"ShortFileBufferError": "File buffer is too short to detect encoding type : %s",
"FailedToUpdateAzureRMWebAppConfigDetails": "Failed to update Web App config details. Error: %s",
"SuccessfullyUpdatedAzureRMWebAppConfigDetails": "Successfully updated Web App config details"
"SuccessfullyUpdatedAzureRMWebAppConfigDetails": "Successfully updated Web App service configuration details",
"RequestedURLforkuduphysicalpath": "Requested URL for kudu physical path : %s",
"Physicalpathalreadyexists": "Physical path '%s' already exists",
"KuduPhysicalpathCreatedSuccessfully": "Kudu physical path created successfully : %s",
"FailedtocreateKuduPhysicalPath" : "Failed to create kudu physical path. %s: %s",
"FailedtocheckphysicalPath" : "Failed to check kudu physical path. %s: %s",
"VirtualApplicationDoesNotExist" : "Virtual application doesn't exists : %s"
}
}
8 changes: 7 additions & 1 deletion Tasks/AzureRmWebAppDeployment/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@
"UnknownFileEncodeError": "ms-resource:loc.messages.UnknownFileEncodeError",
"ShortFileBufferError": "ms-resource:loc.messages.ShortFileBufferError",
"FailedToUpdateAzureRMWebAppConfigDetails": "ms-resource:loc.messages.FailedToUpdateAzureRMWebAppConfigDetails",
"SuccessfullyUpdatedAzureRMWebAppConfigDetails": "ms-resource:loc.messages.SuccessfullyUpdatedAzureRMWebAppConfigDetails"
"SuccessfullyUpdatedAzureRMWebAppConfigDetails": "ms-resource:loc.messages.SuccessfullyUpdatedAzureRMWebAppConfigDetails",
"RequestedURLforkuduphysicalpath": "ms-resource:loc.messages.RequestedURLforkuduphysicalpath",
"Physicalpathalreadyexists": "ms-resource:loc.messages.Physicalpathalreadyexists",
"KuduPhysicalpathCreatedSuccessfully": "ms-resource:loc.messages.KuduPhysicalpathCreatedSuccessfully",
"FailedtocreateKuduPhysicalPath": "ms-resource:loc.messages.FailedtocreateKuduPhysicalPath",
"FailedtocheckphysicalPath": "ms-resource:loc.messages.FailedtocheckphysicalPath",
"VirtualApplicationDoesNotExist": "ms-resource:loc.messages.VirtualApplicationDoesNotExist"
}
}
67 changes: 59 additions & 8 deletions Tasks/Common/webdeployment-common/kuduutility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,10 @@ export async function appOffineKuduService(publishUrl: string, physicalPath: str
*/
export function getVirtualAndPhysicalPaths(virtualApplication: string, virtualApplicationMappings) {
// construct URL depending on virtualApplication or root of webapplication
var physicalPath = "/site/wwwroot";
var virtualPath = "/";
if (virtualApplication) {
virtualPath = "/" + virtualApplication;
}

var physicalPath = null;
var virtualPath = "/" + virtualApplication;

for( var index in virtualApplicationMappings ) {

var mapping = virtualApplicationMappings[index];
if( mapping.virtualPath == virtualPath){
physicalPath = mapping.physicalPath;
Expand Down Expand Up @@ -133,4 +129,59 @@ export async function containsParamFile(webAppPackage: string ) {
}
tl.debug("Is parameter file present in web package : " + isParamFilePresent);
return isParamFilePresent;
}
}

export async function ensurePhysicalPathExists(publishingProfile, physicalPath: string) {
var defer = Q.defer<string>();
physicalPath = physicalPath.replace(/[\\]/g, "/");
var kuduPhysicalpathUrl = "https://" + publishingProfile.publishUrl + "/api/vfs/" + physicalPath + "/";
var basicAuthToken = 'Basic ' + new Buffer(publishingProfile.userName + ':' + publishingProfile.userPWD).toString('base64');
var headers = {
'Authorization': basicAuthToken,
'If-Match': "*"
};
tl.debug("Requested URL for kudu physical path : " + kuduPhysicalpathUrl);

httpObj.send('GET', kuduPhysicalpathUrl, null, headers, async (error, response, body) => {
if (error) {
defer.reject(error);
}
else if (response.statusCode === 200 || response.statusCode === 201 || response.statusCode === 204) {
tl.debug("Physical path '" + physicalPath + "' already exists ");
defer.resolve(tl.loc('Physicalpathalreadyexists'));
}
else if(response.statusCode === 404) {
tl.debug("Physical path doesn't exists. Creating physical path.")
defer.resolve(await createPhysicalPath(publishingProfile, physicalPath));
} else {
tl.debug(body);
defer.reject(tl.loc('FailedtocheckphysicalPath', response.statusCode, response.statusMessage));
}
});
return defer.promise;
}

async function createPhysicalPath(publishingProfile, physicalPath: string) {
var defer = Q.defer<string>();
var kuduPhysicalpathUrl = "https://" + publishingProfile.publishUrl + "/api/vfs/" + physicalPath + "/";
var basicAuthToken = 'Basic ' + new Buffer(publishingProfile.userName + ':' + publishingProfile.userPWD).toString('base64');
var headers = {
'Authorization': basicAuthToken,
'If-Match': "*"
};
tl.debug("Requested URL for kudu physical path : " + kuduPhysicalpathUrl);
httpObj.send('PUT', kuduPhysicalpathUrl, null, headers, (error, response, body) => {
if (error) {
defer.reject(error);
}
else if (response.statusCode === 200 || response.statusCode === 201 || response.statusCode === 204) {
tl.debug("Kudu physical path : '" + physicalPath + "' created successfully ");
defer.resolve(tl.loc('KuduPhysicalpathCreatedSuccessfully', physicalPath));
}
else {
tl.error(response.statusMessage);
defer.reject(tl.loc('FailedtocreateKuduPhysicalPath', response.statusCode, response.statusMessage));
}
});
return defer.promise;
}

0 comments on commit 0b0e605

Please sign in to comment.