Esempio n. 1
0
        /// <summary>
        /// Sets a startup task environment variable.
        /// </summary>
        /// <param name="roleName">The role name</param>
        /// <param name="name">The environment variable name</param>
        /// <param name="value">The environment variable value</param>
        /// <param name="commandLines">The command line to match task.</param>
        public void SetStartupTaskVariable(string roleName, string name, string value, params string[] commandLines)
        {
            Task task  = GetStartupTask(roleName, commandLines);
            bool found = false;

            if (task != null && task.Environment != null)
            {
                for (int i = 0; i < task.Environment.Length; i++)
                {
                    if (task.Environment[i].name.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        task.Environment[i].value = value;
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Variable var = new Variable()
                    {
                        name = name, value = value
                    };
                    task.Environment = GeneralUtilities.ExtendArray <Variable>(task.Environment, var);
                }
            }
        }
        private static void AddCacheConfiguration(RoleSettings cacheRoleSettings, string connectionString = "")
        {
            List <ConfigConfigurationSetting> cachingConfigSettings = new List <ConfigConfigurationSetting>();

            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.NamedCacheSettingName,
                value = Resources.NamedCacheSettingValue
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.DiagnosticLevelName,
                value = Resources.DiagnosticLevelValue
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.CachingCacheSizePercentageSettingName,
                value = string.Empty
            });
            cachingConfigSettings.Add(new ConfigConfigurationSetting
            {
                name  = Resources.CachingConfigStoreConnectionStringSettingName,
                value = connectionString
            });

            cacheRoleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray <ConfigConfigurationSetting>(
                cacheRoleSettings.ConfigurationSettings,
                cachingConfigSettings);
        }
        private static void AddClientDiagnosticLevelToConfig(RoleSettings roleSettings)
        {
            ConfigConfigurationSetting clientDiagnosticLevel = new ConfigConfigurationSetting {
                name = Resources.ClientDiagnosticLevelName, value = Resources.ClientDiagnosticLevelValue
            };

            roleSettings.ConfigurationSettings = GeneralUtilities.ExtendArray <ConfigConfigurationSetting>(roleSettings.ConfigurationSettings, clientDiagnosticLevel);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds new startup task to the given role.
        /// </summary>
        /// <param name="roleName">The role name</param>
        /// <param name="commandLine">The startup task command line</param>
        /// <param name="context">The execution context</param>
        /// <param name="variables">The environment variables</param>
        public void AddStartupTask(
            string roleName,
            string commandLine,
            ExecutionContext context,
            params Variable[] variables)
        {
            Startup roleStartup = GetRoleStartup(roleName) ?? new Startup();
            Task    newTask     = new Task
            {
                Environment      = variables,
                commandLine      = commandLine,
                executionContext = context
            };

            roleStartup.Task = GeneralUtilities.ExtendArray <Task>(roleStartup.Task, newTask);
        }
        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>
        /// Applies required configuration for enabling cache in SDK 1.8.0 version by:
        /// * Add MemcacheShim runtime installation.
        /// * Add startup task to install memcache shim on the client side.
        /// * Add default memcache internal endpoint.
        /// * Add cache diagnostic to local resources.
        /// * Add ClientDiagnosticLevel setting to service configuration.
        /// * Adjust web.config to enable auto discovery for the caching role.
        /// </summary>
        /// <param name="cloudServiceProject">The azure service instance</param>
        /// <param name="webRole">The web role to enable caching on</param>
        /// <param name="isWebRole">Flag indicating if the provided role is web or not</param>
        /// <param name="cacheWorkerRole">The memcache worker role name</param>
        /// <param name="startup">The role startup</param>
        /// <param name="endpoints">The role endpoints</param>
        /// <param name="localResources">The role local resources</param>
        /// <param name="configurationSettings">The role configuration settings</param>
        private void Version180Configuration(
            CloudServiceProject cloudServiceProject,
            string roleName,
            bool isWebRole,
            string cacheWorkerRole,
            Startup startup,
            Endpoints endpoints,
            LocalResources localResources,
            ref DefinitionConfigurationSetting[] configurationSettings)
        {
            if (isWebRole)
            {
                // Generate cache scaffolding for web role
                cloudServiceProject.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WebRole.ToString()),
                                                        roleName, new Dictionary <string, object>());

                // Adjust web.config to enable auto discovery for the caching role.
                string webCloudConfigPath = Path.Combine(cloudServiceProject.Paths.RootPath, roleName, Resources.WebCloudConfig);
                string webConfigPath      = Path.Combine(cloudServiceProject.Paths.RootPath, roleName, Resources.WebConfigTemplateFileName);

                UpdateWebConfig(roleName, cacheWorkerRole, webCloudConfigPath);
                UpdateWebConfig(roleName, cacheWorkerRole, webConfigPath);
            }
            else
            {
                // Generate cache scaffolding for worker role
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters[ScaffoldParams.RoleName] = cacheWorkerRole;

                cloudServiceProject.GenerateScaffolding(Path.Combine(Resources.CacheScaffolding, RoleType.WorkerRole.ToString()),
                                                        roleName, parameters);
            }

            // Add default memcache internal endpoint.
            InternalEndpoint memcacheEndpoint = new InternalEndpoint
            {
                name     = Resources.MemcacheEndpointName,
                protocol = InternalProtocol.tcp,
                port     = Resources.MemcacheEndpointPort
            };

            endpoints.InternalEndpoint = GeneralUtilities.ExtendArray <InternalEndpoint>(endpoints.InternalEndpoint, memcacheEndpoint);

            // Enable cache diagnostic
            LocalStore localStore = new LocalStore
            {
                name = Resources.CacheDiagnosticStoreName,
                cleanOnRoleRecycle = false
            };

            localResources.LocalStorage = GeneralUtilities.ExtendArray <LocalStore>(localResources.LocalStorage, localStore);

            DefinitionConfigurationSetting diagnosticLevel = new DefinitionConfigurationSetting {
                name = Resources.CacheClientDiagnosticLevelAssemblyName
            };

            configurationSettings = GeneralUtilities.ExtendArray <DefinitionConfigurationSetting>(configurationSettings, diagnosticLevel);

            // Add ClientDiagnosticLevel setting to service configuration.
            AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetCloudConfigRole(roleName));
            AddClientDiagnosticLevelToConfig(cloudServiceProject.Components.GetLocalConfigRole(roleName));
        }