Пример #1
0
        public void Merge(UnreliableTransportSettings unreliableTransportSettings)
        {
            Dictionary <string, UnreliableTransportSpecification> specificationsDictionary = new Dictionary <string, UnreliableTransportSpecification>();

            // populate dictionary with this settings
            foreach (var specification in Specification)
            {
                specificationsDictionary.Add(specification.Name, specification);
            }

            // now we merge the settings with precedence of specifications coming from this
            foreach (var specification in unreliableTransportSettings.Specification)
            {
                if (specificationsDictionary.ContainsKey(specification.Name) == false)
                {
                    specificationsDictionary.Add(specification.Name, specification);
                }
                else
                {
                    specificationsDictionary[specification.Name] = specification;
                    DeployerTrace.WriteWarning("Conflicting Unreliable Transport Behavior when merging named {0}. Replacing with new behavior", specification.Name);
                }
            }

            // removing previous specifications to populate with ones in dictionary
            Specification.Clear();
            Specification.AddRange(specificationsDictionary.Values);
        }
Пример #2
0
        private int GenerateAndDeployUnreliableTransportSettings()
        {
            string filePath = System.IO.Path.Combine(this.nodeSettings.DeploymentFoldersInfo.WorkFolder, UnreliableTransportSettings.SettingsFileName);

            DeployerTrace.WriteNoise("Writing Unreliable Transport Settings file at {0}", filePath);

            UnreliableTransportSettings unreliableTransportSettings = new UnreliableTransportSettings(this.clusterSettings);

            // acquiring lock to read and write to unreliable transport settings file.
            FileLock fileLock = new FileLock(filePath, false /* writing lock */);

            if (!fileLock.Acquire(new TimeSpan(0, 0, 5)))
            {
                DeployerTrace.WriteWarning("Failed to acquire lock to load Unreliable Transport Settings File. Aborting loading at file: {0}", filePath);
                return(Constants.ErrorCode_Failure);
            }

            // checks if it necessary to merge
            if (!File.Exists(filePath))
            {
                // writes the result to Unreliable Transport Settings File
                unreliableTransportSettings.WriteUnreliableTransportSettingsFile(filePath);
            }
            else
            {
                // creates a new UnreliableTransportSettings from existing UnreliableTransportSettings file
                UnreliableTransportSettings unreliableTransportSettingsExisting = new UnreliableTransportSettings(filePath);
                // merge files giving precedence to settings coming from cluster manifest
                unreliableTransportSettingsExisting.Merge(unreliableTransportSettings);
                // writes the result to Unreliable Transport Settings File
                unreliableTransportSettingsExisting.WriteUnreliableTransportSettingsFile(filePath);
            }
#if DotNetCoreClrLinux
            Helpers.UpdateFilePermission(filePath);
#endif
            // releasing lock.
            fileLock.Release();

            return(Constants.ErrorCode_Success);
        }