public static void Configure(InstanceGroupConfig groupConfig)
 {
     if (!HttpConfiguration.isConfigured)
     {
         lock (HttpConfiguration.lockObj)
         {
             if (!HttpConfiguration.isConfigured)
             {
                 DxSerializationUtil.UseBinarySerialize = groupConfig.Settings.IsUseBinarySerializerForClientCommunication;
                 HttpConfiguration.UseEncryption        = groupConfig.Settings.IsUseEncryption;
                 HttpConfiguration.IsZeroboxMode        = groupConfig.IsZeroboxMode;
                 bool flag2 = true;
                 if (HttpConfiguration.UseEncryption && flag2)
                 {
                     ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(HttpConfiguration.IgnoreCertValidate);
                 }
                 else
                 {
                     ServicePointManager.ServerCertificateValidationCallback = null;
                 }
                 HttpConfiguration.isConfigured = true;
             }
         }
     }
 }
Exemple #2
0
        public InstanceGroupConfig GetGroupConfig(string groupName, bool isFillDefaultValueIfNotExist = false)
        {
            InstanceGroupConfig instanceGroupConfig = null;

            groupName = this.ResolveGroupName(groupName);
            if (string.IsNullOrEmpty(groupName) && isFillDefaultValueIfNotExist)
            {
                groupName = "B1563499-EA40-4101-A9E6-59A8EB26FF1E";
            }
            using (RegistryKey registryKey = this.OpenGroupConfigKey(groupName, false))
            {
                if (registryKey != null || isFillDefaultValueIfNotExist)
                {
                    instanceGroupConfig = new InstanceGroupConfig();
                    instanceGroupConfig.NameResolver            = this;
                    instanceGroupConfig.Self                    = this.Self;
                    instanceGroupConfig.ComponentName           = this.componentName;
                    instanceGroupConfig.IsZeroboxMode           = this.isZeroboxMode;
                    instanceGroupConfig.Name                    = groupName;
                    instanceGroupConfig.IsExistInConfigProvider = (registryKey != null);
                    instanceGroupConfig.Identity                = string.Format("Group/{0}/{1}/{2}", this.componentName, groupName, this.Self);
                    string defaultGroupName = this.GetDefaultGroupName();
                    instanceGroupConfig.IsAutomaticActionsAllowed        = RegUtils.GetBoolProperty(registryKey, "IsAutomaticActionsAllowed", false);
                    instanceGroupConfig.IsRestartRequested               = RegUtils.GetBoolProperty(registryKey, "IsRestartRequested", false);
                    instanceGroupConfig.IsConfigurationManagedExternally = RegUtils.GetBoolProperty(registryKey, "IsConfigurationManagedExternally", false);
                    instanceGroupConfig.ConfigInProgressExpiryTime       = RegUtils.GetTimeProperty(registryKey, "ConfigInProgressExpiryTime");
                    instanceGroupConfig.IsDefaultGroup       = Utils.IsEqual(groupName, defaultGroupName, StringComparison.OrdinalIgnoreCase);
                    instanceGroupConfig.IsConfigurationReady = (DateTimeOffset.Now > instanceGroupConfig.ConfigInProgressExpiryTime);
                    instanceGroupConfig.Members  = this.GetGroupMemberConfigs(groupName);
                    instanceGroupConfig.Settings = this.GetGroupSettings(groupName);
                }
            }
            return(instanceGroupConfig);
        }
Exemple #3
0
        public static ServiceEndpoint GetStoreInstanceEndpoint(InstanceGroupConfig cfg, string target, bool isUseDefaultGroup, bool isServerBinding, WcfTimeout timeout = null)
        {
            string storeInstanceEndPointAddress = cfg.GetStoreInstanceEndPointAddress(target, isUseDefaultGroup);
            string bindingName = cfg.ConstructUniqueInstanceBindingName(target, isUseDefaultGroup);

            timeout = (timeout ?? cfg.Settings.StoreInstanceWcfTimeout);
            return(EndpointBuilder.ConstructAndInitializeEndpoint(typeof(IDxStoreInstance), storeInstanceEndPointAddress, bindingName, timeout, isServerBinding));
        }
Exemple #4
0
 public static HttpClient.TargetInfo BuildFromNode(string nodeName, InstanceGroupConfig groupConfig)
 {
     if (groupConfig == null)
     {
         return(new HttpClient.TargetInfo(nodeName, nodeName, "NoGroupName"));
     }
     return(new HttpClient.TargetInfo(groupConfig.GetMemberNetworkAddress(nodeName), nodeName, groupConfig.Name));
 }
Exemple #5
0
 public AccessClientFactory(InstanceGroupConfig groupCfg, WcfTimeout timeout = null)
 {
     this.FactoryByTarget = new ConcurrentDictionary <string, Tuple <CachedChannelFactory <IDxStoreAccess>, IDxStoreAccessClient> >();
     this.groupCfg        = groupCfg;
     this.DefaultTimeout  = timeout;
     if (groupCfg.Settings.IsUseHttpTransportForClientCommunication)
     {
         HttpConfiguration.Configure(this.groupCfg);
     }
 }
        public static InstanceGroupMemberConfig GetMemberConfig(this InstanceGroupConfig cfg, string memberName)
        {
            InstanceGroupMemberConfig result = null;

            if (memberName == null)
            {
                memberName = cfg.Self;
            }
            if (cfg.Members != null)
            {
                result = cfg.Members.FirstOrDefault((InstanceGroupMemberConfig mc) => Utils.IsEqual(mc.Name, memberName, StringComparison.OrdinalIgnoreCase));
            }
            return(result);
        }
        public static bool IsMembersChanged(this InstanceGroupConfig groupCfg, InstanceGroupMemberConfig[] members)
        {
            int num  = (members != null) ? members.Length : 0;
            int num2 = (groupCfg != null) ? groupCfg.Members.Length : 0;

            if (num != num2)
            {
                return(true);
            }
            if (groupCfg == null || members == null)
            {
                return(false);
            }
            int num3 = members.Count((InstanceGroupMemberConfig member) => groupCfg.Members.Any((InstanceGroupMemberConfig gm) => Utils.IsEqual(gm.Name, member.Name, StringComparison.OrdinalIgnoreCase)));

            return(num3 != num);
        }
 public static string ConstructUniqueInstanceBindingName(this InstanceGroupConfig cfg, string target, bool isUseDefaultGroup)
 {
     target = ExtensionMethods.ResolveTarget(cfg.Self, target);
     return(EndpointBuilder.ConstructUniqueBindingName(target, cfg.ComponentName, cfg.Settings.InstanceEndpointProtocolName, "Instance", isUseDefaultGroup ? "B1563499-EA40-4101-A9E6-59A8EB26FF1E" : cfg.Name, cfg.IsZeroboxMode));
 }
 public static string GetStoreInstanceEndPointAddress(this InstanceGroupConfig cfg, string target, bool isUseDefaultGroupIdentifier)
 {
     return(cfg.GetGroupEndPointAddress("Instance", target, cfg.Settings.InstanceEndpointPortNumber, cfg.Settings.InstanceEndpointProtocolName, isUseDefaultGroupIdentifier));
 }
 public static string GetGroupEndPointAddress(this InstanceGroupConfig cfg, string interfaceName, string target, int portNumber, string protocolName, bool isUseDefaultGroupIdentifier)
 {
     return(EndpointBuilder.ConstructEndpointAddress(interfaceName, cfg.ComponentName, cfg.Self, target, cfg.GetMemberNetworkAddress(target), isUseDefaultGroupIdentifier ? "B1563499-EA40-4101-A9E6-59A8EB26FF1E" : cfg.Name, cfg.IsZeroboxMode, portNumber, protocolName));
 }
        public static string GetMemberNetworkAddress(this InstanceGroupConfig cfg, string target)
        {
            InstanceGroupMemberConfig memberConfig = cfg.GetMemberConfig(target);

            return(EndpointBuilder.GetNetworkAddress(cfg.Self, target, (memberConfig != null) ? memberConfig.NetworkAddress : null, cfg.NameResolver, false));
        }
        public static Dictionary <string, ServiceEndpoint> GetAllMemberAccessClientEndPoints(this InstanceGroupConfig cfg, bool isUseDefaultGroup = false, WcfTimeout timeout = null)
        {
            Dictionary <string, ServiceEndpoint> dictionary = new Dictionary <string, ServiceEndpoint>();

            foreach (InstanceGroupMemberConfig instanceGroupMemberConfig in cfg.Members)
            {
                ServiceEndpoint storeAccessEndpoint = cfg.GetStoreAccessEndpoint(instanceGroupMemberConfig.Name, false, false, timeout ?? cfg.Settings.StoreAccessWcfTimeout);
                dictionary[instanceGroupMemberConfig.Name] = storeAccessEndpoint;
            }
            return(dictionary);
        }
Exemple #13
0
 public InstanceClientFactory(InstanceGroupConfig groupCfg, WcfTimeout timeout = null)
 {
     this.FactoryByTarget = new ConcurrentDictionary <string, Tuple <CachedChannelFactory <IDxStoreInstance>, DxStoreInstanceClient> >();
     this.groupCfg        = groupCfg;
     this.DefaultTimeout  = timeout;
 }
Exemple #14
0
        public void RefreshTopology(bool isForceRefresh = false)
        {
            TopologyInfo topology = null;
            bool         flag     = DxStoreRegistryConfigProvider.Tracer.IsTraceEnabled(TraceType.DebugTrace);

            Utils.RunOperation(this.ManagerConfig.Identity, "RefreshTopology", delegate
            {
                topology = this.GetLocalServerTopology(isForceRefresh);
            }, this.eventLogger, LogOptions.LogException, true, new TimeSpan?(TimeSpan.FromMinutes(1.0)), new TimeSpan?(this.ManagerConfig.Settings.PeriodicExceptionLoggingDuration), null, null, null);
            if (topology != null)
            {
                if (topology.IsConfigured)
                {
                    if (flag)
                    {
                        DxStoreRegistryConfigProvider.Tracer.TraceDebug <string, string>(0L, "RefreshConfig found a valid topology '{0}' members: {1}", topology.Name, topology.Members.JoinWithComma("<null>"));
                    }
                    if (!topology.IsAllMembersVersionCompatible)
                    {
                        DxStoreRegistryConfigProvider.Tracer.TraceDebug <string>(0L, "RefreshConfig found that some of the members are version compatible - will be retrying in next iteration", topology.Name);
                        return;
                    }
                    bool flag2 = false;
                    InstanceGroupMemberConfig[] configuredMembers = Utils.EmptyArray <InstanceGroupMemberConfig>();
                    string[]            serversToRemove           = Utils.EmptyArray <string>();
                    InstanceGroupConfig groupConfig = this.GetGroupConfig(topology.Name, false);
                    if (groupConfig != null)
                    {
                        if (flag)
                        {
                            DxStoreRegistryConfigProvider.Tracer.TraceDebug <string, string>(0L, "Group {0} already exist with configured members {1}", topology.Name, (from m in groupConfig.Members
                                                                                                                                                                        select m.Name).JoinWithComma("<null>"));
                        }
                        flag2             = true;
                        configuredMembers = groupConfig.Members;
                        if (!groupConfig.Settings.IsAppendOnlyMembership)
                        {
                            serversToRemove = (from m in configuredMembers
                                               let isFound = topology.Members.Any((string tm) => string.Equals(tm, m.Name))
                                                             where !isFound && !m.IsManagedExternally
                                                             select m.Name).ToArray <string>();
                        }
                    }
                    string[] serversToAdd = (from tm in topology.Members
                                             let isFound = configuredMembers.Any((InstanceGroupMemberConfig m) => string.Equals(tm, m.Name))
                                                           where !isFound
                                                           select tm).ToArray <string>();
                    this.UpdateMembers(topology.Name, serversToRemove, serversToAdd, !flag2, !flag2);
                    return;
                }
                else
                {
                    InstanceGroupConfig[] allGroupConfigs = this.GetAllGroupConfigs();
                    foreach (InstanceGroupConfig instanceGroupConfig in allGroupConfigs)
                    {
                        if (instanceGroupConfig.IsMember(instanceGroupConfig.Self, true))
                        {
                            string[] array2 = (from member in instanceGroupConfig.Members
                                               where !member.IsManagedExternally
                                               select member into m
                                               select m.Name).ToArray <string>();
                            if (flag)
                            {
                                DxStoreRegistryConfigProvider.Tracer.TraceDebug <string, string>(0L, "{0}: Removing members '{1}' from group since local node is not part of group member any more", instanceGroupConfig.Identity, array2.JoinWithComma("<null>"));
                            }
                            this.RemoveMembers(instanceGroupConfig.Name, array2);
                        }
                    }
                }
            }
        }