public XDocument GetCrlXDocument(string uniqueLabelForCheckRunSegment) { XDocument result = null; string truncatedId = CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment); try { lock (m_CheckRunLaunchLockObject) { result = m_CRL_XDocuments[truncatedId]; m_CRL_XDocuments.Remove(truncatedId); } } catch (KeyNotFoundException ex) { string existingKeys = null; lock (m_CheckRunArtifactLockObject) { existingKeys = this.ListCrlKeys(); } string message = string.Format("GetCrlXDocument Failed to find a key. ID='{0}{1}{2}', truncated='{3}{4}{5}', existingkeys='{6}'", Environment.NewLine, uniqueLabelForCheckRunSegment, Environment.NewLine, Environment.NewLine, truncatedId, Environment.NewLine, this.ListCrlKeys()); throw new CheckInfrastructureServiceException(message, ex); } return(result); }
public string CompleteCheckRun(XDocument checkRunArtifact) { string uniqueLabelForCheckRunSegment = CrxDepot.Instance.SetCraXDocument(checkRunArtifact); Synchronization.ReleaseOne(CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment)); return(uniqueLabelForCheckRunSegment); }
public XDocument GetCrlXDocument(string uniqueLabelForCheckRunSegment) { XDocument result = null; string truncatedId = CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment); string crlFileName = CrlFilePrefix + this.FileNameFromTruncatedId(truncatedId); result = XDocument.Load(Path.Combine(this.m_CrlDirectory, crlFileName)); return(result); }
public string SetCraXDocument(XDocument xDocCra) { string uniqueLabelForCheckRunSegment = CheckRunDataHandles.CreateIdFromCrxXDocument(xDocCra); string truncatedId = CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment); string craFileName = CraFilePrefix + this.FileNameFromTruncatedId(truncatedId); string fullFileNameAndPath = Path.Combine(this.m_CraDirectory, craFileName); xDocCra.Save(fullFileNameAndPath); return(uniqueLabelForCheckRunSegment); }
public string SetCraXDocument(XDocument xDocCra) { string uniqueLabelForCheckRunSegment = CheckRunDataHandles.CreateIdFromCrxXDocument(xDocCra); string truncatedId = CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment); lock (m_CheckRunArtifactLockObject) { m_CRA_XDocuments.Add(truncatedId, xDocCra); } return(uniqueLabelForCheckRunSegment); }
public string SetCrlXDocument(XDocument crlXDoc) { string uniqueLabelForCheckRunSegment = CheckRunDataHandles.CreateIdFromCrxXDocument(crlXDoc); string truncatedId = CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment); lock (m_CheckRunLaunchLockObject) { m_CRL_XDocuments.Add(truncatedId, crlXDoc); } return(uniqueLabelForCheckRunSegment); }
public bool ClearCrlXDocumentById(string uniqueLabelForCheckRunSegment) { bool documentRemoved = false; try { string truncatedId = CheckRunDataHandles.StripIdOfMachineNames(uniqueLabelForCheckRunSegment); lock (m_CheckRunLaunchLockObject) { documentRemoved = m_CRL_XDocuments.Remove(truncatedId); } } catch (KeyNotFoundException) { // do nothing } return(documentRemoved); }
/// <summary> /// Runs a check to completion, or throws an exception /// </summary> /// <param name="checkRunLaunch">The check run launch (CRL) object</param> /// <returns>The check run artifact (CRA)</returns> public XDocument Run(XDocument checkRunLaunch) { // Always set the root CheckRunData/DataElement[@Name='OriginMachine'] to value EnvironmentMachineName, // so it's clear on which machine/OS instance the named semaphore is stored string xPathToOriginMachineDataElement = string.Format( "{0}/{1}[@{2}='{3}']", DataStringConstants.ElementNames.CheckRunData, DataStringConstants.ElementNames.DataElement, DataStringConstants.AttributeNames.Name, DataStringConstants.NameAttributeValues.OriginMachine); // skip the null-checks because they are unnecessary; the schema enforces this XElement originMachineElement = checkRunLaunch.Root.XPathSelectElement(xPathToOriginMachineDataElement); XAttribute originAttribute = originMachineElement.Attribute(DataStringConstants.AttributeNames.Value); originAttribute.Value = Environment.MachineName; // This identifier is used for the named semaphore that synchronizes for the cross-process, cross-machine check run string uniqueLabelForCheckRunSegment = CheckRunDataHandles.CreateIdFromCrxXDocument(checkRunLaunch); string semaphoreServiceSideUser = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.ThreadPoolUserName); string semaphoreTimeoutString = DataAccessors.GetCheckRunValue(checkRunLaunch, DataStringConstants.NameAttributeValues.SemaphoreTimeOutMilliseconds); int semaphoreTimeoutMS = 0; try { semaphoreTimeoutMS = int.Parse(semaphoreTimeoutString); } catch (Exception ex) { throw new CheckInfrastructureClientException(string.Format("Parse failed for the configured SemaphoreTimeOutMilliseconds string '{0}'. See InnerException", semaphoreTimeoutString), ex); } // Create semaphore with modification rights for the test user Semaphore checkRunSemaphore = MetaAutomationClientMtLibrary.Synchronization.CreateAndGetNamedSemaphore(semaphoreServiceSideUser, uniqueLabelForCheckRunSegment); string startResult = m_MetaAutomationServiceClient.StartCheckRun(checkRunLaunch.ToString()); if (startResult != MetaAutomationBaseMtLibrary.DataStringConstants.StatusString.DefaultServiceSuccessMessage) { throw new CheckInfrastructureClientException(string.Format("StartCheckRun failed with error '{0}'", startResult)); } bool receivedSignal = checkRunSemaphore.WaitOne(semaphoreTimeoutMS); string resultString = null; XDocument resultCRA = null; try { if (receivedSignal) { resultString = m_MetaAutomationServiceClient.GetCheckRunArtifact(uniqueLabelForCheckRunSegment); resultCRA = DataValidation.Instance.ValidateCheckRunArtifactIntoXDocument(resultString); } else { throw new CheckRunException(string.Format("A semaphore waiting on completion of a sub-check timed out at the configured '{0}' milliseconds.", semaphoreTimeoutMS)); } } catch (CheckInfrastructureClientException) { throw; } catch (Exception ex) { string abortMessage = m_MetaAutomationServiceClient.GetAbortMessage(uniqueLabelForCheckRunSegment); throw new CheckInfrastructureClientException(string.Format("Check run failed with error '{0}'. The abort message is '{1}'. See InnerException.", resultString, abortMessage), ex); } return(resultCRA); }
/// <summary> /// This method is ONLY to be used for launching checks, not sub-checks. /// It creates a CheckRunLaunch object from the passed CheckRunArtifact object, the data members supplied, /// and any custom data. /// All custom data from the passed CheckRunArtifact is removed. /// </summary> /// <param name="lastArtifactForThisCheckMethod"></param> /// <returns></returns> public XDocument CreateCheckRunLaunch(XDocument lastArtifactForThisCheckMethod = null) { XDocument crlXDocumentResult = null; if (m_CrlDataElements == null) { throw new CheckInfrastructureClientException("CreateCheckRunLaunch: the DataMember Dictionary is null."); } if (m_CrlDataElements.Count == 0) { throw new CheckInfrastructureClientException("CreateCheckRunLaunch: the DataMember Dictionary has zero entries."); } if (m_CrlDataElements[DataStringConstants.NameAttributeValues.CheckRunGuid] == null) { throw new CheckInfrastructureClientException(string.Format("CreateCheckRunLaunch: the DataMember Dictionary must have a '{0}' entry.", DataStringConstants.NameAttributeValues.CheckRunGuid)); } try { XElement checkRunDataElement = null; if (lastArtifactForThisCheckMethod == null) { crlXDocumentResult = XDocument.Parse(@"<?xml version='1.0' encoding='utf-8'?><CheckRunLaunch><CheckRunData/><CheckCustomData/><CheckFailData/><CompleteCheckStepInfo/></CheckRunLaunch>"); checkRunDataElement = crlXDocumentResult.Root.Element(DataStringConstants.ElementNames.CheckRunData); foreach (KeyValuePair <string, string> nameValuePair in m_CrlDataElements) { // Add the name/value pairs checkRunDataElement.Add( new XElement(DataStringConstants.ElementNames.DataElement, new XAttribute[] { new XAttribute(DataStringConstants.AttributeNames.Name, nameValuePair.Key), new XAttribute(DataStringConstants.AttributeNames.Value, nameValuePair.Value) })); } } else { // Validate CRA DataValidation.Instance.ValidateCheckRunArtifact(lastArtifactForThisCheckMethod); // Transform CRA to CRL CheckRunTransforms checkRunTransforms = new CheckRunTransforms(); crlXDocumentResult = checkRunTransforms.ConvertCheckRunArtifactToCheckRunLaunch(lastArtifactForThisCheckMethod); // Populate or overwrite with the supplied data, and for DataElement elements that are not specified, give them empty-string values // to prevent spurious data passing from the previous CRA to the current CRL checkRunDataElement = crlXDocumentResult.Root.Element(DataStringConstants.ElementNames.CheckRunData); // Iterate through the DataElement elements in doc order var dataElementIterator = checkRunDataElement.Elements(DataStringConstants.ElementNames.DataElement); foreach (XElement dataElement in dataElementIterator) { XAttribute nameAttribute = dataElement.Attribute(DataStringConstants.AttributeNames.Name); XAttribute valueAttribute = dataElement.Attribute(DataStringConstants.AttributeNames.Value); string name = nameAttribute.Value; if (m_CrlDataElements.ContainsKey(name)) { valueAttribute.Value = m_CrlDataElements[name]; } else if ( (nameAttribute.Value == DataStringConstants.NameAttributeValues.CheckBeginTime) || (nameAttribute.Value == DataStringConstants.NameAttributeValues.CheckEndTime) #if DEBUG || (nameAttribute.Value == DataStringConstants.NameAttributeValues.CheckObjectStorageKey) #endif ) { // Begin and end times are special cases, to be cleaned out here valueAttribute.Value = string.Empty; } } } // Initialize Reserved_SubCheckMap in the CRL, for root check and all subchecks this.SetCheckCounters(checkRunDataElement); #if DEBUG this.DecrementCountDownToFail(crlXDocumentResult); #endif #if DEBUG DataValidation.Instance.ValidateCheckRunLaunch(crlXDocumentResult); #endif if ((this.m_CustomDataElements != null) && (this.m_CustomDataElements.Count > 0)) { XElement customDataElement = crlXDocumentResult.Root.Element(DataStringConstants.ElementNames.CheckCustomData); if (customDataElement == null) { checkRunDataElement.AddAfterSelf(new XElement(DataStringConstants.ElementNames.CheckCustomData)); customDataElement = crlXDocumentResult.Root.Element(DataStringConstants.ElementNames.CheckCustomData); } foreach (KeyValuePair <string, string> nameValuePair in m_CustomDataElements) { XElement existingElementForKey = customDataElement.XPathSelectElement( string.Format("{0}[@{1}]", DataStringConstants.ElementNames.DataElement, nameValuePair.Key)); if (existingElementForKey == null) { // Add the name/value pairs customDataElement.Add( new XElement(DataStringConstants.ElementNames.DataElement, new XAttribute[] { new XAttribute(DataStringConstants.AttributeNames.Name, nameValuePair.Key), new XAttribute(DataStringConstants.AttributeNames.Value, nameValuePair.Value) })); } else { // update the value XAttribute valueAttribute = existingElementForKey.Attribute(DataStringConstants.AttributeNames.Value); if (valueAttribute == null) { existingElementForKey.Add(new XAttribute(DataStringConstants.AttributeNames.Value, nameValuePair.Value)); } else { valueAttribute.Value = nameValuePair.Value; } } } } #if DEBUG string id = CheckRunDataHandles.CreateIdFromCrxXDocument(crlXDocumentResult); this.AddSafeDataElement( crlXDocumentResult.Root.Element(DataStringConstants.ElementNames.CheckRunData), DataStringConstants.NameAttributeValues.CheckObjectStorageKey, id); #endif #if DEBUG DataValidation.Instance.ValidateCheckRunLaunch(crlXDocumentResult); #endif } catch (Exception) { throw; } return(crlXDocumentResult); }
public string GetDestinationMachineName(string uniqueLabelForCheckRunSegment) { return(CheckRunDataHandles.GetDestinationMachineName(uniqueLabelForCheckRunSegment)); }
public bool IsDestinationMachineLocalInstance(string uniqueLabelForCheckRunSegment) { return(CheckRunDataHandles.GetDestinationMachineName(uniqueLabelForCheckRunSegment) == System.Net.Dns.GetHostName().ToUpper()); }