Esempio n. 1
0
        internal override void Load(XmlElement root)
        {
            var logger = TraceLogger.GetLogger("OrleansConfiguration", TraceLogger.LoggerType.Runtime);

            SeedNodes = new List <IPEndPoint>();

            XmlElement child;

            foreach (XmlNode c in root.ChildNodes)
            {
                child = c as XmlElement;
                if (child != null && child.LocalName == "Networking")
                {
                    Subnet = child.HasAttribute("Subnet")
                        ? ConfigUtilities.ParseSubnet(child.GetAttribute("Subnet"), "Invalid Subnet")
                        : null;
                }
            }
            foreach (XmlNode c in root.ChildNodes)
            {
                child = c as XmlElement;
                if (child == null)
                {
                    continue;                // Skip comment lines
                }
                switch (child.LocalName)
                {
                case "Liveness":
                    if (child.HasAttribute("LivenessEnabled"))
                    {
                        LivenessEnabled = ConfigUtilities.ParseBool(child.GetAttribute("LivenessEnabled"),
                                                                    "Invalid boolean value for the LivenessEnabled attribute on the Liveness element");
                    }
                    if (child.HasAttribute("ProbeTimeout"))
                    {
                        ProbeTimeout = ConfigUtilities.ParseTimeSpan(child.GetAttribute("ProbeTimeout"),
                                                                     "Invalid time value for the ProbeTimeout attribute on the Liveness element");
                    }
                    if (child.HasAttribute("TableRefreshTimeout"))
                    {
                        TableRefreshTimeout = ConfigUtilities.ParseTimeSpan(child.GetAttribute("TableRefreshTimeout"),
                                                                            "Invalid time value for the TableRefreshTimeout attribute on the Liveness element");
                    }
                    if (child.HasAttribute("DeathVoteExpirationTimeout"))
                    {
                        DeathVoteExpirationTimeout = ConfigUtilities.ParseTimeSpan(child.GetAttribute("DeathVoteExpirationTimeout"),
                                                                                   "Invalid time value for the DeathVoteExpirationTimeout attribute on the Liveness element");
                    }
                    if (child.HasAttribute("NumMissedProbesLimit"))
                    {
                        NumMissedProbesLimit = ConfigUtilities.ParseInt(child.GetAttribute("NumMissedProbesLimit"),
                                                                        "Invalid integer value for the NumMissedIAmAlive attribute on the Liveness element");
                    }
                    if (child.HasAttribute("NumProbedSilos"))
                    {
                        NumProbedSilos = ConfigUtilities.ParseInt(child.GetAttribute("NumProbedSilos"),
                                                                  "Invalid integer value for the NumProbedSilos attribute on the Liveness element");
                    }
                    if (child.HasAttribute("NumVotesForDeathDeclaration"))
                    {
                        NumVotesForDeathDeclaration = ConfigUtilities.ParseInt(child.GetAttribute("NumVotesForDeathDeclaration"),
                                                                               "Invalid integer value for the NumVotesForDeathDeclaration attribute on the Liveness element");
                    }
                    if (child.HasAttribute("UseLivenessGossip"))
                    {
                        UseLivenessGossip = ConfigUtilities.ParseBool(child.GetAttribute("UseLivenessGossip"),
                                                                      "Invalid boolean value for the UseLivenessGossip attribute on the Liveness element");
                    }
                    if (child.HasAttribute("IAmAliveTablePublishTimeout"))
                    {
                        IAmAliveTablePublishTimeout = ConfigUtilities.ParseTimeSpan(child.GetAttribute("IAmAliveTablePublishTimeout"),
                                                                                    "Invalid time value for the IAmAliveTablePublishTimeout attribute on the Liveness element");
                    }
                    if (child.HasAttribute("NumMissedTableIAmAliveLimit"))
                    {
                        NumMissedTableIAmAliveLimit = ConfigUtilities.ParseInt(child.GetAttribute("NumMissedTableIAmAliveLimit"),
                                                                               "Invalid integer value for the NumMissedTableIAmAliveLimit attribute on the Liveness element");
                    }
                    if (child.HasAttribute("MaxJoinAttemptTime"))
                    {
                        MaxJoinAttemptTime = ConfigUtilities.ParseTimeSpan(child.GetAttribute("MaxJoinAttemptTime"),
                                                                           "Invalid time value for the MaxJoinAttemptTime attribute on the Liveness element");
                    }
                    if (child.HasAttribute("ExpectedClusterSize"))
                    {
                        int expectedClusterSize = ConfigUtilities.ParseInt(child.GetAttribute("ExpectedClusterSize"),
                                                                           "Invalid integer value for the ExpectedClusterSize attribute on the Liveness element");
                        ExpectedClusterSizeConfigValue = new ConfigValue <int>(expectedClusterSize, false);
                    }
                    break;

                case "Azure":
                case "SystemStore":
                    if (child.LocalName == "Azure")
                    {
                        // Log warning about deprecated <Azure> element, but then continue on to parse it for connection string info
                        logger.Warn(ErrorCode.SiloConfigDeprecated, "The Azure element has been deprecated -- use SystemStore element instead.");
                    }

                    if (child.HasAttribute("SystemStoreType"))
                    {
                        var sst = child.GetAttribute("SystemStoreType");
                        if (!"None".Equals(sst, StringComparison.InvariantCultureIgnoreCase))
                        {
                            LivenessType = (LivenessProviderType)Enum.Parse(typeof(LivenessProviderType), sst);
                            SetReminderServiceType((ReminderServiceProviderType)Enum.Parse(typeof(ReminderServiceProviderType), sst));
                        }
                    }
                    if (child.HasAttribute("ServiceId"))
                    {
                        ServiceId = ConfigUtilities.ParseGuid(child.GetAttribute("ServiceId"),
                                                              "Invalid Guid value for the ServiceId attribute on the Azure element");
                    }
                    if (child.HasAttribute("DeploymentId"))
                    {
                        DeploymentId = child.GetAttribute("DeploymentId");
                    }
                    if (child.HasAttribute(Constants.DATA_CONNECTION_STRING_NAME))
                    {
                        DataConnectionString = child.GetAttribute(Constants.DATA_CONNECTION_STRING_NAME);
                        if (String.IsNullOrWhiteSpace(DataConnectionString))
                        {
                            throw new FormatException("SystemStore.DataConnectionString cannot be blank");
                        }
                    }
                    if (child.HasAttribute("MaxStorageBusyRetries"))
                    {
                        int maxBusyRetries = ConfigUtilities.ParseInt(child.GetAttribute("MaxStorageBusyRetries"),
                                                                      "Invalid integer value for the MaxStorageBusyRetries attribute on the SystemStore element");
                        AzureTableDefaultPolicies.MaxBusyRetries = maxBusyRetries;
                    }
                    if (child.HasAttribute("UseMockReminderTable"))
                    {
                        MockReminderTableTimeout = ConfigUtilities.ParseTimeSpan(child.GetAttribute("UseMockReminderTable"), "Invalid timeout value");
                        UseMockReminderTable     = true;
                    }
                    break;

                case "SeedNode":
                    SeedNodes.Add(ConfigUtilities.ParseIPEndPoint(child, Subnet));
                    break;

                case "Messaging":
                    base.Load(child);
                    break;

                case "Application":
                    Application.Load(child, logger);
                    break;

                case "PlacementStrategy":
                    if (child.HasAttribute("DefaultPlacementStrategy"))
                    {
                        DefaultPlacementStrategy = child.GetAttribute("DefaultPlacementStrategy");
                    }
                    if (child.HasAttribute("DeploymentLoadPublisherRefreshTime"))
                    {
                        DeploymentLoadPublisherRefreshTime = ConfigUtilities.ParseTimeSpan(child.GetAttribute("DeploymentLoadPublisherRefreshTime"),
                                                                                           "Invalid time span value for PlacementStrategy.DeploymentLoadPublisherRefreshTime");
                    }
                    if (child.HasAttribute("ActivationCountBasedPlacementChooseOutOf"))
                    {
                        ActivationCountBasedPlacementChooseOutOf = ConfigUtilities.ParseInt(child.GetAttribute("ActivationCountBasedPlacementChooseOutOf"),
                                                                                            "Invalid ActivationCountBasedPlacementChooseOutOf setting");
                    }
                    break;

                case "Caching":
                    if (child.HasAttribute("CacheSize"))
                    {
                        CacheSize = ConfigUtilities.ParseInt(child.GetAttribute("CacheSize"),
                                                             "Invalid integer value for Caching.CacheSize");
                    }

                    if (child.HasAttribute("InitialTTL"))
                    {
                        InitialCacheTTL = ConfigUtilities.ParseTimeSpan(child.GetAttribute("InitialTTL"),
                                                                        "Invalid time value for Caching.InitialTTL");
                    }

                    if (child.HasAttribute("MaximumTTL"))
                    {
                        MaximumCacheTTL = ConfigUtilities.ParseTimeSpan(child.GetAttribute("MaximumTTL"),
                                                                        "Invalid time value for Caching.MaximumTTL");
                    }

                    if (child.HasAttribute("TTLExtensionFactor"))
                    {
                        CacheTTLExtensionFactor = ConfigUtilities.ParseDouble(child.GetAttribute("TTLExtensionFactor"),
                                                                              "Invalid double value for Caching.TTLExtensionFactor");
                    }
                    if (CacheTTLExtensionFactor <= 1.0)
                    {
                        throw new FormatException("Caching.TTLExtensionFactor must be greater than 1.0");
                    }

                    if (child.HasAttribute("DirectoryCachingStrategy"))
                    {
                        DirectoryCachingStrategy = ConfigUtilities.ParseEnum <DirectoryCachingStrategyType>(child.GetAttribute("DirectoryCachingStrategy"),
                                                                                                            "Invalid value for Caching.Strategy");
                    }

                    break;

                case "Directory":
                    if (child.HasAttribute("DirectoryLazyDeregistrationDelay"))
                    {
                        DirectoryLazyDeregistrationDelay = ConfigUtilities.ParseTimeSpan(child.GetAttribute("DirectoryLazyDeregistrationDelay"),
                                                                                         "Invalid time span value for Directory.DirectoryLazyDeregistrationDelay");
                    }
                    break;

                default:
                    if (child.LocalName.EndsWith("Providers", StringComparison.Ordinal))
                    {
                        var providerConfig = new ProviderCategoryConfiguration();
                        providerConfig.Load(child);
                        ProviderConfigurations.Add(providerConfig.Name, providerConfig);
                    }
                    break;
                }
            }
        }