protected virtual _InstructionSet GetTemplateInstance(string templateName, bool cloneTemplate = false) { string txt = STEM.Sys.IO.TextFileManager.GetFileText(templateName); if (txt != null) { DateTime lwt = STEM.Sys.IO.TextFileManager.GetFileLastWriteTime(templateName); if (!_LastWriteTime.ContainsKey(templateName) || lwt > _LastWriteTime[templateName]) { try { _InstructionSet[templateName] = STEM.Sys.Serializable.Deserialize(txt) as _InstructionSet; _LastWriteTime[templateName] = lwt; } catch { } } } if (_InstructionSet.ContainsKey(templateName)) { _InstructionSet iSet = _InstructionSet[templateName]; if (cloneTemplate) { return(iSet.Clone(iSet)); } return(iSet); } return(null); }
public _InstructionSet(_InstructionSet iSet) { if (iSet == null) { throw new ArgumentNullException(nameof(iSet)); } Connection = iSet.Connection; DeploymentManagerRelease = iSet.DeploymentManagerRelease; ID = iSet.ID; BranchIP = iSet.BranchIP; Assigned = iSet.Assigned; Received = iSet.Received; Started = iSet.Started; Completed = iSet.Completed; DeploymentManagerIP = iSet.DeploymentManagerIP; DeploymentControllerID = iSet.DeploymentControllerID; DeploymentController = iSet.DeploymentController; InstructionSetTemplate = iSet.InstructionSetTemplate; InitiationSource = iSet.InitiationSource; ProcessName = iSet.ProcessName; ContinuousExecution = iSet.ContinuousExecution; ContinuousExecutionInterval = iSet.ContinuousExecutionInterval; ExecuteStaticInSandboxes = iSet.ExecuteStaticInSandboxes; CachePostMortem = iSet.CachePostMortem; ProcessName = iSet.ProcessName; PostMortemMetaData = new Sys.Serialization.Dictionary <string, string>(iSet.PostMortemMetaData); _Instructions = iSet._Instructions; _InstructionDocument = iSet._InstructionDocument; _SerializationSourceInstructionDocument = iSet._SerializationSourceInstructionDocument; }
/// <summary> /// This method generates InstructionSets upon request. When called, GenerateDeploymentDetails is assured that tainitiationSourcergetSource is /// exclusively "locked" for assignment at that time. /// </summary> /// <param name="listPreprocessResult">The list of initiationSources returned from the most recent call to ListPreprocess</param> /// <param name="initiationSource">The initiationSource from the listPreprocessResult list for which an InstructionSet is being requested</param> /// <param name="recommendedBranchIP">The Branch IP that is preferred for this assignment</param> /// <param name="limitedToBranches">The Branch IPs that this assignment is limited to in case you choose to override recommendedBranchIP</param> /// <returns>The DeploymentDetails instance containing the InstructionSet to be assigned, or null if no assignment should be made at this time</returns> public virtual DeploymentDetails GenerateDeploymentDetails(IReadOnlyList <string> listPreprocessResult, string initiationSource, string recommendedBranchIP, IReadOnlyList <string> limitedToBranches) { DeploymentDetails ret = null; try { _InstructionSet clone = GetTemplateInstance(true); CustomizeInstructionSet(clone, TemplateKVP, recommendedBranchIP, initiationSource, true); bool updated = clone.PopulateAuthenticationDetails(GetAuthenticationStore()); if (updated) { CustomizeInstructionSet(clone, TemplateKVP, recommendedBranchIP, initiationSource, true); } return(new DeploymentDetails(clone, recommendedBranchIP)); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("DeploymentController.GenerateDeploymentDetails", new Exception(InstructionSetTemplate + ": " + initiationSource, ex).ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } return(ret); }
/// <summary> /// Typically used from GenerateDeploymentDetails /// </summary> /// <param name="iSet">The InstructionSet being deployed</param> /// <param name="branchIP">The Branch to which it should be delivered</param> public DeploymentDetails(_InstructionSet iSet, string branchIP) { if (iSet == null) { throw new System.ArgumentNullException(nameof(iSet)); } if (System.String.IsNullOrEmpty(branchIP)) { throw new System.ArgumentNullException(nameof(branchIP)); } ISet = iSet; BranchIP = branchIP; DeploymentManagerIP = "0.0.0.0"; InitiationSource = ISet.InitiationSource; InstructionSetID = ISet.ID; DeploymentControllerID = ISet.DeploymentControllerID; SwitchboardRowID = ""; Issued = DateTime.MinValue; Received = DateTime.MinValue; Completed = DateTime.MinValue; LastModified = DateTime.MinValue; DeploymentController = ""; Exceptions = new List <Exception>(); }
/// <summary> /// Customize an iSetTemplate by applying the TemplateKVP map to the InstructionsXml /// </summary> /// <param name="iSetTemplate">A clone of the template to be modified in this method</param> /// <param name="map">The TemplateKVP map used to modify the iSetTemplate</param> /// <param name="cloneMap">Should the map be cloned as it will be modified in this method</param> public virtual void CustomizeInstructionSet(_InstructionSet iSetTemplate, System.Collections.Generic.Dictionary <string, string> map, bool cloneMap = true) { if (iSetTemplate == null) { throw new ArgumentNullException(nameof(iSetTemplate)); } if (map == null) { throw new ArgumentNullException(nameof(map)); } iSetTemplate.SerializationSourceInstructionDocument = ApplyKVP(iSetTemplate.SerializationSourceInstructionDocument, map, cloneMap); iSetTemplate.RandomizeInstructionIDs(); }
/// <summary> /// Customize an iSetTemplate by applying the TemplateKVP map to the InstructionsXml /// </summary> /// <param name="iSetTemplate">A clone of the template to be modified in this method</param> /// <param name="map">The TemplateKVP map used to modify the iSetTemplate</param> /// <param name="branchIP">The branchIP this will be assigned to</param> /// <param name="initiationSource">The initiationSource passed in to GenerateDeploymentDetails()</param> /// <param name="cloneMap">Should the map be cloned as it will be modified in this method</param> public virtual void CustomizeInstructionSet(_InstructionSet iSetTemplate, System.Collections.Generic.Dictionary <string, string> map, string branchIP, string initiationSource, bool cloneMap = true) { if (iSetTemplate == null) { throw new ArgumentNullException(nameof(iSetTemplate)); } if (map == null) { throw new ArgumentNullException(nameof(map)); } if (String.IsNullOrEmpty(branchIP)) { throw new ArgumentNullException(nameof(branchIP)); } if (String.IsNullOrEmpty(initiationSource)) { throw new ArgumentNullException(nameof(initiationSource)); } System.Collections.Generic.Dictionary <string, string> kvp = map; if (cloneMap) { kvp = new System.Collections.Generic.Dictionary <string, string>(map); } Guid iSetID = Guid.NewGuid(); kvp["[BranchIP]"] = branchIP; kvp["[BranchName]"] = STEM.Sys.IO.Net.MachineName(branchIP); kvp["[ISetID]"] = iSetID.ToString(); kvp["[InitiationSource]"] = initiationSource; CustomizeInstructionSet(iSetTemplate, kvp, false); iSetTemplate.ID = iSetID; }
/// <summary> /// Customize an iSetTemplate by applying the TemplateKVP map to the InstructionsXml /// </summary> /// <param name="iSetTemplate">A clone of the template to be modified in this method</param> /// <param name="map">The TemplateKVP map used to modify the iSetTemplate</param> /// <param name="branchIP">The branchIP this will be assigned to</param> /// <param name="initiationSource">The initiationSource passed in to GenerateDeploymentDetails()</param> /// <param name="cloneMap">Should the map be cloned as it will be modified in this method</param> public override void CustomizeInstructionSet(_InstructionSet iSetTemplate, System.Collections.Generic.Dictionary <string, string> map, string branchIP, string initiationSource, bool cloneMap = true) { if (iSetTemplate == null) { throw new ArgumentNullException(nameof(iSetTemplate)); } if (map == null) { throw new ArgumentNullException(nameof(map)); } if (String.IsNullOrEmpty(branchIP)) { throw new ArgumentNullException(nameof(branchIP)); } if (String.IsNullOrEmpty(initiationSource)) { throw new ArgumentNullException(nameof(initiationSource)); } System.Collections.Generic.Dictionary <string, string> kvp = map; if (cloneMap) { kvp = new System.Collections.Generic.Dictionary <string, string>(map); } kvp["[TargetPath]"] = STEM.Sys.IO.Path.GetDirectoryName(initiationSource); if (!String.IsNullOrEmpty(kvp["[TargetPath]"])) { kvp["[TargetDirectoryName]"] = STEM.Sys.IO.Path.GetFileName(kvp["[TargetPath]"]); kvp["[TargetName]"] = STEM.Sys.IO.Path.GetFileName(initiationSource); kvp["[TargetNameWithoutExt]"] = STEM.Sys.IO.Path.GetFileNameWithoutExtension(initiationSource); kvp["[TargetExt]"] = STEM.Sys.IO.Path.GetExtension(initiationSource); } else { kvp["[TargetPath]"] = ""; kvp["[TargetDirectoryName]"] = ""; kvp["[TargetName]"] = ""; kvp["[TargeteNameWithoutExt]"] = ""; kvp["[TargetExt]"] = ""; } kvp["[SourceAddress]"] = STEM.Sys.IO.Path.IPFromPath(initiationSource); kvp["[SourceMachineName]"] = STEM.Sys.IO.Net.MachineName(kvp["[SourceAddress]"]); string xml = iSetTemplate.SerializationSourceInstructionDocument; bool getFileInfo = false; if (xml.IndexOf("[LastWriteTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } if (getFileInfo == false) { if (xml.IndexOf("[LastAccessTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } } if (getFileInfo == false) { if (xml.IndexOf("[CreationTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } } if (getFileInfo == false) { if (xml.IndexOf("[FileSize]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; } } if (getFileInfo == false) { foreach (string k in kvp.Keys) { if (kvp[k] != null) { if (kvp[k].IndexOf("[LastWriteTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } if (kvp[k].IndexOf("[LastAccessTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } if (kvp[k].IndexOf("[CreationTimeUtc]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } if (kvp[k].IndexOf("[FileSize]", StringComparison.InvariantCultureIgnoreCase) >= 0) { getFileInfo = true; break; } } } } if (getFileInfo) { STEM.Sys.IO.Listing.FileInfo info = GetFileInfo(initiationSource); if (info == null) { info = new STEM.Sys.IO.Listing.FileInfo { CreationTimeUtc = DateTime.MinValue, LastAccessTimeUtc = DateTime.MinValue, LastWriteTimeUtc = DateTime.MinValue, Size = 0 } } ; foreach (string key in kvp.Keys.Where(i => i.Equals("[LastWriteTimeUtc]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.LastWriteTimeUtc.ToString(kvp[key], System.Globalization.CultureInfo.CurrentCulture); } catch { } } foreach (string key in kvp.Keys.Where(i => i.Equals("[LastAccessTimeUtc]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.LastAccessTimeUtc.ToString(kvp[key], System.Globalization.CultureInfo.CurrentCulture); } catch { } } foreach (string key in kvp.Keys.Where(i => i.Equals("[CreationTimeUtc]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.CreationTimeUtc.ToString(kvp[key], System.Globalization.CultureInfo.CurrentCulture); } catch { } } foreach (string key in kvp.Keys.Where(i => i.Equals("[FileSize]", StringComparison.InvariantCultureIgnoreCase)).ToList()) { try { kvp[key] = info.Size.ToString(); } catch { } } } string subDir = null; if (!String.IsNullOrEmpty(RecreateSubFromRootOf) && RecreateSubFromRootOf.Trim().Length > 0) { if (initiationSource.ToUpper(System.Globalization.CultureInfo.CurrentCulture).IndexOf(RecreateSubFromRootOf.ToUpper(System.Globalization.CultureInfo.CurrentCulture), StringComparison.InvariantCultureIgnoreCase) >= 0) { int startIndex = initiationSource.ToUpper(System.Globalization.CultureInfo.CurrentCulture).IndexOf(RecreateSubFromRootOf.ToUpper(System.Globalization.CultureInfo.CurrentCulture), StringComparison.InvariantCultureIgnoreCase) + RecreateSubFromRootOf.Length + 1; if (startIndex < STEM.Sys.IO.Path.GetDirectoryName(initiationSource).Length) { subDir = initiationSource.Substring(startIndex, STEM.Sys.IO.Path.GetDirectoryName(initiationSource).Length - startIndex); } } } if (subDir == null) { subDir = ""; } kvp["[SubDir]"] = subDir; base.CustomizeInstructionSet(iSetTemplate, kvp, branchIP, initiationSource, false); }
public void Unlock(STEM.Surge.Messages.ExecutionCompleted message) { lock (this) { if (ExecutionCompleted) { return; } if (Branch != null) { try { Branch.Remove(this); } catch { } } if (DeploymentDetails != null && message != null) { try { if (DeploymentDetails.Completed == DateTime.MinValue || message.TimeCompleted > DateTime.MinValue) { DeploymentDetails.Exceptions = message.Exceptions; DeploymentDetails.Completed = message.TimeCompleted; if (DeploymentDetails.Completed == DateTime.MinValue) { DeploymentDetails.Completed = DateTime.UtcNow; } if (DeploymentDetails.Issued == DateTime.MinValue || DeploymentDetails.Issued > DeploymentDetails.Completed) { DeploymentDetails.Issued = DeploymentDetails.Completed; } if (DeploymentDetails.Received == DateTime.MinValue || DeploymentDetails.Received > DeploymentDetails.Completed) { DeploymentDetails.Received = DeploymentDetails.Completed; } DeploymentDetails.LastModified = DateTime.UtcNow; if (message.InstructionSetXml != null) { try { _InstructionSet iSet = _InstructionSet.Deserialize(message.InstructionSetXml) as _InstructionSet; if (iSet != null) { DeploymentDetails.ISet = iSet; } else if (DeploymentDetails.ISet != null) { DeploymentDetails.ISet.Assigned = DeploymentDetails.Issued; DeploymentDetails.ISet.Started = DeploymentDetails.Received; DeploymentDetails.ISet.Received = DeploymentDetails.Received; DeploymentDetails.ISet.Completed = DeploymentDetails.Completed; } } catch { } } else if (DeploymentDetails.ISet != null) { DeploymentDetails.ISet.Assigned = DeploymentDetails.Issued; DeploymentDetails.ISet.Started = DeploymentDetails.Received; DeploymentDetails.ISet.Received = DeploymentDetails.Received; DeploymentDetails.ISet.Completed = DeploymentDetails.Completed; } } } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("InitiationSourceLockOwner.Unlock", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } } try { if (message != null) { try { _DeploymentController controller = ControllerManager.ValidatedController; if (controller != null) { _ExecutionCompletePool.BeginAsync(new ExecutionComplete(ControllerManager, DeploymentDetails, controller, message), TimeSpan.FromMilliseconds(100)); } //if (ControllerManager.CurrentPhase != _ControllerManager.ExecutionPhase.Disposing) //{ // DateTime n = DateTime.UtcNow; // DateTime e = DateTime.UtcNow; // _DeploymentController controller = ControllerManager.ValidatedController; // if (controller != null) // try // { // if (DeploymentDetails != null) // { // controller.ExecutionComplete(DeploymentDetails, message.Exceptions); // controller.InstructionMessageReceived(message, DeploymentDetails); // } // controller.MessageReceived(message); // e = DateTime.UtcNow; // if ((e - n).TotalMilliseconds > 1000) // STEM.Sys.EventLog.WriteEntry("InitiationSourceLockOwner.InstructionMessageReceived", "Direct Call \r\nController: " + ControllerManager.DeploymentController + " - Time: " + (e - n).TotalMilliseconds + " ms", STEM.Sys.EventLog.EventLogEntryType.Error); // } // catch (Exception ex) // { // STEM.Sys.EventLog.WriteEntry("InitiationSourceLockOwner.Unlock", new Exception("Call into " + ControllerManager.DeploymentController + ".ExecutionComplete() threw an exception.", ex), STEM.Sys.EventLog.EventLogEntryType.Error); // } //} } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("InitiationSourceLockOwner.Unlock", ex, STEM.Sys.EventLog.EventLogEntryType.Error); } } if (InitiationSource != null) { try { if (RequiredTargetNameCoordination) { string key = STEM.Sys.IO.Path.GetFileName(InitiationSource); ControllerManager.KeyManager.Unlock(key, this); } ControllerManager.KeyManager.Unlock(InitiationSource, this); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("InitiationSourceLockOwner.Unlock", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } } finally { InitiationSource = null; } }
public abstract _InstructionSet Clone(_InstructionSet iSet);
public RequestResume(STEM.Surge._InstructionSet iSet) { InstructionSet = iSet; }