Skip to content

Commit

Permalink
Merge pull request #1750 from ogail/1749
Browse files Browse the repository at this point in the history
Throw error for 1.8 cache
  • Loading branch information
Abdelrahman Elogeel authored and Abdelrahman Elogeel committed Jul 11, 2013
2 parents 70f2ba2 + 5648678 commit e466ba3
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 10 deletions.
2 changes: 1 addition & 1 deletion WindowsAzurePowershell/setup/azurecmd.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<?define caSourceDir="$(var.SolutionDir)setup\bin\$(var.Configuration)" ?>

<?define version="0.6.17" ?>
<?define azureSdkVersion="1.8" ?>
<?define azureSdkVersion="2.0" ?>
<?define versionedStartMenuFolder="Windows Azure" ?>

<Product Id="*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Microsoft.WindowsAzure.Management.Test.CloudService.Development
{
using System;
using System.IO;
using System.Management.Automation;
using Microsoft.WindowsAzure.Management.CloudService.Development;
Expand Down Expand Up @@ -119,5 +120,36 @@ public void TestCreatePackageWithMultipleRolesSuccessfull()
Assert.IsTrue(File.Exists(packagePath));
}
}

[TestMethod]
public void ThrowsErrorForInvalidCacheVersion()
{
using (FileSystemHelper files = new FileSystemHelper(this))
{
files.CreateAzureSdkDirectoryAndImportPublishSettings();
files.CreateNewService("NEW_SERVICE");
string rootPath = Path.Combine(files.RootPath, "NEW_SERVICE");
string packagePath = Path.Combine(rootPath, Resources.CloudPackageFileName);
string cacheRoleName = "WorkerRole1";
AddAzureCacheWorkerRoleCommand addCacheWorkerCmdlet = new AddAzureCacheWorkerRoleCommand()
{
CommandRuntime = mockCommandRuntime
};
EnableAzureMemcacheRoleCommand enableCacheCmdlet = new EnableAzureMemcacheRoleCommand()
{
CacheRuntimeVersion = "1.8.0",
CommandRuntime = mockCommandRuntime
};

CloudServiceProject service = new CloudServiceProject(rootPath, null);
service.AddWebRole(Data.NodeWebRoleScaffoldingPath);
addCacheWorkerCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath);
enableCacheCmdlet.EnableAzureMemcacheRoleProcess("WebRole1", cacheRoleName, rootPath);

Testing.AssertThrows<Exception>(
() => cmdlet.ExecuteCmdlet(),
string.Format(Resources.CacheMismatchMessage, "WebRole1", "2.0.0"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ namespace Microsoft.WindowsAzure.Management.Utilities.CloudService
public class CloudServiceProject
{
public ServicePathInfo Paths { get; private set; }

public ServiceComponents Components { get; private set; }

private string scaffoldingFolderPath;

public string ServiceName { get { return this.Components.Definition.name; } }
Expand Down Expand Up @@ -253,10 +255,31 @@ public void ChangeRolePermissions(RoleInfo role)
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]
public void CreatePackage(DevEnv type, out string standardOutput, out string standardError)
{
var packageTool = new CsPack();
VerifyCloudServiceProjectComponents();
CsPack packageTool = new CsPack();
packageTool.CreatePackage(Components.Definition, Paths.RootPath, type, out standardOutput, out standardError);
}

private void VerifyCloudServiceProjectComponents()
{
const string CacheVersion = "2.0.0";

// Verify caching version is 2.0
foreach (string roleName in Components.GetRoles())
{
string value = Components.GetStartupTaskVariable(
roleName,
Resources.CacheRuntimeVersionKey,
Resources.WebRoleStartupTaskCommandLine,
Resources.WorkerRoleStartupTaskCommandLine);

if (!string.IsNullOrEmpty(value) && value != CacheVersion)
{
throw new Exception(string.Format(Resources.CacheMismatchMessage, roleName, CacheVersion));
}
}
}

/// <summary>
/// Starts azure emulator for this service.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ public IEnumerable<RoleSettings> GetRoles(IEnumerable<string> roleNames)
return Enumerable.Empty<RoleSettings>();
}

/// <summary>
/// Gets all existing role names.
/// </summary>
/// <returns>All roles in the cloud service project</returns>
public IEnumerable<string> GetRoles()
{
if (CloudConfig.Role != null)
{
return CloudConfig.Role.Select(r => r.name);
}

return Enumerable.Empty<string>();
}

/// <summary>
/// Gets all worker roles that matches given predicate.
/// </summary>
Expand Down Expand Up @@ -421,21 +435,49 @@ public void SetStartupTaskVariable(string roleName, string name, string value, p
Task task = GetStartupTask(roleName, commandLines);
bool found = false;

for (int i = 0; i < task.Environment.Length; i++)
if (task != null && task.Environment != null)
{
if (task.Environment[i].name.Equals(name, StringComparison.OrdinalIgnoreCase))
for (int i = 0; i < task.Environment.Length; i++)
{
if (task.Environment[i].name.Equals(name, StringComparison.OrdinalIgnoreCase))
{
task.Environment[i].value = value;
found = true;
break;
}
}

if (!found)
{
task.Environment[i].value = value;
found = true;
break;
Variable var = new Variable() { name = name, value = value };
task.Environment = General.ExtendArray<Variable>(task.Environment, var);
}
}
}

if (!found)
/// <summary>
/// Gets startup task variable with the specified name.
/// </summary>
/// <param name="roleName">The role name</param>
/// <param name="name">The variable name</param>
/// <param name="commandLines">The startup task command line arguments</param>
/// <returns></returns>
public string GetStartupTaskVariable(string roleName, string name, params string[] commandLines)
{
Task task = GetStartupTask(roleName, commandLines);
Variable variable = null;

if (task != null && task.Environment != null)
{
variable = task.Environment.FirstOrDefault(v => v.name.Equals(name, StringComparison.OrdinalIgnoreCase));
}

if (variable != null)
{
Variable var = new Variable() { name = name, value = value };
task.Environment = General.ExtendArray<Variable>(task.Environment, var);
return variable.value;
}

return null;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1289,4 +1289,7 @@ Please follow these steps in the portal:
<data name="ChangePublicEnvironmentMessage" xml:space="preserve">
<value>Changing/Removing public environment '{0}' is not allowed.</value>
</data>
<data name="CacheMismatchMessage" xml:space="preserve">
<value>Please upgrade the cache runtime of role '{0}' to '{1}' using Set-AzureServiceProjectRole -RoleName {0} -Runtime Cache -Version {1}</value>
</data>
</root>

0 comments on commit e466ba3

Please sign in to comment.