Пример #1
0
        /// <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 = General.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 = General.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);
        }
Пример #2
0
        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 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);
        }
Пример #4
0
        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");
            }
        }
        /// <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);
        }
        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, FileUtilities.GetContentFilePath("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");
                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);
            }
        }