コード例 #1
0
        /// <summary>
        /// Add the specified runtime to a role, checking that the runtime and version are currently available int he cloud
        /// </summary>
        /// <param name="paths">service path info</param>
        /// <param name="roleName">Name of the role to change</param>
        /// <param name="runtimeType">The runtime identifier</param>
        /// <param name="runtimeVersion">The runtime version</param>
        /// <param name="manifest">Location fo the manifest file, default is the cloud manifest</param>
        public void AddRoleRuntime(
            ServicePathInfo paths,
            string roleName,
            string runtimeType,
            string runtimeVersion,
            string manifest = null)
        {
            if (this.Components.RoleExists(roleName))
            {
                CloudRuntimeCollection collection;
                CloudRuntimeCollection.CreateCloudRuntimeCollection(out collection, manifest);
                CloudRuntime        desiredRuntime = CloudRuntime.CreateCloudRuntime(runtimeType, runtimeVersion, roleName, Path.Combine(paths.RootPath, roleName));
                CloudRuntimePackage foundPackage;
                if (collection.TryFindMatch(desiredRuntime, out foundPackage))
                {
                    WorkerRole worker = (this.Components.Definition.WorkerRole == null ? null :
                                         this.Components.Definition.WorkerRole.FirstOrDefault <WorkerRole>(r => string.Equals(r.name, roleName,
                                                                                                                              StringComparison.OrdinalIgnoreCase)));
                    WebRole web = (this.Components.Definition.WebRole == null ? null :
                                   this.Components.Definition.WebRole.FirstOrDefault <WebRole>(r => string.Equals(r.name, roleName,
                                                                                                                  StringComparison.OrdinalIgnoreCase)));
                    desiredRuntime.CloudServiceProject = this;
                    if (worker != null)
                    {
                        desiredRuntime.ApplyRuntime(foundPackage, worker);
                    }
                    else if (web != null)
                    {
                        desiredRuntime.ApplyRuntime(foundPackage, web);
                    }

                    this.Components.Save(this.Paths);
                }
            }
        }
コード例 #2
0
        public static CloudRuntime CreateCloudRuntime(string runtimeType, string runtimeVersion, string roleName, string rolePath)
        {
            CloudRuntime runtime = CreateRuntimeInternal(GetRuntimeByType(runtimeType), roleName, rolePath);

            runtime.Version = runtimeVersion;
            return(runtime);
        }
コード例 #3
0
        /// <summary>
        /// Configuration action to enable using dedicated caching on the client role.
        /// </summary>
        /// <param name="cloudServiceProject">The cloud service project instance</param>
        /// <param name="roleName">The role name</param>
        /// <param name="cacheWorkerRoleName">The dedicated cache worker role name</param>
        private static void CacheClientRole180(
            CloudServiceProject cloudServiceProject,
            string roleName,
            string cacheWorkerRoleName)
        {
            // Add MemcacheShim runtime installation.
            cloudServiceProject.AddRoleRuntime(
                cloudServiceProject.Paths,
                roleName,
                Resources.CacheRuntimeValue,
                CurrentVersion);

            // 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;

                CacheClientCommonConfiguration(
                    cloudServiceProject,
                    roleName,
                    true,
                    cacheWorkerRoleName,
                    webRole.Startup,
                    webRole.Endpoints,
                    webRole.LocalResources,
                    ref configurationSettings);
                webRole.ConfigurationSettings = configurationSettings;
            }
            else
            {
                WorkerRole workerRole = cloudServiceProject.Components.GetWorkerRole(roleName);
                workerRole.LocalResources = General.InitializeIfNull <LocalResources>(workerRole.LocalResources);
                DefinitionConfigurationSetting[] configurationSettings = workerRole.ConfigurationSettings;

                CacheClientCommonConfiguration(
                    cloudServiceProject,
                    roleName,
                    false,
                    cacheWorkerRoleName,
                    workerRole.Startup,
                    workerRole.Endpoints,
                    workerRole.LocalResources,
                    ref configurationSettings);
                workerRole.ConfigurationSettings = configurationSettings;
            }

            // Save changes
            cloudServiceProject.Components.Save(cloudServiceProject.Paths);
        }
コード例 #4
0
        public static string GetRuntimeUrl(string runtimeType, string runtimeVersion, string manifest = null)
        {
            CloudRuntimeCollection collection;

            CloudRuntimeCollection.CreateCloudRuntimeCollection(out collection, manifest);
            CloudRuntime        desiredRuntime = CloudRuntime.CreateCloudRuntime(runtimeType, runtimeVersion, null, null);
            CloudRuntimePackage foundPackage;
            bool found = collection.TryFindMatch(desiredRuntime, out foundPackage);

            return(found ? foundPackage.PackageUri.AbsoluteUri : null);
        }
コード例 #5
0
        /// <summary>
        /// Create a cloud runtime application, essentialy this is a tuple of runtime X package X role
        /// </summary>
        /// <param name="cloudRuntime">The runtime in the tuple</param>
        /// <param name="cloudRuntimePackage">The package in the tuple</param>
        /// <param name="role">The role to apply the package to</param>
        /// <returns>The tuple, use the apply method to apply the runtime as specified</returns>
        public static CloudRuntimeApplicator CreateCloudRuntimeApplicator(CloudRuntime cloudRuntime, CloudRuntimePackage cloudRuntimePackage, WorkerRole role)
        {
            CloudRuntimeApplicator applicator = new CloudRuntimeApplicator
            {
                Runtime    = cloudRuntime,
                Package    = cloudRuntimePackage,
                WorkerRole = role
            };

            return(applicator);
        }
コード例 #6
0
        /// <summary>
        /// Create a cloud runtime application, essentialy this is a tuple of runtime X package X role
        /// </summary>
        /// <param name="cloudRuntime">The runtime in the tuple</param>
        /// <param name="cloudRuntimePackage">The package in the tuple</param>
        /// <param name="role">The role to apply the package to</param>
        /// <returns>The tuple, use the apply method to apply the runtime as specified</returns>
        public static CloudRuntimeApplicator CreateCloudRuntimeApplicator(CloudRuntime cloudRuntime, CloudRuntimePackage cloudRuntimePackage, WorkerRole role)
        {
            CloudRuntimeApplicator applicator = new CloudRuntimeApplicator
            {
                Runtime = cloudRuntime,
                Package = cloudRuntimePackage,
                WorkerRole = role
            };

            return applicator;
        }
コード例 #7
0
        private static Collection <CloudRuntime> GetRuntimes(Dictionary <string, string> settings,
                                                             string roleName, string rolePath)
        {
            Collection <CloudRuntime> runtimes = new Collection <CloudRuntime>(new List <CloudRuntime>());

            foreach (RuntimeType runtimeType in GetRuntimeTypes(settings))
            {
                CloudRuntime runtime = CreateRuntimeInternal(runtimeType, roleName, rolePath);
                runtime.Configure(settings);
                runtimes.Add(runtime);
            }

            return(runtimes);
        }
コード例 #8
0
        public bool TryFindMatch(CloudRuntime runtime, out CloudRuntimePackage matchingPackage)
        {
            matchingPackage = packages[runtime.Runtime].OrderByDescending <CloudRuntimePackage, string>(p => p.Version, new VersionComparer()).FirstOrDefault <CloudRuntimePackage>(crp => runtime.Match(crp));
            if (matchingPackage != null)
            {
                return(true);
            }

            if (defaults.ContainsKey(runtime.Runtime))
            {
                matchingPackage = defaults[runtime.Runtime];
            }

            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Resolves the service runtimes into downloadable URLs.
        /// </summary>
        /// <param name="manifest">The custom manifest file</param>
        /// <returns>Warning text if any</returns>
        public string ResolveRuntimePackageUrls(string manifest = null)
        {
            ServiceSettings settings = ServiceSettings.Load(Paths.Settings);

            CloudRuntimeCollection availableRuntimePackages;

            if (!CloudRuntimeCollection.CreateCloudRuntimeCollection(out availableRuntimePackages, manifest))
            {
                throw new ArgumentException(
                          string.Format(Resources.ErrorRetrievingRuntimesForLocation,
                                        settings.Location));
            }

            ServiceDefinition             definition  = this.Components.Definition;
            StringBuilder                 warningText = new StringBuilder();
            List <CloudRuntimeApplicator> applicators = new List <CloudRuntimeApplicator>();

            if (definition.WebRole != null)
            {
                foreach (WebRole role in
                         definition.WebRole.Where(role => role.Startup != null &&
                                                  CloudRuntime.GetRuntimeStartupTask(role.Startup) != null))
                {
                    CloudRuntime.ClearRuntime(role);
                    string rolePath = Path.Combine(this.Paths.RootPath, role.name);
                    foreach (CloudRuntime runtime in CloudRuntime.CreateRuntime(role, rolePath))
                    {
                        CloudRuntimePackage package;
                        runtime.CloudServiceProject = this;
                        if (!availableRuntimePackages.TryFindMatch(runtime, out package))
                        {
                            string warning;
                            if (!runtime.ValidateMatch(package, out warning))
                            {
                                warningText.AppendFormat("{0}\r\n", warning);
                            }
                        }

                        applicators.Add(CloudRuntimeApplicator.CreateCloudRuntimeApplicator(
                                            runtime,
                                            package,
                                            role));
                    }
                }
            }

            if (definition.WorkerRole != null)
            {
                foreach (WorkerRole role in
                         definition.WorkerRole.Where(role => role.Startup != null &&
                                                     CloudRuntime.GetRuntimeStartupTask(role.Startup) != null))
                {
                    string rolePath = Path.Combine(this.Paths.RootPath, role.name);
                    CloudRuntime.ClearRuntime(role);
                    foreach (CloudRuntime runtime in CloudRuntime.CreateRuntime(role, rolePath))
                    {
                        CloudRuntimePackage package;
                        runtime.CloudServiceProject = this;
                        if (!availableRuntimePackages.TryFindMatch(runtime, out package))
                        {
                            string warning;
                            if (!runtime.ValidateMatch(package, out warning))
                            {
                                warningText.AppendFormat(warning + Environment.NewLine);
                            }
                        }
                        applicators.Add(CloudRuntimeApplicator.CreateCloudRuntimeApplicator(runtime,
                                                                                            package, role));
                    }
                }
            }

            applicators.ForEach <CloudRuntimeApplicator>(a => a.Apply());
            this.Components.Save(this.Paths);

            return(warningText.ToString());
        }