/// <summary> /// Initializes a new instance of the <see cref="PseudoNodes"/> class. /// </summary> /// <param name="backend">the backend to use</param> /// <param name="getSettingFunction">Function to get settings</param> public PseudoNodes(RingMasterBackendCore backend, Func <string, string> getSettingFunction) { if (getSettingFunction == null) { getSettingFunction = (s) => null; } this.getSetting = getSettingFunction; this.backend = backend; this.serviceHealingMgr = new ServiceHealingManager(this); }
/// <summary> /// establishes a candidate for the new member set. /// </summary> /// <param name="clusterMemberset">cluste memberset</param> /// <param name="proposedMemberset">proposed memberset</param> public void EnableNewRuntimeMemberset(List <ClusterMember> clusterMemberset, List <ClusterMember> proposedMemberset) { this.newMapping = null; if (clusterMemberset != null && proposedMemberset != null) { this.newMapping = ServiceHealingManager.GetMapping(clusterMemberset, proposedMemberset); if (this.newMapping.Count == 0) { this.newMapping = null; } } if (this.newMapping == null) { this.newMapping = null; this.minMembers = int.MaxValue; this.serviceHealingString = null; } else { if (proposedMemberset == null || clusterMemberset == null) { return; } if (clusterMemberset.Count == proposedMemberset.Count) { Trace.TraceInformation("EnableNewRuntimeMemberset: Service Healing detected: {0}", ServiceHealingManager.ToString(this.newMapping.Values)); } else { Trace.TraceInformation("EnableNewRuntimeMemberset: Scale Out detected: {0}", ServiceHealingManager.ToString(this.newMapping.Values)); } this.minMembers = (int)(clusterMemberset.Count / 2) + 1; this.serviceHealingString = string.Format("Cluster={0}-Runtime={1}", ServiceHealingManager.ToString(clusterMemberset), ServiceHealingManager.ToString(proposedMemberset)); } }
/// <summary> /// updates the health pesudo-nodes /// </summary> private void UpdateHealthNodes() { try { string basepath = "/$metadata/health"; Dictionary <string, HealthDefinition> health = this.backend.Factory.GetHealth(); List <Op> ops = new List <Op>(); foreach (string child in this.self.GetChildren(basepath, false)) { ops.Add(Op.Delete(basepath + "/" + child, -1, DeleteMode.SuccessEvenIfNodeDoesntExist)); } foreach (KeyValuePair <string, HealthDefinition> line in health) { ops.Add(Op.Delete(basepath + "/" + line.Key + " : " + line.Value.Description, -1, DeleteMode.SuccessEvenIfNodeDoesntExist)); ops.Add(Op.Create(basepath + "/" + line.Key + " : " + line.Value.Description, null, null, CreateMode.Ephemeral)); } string clusterpath = "/$metadata/clusterreplicaset"; foreach (string child in this.self.GetChildren(clusterpath, false)) { ops.Add(Op.Delete(clusterpath + "/" + child, -1)); } ops.Add(Op.Create(clusterpath + "/" + ServiceHealingManager.ToString(this.GetClusterMemberset()), null, null, CreateMode.Ephemeral | CreateMode.SuccessEvenIfNodeExistsFlag)); this.self.Multi(ops.AsReadOnly(), true, null, 0); } catch (Exception e) { Trace.TraceWarning("While UpdateHealthNodes: {0}", e); } }