public WorkerRole AddAzureCacheWorkerRoleProcess(string workerRoleName, int instances, string rootPath) { // Create cache worker role. Action <string, RoleInfo> cacheWorkerRoleAction = CacheConfigurationFactory.GetCacheRoleConfigurationAction( new AzureTool().AzureSdkVersion); CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null); RoleInfo genericWorkerRole = cloudServiceProject.AddWorkerRole( Path.Combine(Resources.GeneralScaffolding, RoleType.WorkerRole.ToString()), workerRoleName, instances); // Dedicate the worker role for caching. cacheWorkerRoleAction(cloudServiceProject.Paths.RootPath, genericWorkerRole); cloudServiceProject.Reload(); WorkerRole cacheWorkerRole = cloudServiceProject.Components.GetWorkerRole(genericWorkerRole.Name); // Write output SafeWriteOutputPSObject( cacheWorkerRole.GetType().FullName, Parameters.CacheWorkerRoleName, genericWorkerRole.Name, Parameters.Instances, genericWorkerRole.InstanceCount ); return(cloudServiceProject.Components.GetWorkerRole(workerRoleName)); }
public WebRole EnableAzureMemcacheRoleProcess(string roleName, string cacheWorkerRoleName, string rootPath) { CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null); if (string.IsNullOrEmpty(cacheWorkerRoleName)) { WorkerRole defaultCache = cloudServiceProject.Components.Definition.WorkerRole.FirstOrDefault <WorkerRole>( w => w.Imports != null && w.Imports.Any(i => i.moduleName.Equals(Resources.CachingModuleName))); if (defaultCache == null) { throw new Exception(Resources.NoCacheWorkerRoles); } cacheWorkerRoleName = defaultCache.name; } // Verify cache worker role exists if (!cloudServiceProject.Components.RoleExists(cacheWorkerRoleName)) { throw new Exception(string.Format(Resources.RoleNotFoundMessage, cacheWorkerRoleName)); } WorkerRole cacheWorkerRole = cloudServiceProject.Components.GetWorkerRole(cacheWorkerRoleName); // Verify that the cache worker role has proper caching configuration. if (!IsCacheWorkerRole(cacheWorkerRole)) { throw new Exception(string.Format(Resources.NotCacheWorkerRole, cacheWorkerRoleName)); } // Verify that user is not trying to enable cache on a cache worker role. if (roleName.Equals(cacheWorkerRole)) { throw new Exception(string.Format(Resources.InvalidCacheRoleName, roleName)); } // Verify role to enable cache on exists if (!cloudServiceProject.Components.RoleExists(roleName)) { throw new Exception(string.Format(Resources.RoleNotFoundMessage, roleName)); } // Verify that caching is not enabled for the role if (IsCacheEnabled(cloudServiceProject.Components.GetRoleStartup(roleName))) { throw new Exception(string.Format(Resources.CacheAlreadyEnabledMessage, roleName)); } // All validations passed, enable caching. //EnableMemcache(roleName, cacheWorkerRoleName, ref message, ref cloudServiceProject); var applyConfiguration = CacheConfigurationFactory.GetClientRoleConfigurationAction(CacheRuntimeVersion); applyConfiguration(cloudServiceProject, roleName, cacheWorkerRoleName); string message = string.Format( Resources.EnableMemcacheMessage, roleName, cacheWorkerRoleName, Resources.MemcacheEndpointPort); WriteVerbose(message); if (PassThru) { SafeWriteOutputPSObject(typeof(RoleSettings).FullName, Parameters.RoleName, roleName); } return(cloudServiceProject.Components.GetWebRole(roleName)); }