/// <summary> /// This is for internal use only /// </summary> /// <param name="key"></param> public override sealed void BranchStatusUpdate(string address, BranchState state) { try { if (String.IsNullOrEmpty(address) || address == STEM.Sys.IO.Net.EmptyAddress) { return; } lock (_BranchBoundWeight) if (!_BranchBoundWeight.ContainsKey(address) && state == BranchState.Online) { _BranchBoundWeight[address] = 0; } if (state != BranchState.Online) { lock (_Keys) { List <string> bad = new List <string>(); foreach (string tag in _Keys.Keys) { if (_Keys[tag].BranchIP == address) { bad.Add(tag); } } foreach (string tag in bad) { lock (_Keys[tag]) { CoordinatedKeyManager.Unlock(tag, _Keys[tag]); } } lock (_BranchBoundWeight) _BranchBoundWeight.Remove(address); } } } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("KeyedDeploymentController.BranchStatusUpdate", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } SafeBranchStatusUpdate(address, state); }
public override void ExecutionComplete(DeploymentDetails details, List <Exception> exceptions) { base.ExecutionComplete(details, exceptions); List <string> locks = STEM.Sys.State.Containers.Session[details.InstructionSetID.ToString()] as List <string>; if (locks != null) { foreach (string s in locks) { CoordinatedKeyManager.Unlock(s); } STEM.Sys.State.Containers.Session[details.InstructionSetID.ToString()] = null; } }
public override DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches) { DeploymentDetails ret = null; List <string> locks = new List <string>(); Guid iSetID = Guid.Empty; try { int iter = _ListMap[initiationSource]; InstructionSet clone = GetTemplateInstance(true); CustomizeInstructionSet(clone, TemplateKVP, recommendedBranchIP, initiationSource, true); iSetID = clone.ID; List <List <string> > iSetLists = new List <List <string> >(); foreach (Instruction i in clone.Instructions) { foreach (PropertyInfo pi in i.GetType().GetProperties()) { if (ListPropertyNames.Contains(pi.Name)) { List <string> li = pi.GetValue(i) as List <string>; if (li != null) { iSetLists.Add(li); } } } } if (iSetLists.Count == 0) { throw new Exception("No fillable properties found in InstructionSet."); } if (CoordinatedKeyManager != null) { for (int x = (iter * GroupSize); x < ((iter * GroupSize) + GroupSize); x++) { if (_LastList.Count <= x) { break; } string s = ApplyKVP(_LastList[x], TemplateKVP, recommendedBranchIP, initiationSource, true); if (CoordinatedKeyManager.Lock(s, CoordinateWith)) { locks.Add(s); foreach (List <string> li in iSetLists) { li.Add(s); } } } } if (locks.Count == 0) { return(null); } ret = new DeploymentDetails(clone, recommendedBranchIP); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("GroupingController.GenerateDeploymentDetails", new Exception(InstructionSetTemplate + ": " + initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); foreach (string s in locks) { CoordinatedKeyManager.Unlock(s); } locks.Clear(); } finally { if (locks.Count > 0 && ret != null) { STEM.Sys.State.Containers.Session[iSetID.ToString()] = locks; } } return(ret); }
bool LockSerializationKey(string initiationSource) { try { string key = GenerateKey(initiationSource); BoundKey binding = null; while (true) { try { binding = _Keys.Values.FirstOrDefault(i => i.InitiationSource != null && i.InitiationSource.ToUpper() == initiationSource.ToUpper()); if (binding != null) { lock (binding) { if (key != null) { if (!binding.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)) { CoordinatedKeyManager.Unlock(binding.Key, binding); } } else if (!CoordinatedKeyManager.Locked(binding.InitiationSource)) { CoordinatedKeyManager.Unlock(binding.Key, binding); return(false); } } } break; } catch { } } if (key == null) { return(true); } lock (_Keys) { key = key.ToUpper(); binding = null; if (_Keys.ContainsKey(key)) { binding = _Keys[key]; } if (binding != null) { lock (binding) { if (binding.Assigned) { if (binding.InitiationSource != null) { if (!CoordinatedKeyManager.Locked(binding.InitiationSource)) { binding.InitiationSource = null; binding.Assigned = false; } else { return(false); } } else { binding.Assigned = false; } if (binding.Assigned) { return(false); } } if (CoordinatedKeyManager.CoordinatedMachineHasLock(key, CoordinateWith) == CoordinatedKeyManager.RemoteLockExists.True) { CoordinatedKeyManager.Unlock(key, binding); STEM.Sys.EventLog.WriteEntry("SerialDeploymentController.KeyedBranchIP", "A previously bound key has been found to be owned by a different DeploymentService.", STEM.Sys.EventLog.EventLogEntryType.Error); return(false); } _Keys[key].InitiationSource = initiationSource; _Keys[key].Assigned = true; } } else { binding = new BoundKey(this, initiationSource, key, true); if (UseSubnetCoordination) { if (!CoordinatedKeyManager.Lock(key, binding, CoordinateWith)) { return(false); } } else { if (!CoordinatedKeyManager.Lock(key, binding)) { return(false); } } } } } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("SerialDeploymentController.LockSerializationKey", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); return(false); } return(true); }
string LockSerializationKey(string initiationSource, string branchIP) { try { string key = GenerateKey(initiationSource); BoundKey binding = null; while (true) { try { binding = _Keys.Values.FirstOrDefault(i => i.InitiationSource != null && i.InitiationSource.ToUpper() == initiationSource.ToUpper()); if (binding != null) { lock (binding) { if (key != null) { if (!binding.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)) { CoordinatedKeyManager.Unlock(binding.Key, binding); } } else if (!CoordinatedKeyManager.Locked(binding.InitiationSource)) { CoordinatedKeyManager.Unlock(binding.Key, binding); return(null); } } } break; } catch { } } if (key == null) { return(branchIP); } lock (_Keys) { key = key.ToUpper(); binding = null; if (_Keys.ContainsKey(key)) { binding = _Keys[key]; } if (binding != null) { lock (binding) { if (binding.Assigned) { if (binding.InitiationSource != null) { if (!CoordinatedKeyManager.Locked(binding.InitiationSource)) { binding.InitiationSource = null; binding.Assigned = false; } else { return(null); } } else { binding.Assigned = false; } if (binding.Assigned) { return(null); } } if (CoordinatedKeyManager.CoordinatedMachineHasLock(key, CoordinateWith) == CoordinatedKeyManager.RemoteLockExists.True) { CoordinatedKeyManager.Unlock(key, binding); STEM.Sys.EventLog.WriteEntry("KeyedDeploymentController.LockSerializationKey", "A previously bound key has been found to be owned by a different DeploymentService.", STEM.Sys.EventLog.EventLogEntryType.Error); return(null); } if (FileExists(initiationSource)) { _Keys[key].FileSize = new FileInfo(initiationSource).Length; } _Keys[key].InitiationSource = initiationSource; _Keys[key].Assigned = true; return(_Keys[key].BranchIP); } } else { if (String.IsNullOrEmpty(branchIP) || branchIP == STEM.Sys.IO.Net.EmptyAddress) { return(null); } if (!_BranchBoundWeight.ContainsKey(branchIP)) { return(null); } branchIP = BestBranchByWeight(branchIP); if (branchIP == null) { return(null); } long fileLen = 0; if (FileExists(initiationSource)) { fileLen = GetFileInfo(initiationSource).Size; } binding = new BoundKey(this, initiationSource, key, branchIP, fileLen, true); if (!CoordinatedKeyManager.Lock(key, binding, CoordinateWith)) { return(null); } return(binding.BranchIP); } } } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("KeyedDeploymentController.LockSerializationKey", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } return(null); }