public CloudServiceProject StartAzureEmulatorProcess(string rootPath) { string standardOutput; string standardError; StringBuilder message = new StringBuilder(); CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath ,null); if (Directory.Exists(cloudServiceProject.Paths.LocalPackage)) { WriteVerbose(Resources.StopEmulatorMessage); cloudServiceProject.StopEmulator(out standardOutput, out standardError); WriteVerbose(Resources.StoppedEmulatorMessage); WriteVerbose(string.Format(Resources.RemovePackage, cloudServiceProject.Paths.LocalPackage)); Directory.Delete(cloudServiceProject.Paths.LocalPackage, true); } WriteVerbose(string.Format(Resources.CreatingPackageMessage, "local")); cloudServiceProject.CreatePackage(DevEnv.Local, out standardOutput, out standardError); WriteVerbose(Resources.StartingEmulator); cloudServiceProject.ResolveRuntimePackageUrls(); cloudServiceProject.StartEmulator(Launch.ToBool(), out standardOutput, out standardError); WriteVerbose(standardOutput); WriteVerbose(Resources.StartedEmulator); SafeWriteOutputPSObject( cloudServiceProject.GetType().FullName, Parameters.ServiceName, cloudServiceProject.ServiceName, Parameters.RootPath, cloudServiceProject.Paths.RootPath); return cloudServiceProject; }
public WorkerRole AddAzureCacheWorkerRoleProcess(string workerRoleName, int instances, string rootPath) { // Create cache worker role. Action<string, RoleInfo> cacheWorkerRoleAction = CacheConfigurationFactory.GetCacheRoleConfigurationAction( AzureTool.GetAzureSdkVersion()); 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 void CreateLocalPackageWithNodeWorkerRoleTest() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWorkerRole(Data.NodeWorkerRoleScaffoldingPath); service.CreatePackage(DevEnv.Local); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WorkerRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WorkerRole)); } }
/// <summary> /// The code to run if setting azure instances /// </summary> /// <param name="roleName">The name of the role to update</param> /// <param name="instances">The new number of instances for the role</param> /// <param name="rootPath">The root path to the service containing the role</param> /// <returns>Role after updating instance count</returns> public RoleSettings SetAzureInstancesProcess(string roleName, int instances, string rootPath) { CloudServiceProject service = new CloudServiceProject(rootPath, null); service.SetRoleInstances(service.Paths, roleName, instances); if (PassThru) { SafeWriteOutputPSObject(typeof(RoleSettings).FullName, Parameters.RoleName, roleName); } return service.Components.GetCloudConfigRole(roleName); }
public void StopAzureEmulatorProcess() { CloudServiceProject service = new CloudServiceProject(); WriteVerbose(Resources.StopEmulatorMessage); service.StopEmulator(); WriteVerbose(Resources.StoppedEmulatorMessage); if (PassThru.IsPresent) { WriteObject(true); } }
public CloudServiceProject StartAzureEmulatorProcess(string rootPath) { string warning; string roleInformation; StringBuilder message = new StringBuilder(); CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null); if (Directory.Exists(cloudServiceProject.Paths.LocalPackage)) { WriteVerbose(Resources.StopEmulatorMessage); cloudServiceProject.StopEmulators(out warning); if (!string.IsNullOrEmpty(warning)) { WriteWarning(warning); } WriteVerbose(Resources.StoppedEmulatorMessage); string packagePath = cloudServiceProject.Paths.LocalPackage; WriteVerbose(string.Format(Resources.RemovePackage, packagePath)); try { Directory.Delete(packagePath, true); } catch (IOException) { throw new InvalidOperationException(string.Format(Resources.FailedToCleanUpLocalPackage, packagePath)); } } WriteVerbose(string.Format(Resources.CreatingPackageMessage, "local")); cloudServiceProject.CreatePackage(DevEnv.Local); WriteVerbose(Resources.StartingEmulator); cloudServiceProject.ResolveRuntimePackageUrls(); cloudServiceProject.StartEmulators(Launch.ToBool(), Mode, out roleInformation, out warning); WriteVerbose(roleInformation); if (!string.IsNullOrEmpty(warning)) { WriteWarning(warning); } WriteVerbose(Resources.StartedEmulator); SafeWriteOutputPSObject( cloudServiceProject.GetType().FullName, Parameters.ServiceName, cloudServiceProject.ServiceName, Parameters.RootPath, cloudServiceProject.Paths.RootPath); return cloudServiceProject; }
private static void VerifyDisableRoleSettings(CloudServiceProject service) { IEnumerable<RoleSettings> settings = Enumerable.Concat( service.Components.CloudConfig.Role, service.Components.LocalConfig.Role); foreach (RoleSettings roleSettings in settings) { Assert.AreEqual( 1, roleSettings.ConfigurationSettings .Where(c => c.name == "Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" && c.value == "false") .Count()); } }
internal CloudServiceProject NewAzureServiceProcess(string parentDirectory, string serviceName) { // Create scaffolding structure // CloudServiceProject newService = new CloudServiceProject(parentDirectory, serviceName, null); SafeWriteOutputPSObject( newService.GetType().FullName, Parameters.ServiceName, newService.ServiceName, Parameters.RootPath, newService.Paths.RootPath ); WriteVerbose(string.Format(Resources.NewServiceCreatedMessage, newService.Paths.RootPath)); return newService; }
public void TestStartAzureService() { stopServiceCmdlet.ServiceName = serviceName; stopServiceCmdlet.Slot = slot; cloudServiceClientMock.Setup(f => f.StartCloudService(serviceName, slot)); using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); stopServiceCmdlet.ExecuteCmdlet(); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); cloudServiceClientMock.Verify(f => f.StartCloudService(serviceName, slot), Times.Once()); } }
public void StopAzureEmulatorProcess() { string standardOutput; string standardError; CloudServiceProject service = new CloudServiceProject(); WriteVerbose(Resources.StopEmulatorMessage); service.StopEmulator(out standardOutput, out standardError); WriteVerbose(Resources.StoppedEmulatorMessage); if (PassThru.IsPresent) { WriteObject(true); } }
public void CreateLocalPackageWithOnePHPWebRoleTest() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); RoleInfo webRoleInfo = service.AddWebRole(Data.PHPWebRoleScaffoldingPath); string logsDir = Path.Combine(service.Paths.RootPath, webRoleInfo.Name, "server.js.logs"); string logFile = Path.Combine(logsDir, "0.txt"); string targetLogsFile = Path.Combine(service.Paths.LocalPackage, "roles", webRoleInfo.Name, @"approot\server.js.logs\0.txt"); files.CreateDirectory(logsDir); files.CreateEmptyFile(logFile); service.CreatePackage(DevEnv.Local); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WebRole1\approot"), Path.Combine(Resources.PHPScaffolding, Resources.WebRole)); Assert.IsTrue(File.Exists(targetLogsFile)); } }
public void SetAzureVMSizeProcessTestsNode() { string newRoleVMSize = RoleSize.Large.ToString(); using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.NodeWebRoleScaffoldingPath); cmdlet.PassThru = false; RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath); service = new CloudServiceProject(service.Paths.RootPath, null); Assert.AreEqual<string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString()); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void DisableRemoteDesktop() { CloudServiceProject service = new CloudServiceProject(General.GetServiceRootPath(CurrentPath()), null); WebRole[] webRoles = service.Components.Definition.WebRole ?? new WebRole[0]; WorkerRole[] workerRoles = service.Components.Definition.WorkerRole ?? new WorkerRole[0]; string forwarderName = GetForwarderName(webRoles, workerRoles); if (forwarderName != null) { UpdateServiceConfigurations(service, forwarderName); service.Components.Save(service.Paths); } if (PassThru) { WriteObject(true); } }
public void TestSetAzureRuntimeValidRuntimeVersions() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); string roleName = "WebRole1"; cmdlet.PassThru = false; RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(roleName, "node", "0.8.2", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(roleName, "iisnode", "0.1.21", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); VerifyPackageJsonVersion(service.Paths.RootPath, roleName, "node", "0.8.2"); VerifyPackageJsonVersion(service.Paths.RootPath, roleName, "iisnode", "0.1.21"); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); Assert.AreEqual<string>(roleName, roleSettings1.name); Assert.AreEqual<string>(roleName, roleSettings2.name); } }
public void StopAzureEmulatorProcess() { CloudServiceProject service = new CloudServiceProject(); WriteVerbose(Resources.StopEmulatorMessage); string warning; service.StopEmulators(out warning); if (!string.IsNullOrEmpty(warning)) { WriteWarning(warning); } WriteVerbose(Resources.StoppedEmulatorMessage); if (PassThru.IsPresent) { WriteObject(true); } }
public void SetAzureVMSizeProcessTestsPHP() { string newRoleVMSize = RoleSize.Medium.ToString(); using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.PHPWebRoleScaffoldingPath); RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath); service = new CloudServiceProject(service.Paths.RootPath, null); Assert.AreEqual<string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString()); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString()); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void TestCreatePackageSuccessfull() { 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); CloudServiceProject service = new CloudServiceProject(rootPath, FileUtilities.GetContentFilePath("Services")); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); cmdlet.ExecuteCmdlet(); PSObject obj = mockCommandRuntime.OutputPipeline[0] as PSObject; Assert.AreEqual<string>(string.Format(Resources.PackageCreated, packagePath), mockCommandRuntime.VerboseStream[0]); Assert.AreEqual<string>(packagePath, obj.GetVariableValue<string>(Parameters.PackagePath)); Assert.IsTrue(File.Exists(packagePath)); } }
public void SetAzureInstancesProcessTestsPHP() { int newRoleInstances = 10; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.PHPWebRoleScaffoldingPath); RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath); service = new CloudServiceProject(service.Paths.RootPath, null); Assert.AreEqual<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count); Assert.AreEqual<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString()); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.AreEqual<int>(newRoleInstances, roleSettings.Instances.count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void SetAzureInstancesProcessTestsNode() { int newRoleInstances = 10; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.NodeWebRoleScaffoldingPath); cmdlet.PassThru = false; RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath); service = new CloudServiceProject(service.Paths.RootPath, null); Assert.AreEqual<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count); Assert.AreEqual<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); Assert.AreEqual<int>(newRoleInstances, roleSettings.Instances.count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void EnableRemoteDesktop() { Validate.ValidateStringIsNullOrEmpty(Username, "Username"); if (Password == null) { throw new ArgumentNullException("Password"); } string plainPassword = GetPlainPassword(); if (!IsPasswordComplex(plainPassword)) { throw new ArgumentException(Resources.EnableAzureRemoteDesktopCommand_Enable_NeedComplexPassword); } CloudServiceProject service = new CloudServiceProject(CommonUtilities.GetServiceRootPath(CurrentPath()), null); WebRole[] webRoles = service.Components.Definition.WebRole ?? new WebRole[0]; WorkerRole[] workerRoles = service.Components.Definition.WorkerRole ?? new WorkerRole[0]; string forwarderName = GetForwarderName(webRoles, workerRoles); RemoveOtherRemoteForwarders(webRoles, workerRoles, forwarderName); AddRemoteAccess(webRoles, workerRoles); X509Certificate2 cert = ChooseCertificate(); Certificate certElement = new Certificate { name = "Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption", thumbprintAlgorithm = ThumbprintAlgorithmTypes.sha1, thumbprint = cert.Thumbprint }; string encryptedPassword = Encrypt(plainPassword, cert); UpdateServiceConfigurations(service, forwarderName, certElement, encryptedPassword); service.Components.Save(service.Paths); if (PassThru) { WriteObject(true); } }
public override void ExecuteCmdlet() { AzureTool.Validate(); string rootPath = GeneralUtilities.GetServiceRootPath(CurrentPath()); string packagePath; CloudServiceProject service = new CloudServiceProject(rootPath, null); if (!Local.IsPresent) { service.CreatePackage(DevEnv.Cloud); packagePath = Path.Combine(rootPath, Resources.CloudPackageFileName); } else { service.CreatePackage(DevEnv.Local); packagePath = Path.Combine(rootPath, Resources.LocalPackageFileName); } WriteVerbose(string.Format(Resources.PackageCreated, packagePath)); SafeWriteOutputPSObject(typeof(PSObject).FullName, Parameters.PackagePath, packagePath); }
public void SetAzureVMSizeProcessTestsRoleNameDoesNotExistFail() { string roleName = "WebRole1"; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, roleName, RoleSize.Medium.ToString()), string.Format(Resources.RoleNotFoundMessage, roleName)); } }
/// <summary> /// Gets the role settings object from local service configuration. /// </summary> /// <param name="rootPath">The azure service rootPath path</param> /// <returns>The role settings object</returns> internal static RoleSettings GetLocalRole(string rootPath, string name) { CloudServiceProject service = new CloudServiceProject(rootPath, null); return(service.Components.GetLocalConfigRole(name)); }
/// <summary> /// Gets web role object from service definition. /// </summary> /// <param name="rootPath">The azure service rootPath path</param> /// <returns>The web role object</returns> internal static WebRole GetWebRole(string rootPath, string name) { CloudServiceProject service = new CloudServiceProject(rootPath, null); return(service.Components.GetWebRole(name)); }
public void SetAzureVMSizeProcessTestsNullRoleNameFail() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, null, RoleSize.Large.ToString()), string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.RoleName)); } }
public void SetAzureVMSizeProcessNegativeRoleInstanceFail() { string roleName = "WebRole1"; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, roleName, string.Empty), string.Format(Resources.InvalidVMSize, roleName)); } }
/// <summary> /// Gets web role object from service definition. /// </summary> /// <param name="rootPath">The azure service rootPath path</param> /// <returns>The web role object</returns> internal static WebRole GetWebRole(string rootPath, string name) { CloudServiceProject service = new CloudServiceProject(rootPath, FileUtilities.GetContentFilePath("Services")); return(service.Components.GetWebRole(name)); }
/// <summary> /// Gets the role settings object from local service configuration. /// </summary> /// <param name="rootPath">The azure service rootPath path</param> /// <returns>The role settings object</returns> internal static RoleSettings GetLocalRole(string rootPath, string name) { CloudServiceProject service = new CloudServiceProject(rootPath, FileUtilities.GetContentFilePath("Services")); return(service.Components.GetLocalConfigRole(name)); }
public RoleSettings SetAzureRuntimesProcess( string roleName, string runtimeType, string runtimeVersion, string rootPath, string manifest = null) { CloudServiceProject service = new CloudServiceProject(rootPath, null); service.AddRoleRuntime(service.Paths, roleName, runtimeType, runtimeVersion, manifest); if (PassThru) { SafeWriteOutputPSObject(typeof(RoleSettings).FullName, Parameters.RoleName, roleName); } return service.Components.GetCloudConfigRole(roleName); }
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)); }
public void GetNextPortWithEmptyPortIndpoints() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultPort); CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); service.Components.Definition.WebRole[0].Endpoints.InputEndpoint = null; service.Components.Save(service.Paths); service.AddWebRole(Data.PHPWebRoleScaffoldingPath); service = new AzureServiceWrapper(service.Paths.RootPath, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
public void GetNextPortAddingThirdEndpoint() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultPort) + 1; CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); service.AddWebRole(Data.PHPWebRoleScaffoldingPath); service = new AzureServiceWrapper(service.Paths.RootPath, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
public void GetNextPortNullPHPWebEndpointAndWorkerRole() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultPort); CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.PHPWebRoleScaffoldingPath); service.Components.Definition.WebRole.ToList().ForEach(wr => wr.Endpoints = null); service.AddWorkerRole(Data.PHPWorkerRoleScaffoldingPath); service = new CloudServiceProject(service.Paths.RootPath, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
/// <summary> /// Main entry for enabling memcache. /// </summary> /// <param name="roleName">The web role name</param> /// <param name="cacheWorkerRoleName">The cache worker role name</param> /// <param name="rootPath">The service root path</param> /// <param name="message">The resulted message</param> /// <param name="cloudServiceProject">The azure service instance</param> /// <param name="webRole">The web role to enable caching one</param> private void EnableMemcache(string roleName, string cacheWorkerRoleName, ref string message, ref CloudServiceProject cloudServiceProject) { // Add MemcacheShim runtime installation. cloudServiceProject.AddRoleRuntime(cloudServiceProject.Paths, roleName, Resources.CacheRuntimeValue, CacheRuntimeVersion); // Fetch web role information. Startup startup = cloudServiceProject.Components.GetRoleStartup(roleName); // Assert that cache runtime is added to the runtime startup. Debug.Assert(Array.Exists <Variable>(CloudRuntime.GetRuntimeStartupTask(startup).Environment, v => v.name.Equals(Resources.RuntimeTypeKey) && v.value.Contains(Resources.CacheRuntimeValue))); if (cloudServiceProject.Components.IsWebRole(roleName)) { WebRole webRole = cloudServiceProject.Components.GetWebRole(roleName); webRole.LocalResources = GeneralUtilities.InitializeIfNull <LocalResources>(webRole.LocalResources); DefinitionConfigurationSetting[] configurationSettings = webRole.ConfigurationSettings; CachingConfigurationFactoryMethod( cloudServiceProject, roleName, true, cacheWorkerRoleName, webRole.Startup, webRole.Endpoints, webRole.LocalResources, ref configurationSettings, CacheRuntimeVersion); webRole.ConfigurationSettings = configurationSettings; } else { WorkerRole workerRole = cloudServiceProject.Components.GetWorkerRole(roleName); workerRole.LocalResources = GeneralUtilities.InitializeIfNull <LocalResources>(workerRole.LocalResources); DefinitionConfigurationSetting[] configurationSettings = workerRole.ConfigurationSettings; CachingConfigurationFactoryMethod( cloudServiceProject, roleName, false, cacheWorkerRoleName, workerRole.Startup, workerRole.Endpoints, workerRole.LocalResources, ref configurationSettings, CacheRuntimeVersion); workerRole.ConfigurationSettings = configurationSettings; } // Save changes cloudServiceProject.Components.Save(cloudServiceProject.Paths); message = string.Format(Resources.EnableMemcacheMessage, roleName, cacheWorkerRoleName, Resources.MemcacheEndpointPort); }
/// <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 = GeneralUtilities.ExtendArray <InternalEndpoint>(endpoints.InternalEndpoint, memcacheEndpoint); // Enable cache diagnostic LocalStore localStore = new LocalStore { name = Resources.CacheDiagnosticStoreName, cleanOnRoleRecycle = false }; localResources.LocalStorage = GeneralUtilities.ExtendArray <LocalStore>(localResources.LocalStorage, localStore); DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting { name = Resources.CacheClientDiagnosticLevelAssemblyName }; configurationSettings = GeneralUtilities.ExtendArray <DefinitionConfigurationSetting>(configurationSettings, diagnosticLevel); // Add ClientDiagnosticLevel setting to service configuration. AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetCloudConfigRole(roleName)); AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetLocalConfigRole(roleName)); }
public void SetAzureVMSizeProcessTestsNodeRoleNameDoesNotExistServiceContainsWebRoleFail() { string roleName = "WebRole1"; string invalidRoleName = "foo"; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath, roleName, 1); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, invalidRoleName, RoleSize.Large.ToString()), string.Format(Resources.RoleNotFoundMessage, invalidRoleName)); } }
public void EnableDisableEnableRemoteDesktopForWebAndWorkerRoles() { using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); string rootPath = files.CreateNewService("NEW_SERVICE"); addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WebRole" }; addNodeWebCmdlet.ExecuteCmdlet(); addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = "WorkerRole" }; addNodeWorkerCmdlet.ExecuteCmdlet(); EnableAzureRemoteDesktopCommandTest.EnableRemoteDesktop("user", "GoodPassword!"); disableRDCmdlet.DisableRemoteDesktop(); EnableAzureRemoteDesktopCommandTest.EnableRemoteDesktop("user", "GoodPassword!"); // Verify the roles have been setup with forwarding, access, // and certs CloudServiceProject service = new CloudServiceProject(rootPath, FileUtilities.GetContentFilePath("Services")); EnableAzureRemoteDesktopCommandTest.VerifyWebRole(service.Components.Definition.WebRole[0], false); EnableAzureRemoteDesktopCommandTest.VerifyWorkerRole(service.Components.Definition.WorkerRole[0], true); EnableAzureRemoteDesktopCommandTest.VerifyRoleSettings(service); } }
/// <summary> /// This method handles most possible cases that user can do to create role /// </summary> /// <param name="webRole">Count of web roles to add</param> /// <param name="workerRole">Count of worker role to add</param> /// <param name="addWebBeforeWorker">Decides in what order to add roles. There are three options, note that value between brackets is the value to pass: /// 1. Web then, interleaving (0): interleave adding and start by adding web role first. /// 2. Worker then, interleaving (1): interleave adding and start by adding worker role first. /// 3. Web then worker (2): add all web roles then worker roles. /// 4. Worker then web (3): add all worker roles then web roles. /// By default this parameter is set to 0 /// </param> private void AddNodeRoleTest(int webRole, int workerRole, int order = 0) { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureServiceWrapper wrappedService = new AzureServiceWrapper(files.RootPath, serviceName, null); CloudServiceProject service = new CloudServiceProject(Path.Combine(files.RootPath, serviceName), null); WebRoleInfo[] webRoles = null; if (webRole > 0) { webRoles = new WebRoleInfo[webRole]; for (int i = 0; i < webRoles.Length; i++) { webRoles[i] = new WebRoleInfo(string.Format("{0}{1}", Resources.WebRole, i + 1), 1); } } WorkerRoleInfo[] workerRoles = null; if (workerRole > 0) { workerRoles = new WorkerRoleInfo[workerRole]; for (int i = 0; i < workerRoles.Length; i++) { workerRoles[i] = new WorkerRoleInfo(string.Format("{0}{1}", Resources.WorkerRole, i + 1), 1); } } RoleInfo[] roles = (webRole + workerRole > 0) ? new RoleInfo[webRole + workerRole] : null; if (order == 0) { for (int i = 0, w = 0, wo = 0; i < webRole + workerRole;) { if (w++ < webRole) { roles[i++] = wrappedService.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath); } if (wo++ < workerRole) { roles[i++] = wrappedService.AddWorkerRole(Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath); } } } else if (order == 1) { for (int i = 0, w = 0, wo = 0; i < webRole + workerRole;) { if (wo++ < workerRole) { roles[i++] = wrappedService.AddWorkerRole(Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath); } if (w++ < webRole) { roles[i++] = wrappedService.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath); } } } else if (order == 2) { wrappedService.AddRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, webRole, workerRole); webRoles.CopyTo(roles, 0); Array.Copy(workerRoles, 0, roles, webRole, workerRoles.Length); } else if (order == 3) { wrappedService.AddRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, 0, workerRole); workerRoles.CopyTo(roles, 0); wrappedService.AddRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, webRole, 0); Array.Copy(webRoles, 0, roles, workerRole, webRoles.Length); } else { throw new ArgumentException("value for order parameter is unknown"); } AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, webRoles: webRoles, workerRoles: workerRoles, webScaff: Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath, workerScaff: Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath, roles: roles); } }
public void TestResolveRuntimePackageUrls() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; string rootPath = files.CreateNewService(serviceName); // Add web and worker roles string defaultWebRoleName = "WebRoleDefault"; addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = defaultWebRoleName, Instances = 2 }; addNodeWebCmdlet.ExecuteCmdlet(); string defaultWorkerRoleName = "WorkerRoleDefault"; addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = defaultWorkerRoleName, Instances = 2 }; addNodeWorkerCmdlet.ExecuteCmdlet(); AddAzureNodeWebRoleCommand matchWebRole = addNodeWebCmdlet; string matchWebRoleName = "WebRoleExactMatch"; addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = matchWebRoleName, Instances = 2 }; addNodeWebCmdlet.ExecuteCmdlet(); AddAzureNodeWorkerRoleCommand matchWorkerRole = addNodeWorkerCmdlet; string matchWorkerRoleName = "WorkerRoleExactMatch"; addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = matchWorkerRoleName, Instances = 2 }; addNodeWorkerCmdlet.ExecuteCmdlet(); AddAzureNodeWebRoleCommand overrideWebRole = addNodeWebCmdlet; string overrideWebRoleName = "WebRoleOverride"; addNodeWebCmdlet = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = overrideWebRoleName, Instances = 2 }; addNodeWebCmdlet.ExecuteCmdlet(); AddAzureNodeWorkerRoleCommand overrideWorkerRole = addNodeWorkerCmdlet; string overrideWorkerRoleName = "WorkerRoleOverride"; addNodeWorkerCmdlet = new AddAzureNodeWorkerRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = overrideWorkerRoleName, Instances = 2 }; addNodeWorkerCmdlet.ExecuteCmdlet(); string webRole2Name = "WebRole2"; AddAzureNodeWebRoleCommand addAzureWebRole = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = webRole2Name }; addAzureWebRole.ExecuteCmdlet(); CloudServiceProject testService = new CloudServiceProject(rootPath, FileUtilities.GetContentFilePath(@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Services")); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWebRoleName, testService.Paths, version: "0.8.2"); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWorkerRoleName, testService.Paths, version: "0.8.2"); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWebRoleName, testService.Paths, overrideUrl: "http://OVERRIDE"); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWorkerRoleName, testService.Paths, overrideUrl: "http://OVERRIDE"); bool exceptionWasThrownOnSettingCacheRole = false; try { string cacheRuntimeVersion = "1.7.0"; testService.AddRoleRuntime(testService.Paths, webRole2Name, Resources.CacheRuntimeValue, cacheRuntimeVersion, RuntimePackageHelper.GetTestManifest(files)); } catch (NotSupportedException) { exceptionWasThrownOnSettingCacheRole = true; } Assert.True(exceptionWasThrownOnSettingCacheRole); testService.Components.Save(testService.Paths); // Get the publishing process started by creating the package testService.ResolveRuntimePackageUrls(RuntimePackageHelper.GetTestManifest(files)); CloudServiceProject updatedService = new CloudServiceProject(testService.Paths.RootPath, null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWebRoleName, "http://cdn/node/default.exe;http://cdn/iisnode/default.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWorkerRoleName, "http://cdn/node/default.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWorkerRoleName, "http://cdn/node/foo.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWebRoleName, "http://cdn/node/foo.exe;http://cdn/iisnode/default.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWebRoleName, null, "http://OVERRIDE"); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWorkerRoleName, null, "http://OVERRIDE"); } }