Class that encapsulates all of the info about a service, to which we can add roles. This is all in memory, so no disk operations occur.
示例#1
0
        public override void ExecuteCmdlet()
        {
            RootPath = RootPath ?? CommonUtilities.GetServiceRootPath(CurrentPath());
            CloudServiceProject service = new CloudServiceProject(RootPath, null);
            RoleInfo roleInfo = null;
            
            if (isWebRole)
            {
                roleInfo = service.AddWebRole(Scaffolding, Name, Instances);
            }
            else
            {
                roleInfo = service.AddWorkerRole(Scaffolding, Name, Instances);
            }

            OnProcessing(roleInfo);

            try
            {
                service.ChangeRolePermissions(roleInfo);
                SafeWriteOutputPSObject(typeof(RoleSettings).FullName, Parameters.RoleName, roleInfo.Name);
                WriteVerbose(string.Format(successMessage, RootPath, roleInfo.Name));
            }
            catch (UnauthorizedAccessException)
            {
                WriteWarning(Resources.AddRoleMessageInsufficientPermissions);
            }
        }
        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);
        }
        private static void CacheWorkerRole180(string rootPath, RoleInfo cacheRoleInfo)
        {
            // Fetch cache role information from service definition and service configuration files.
            CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null);
            WorkerRole cacheWorkerRole = cloudServiceProject.Components.GetWorkerRole(cacheRoleInfo.Name);
            RoleSettings cacheRoleSettings = cloudServiceProject.Components.GetCloudConfigRole(cacheRoleInfo.Name);

            // Add caching module to the role imports
            cacheWorkerRole.Imports = GeneralUtilities.ExtendArray<Import>(
                cacheWorkerRole.Imports,
                new Import { moduleName = Resources.CachingModuleName });

            // Enable caching Diagnostic store.
            LocalStore diagnosticStore = new LocalStore
            {
                name = Resources.CacheDiagnosticStoreName,
                cleanOnRoleRecycle = false
            };
            cacheWorkerRole.LocalResources = GeneralUtilities.InitializeIfNull<LocalResources>(cacheWorkerRole.LocalResources);
            cacheWorkerRole.LocalResources.LocalStorage = GeneralUtilities.ExtendArray<LocalStore>(
                cacheWorkerRole.LocalResources.LocalStorage,
                diagnosticStore);

            // Remove input endpoints.
            cacheWorkerRole.Endpoints.InputEndpoint = null;

            // Add caching configuration settings
            AddCacheConfiguration(cloudServiceProject.Components.GetCloudConfigRole(cacheRoleInfo.Name));
            AddCacheConfiguration(
                cloudServiceProject.Components.GetLocalConfigRole(cacheRoleInfo.Name),
                Resources.EmulatorConnectionString);

            cloudServiceProject.Components.Save(cloudServiceProject.Paths);
        }
        /// <summary>
        /// Configuration required to enable dedicated caching on a given role.
        /// </summary>
        /// <param name="rootPath">The service project root path</param>
        /// <param name="cacheRoleInfo">The cache role info</param>
        private static void CacheRole180(string rootPath, RoleInfo cacheRoleInfo)
        {
            CloudServiceProject cloudServiceProject = new CloudServiceProject(rootPath, null);

            if (!cloudServiceProject.Components.IsWebRole(cacheRoleInfo.Name))
            {
                CacheWorkerRole180(rootPath, cacheRoleInfo);
            }
        }
示例#5
0
        public void CreateLocalPackageWithNodeWorkerRoleTest()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                service.AddWorkerRole(Test.Utilities.Common.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 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.Equal(
             1,
             roleSettings.ConfigurationSettings
                 .Where(c => c.name == "Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled" && c.value == "false")
                 .Count());
     }
 }
        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.Equal<int>(0, mockCommandRuntime.OutputPipeline.Count);
                cloudServiceClientMock.Verify(f => f.StartCloudService(serviceName, slot), Times.Once());
            }
        }
        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;
        }
示例#11
0
        public void CreateLocalPackageWithOnePHPWebRoleTest()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                RoleInfo webRoleInfo = service.AddWebRole(Test.Utilities.Common.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.True(File.Exists(targetLogsFile));
            }
        }
示例#12
0
        public void CreateCloudPackageWithMultipleRoles()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                service.AddWorkerRole(Test.Utilities.Common.Data.NodeWorkerRoleScaffoldingPath);
                service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
                service.AddWorkerRole(Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath);
                service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath);
                service.CreatePackage(DevEnv.Cloud);

                using (Package package = Package.Open(service.Paths.CloudPackage))
                {
                    Assert.Equal(9, package.GetParts().Count());
                }
            }
        }
 public void TestSetAzureRuntimeValidRuntimeVersions()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
         service.AddWebRole(Test.Utilities.Common.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.Equal<int>(0, mockCommandRuntime.OutputPipeline.Count);
         Assert.Equal<string>(roleName, roleSettings1.name);
         Assert.Equal<string>(roleName, roleSettings2.name);
     }
 }
        public void SetAzureVMSizeProcessTestsNode()
        {
            string newRoleVMSize = "Large";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                string roleName = "WebRole1";
                service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath);
                service = new CloudServiceProject(service.Paths.RootPath, null);

                Assert.Equal<string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString());
                Assert.Equal<int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.Equal<string>(roleName, roleSettings.name);
            }
        }
        public void DisableRemoteDesktop()
        {
            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);
            if (forwarderName != null)
            {
                UpdateServiceConfigurations(service, forwarderName);
                service.Components.Save(service.Paths);
            }

            if (PassThru)
            {
                WriteObject(true);
            }
        }
        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 = "Medium";

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                string roleName = "WebRole1";
                service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath);
                RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath);
                service = new CloudServiceProject(service.Paths.RootPath, null);

                
                Assert.Equal<string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString());
                Assert.Equal<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString());
                Assert.True(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName));
                Assert.Equal<string>(roleName, roleSettings.name);
            }
        }
示例#18
0
        /// <summary>
        /// Gets role name for the current pathif exists.
        /// </summary>
        /// <returns>The role name</returns>
        public static string GetRoleName(string rootPath, string currentPath)
        {
            bool found = false;
            string roleName = null;

            if (!(rootPath.Length >= currentPath.Length))
            {
                string difference = currentPath.Replace(rootPath, string.Empty);
                roleName = difference.Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).GetValue(0).ToString();
                CloudServiceProject service = new CloudServiceProject(rootPath, null);
                found = service.Components.RoleExists(roleName);
            }

            if (!found)
            {
                throw new ArgumentException(string.Format(Resources.CannotFindRole, currentPath));
            }

            return roleName;
        }
        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(@"..\..\..\..\..\Package\Debug\ServiceManagement\Azure\Services"));
                service.AddWebRole(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);

                cmdlet.ExecuteCmdlet();

                PSObject obj = mockCommandRuntime.OutputPipeline[0] as PSObject;
                Assert.Equal<string>(string.Format(Resources.PackageCreated, packagePath), mockCommandRuntime.VerboseStream[0]);
                Assert.Equal<string>(packagePath, obj.GetVariableValue<string>(Parameters.PackagePath));
                Assert.True(File.Exists(packagePath));
            }
        }
        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(Test.Utilities.Common.Data.NodeWebRoleScaffoldingPath);
                cmdlet.PassThru = false;
                RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath);
                service = new CloudServiceProject(service.Paths.RootPath, null);

                Assert.Equal<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count);
                Assert.Equal<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count);
                Assert.Equal<int>(0, mockCommandRuntime.OutputPipeline.Count);
                Assert.Equal<int>(newRoleInstances, roleSettings.Instances.count);
                Assert.Equal<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 = CommonUtilities.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);
        }
        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 = 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));
        }
        /// <summary>
        /// Create a new service with a given name and make that the current
        /// directory used by cmdlets.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <returns>Directory created for the service.</returns>
        public string CreateNewService(string serviceName)
        {
            CloudServiceProject newService = new CloudServiceProject(RootPath, serviceName, FileUtilities.GetContentFilePath("Services"));
            string path = Path.Combine(RootPath, serviceName);
            _previousDirectory = Environment.CurrentDirectory;
            Environment.CurrentDirectory = path;

            return path;
        }
        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");
            }
        }
示例#26
0
        public static string GetServiceRootPath(string currentPath)
        {
            // Get the service path
            string servicePath = FindServiceRootDirectory(currentPath);

            // Was the service path found?
            if (servicePath == null)
            {
                throw new InvalidOperationException(Resources.CannotFindServiceRoot);
            }

            CloudServiceProject service = new CloudServiceProject(servicePath, null);
            if (service.Components.CloudConfig.Role != null)
            {
                foreach (RoleSettings role in service.Components.CloudConfig.Role)
                {
                    string roleDirectory = Path.Combine(service.Paths.RolesPath, role.name);

                    if (!FileUtilities.DataStore.DirectoryExists(roleDirectory))
                    {
                        throw new InvalidOperationException(Resources.CannotFindServiceRoot);
                    }
                }
            }

            return servicePath;
        }
        /// <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 SetPHPRoleInstancesTest()
        {
            int newInstances = 10;

            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "WebRole", 1);
                service.SetRoleInstances(service.Paths, "WebRole", newInstances);
                Assert.Equal<int>(service.Components.CloudConfig.Role[0].Instances.count, newInstances);
                Assert.Equal<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.Equal<string>(newName, service.Components.CloudConfig.serviceName);
                Assert.Equal<string>(newName, service.Components.LocalConfig.serviceName);
                Assert.Equal<string>(newName, service.Components.Definition.name);
            }
        }
 public void AzureServiceAddExistingPHPRoleFail()
 {
     using (FileSystemHelper files = new FileSystemHelper(this))
     {
         CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
         service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "WebRole");
         Testing.AssertThrows<ArgumentException>(() => service.AddWebRole(Test.Utilities.Common.Data.PHPWebRoleScaffoldingPath, "WebRole"), string.Format(Resources.AddRoleMessageRoleExists, "WebRole"));
     }
 }
        public void AzureServiceAddNewPHPWorkerRoleTest()
        {
            using (FileSystemHelper files = new FileSystemHelper(this))
            {
                CloudServiceProject service = new CloudServiceProject(files.RootPath, serviceName, null);
                RoleInfo workerRole = service.AddWorkerRole(Test.Utilities.Common.Data.PHPWorkerRoleScaffoldingPath, "MyWorkerRole", 10);

                AzureAssert.AzureServiceExists(Path.Combine(files.RootPath, serviceName), Resources.GeneralScaffolding, serviceName, workerRoles: new WorkerRoleInfo[] { (WorkerRoleInfo)workerRole }, workerScaff: Path.Combine(Resources.PHPScaffolding, Resources.WorkerRole), roles: new RoleInfo[] { workerRole });
            }
        }