Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Test-UploadApplicationPackage
# Setup
$context = New-Object Microsoft.Azure.Commands.Batch.Test.ScenarioTests.ScenarioTestContext

$addAppPack = New-AzBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationName $applicationName -ApplicationVersion $applicationVersion -format "zip" -ActivateOnly
$addAppPack = New-AzBatchApplicationPackage -ResourceGroupName $context.ResourceGroupName -AccountName $context.AccountName -ApplicationName $applicationName -ApplicationVersion $applicationVersion -format "zip" -FilePath $filePath
$subId = $context.Subscription
$resourceGroup = $context.ResourceGroupName
$batchAccountName = $context.AccountName
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions src/Batch/Batch/Models/BatchClient.ApplicationPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,18 @@ public virtual PSApplicationPackage UploadAndActivateApplicationPackage(
throw new FileNotFoundException(string.Format(Resources.FileNotFound, filePath), filePath);
}

// Else create Application Package and upload.
bool appPackageAlreadyExists;

var storageUrl = GetStorageUrl(resourceGroupName, accountName, applicationName, version, out appPackageAlreadyExists);
// check to see if the application package already exists
bool appPackageAlreadyExists = AppPackageExists(resourceGroupName, accountName, applicationName, version);

// if exist verify it allows updates
if (appPackageAlreadyExists)
{
CheckApplicationAllowsUpdates(resourceGroupName, accountName, applicationName, version);
}

// Get the storage URL to upload the application package to by call create/update
var storageUrl = GetStorageUrl(resourceGroupName, accountName, applicationName, version);

UploadFileToApplicationPackage(resourceGroupName, accountName, applicationName, version, filePath, storageUrl, appPackageAlreadyExists);

ActivateApplicationPackage(resourceGroupName, accountName, applicationName, version, format, Resources.UploadedApplicationButFailedToActivate);
Expand Down Expand Up @@ -189,8 +191,10 @@ private void ActivateApplicationPackage(string resourceGroupName, string account
}
}

private string GetStorageUrl(string resourceGroupName, string accountName, string applicationName, string version, out bool appPackageAlreadyExists)

private bool AppPackageExists(string resourceGroupName, string accountName, string applicationName, string version)
{

try
{
// Checks to see if the package exists
Expand All @@ -200,8 +204,8 @@ private string GetStorageUrl(string resourceGroupName, string accountName, strin
applicationName,
version);

appPackageAlreadyExists = true;
return response.StorageUrl;
return true;

}
catch (CloudException exception)
{
Expand All @@ -213,6 +217,13 @@ private string GetStorageUrl(string resourceGroupName, string accountName, strin
}
}

return false;
}


private string GetStorageUrl(string resourceGroupName, string accountName, string applicationName, string version)
{

try
{
var addResponse = BatchManagementClient.ApplicationPackage.Create(
Expand All @@ -221,8 +232,6 @@ private string GetStorageUrl(string resourceGroupName, string accountName, strin
applicationName,
version);

//Package didn't exist before we created it
appPackageAlreadyExists = false;
return addResponse.StorageUrl;
}
catch (Exception exception)
Expand All @@ -237,7 +246,7 @@ private static PSApplicationPackage ConvertGetApplicationPackageResponseToApplic
return new PSApplicationPackage
{
Format = response.Format,
StorageUrl = response.StorageUrl,
//StorageUrl = response.StorageUrl,
StorageUrlExpiry = response.StorageUrlExpiry,
State = response.State.Value,
Id = response.Id,
Expand Down
Loading