public void EnableAzureMemcacheRoleProcessOnWorkerRoleSuccess() { using (FileSystemHelper files = new FileSystemHelper(this)) { string serviceName = "AzureService"; string rootPath = files.CreateNewService(serviceName); string cacheRoleName = "CacheWorkerRole"; string workerRoleName = "WorkerRole"; string expectedMessage = string.Format(Resources.EnableMemcacheMessage, workerRoleName, cacheRoleName, Resources.MemcacheEndpointPort); addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName }; addNodeWorkerCmdlet.ExecuteCmdlet(); addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath); mockCommandRuntime.ResetPipelines(); enableCacheCmdlet.PassThru = true; enableCacheCmdlet.EnableAzureMemcacheRoleProcess(workerRoleName, cacheRoleName, rootPath); WorkerRole workerRole = Testing.GetWorkerRole(rootPath, workerRoleName); AzureAssert.RuntimeUrlAndIdExists(workerRole.Startup.Task, Resources.CacheRuntimeValue); AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, workerRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WorkerRole)); AzureAssert.StartupTaskExists(workerRole.Startup.Task, Resources.CacheStartupCommand); AzureAssert.InternalEndpointExists(workerRole.Endpoints.InternalEndpoint, new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }); LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; AzureAssert.LocalResourcesLocalStoreExists(localStore, workerRole.LocalResources); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; AzureAssert.ConfigurationSettingExist(diagnosticLevel, workerRole.ConfigurationSettings); ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue }; AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, Testing.GetCloudRole(rootPath, workerRoleName).ConfigurationSettings); AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, Testing.GetLocalRole(rootPath, workerRoleName).ConfigurationSettings); string workerConfigPath = string.Format(@"{0}\{1}\{2}", rootPath, workerRoleName, "web.config"); string workerCloudConfig = File.ReadAllText(workerConfigPath); Assert.IsTrue(workerCloudConfig.Contains("configSections")); Assert.IsTrue(workerCloudConfig.Contains("dataCacheClients")); Assert.AreEqual <string>(expectedMessage, mockCommandRuntime.VerboseStream[0]); Assert.AreEqual <string>(workerRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue <string>(Parameters.RoleName)); } }
private void AssertCachingEnabled( FileSystemHelper files, string serviceName, string rootPath, string webRoleName, string expectedMessage) { WebRole webRole = Testing.GetWebRole(rootPath, webRoleName); RoleSettings roleSettings = Testing.GetCloudRole(rootPath, webRoleName); AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue); Assert.AreEqual <string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name); Assert.AreEqual <string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value); Assert.AreEqual <string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name); Assert.AreEqual <string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath); Assert.AreEqual <string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name); Assert.AreEqual <string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value); Assert.AreEqual(1, webRole.Startup.Task.Count(t => t.commandLine.Equals(Resources.CacheStartupCommand))); AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole)); AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand); AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint, new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }); LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings); ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue }; AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings); AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig)); AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName)); Assert.AreEqual <string>(expectedMessage, mockCommandRuntime.VerboseStream[0]); Assert.AreEqual <string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue <string>(Parameters.RoleName)); }
/// <summary> /// Applies required configuration for enabling cache in SDK 1.8.0 version by: /// * Add MemcacheShim runtime installation. /// * Add startup task to install memcache shim on the client side. /// * Add default memcache internal endpoint. /// * Add cache diagnostic to local resources. /// * Add ClientDiagnosticLevel setting to service configuration. /// * Adjust web.config to enable auto discovery for the caching role. /// </summary> /// <param name="azureService">The azure service instance</param> /// <param name="webRole">The web role to enable caching on</param> /// <param name="isWebRole">Flag indicating if the provided role is web or not</param> /// <param name="cacheWorkerRole">The memcache worker role name</param> /// <param name="startup">The role startup</param> /// <param name="endpoints">The role endpoints</param> /// <param name="localResources">The role local resources</param> /// <param name="configurationSettings">The role configuration settings</param> private void Version180Configuration( AzureService azureService, string roleName, bool isWebRole, string cacheWorkerRole, Startup startup, Endpoints endpoints, LocalResources localResources, ref DefinitionConfigurationSetting[] configurationSettings) { if (isWebRole) { // Generate cache scaffolding for web role azureService.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WebRole.ToString()), roleName, new Dictionary <string, object>()); // Adjust web.config to enable auto discovery for the caching role. string webCloudConfigPath = Path.Combine(azureService.Paths.RootPath, roleName, Resources.WebCloudConfig); string webConfigPath = Path.Combine(azureService.Paths.RootPath, roleName, Resources.WebConfigTemplateFileName); UpdateWebConfig(roleName, cacheWorkerRole, webCloudConfigPath); UpdateWebConfig(roleName, cacheWorkerRole, webConfigPath); } else { // Generate cache scaffolding for worker role Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters[ScaffoldParams.RoleName] = cacheWorkerRole; azureService.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WorkerRole.ToString()), roleName, parameters); } // Add startup task to install memcache shim on the client side. string cacheRuntimeUri = CloudRuntimeCollection.GetRuntimeUrl(Resources.CacheRuntimeValue, CacheRuntimeVersion); Debug.Assert(!string.IsNullOrEmpty(cacheRuntimeUri)); Variable emulated = new Variable { name = Resources.EmulatedKey, RoleInstanceValue = new RoleInstanceValueElement { xpath = "/RoleEnvironment/Deployment/@emulated" } }; Variable[] env = { emulated, new Variable { name = Resources.CacheRuntimeUrl,value = cacheRuntimeUri } }; Task shimStartupTask = new Task { Environment = env, commandLine = Resources.CacheStartupCommand, executionContext = ExecutionContext.elevated }; startup.Task = General.ExtendArray <Task>(startup.Task, shimStartupTask); // Add default memcache internal endpoint. InternalEndpoint memcacheEndpoint = new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }; endpoints.InternalEndpoint = General.ExtendArray <InternalEndpoint>(endpoints.InternalEndpoint, memcacheEndpoint); // Enable cache diagnostic LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; localResources.LocalStorage = General.ExtendArray <LocalStore>(localResources.LocalStorage, localStore); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; configurationSettings = General.ExtendArray <DefinitionConfigurationSetting>(configurationSettings, diagnosticLevel); // Add ClientDiagnosticLevel setting to service configuration. AddClientDiagnosticLevelToConfig(azureService.Components.GetCloudConfigRole(roleName)); AddClientDiagnosticLevelToConfig(azureService.Components.GetLocalConfigRole(roleName)); }
public static void ConfigurationSettingExist(DefinitionConfigurationSetting expected, DefinitionConfigurationSetting[] actual) { Assert.IsTrue(Array.Exists <DefinitionConfigurationSetting>(actual, c => c.name == expected.name)); }
private void AssertCachingEnabled(FileSystemHelper files, string serviceName, string rootPath, string webRoleName, string expectedMessage) { WebRole webRole = Testing.GetWebRole(rootPath, webRoleName); RoleSettings roleSettings = Testing.GetCloudRole(rootPath, webRoleName); AzureAssert.RuntimeUrlAndIdExists(webRole.Startup.Task, Resources.CacheRuntimeValue); Assert.AreEqual<string>(Resources.CacheRuntimeVersionKey, webRole.Startup.Task[0].Environment[0].name); Assert.AreEqual<string>(enableCacheCmdlet.CacheRuntimeVersion, webRole.Startup.Task[0].Environment[0].value); Assert.AreEqual<string>(Resources.EmulatedKey, webRole.Startup.Task[2].Environment[0].name); Assert.AreEqual<string>("/RoleEnvironment/Deployment/@emulated", webRole.Startup.Task[2].Environment[0].RoleInstanceValue.xpath); Assert.AreEqual<string>(Resources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].name); Assert.AreEqual<string>(TestResources.CacheRuntimeUrl, webRole.Startup.Task[2].Environment[1].value); AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, webRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WebRole)); AzureAssert.StartupTaskExists(webRole.Startup.Task, Resources.CacheStartupCommand); AzureAssert.InternalEndpointExists(webRole.Endpoints.InternalEndpoint, new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }); LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; AzureAssert.LocalResourcesLocalStoreExists(localStore, webRole.LocalResources); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; AzureAssert.ConfigurationSettingExist(diagnosticLevel, webRole.ConfigurationSettings); ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue }; AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, roleSettings.ConfigurationSettings); AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebCloudConfig)); AssertWebConfig(string.Format(@"{0}\{1}\{2}", rootPath, webRoleName, Resources.WebConfigTemplateFileName)); Assert.AreEqual<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]); Assert.AreEqual<string>(webRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName)); }
public static void ConfigurationSettingExist(DefinitionConfigurationSetting expected, DefinitionConfigurationSetting[] actual) { Assert.IsTrue(Array.Exists<DefinitionConfigurationSetting>(actual, c => c.name == expected.name)); }
public void EnableAzureMemcacheRoleProcessOnWorkerRoleSuccess() { using (FileSystemHelper files = new FileSystemHelper(this)) { string serviceName = "AzureService"; string rootPath = files.CreateNewService(serviceName); string cacheRoleName = "CacheWorkerRole"; string workerRoleName = "WorkerRole"; string expectedMessage = string.Format(Resources.EnableMemcacheMessage, workerRoleName, cacheRoleName, Resources.MemcacheEndpointPort); addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = workerRoleName }; addNodeWorkerCmdlet.ExecuteCmdlet(); addCacheRoleCmdlet.AddAzureCacheWorkerRoleProcess(cacheRoleName, 1, rootPath); mockCommandRuntime.ResetPipelines(); enableCacheCmdlet.PassThru = true; enableCacheCmdlet.EnableAzureMemcacheRoleProcess(workerRoleName, cacheRoleName, rootPath); WorkerRole workerRole = Testing.GetWorkerRole(rootPath, workerRoleName); AzureAssert.RuntimeUrlAndIdExists(workerRole.Startup.Task, Resources.CacheRuntimeValue); AzureAssert.ScaffoldingExists(Path.Combine(files.RootPath, serviceName, workerRoleName), Path.Combine(Resources.CacheScaffolding, Resources.WorkerRole)); AzureAssert.StartupTaskExists(workerRole.Startup.Task, Resources.CacheStartupCommand); AzureAssert.InternalEndpointExists(workerRole.Endpoints.InternalEndpoint, new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }); LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; AzureAssert.LocalResourcesLocalStoreExists(localStore, workerRole.LocalResources); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; AzureAssert.ConfigurationSettingExist(diagnosticLevel, workerRole.ConfigurationSettings); ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting { name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue }; AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, Testing.GetCloudRole(rootPath, workerRoleName).ConfigurationSettings); AzureAssert.ConfigurationSettingExist(clientDiagnosticLevel, Testing.GetLocalRole(rootPath, workerRoleName).ConfigurationSettings); string workerConfigPath = string.Format(@"{0}\{1}\{2}", rootPath, workerRoleName, "web.config"); string workerCloudConfig = File.ReadAllText(workerConfigPath); Assert.IsTrue(workerCloudConfig.Contains("configSections")); Assert.IsTrue(workerCloudConfig.Contains("dataCacheClients")); Assert.AreEqual<string>(expectedMessage, mockCommandRuntime.VerboseStream[0]); Assert.AreEqual<string>(workerRoleName, (mockCommandRuntime.OutputPipeline[0] as PSObject).GetVariableValue<string>(Parameters.RoleName)); } }
/// <summary> /// Applies required configuration for enabling cache in SDK 1.8.0 version by: /// * Add MemcacheShim runtime installation. /// * Add startup task to install memcache shim on the client side. /// * Add default memcache internal endpoint. /// * Add cache diagnostic to local resources. /// * Add ClientDiagnosticLevel setting to service configuration. /// * Adjust web.config to enable auto discovery for the caching role. /// </summary> /// <param name="cloudServiceProject">The azure service instance</param> /// <param name="webRole">The web role to enable caching on</param> /// <param name="isWebRole">Flag indicating if the provided role is web or not</param> /// <param name="cacheWorkerRole">The memcache worker role name</param> /// <param name="startup">The role startup</param> /// <param name="endpoints">The role endpoints</param> /// <param name="localResources">The role local resources</param> /// <param name="configurationSettings">The role configuration settings</param> private void Version180Configuration( CloudServiceProject cloudServiceProject, string roleName, bool isWebRole, string cacheWorkerRole, Startup startup, Endpoints endpoints, LocalResources localResources, ref DefinitionConfigurationSetting[] configurationSettings) { if (isWebRole) { // Generate cache scaffolding for web role cloudServiceProject.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WebRole.ToString()), roleName, new Dictionary <string, object>()); // Adjust web.config to enable auto discovery for the caching role. string webCloudConfigPath = Path.Combine(cloudServiceProject.Paths.RootPath, roleName, Resources.WebCloudConfig); string webConfigPath = Path.Combine(cloudServiceProject.Paths.RootPath, roleName, Resources.WebConfigTemplateFileName); UpdateWebConfig(roleName, cacheWorkerRole, webCloudConfigPath); UpdateWebConfig(roleName, cacheWorkerRole, webConfigPath); } else { // Generate cache scaffolding for worker role Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters[ScaffoldParams.RoleName] = cacheWorkerRole; cloudServiceProject.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WorkerRole.ToString()), roleName, parameters); } // Add default memcache internal endpoint. InternalEndpoint memcacheEndpoint = new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }; endpoints.InternalEndpoint = General.ExtendArray <InternalEndpoint>(endpoints.InternalEndpoint, memcacheEndpoint); // Enable cache diagnostic LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; localResources.LocalStorage = General.ExtendArray <LocalStore>(localResources.LocalStorage, localStore); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; configurationSettings = General.ExtendArray <DefinitionConfigurationSetting>(configurationSettings, diagnosticLevel); // Add ClientDiagnosticLevel setting to service configuration. AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetCloudConfigRole(roleName)); AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetLocalConfigRole(roleName)); }
private static void CacheClientCommonConfiguration( CloudServiceProject cloudServiceProject, string roleName, bool isWebRole, string cacheWorkerRole, Startup startup, Endpoints endpoints, LocalResources localResources, ref DefinitionConfigurationSetting[] configurationSettings) { if (isWebRole) { // Generate cache scaffolding for web role cloudServiceProject.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WebRole.ToString()), roleName, new Dictionary<string, object>()); // Adjust web.config to enable auto discovery for the caching role. string webCloudConfigPath = Path.Combine(cloudServiceProject.Paths.RootPath, roleName, Resources.WebCloudConfig); string webConfigPath = Path.Combine(cloudServiceProject.Paths.RootPath, roleName, Resources.WebConfigTemplateFileName); UpdateWebConfig(roleName, cacheWorkerRole, webCloudConfigPath); UpdateWebConfig(roleName, cacheWorkerRole, webConfigPath); } else { // Generate cache scaffolding for worker role Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters[ScaffoldParams.RoleName] = cacheWorkerRole; cloudServiceProject.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WorkerRole.ToString()), roleName, parameters); } // Add default memcache internal endpoint. InternalEndpoint memcacheEndpoint = new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }; endpoints.InternalEndpoint = General.ExtendArray<InternalEndpoint>(endpoints.InternalEndpoint, memcacheEndpoint); // Enable cache diagnostic LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; localResources.LocalStorage = General.ExtendArray<LocalStore>(localResources.LocalStorage, localStore); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; configurationSettings = General.ExtendArray<DefinitionConfigurationSetting>(configurationSettings, diagnosticLevel); // Add ClientDiagnosticLevel setting to service configuration. AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetCloudConfigRole(roleName)); AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetLocalConfigRole(roleName)); }
/// <summary> /// Applies required configuration for enabling cache in SDK 1.8.0 version by: /// * Add MemcacheShim runtime installation. /// * Add startup task to install memcache shim on the client side. /// * Add default memcache internal endpoint. /// * Add cache diagnostic to local resources. /// * Add ClientDiagnosticLevel setting to service configuration. /// * Adjust web.config to enable auto discovery for the caching role. /// </summary> /// <param name="azureService">The azure service instance</param> /// <param name="webRole">The web role to enable caching on</param> /// <param name="isWebRole">Flag indicating if the provided role is web or not</param> /// <param name="cacheWorkerRole">The memcache worker role name</param> /// <param name="startup">The role startup</param> /// <param name="endpoints">The role endpoints</param> /// <param name="localResources">The role local resources</param> /// <param name="configurationSettings">The role configuration settings</param> private void Version180Configuration( AzureService azureService, string roleName, bool isWebRole, string cacheWorkerRole, Startup startup, Endpoints endpoints, LocalResources localResources, ref DefinitionConfigurationSetting[] configurationSettings) { if (isWebRole) { // Generate cache scaffolding for web role azureService.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WebRole.ToString()), roleName, new Dictionary<string, object>()); // Adjust web.config to enable auto discovery for the caching role. string webCloudConfigPath = Path.Combine(azureService.Paths.RootPath, roleName, Resources.WebCloudConfig); string webConfigPath = Path.Combine(azureService.Paths.RootPath, roleName, Resources.WebConfigTemplateFileName); UpdateWebConfig(roleName, cacheWorkerRole, webCloudConfigPath); UpdateWebConfig(roleName, cacheWorkerRole, webConfigPath); } else { // Generate cache scaffolding for worker role Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters[ScaffoldParams.RoleName] = cacheWorkerRole; azureService.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WorkerRole.ToString()), roleName, parameters); } // Add startup task to install memcache shim on the client side. string cacheRuntimeUri = CloudRuntimeCollection.GetRuntimeUrl(Resources.CacheRuntimeValue, CacheRuntimeVersion); Debug.Assert(!string.IsNullOrEmpty(cacheRuntimeUri)); Variable emulated = new Variable { name = Resources.EmulatedKey, RoleInstanceValue = new RoleInstanceValueElement { xpath = "/RoleEnvironment/Deployment/@emulated" } }; Variable[] env = { emulated, new Variable { name = Resources.CacheRuntimeUrl, value = cacheRuntimeUri } }; Task shimStartupTask = new Task { Environment = env, commandLine = Resources.CacheStartupCommand, executionContext = ExecutionContext.elevated }; startup.Task = General.ExtendArray<Task>(startup.Task, shimStartupTask); // Add default memcache internal endpoint. InternalEndpoint memcacheEndpoint = new InternalEndpoint { name = Resources.MemcacheEndpointName, protocol = InternalProtocol.tcp, port = Resources.MemcacheEndpointPort }; endpoints.InternalEndpoint = General.ExtendArray<InternalEndpoint>(endpoints.InternalEndpoint, memcacheEndpoint); // Enable cache diagnostic LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; localResources.LocalStorage = General.ExtendArray<LocalStore>(localResources.LocalStorage, localStore); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; configurationSettings = General.ExtendArray<DefinitionConfigurationSetting>(configurationSettings, diagnosticLevel); // Add ClientDiagnosticLevel setting to service configuration. AddClientDiagnosticLevelToConfig(azureService.Components.GetCloudConfigRole(roleName)); AddClientDiagnosticLevelToConfig(azureService.Components.GetLocalConfigRole(roleName)); }
/// <summary> /// Factory method to apply memcache required configuration based on the installed SDK version. /// </summary> /// <param name="azureService">The azure service instance</param> /// <param name="webRole">The web role to enable caching on</param> /// <param name="isWebRole">Flag indicating if the provided role is web or not</param> /// <param name="cacheWorkerRole">The memcache worker role name</param> /// <param name="startup">The role startup</param> /// <param name="endpoints">The role endpoints</param> /// <param name="localResources">The role local resources</param> /// <param name="configurationSettings">The role configuration settings</param> /// <param name="sdkVersion">The current SDK version</param> private void CachingConfigurationFactoryMethod( AzureService azureService, string roleName, bool isWebRole, string cacheWorkerRole, Startup startup, Endpoints endpoints, LocalResources localResources, ref DefinitionConfigurationSetting[] configurationSettings, string sdkVersion) { switch (sdkVersion) { case SDKVersion.Version180: Version180Configuration( azureService, roleName, isWebRole, cacheWorkerRole, startup, endpoints, localResources, ref configurationSettings); break; default: throw new Exception(string.Format(Resources.AzureSdkVersionNotSupported, Resources.MinSupportAzureSdkVersion, Resources.MaxSupportAzureSdkVersion)); } }