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 void TestCreateStorageServiceWithPublish() { using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Setup string rootPath = files.CreateNewService(serviceName); files.CreateAzureSdkDirectoryAndImportPublishSettings(); CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null); cloudServiceProject.AddWebRole(Data.NodeWebRoleScaffoldingPath); cloudService.Deployments.Add(deployment); serviceManagementChannelMock.Setup(f => f.EndGetStorageService(It.IsAny<IAsyncResult>())) .Callback(() => serviceManagementChannelMock.Setup(f => f.EndGetStorageService( It.IsAny<IAsyncResult>())) .Returns(storageService)) .Throws(new EndpointNotFoundException()); ExecuteInTempCurrentDirectory(rootPath, () => client.PublishCloudService(location: "West US")); serviceManagementChannelMock.Verify(f => f.BeginCreateStorageService( subscription.SubscriptionId, It.IsAny<CreateStorageServiceInput>(), null, null), Times.Once()); } }
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 void SetAzureInstancesProcessTestsEmptyRoleNameFail() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, string.Empty, 10), string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.RoleName)); } }
public void GetNextPortAllNull() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultWebPort); CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
public void SetAzureInstancesProcessNegativeRoleInstanceFail() { string roleName = "WebRole1"; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, roleName, -1), string.Format(Resources.InvalidInstancesCount, roleName)); } }
public void GetNextPortNodeWebRoleNull() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultPort); CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWorkerRole(Data.NodeWorkerRoleScaffoldingPath); service = new CloudServiceProject(service.Paths.RootPath, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
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 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 TestStopAzureService() { stopServiceCmdlet.ServiceName = serviceName; stopServiceCmdlet.Slot = slot; cloudServiceClientMock.Setup(f => f.StopCloudService(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.StopCloudService(serviceName, slot), Times.Once()); } }
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 TestSetAzureRuntimeInvalidRuntimeType() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.NodeWebRoleScaffoldingPath); RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(roleName, "noide", "0.8.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(roleName, "iisnoide", "0.9.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "node", "*"); VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "iisnode", "*"); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString()); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[1]).Members[Parameters.RoleName].Value.ToString()); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[1]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.AreEqual<string>(roleName, roleSettings1.name); Assert.AreEqual<string>(roleName, roleSettings2.name); } }
public void SetAzureVMSizeProcessTestsCaseInsensitiveVMSizeSize() { string newRoleVMSize = "ExTraLaRge"; 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.ToLower(), service.Components.Definition.WebRole[0].vmsize.ToString().ToLower()); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void CreateLocalPackageWithMultipleRoles() { using (FileSystemHelper files = new FileSystemHelper(this)) { string standardOutput; string standardError; CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWorkerRole(Data.NodeWorkerRoleScaffoldingPath); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); service.AddWorkerRole(Data.PHPWorkerRoleScaffoldingPath); service.AddWebRole(Data.PHPWebRoleScaffoldingPath); service.CreatePackage(DevEnv.Local, out standardOutput, out standardError); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WorkerRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WorkerRole)); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WebRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WebRole)); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WorkerRole2\approot"), Path.Combine(Resources.PHPScaffolding, Resources.WorkerRole)); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WebRole2\approot"), Path.Combine(Resources.PHPScaffolding, Resources.WebRole)); } }
public void CreateCloudPackageWithMultipleRoles() { using (FileSystemHelper files = new FileSystemHelper(this)) { string standardOutput; string standardError; CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWorkerRole(Data.NodeWorkerRoleScaffoldingPath); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); service.AddWorkerRole(Data.PHPWorkerRoleScaffoldingPath); service.AddWebRole(Data.PHPWebRoleScaffoldingPath); service.CreatePackage(DevEnv.Cloud, out standardOutput, out standardError); using (Package package = Package.Open(service.Paths.CloudPackage)) { Assert.AreEqual(9, package.GetParts().Count()); } } }
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, null); 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 SetAzureInstancesProcessTestsCaseInsensitive() { 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 TestPublishNewCloudService() { using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Setup string rootPath = files.CreateNewService(serviceName); files.CreateAzureSdkDirectoryAndImportPublishSettings(); CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null); cloudServiceProject.AddWebRole(Data.NodeWebRoleScaffoldingPath); ExecuteInTempCurrentDirectory(rootPath, () => client.PublishCloudService(location: "West US")); serviceManagementChannelMock.Verify(f => f.BeginCreateOrUpdateDeployment( subscription.SubscriptionId, serviceName, DeploymentSlotType.Production, It.IsAny<CreateDeploymentInput>(), null, null), Times.Once()); } }
public override void ExecuteCmdlet() { AzureTool.Validate(); string unused; string rootPath = General.GetServiceRootPath(CurrentPath()); string packagePath; CloudServiceProject service = new CloudServiceProject(rootPath, null); if (!Local.IsPresent) { service.CreatePackage(DevEnv.Cloud, out unused, out unused); packagePath = Path.Combine(rootPath, Resources.CloudPackageFileName); } else { service.CreatePackage(DevEnv.Local, out unused, out unused); packagePath = Path.Combine(rootPath, Resources.LocalPackageFileName); } WriteVerbose(string.Format(Resources.PackageCreated, packagePath)); SafeWriteOutputPSObject(typeof(PSObject).FullName, Parameters.PackagePath, packagePath); }
private void UpdateCacheWorkerRolesCloudConfiguration(PublishContext context) { string connectionString = GetStorageServiceConnectionString(context.ServiceSettings.StorageServiceName); CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null); ConfigConfigurationSetting connectionStringConfig = new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = string.Empty }; cloudServiceProject.Components.ForEachRoleSettings( r => Array.Exists<ConfigConfigurationSetting>(r.ConfigurationSettings, c => c.Equals(connectionStringConfig)), delegate(RoleSettings r) { int index = Array.IndexOf<ConfigConfigurationSetting>(r.ConfigurationSettings, connectionStringConfig); r.ConfigurationSettings[index] = new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = connectionString }; }); cloudServiceProject.Components.Save(cloudServiceProject.Paths); }
private void PrepareCloudServicePackagesRuntime(PublishContext context) { CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null); string warning = cloudServiceProject.ResolveRuntimePackageUrls(); if (!string.IsNullOrEmpty(warning)) { WriteWarning(Resources.RuntimeMismatchWarning, context.ServiceName); WriteWarning(warning); } }
private void AddCertificates(CertificateList uploadedCertificates, PublishContext context) { string name = context.ServiceName; CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null); if (cloudServiceProject.Components.CloudConfig.Role != null) { foreach (ConfigCertificate certElement in cloudServiceProject.Components.CloudConfig.Role. SelectMany(r => r.Certificates ?? new ConfigCertificate[0]).Distinct()) { if (uploadedCertificates == null || (uploadedCertificates.Count(c => c.Thumbprint.Equals( certElement.thumbprint, StringComparison.OrdinalIgnoreCase)) < 1)) { X509Certificate2 cert = General.GetCertificateFromStore(certElement.thumbprint); CertificateFile certFile = null; try { certFile = new CertificateFile { Data = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, string.Empty)), Password = string.Empty, CertificateFormat = "pfx" }; } catch (CryptographicException exception) { throw new ArgumentException(string.Format( Resources.CertificatePrivateKeyAccessError, certElement.name), exception); } CallSync(() => ServiceManagementChannel.AddCertificates(subscriptionId, name, certFile)); } } } }
/// <summary> /// Publishes a service project on Windows Azure. /// </summary> /// <param name="name">The cloud service name</param> /// <param name="slot">The deployment slot</param> /// <param name="location">The deployment location</param> /// <param name="affinityGroup">The deployment affinity group</param> /// <param name="storageAccount">The storage account to store the package</param> /// <param name="deploymentName">The deployment name</param> /// <param name="launch">Launch the service after publishing</param> /// <returns>The created deployment</returns> public Deployment PublishCloudService( string name = null, string slot = null, string location = null, string affinityGroup = null, string storageAccount = null, string deploymentName = null, bool launch = false) { // Initialize publish context PublishContext context = CreatePublishContext( name, slot, location, affinityGroup, storageAccount, deploymentName); WriteVerbose(string.Format(Resources.PublishServiceStartMessage, context.ServiceName)); // Set package runtime information WriteVerboseWithTimestamp(Resources.RuntimeDeploymentStart, context.ServiceName); PrepareCloudServicePackagesRuntime(context); // Verify storage account exists WriteVerboseWithTimestamp( Resources.PublishVerifyingStorageMessage, context.ServiceSettings.StorageServiceName); CreateStorageServiceIfNotExist( context.ServiceSettings.StorageServiceName, context.ServiceName, context.ServiceSettings.Location, context.ServiceSettings.AffinityGroup); // Update cache worker roles configuration WriteVerboseWithTimestamp( Resources.PublishPreparingDeploymentMessage, context.ServiceName, subscriptionId); UpdateCacheWorkerRolesCloudConfiguration(context); // Create cloud package AzureTool.Validate(); if (File.Exists(context.PackagePath)) { File.Delete(context.PackagePath); } CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null); string unused; cloudServiceProject.CreatePackage(DevEnv.Cloud, out unused, out unused); // Publish cloud service WriteVerboseWithTimestamp(Resources.PublishConnectingMessage); CreateCloudServiceIfNotExist( context.ServiceName, affinityGroup: context.ServiceSettings.AffinityGroup, location: context.ServiceSettings.Location); if (DeploymentExists(context.ServiceName, context.ServiceSettings.Slot)) { // Upgrade the deployment UpgradeDeployment(context); } else { // Create new deployment CreateDeployment(context); } // Get the deployment id and show it. WriteVerboseWithTimestamp(Resources.PublishCreatedDeploymentMessage, GetDeploymentId(context)); // Verify the deployment succeeded by checking that each of the roles are running VerifyDeployment(context); // Get object of the published deployment Deployment deployment = ServiceManagementChannel.GetDeploymentBySlot( subscriptionId, context.ServiceName, context.ServiceSettings.Slot); if (launch) { General.LaunchWebPage(deployment.Url.ToString()); } return deployment; }
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)); }
public void TestSetAzureRuntimeValidRuntimeVersionsCanInsensitive() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); string roleName = "WebRole1"; string caseInsensitiveName = "weBrolE1"; cmdlet.PassThru = false; RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(caseInsensitiveName, "node", "0.8.2", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(caseInsensitiveName, "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); } }
private void UpdateServiceConfigurations(CloudServiceProject service, string forwarderName) { foreach (ServiceConfiguration config in new[] { service.Components.LocalConfig, service.Components.CloudConfig }) { foreach (RoleSettings role in config.Role) { if (role.ConfigurationSettings != null) { ConfigurationSetting setting = role.ConfigurationSettings. FirstOrDefault<ConfigurationSetting>(t => t.name.Equals( "Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled")); if (setting != null) { setting.value = "false"; } if (role.name == forwarderName) { ConfigurationSetting forwarderSetting = role.ConfigurationSettings. FirstOrDefault<ConfigurationSetting>(t => t.name.Equals( "Microsoft.WindowsAzure.Plugins.RemoteForwarder.Enabled")); if (forwarderSetting != null) { forwarderSetting.value = "false"; } } } } } }
/// <summary> /// Publishes a service project on Windows Azure. /// </summary> /// <param name="name">The cloud service name</param> /// <param name="slot">The deployment slot</param> /// <param name="location">The deployment location</param> /// <param name="affinityGroup">The deployment affinity group</param> /// <param name="storageAccount">The storage account to store the package</param> /// <param name="deploymentName">The deployment name</param> /// <param name="launch">Launch the service after publishing</param> /// <returns>The created deployment</returns> public Deployment PublishCloudService( string name = null, string slot = null, string location = null, string affinityGroup = null, string storageAccount = null, string deploymentName = null, bool launch = false) { // Initialize publish context PublishContext context = CreatePublishContext( name, slot, location, affinityGroup, storageAccount, deploymentName); WriteVerbose(string.Format(Resources.PublishServiceStartMessage, context.ServiceName)); // Set package runtime information WriteVerboseWithTimestamp(Resources.RuntimeDeploymentStart, context.ServiceName); PrepareCloudServicePackagesRuntime(context); // Verify storage account exists WriteVerboseWithTimestamp( Resources.PublishVerifyingStorageMessage, context.ServiceSettings.StorageServiceName); CreateStorageServiceIfNotExist( context.ServiceSettings.StorageServiceName, context.ServiceName, context.ServiceSettings.Location, context.ServiceSettings.AffinityGroup); // Update cache worker roles configuration WriteVerboseWithTimestamp( Resources.PublishPreparingDeploymentMessage, context.ServiceName, subscriptionId); UpdateCacheWorkerRolesCloudConfiguration(context); // Create cloud package AzureTool.Validate(); if (File.Exists(context.PackagePath)) { File.Delete(context.PackagePath); } CloudServiceProject cloudServiceProject = new CloudServiceProject(context.RootPath, null); string unused; cloudServiceProject.CreatePackage(DevEnv.Cloud, out unused, out unused); // Publish cloud service WriteVerboseWithTimestamp(Resources.PublishConnectingMessage); CreateCloudServiceIfNotExist( context.ServiceName, affinityGroup: context.ServiceSettings.AffinityGroup, location: context.ServiceSettings.Location); if (DeploymentExists(context.ServiceName, context.ServiceSettings.Slot)) { // Upgrade the deployment UpgradeDeployment(context); } else { // Create new deployment CreateDeployment(context); } // Get the deployment id and show it. WriteVerboseWithTimestamp(Resources.PublishCreatedDeploymentMessage, GetDeploymentId(context)); // Verify the deployment succeeded by checking that each of the roles are running VerifyDeployment(context); // Get object of the published deployment Deployment deployment = ServiceManagementChannel.GetDeploymentBySlot( subscriptionId, context.ServiceName, context.ServiceSettings.Slot); if (launch) { General.LaunchWebPage(deployment.Url.ToString()); } return(deployment); }
private void AddPHPRoleTest(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(Data.PHPWebRoleScaffoldingPath); if (wo++ < workerRole) roles[i++] = wrappedService.AddWorkerRole(Data.PHPWorkerRoleScaffoldingPath); } } else if (order == 1) { for (int i = 0, w = 0, wo = 0; i < webRole + workerRole; ) { if (wo++ < workerRole) roles[i++] = wrappedService.AddWorkerRole(Data.PHPWorkerRoleScaffoldingPath); if (w++ < webRole) roles[i++] = wrappedService.AddWebRole(Data.PHPWebRoleScaffoldingPath); } } else if (order == 2) { wrappedService.AddRole(Data.PHPWebRoleScaffoldingPath, Data.PHPWorkerRoleScaffoldingPath, webRole, workerRole); webRoles.CopyTo(roles, 0); Array.Copy(workerRoles, 0, roles, webRole, workerRoles.Length); } else if (order == 3) { wrappedService.AddRole(Data.PHPWebRoleScaffoldingPath, Data.PHPWorkerRoleScaffoldingPath, 0, workerRole); workerRoles.CopyTo(roles, 0); wrappedService.AddRole(Data.PHPWebRoleScaffoldingPath, Data.PHPWorkerRoleScaffoldingPath, 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: Data.PHPWebRoleScaffoldingPath, workerScaff: Data.PHPWorkerRoleScaffoldingPath, 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 cacheWebRoleName = "cacheWebRole"; string cacheRuntimeVersion = "1.7.0"; AddAzureNodeWebRoleCommand addAzureWebRole = new AddAzureNodeWebRoleCommand() { RootPath = rootPath, CommandRuntime = mockCommandRuntime, Name = cacheWebRoleName }; addAzureWebRole.ExecuteCmdlet(); CloudServiceProject testService = new CloudServiceProject(rootPath, null); 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"); testService.AddRoleRuntime(testService.Paths, cacheWebRoleName, Resources.CacheRuntimeValue, cacheRuntimeVersion, RuntimePackageHelper.GetTestManifest(files)); 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"); RuntimePackageHelper.ValidateRoleRuntimeVariable(updatedService.Components.GetRoleStartup(cacheWebRoleName), Resources.CacheRuntimeVersionKey, cacheRuntimeVersion); } }
public void SetPHPRoleInstancesTest() { int newInstances = 10; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.AddWebRole(Data.PHPWebRoleScaffoldingPath, "WebRole", 1); service.SetRoleInstances(service.Paths, "WebRole", newInstances); Assert.AreEqual<int>(service.Components.CloudConfig.Role[0].Instances.count, newInstances); Assert.AreEqual<int>(service.Components.LocalConfig.Role[0].Instances.count, newInstances); } }
public void ChangeServiceNameTest() { string newName = "NodeAppService"; using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); service.ChangeServiceName(newName, service.Paths); Assert.AreEqual<string>(newName, service.Components.CloudConfig.serviceName); Assert.AreEqual<string>(newName, service.Components.LocalConfig.serviceName); Assert.AreEqual<string>(newName, service.Components.Definition.name); } }
public void AzureServiceCreateNew() { using (FileSystemHelper files = new FileSystemHelper(this)) { CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null); AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName); } }