/// <summary> /// Generate the delta table /// </summary> public void GenerateDeltaTable() { int[] mappedChangesets = getMappedSubversionChanges(); if (null == mappedChangesets || 0 == mappedChangesets.Length) { TraceManager.TraceInformation("There are no changes in the repository '{0}'", m_repository.URI); return; } var pager = new ChangeSetPageManager(m_repository, mappedChangesets, m_configurationManager.ChangesetCacheSize); do { TraceManager.TraceInformation("Analyzing Subversion revision {0} : {1}/{2}", pager.CurrentRevision, pager.CurrentIndex + 1, mappedChangesets.Length); ChangeSet changeSet = pager.Current; if (null != changeSet) { int actions = analyzeChangeset(changeSet, mappedChangesets); TraceManager.TraceInformation("Created {0} actions for subversion revision {1}", actions, pager.CurrentRevision); } else { //TODO Maybe add a conflict here so that the user can decide what to do. This condition should not occur though TraceManager.TraceWarning("Unable to retrieve the change details for revision {0}", pager.CurrentRevision); } m_hwmDelta.Update(pager.CurrentRevision); m_changeGroupService.PromoteDeltaToPending(); }while (pager.MoveNext()); pager.Reset(); }
private void generateSnapshotForVCSession() { foreach (var setting in m_configurationService.VcCustomSetting.Settings.Setting) { if (setting.SettingKey == "SnapshotStartPoint") { m_sessionLevelSnapshotTime = parseSnapShotStartPoint(setting.SettingValue); } } m_hwmDelta.Reload(); if (m_hwmDelta.Value >= m_sessionLevelSnapshotTime) { // We've already passed snapshot changeset Id, just return. m_sessionlevelSnapshotCompleted = true; return; } ChangeGroup snapshotGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotTime, 0); m_clearCaseServer.SetConfigSpecForSnapshotStartPoint(m_sessionLevelSnapshotTime); try { foreach (MappingEntry mappingEntry in m_configurationService.Filters) { if (mappingEntry.Cloak) { continue; } string localMappingPath = m_clearCaseServer.GetViewLocalPathFromServerPath(mappingEntry.Path); foreach (string subDirectory in Directory.GetDirectories(localMappingPath, "*", SearchOption.AllDirectories)) { createAddActionForSnapshot(snapshotGroup, subDirectory, true); } foreach (string subFile in Directory.GetFiles(localMappingPath, "*", SearchOption.AllDirectories)) { createAddActionForSnapshot(snapshotGroup, subFile, false); } } } finally { m_clearCaseServer.ResetConfigSpec(); } snapshotGroup.Save(); m_hwmDelta.Update(m_sessionLevelSnapshotTime); m_changeGroupService.PromoteDeltaToPending(); m_sessionlevelSnapshotCompleted = true; }
/// <summary> /// Generates the delta table. /// </summary> public override void GenerateDeltaTable() { string viewName = this.configurationService.Filters[0].Path; TraceManager.TraceInformation("WSSWIT:AP:GenerateDeltaTable:View - {0}", viewName); highWaterMarkDelta.Reload(); GetSharePointTaskUpdates(viewName); highWaterMarkDelta.Update(DateTime.Now); changeGroupService.PromoteDeltaToPending(); }
/// <summary> /// Generate the delta table. /// </summary> public override void GenerateDeltaTable() { TraceManager.TraceInformation("WSSVC:AP:GenerateDeltaTable"); highWaterMarkDelta.Reload(); TraceManager.TraceInformation("\tWSSVC:AP:Initial HighWaterMark {0} ", highWaterMarkDelta.Value); deltaTableStartTime = DateTime.Now; TraceManager.TraceInformation("\tWSSVC:AP:CutOff {0} ", deltaTableStartTime); GetSharePointUpdates(); highWaterMarkDelta.Update(deltaTableStartTime); TraceManager.TraceInformation("\tWSSVC:AP:Updated HighWaterMark {0} ", highWaterMarkDelta.Value); changeGroupService.PromoteDeltaToPending(); }
/// <summary> /// Gets the share point task updates. /// </summary> /// <param name="viewName">Name of the view.</param> private void GetSharePointTaskUpdates(string viewName) { TraceManager.TraceInformation("WSSWIT:AP:GetSharePointTaskUpdates"); using (SharePoint.Lists sharePointList = new SharePoint.Lists()) { sharePointList.Url = string.Format(CultureInfo.CurrentCulture, "{0}/_vti_bin/lists.asmx", configurationService.ServerUrl); string listName = configurationService.MigrationSource.SourceIdentifier; string username = string.Empty; string password = string.Empty; foreach (CustomSetting customSetting in configurationService.MigrationSource.CustomSettings.CustomSetting) { switch (customSetting.SettingKey) { case "username": { username = customSetting.SettingValue; break; } case "password": { password = customSetting.SettingValue; break; } } } sharePointList.Credentials = new System.Net.NetworkCredential(username, password); TraceManager.TraceInformation("\tWSSWIT:AP:Getting items from the list {0} on {1} with username {2}", listName, sharePointList.Url, username); XElement rawListItems = XDocument.Parse(sharePointList.GetListItems(listName, viewName, (XmlNode)SharePointHelpers.Query, (XmlNode)SharePointHelpers.ViewFields, "0", (XmlNode)SharePointHelpers.QueryOptions, string.Empty).OuterXml).Root; Collection <SharePointListItem> listItems = SharePointHelpers.ParseItems(rawListItems); foreach (SharePointListItem task in listItems) { Guid actionGuid = WellKnownChangeActionId.Add; if (highWaterMarkDelta.Value != DateTime.MinValue && task.ModifiedOn.CompareTo(highWaterMarkDelta.Value) > 0) { actionGuid = WellKnownChangeActionId.Edit; } else { actionGuid = WellKnownChangeActionId.Add; } ChangeGroup changeGroup = CreateChangeGroup(highWaterMarkChangeSet.Value, 0); changeGroup.CreateAction(actionGuid, task, string.Empty, listName, string.Empty, string.Empty, WellKnownContentType.WorkItem.ReferenceName, CreateFieldRevisionDescriptionDoc(task)); changeGroup.Save(); highWaterMarkChangeSet.Update(highWaterMarkChangeSet.Value + 1); } } }
public override void GenerateDeltaTable() { TraceManager.TraceInformation("POC:AP:GenerateDeltaTable"); m_hwmDelta.Reload(); TraceManager.TraceInformation(" POC:HighWaterMark {0} ", m_hwmDelta.Value); deltaTableStartTime = DateTime.Now; TraceManager.TraceInformation(" POC:CutOff {0} ", deltaTableStartTime); ReadOnlyCollection <MappingEntry> filters = ConfigurationService.Filters; GetPocUpdates(filters[0].Path); m_hwmDelta.Update(deltaTableStartTime); m_changeGroupService.PromoteDeltaToPending(); }
public override bool ProceedToAnalysis(AnalysisContext analysisContext) { m_semaphoreFileTouchedTime = GetSemaphoreFileTouchedTime(); m_hwmSemaphoreFile.Reload(); if (m_semaphoreFileTouchedTime > m_hwmSemaphoreFile.Value) { // Persisted DateTime is rounded down to the nearest second in the DB. Add // a second to the HWM to make sure we don't take changes due to shaved milliseconds. TimeSpan oneSecond = new TimeSpan(0, 0, 1); m_hwmSemaphoreFile.Update(m_semaphoreFileTouchedTime + oneSecond); return(true); } else { return(false); } }
private ChangeGroup createMigrationAction(CCHistoryRecord historyRecord, Guid actionId) { string versionExtendedPath; if (m_clearCaseServer.UsePrecreatedView) { versionExtendedPath = historyRecord.VersionExtendedPath; } else { versionExtendedPath = ClearCasePath.removeViewLocationFromVersion(historyRecord.VersionExtendedPath, m_clearCaseServer.ViewRootPath); } ChangeGroup oldChangeGroup; ChangeGroup currentChangeGroup = m_changeGroupService.AddMigrationActionToDeltaTable(historyRecord.EventId.ToString(CultureInfo.InvariantCulture), historyRecord.Comment, null, historyRecord.EventId, actionId, new ClearCaseMigrationItem( m_ccConfiguration.GetViewName("Analysis"), versionExtendedPath, historyRecord.IsDirectory), historyRecord.AbsoluteVobPathFrom, historyRecord.AbsoluteVobPath, null, null, historyRecord.IsDirectory ? WellKnownContentType.VersionControlledFolder.ReferenceName : WellKnownContentType.VersionControlledFile.ReferenceName, null, historyRecord.VersionTime, out oldChangeGroup); m_hwmEventId.Update(historyRecord.EventId); if ((oldChangeGroup != null) && (oldChangeGroup != currentChangeGroup)) { oldChangeGroup.Save(); m_changeGroupService.PromoteDeltaToPending(); m_hwmDelta.Update(historyRecord.VersionTime); } return(currentChangeGroup); }
private void initializeDestinationTfsClient() { try { m_destinationTfs = VersionSpecificUtils.GetVersionControlServer(ConfigurationService.PeerServerUrl); if (m_hwmLastSyncedTfsChangeset != null) { ConfigurationService.RegisterHighWaterMarkWithSession(m_hwmLastSyncedTfsChangeset); m_hwmLastSyncedTfsChangeset.Reload(); if (m_hwmLastSyncedTfsChangeset.Value < 1) { m_hwmLastSyncedTfsChangeset.Update(1); } } } catch (Exception ex) { // The destination must be a TFS server. throw new MigrationException(string.Format(TfsFileSystemResources.ErrorConnectingTargetTfsServer, ex.Message), ex); } }
/// <summary> /// Generate the delta table /// </summary> public void GenerateDeltaTable() { // Load the current high water mark from any previous run of this session m_hwmDelta.Reload(); m_renameList = null; m_renameListUpdated = false; // Removing the in-progress change groups created by this side (fils system) m_changeGroupService.RemoveInProgressChangeGroups(); if (m_changeGroupService.GetInProgressMigrationInstructionCount() > 0) { // If there are in-progress migration instructions translated from the other side, mark this delta table as contentcon flict detection only. m_contentConflictDetectionOnly = true; TraceManager.TraceInformation("Migration instruction in progress, the delta table will be generated for content conflict detection only"); } else { m_contentConflictDetectionOnly = false; } DateTime newHighWaterMarkTime = DateTime.Now; List <String> pathsToBeVerified = new List <String>(); int versionToBeSynced = 0; // In a two-way sync, versionToBeSynced is set to the last sync point - either the latest changeset migrated from TFS or the latest changeset migrated to TFS // In one way sync, versionToBeSynced is always set to the GetLatestChangesetId of TFS if (m_hwmLastSyncedTfsChangeset != null) { // m_hwmLastSyncedTfsChangeset is the latest TFS changeset migrated to the file system side. // This highwater mark will be set when TfsFileSystemAnalysisProvider is combined with another provider to form a two-way sync. m_hwmLastSyncedTfsChangeset.Reload(); // m_lastHighWaterMarkMigratedToPeer is the latest TFS changeset migrated from this TfsFileSystemAnalysisProvider. m_lastHighWaterMarkMigratedToPeer.Reload(); versionToBeSynced = m_lastHighWaterMarkMigratedToPeer.Value > m_hwmLastSyncedTfsChangeset.Value ? m_lastHighWaterMarkMigratedToPeer.Value : m_hwmLastSyncedTfsChangeset.Value; } else { versionToBeSynced = m_destinationTfs.GetLatestChangesetId(); } FileSystemVerifier fileSystemVerifier = new FileSystemVerifier(); ChangeGroup changeGroup = m_changeGroupService.CreateChangeGroupForDeltaTable(DateTime.Now.ToString()); populateChangeGroupMetaData(changeGroup); foreach (MappingEntry m in ConfigurationService.Filters) { if (m.Cloak) { continue; } string canonicalPath = removeTrailingSlash(m.Path); fileSystemVerifier.AddPathForVerification(canonicalPath); analyzeFolder(canonicalPath, versionToBeSynced, changeGroup); } if (!fileSystemVerifier.Verify()) { TraceManager.TraceError( "Analysis failed as the local file system state was changed during the analysis phase. No changes were created."); markChangeGroupAsObsolete(changeGroup); return; } if (changeGroup.Actions.Count > 0) { // We only want to promote deltas to pending if we actually created and saved a change group. changeGroup.Save(); m_changeGroupService.PromoteDeltaToPending(); } else { markChangeGroupAsObsolete(changeGroup); } m_lastTfsChangesetAnalyzed.Update(versionToBeSynced); m_hwmDelta.Update(newHighWaterMarkTime); TraceManager.TraceInformation(String.Format(CultureInfo.InvariantCulture, TfsFileSystemResources.UpdatedHighWaterMark, newHighWaterMarkTime)); }
public void GenerateDeltaTable() { try { if (!m_isLoginUserSQLEditor) { ValidateIsSQLEditor(); m_isLoginUserSQLEditor = true; } // load high watermark; as for CQ, we store local time for queries m_hwmDelta.Reload(); DateTime hwmDeltaValue = m_hwmDelta.Value; if (hwmDeltaValue.Equals(default(DateTime))) { hwmDeltaValue = new DateTime(1900, 1, 1); } hwmDeltaValue = hwmDeltaValue.AddSeconds(-1); // go back 1 second as we'll drop the millisec below m_migrationContext.CurrentHWMBaseLine = hwmDeltaValue; // HACK HACK HACK //string hwmDeltaValueStr = hwmDeltaValue.ToString("o"); // using "ISO 8601" DateTime string format string hwmDeltaValueStr = hwmDeltaValue.ToString("u").Replace("Z", ""); // using "ISO 8601" DateTime string format if (hwmDeltaValueStr.LastIndexOf('.') >= 0) { hwmDeltaValueStr = hwmDeltaValueStr.Substring(0, hwmDeltaValueStr.LastIndexOf('.')); // drop the millisec } // HACK HACK HACK DateTime newHwmValue = DateTime.Now; foreach (CQRecordFilter filter in m_filters) { ComputeDeltaPerRecordType(filter, hwmDeltaValueStr); } // persist results and hwm TraceManager.TraceInformation("Promote delta to pending."); m_changeGroupService.PromoteDeltaToPending(); m_hwmDelta.Update(newHwmValue); TraceManager.TraceInformation("Persisted CQ HWM: {0}", ClearQuestConstants.CqRecordHwm); TraceManager.TraceInformation("Updated CQ HWM: {0}", newHwmValue.ToString()); } catch (ClearQuestInsufficientPrivilegeException privEx) { ConflictResolutionResult rslt = UtilityMethods.HandleInsufficientPriviledgeException(privEx, m_conflictManagerService); if (rslt.Resolved) { // todo: currently not expected, as we only enabled manual/skip resolution action } } catch (ClearQuestCOMDllNotFoundException cqComNotFoundEx) { UtilityMethods.HandleCOMDllNotFoundException(cqComNotFoundEx, ErrorManager, m_conflictManagerService); } catch (ClearQuestCOMCallException cqComCallEx) { UtilityMethods.HandleCQComCallException(cqComCallEx, ErrorManager, m_conflictManagerService); } catch (Exception ex) { ErrorManager errMgr = null; if (m_analysisServiceContainer != null) { errMgr = m_analysisServiceContainer.GetService(typeof(ErrorManager)) as ErrorManager; } UtilityMethods.HandleGeneralException(ex, errMgr, m_conflictManagerService); } }
/// <summary> /// Create a changegroup that contains all change actions needed to bring a migration target to the specificed snapshot /// </summary> /// <param name="changeGroupName">The change group name of the snapshot</param> private void generateSnapshotForVCSession() { foreach (var setting in ConfigurationService.VcCustomSetting.Settings.Setting) { if (setting.SettingKey == "SnapshotStartPoint") { m_sessionLevelSnapshotChangeset = parseSnapShotStartPoint(setting.SettingValue); } else if (setting.SettingKey == "SnapshotBatchSize") { try { m_snapshotCheckinBatchSize = int.Parse(setting.SettingValue); } catch (Exception) { // wrong format, use the default batch size } } } m_hwmDelta.Reload(); if (m_hwmDelta.Value >= m_sessionLevelSnapshotChangeset) { // We've already passed snapshot changeset Id, just return. m_sessionlevelSnapshotCompleted = true; return; } VersionSpec snapshotVersionSpec = new ChangesetVersionSpec(m_sessionLevelSnapshotChangeset); List <string> pathsToGet = new List <string>(); foreach (MappingEntry mappingEntry in ConfigurationService.Filters) { if (mappingEntry.Cloak) { continue; } // Always query at one level down the mapping ItemSet itemSet = m_tfsClient.GetItems(mappingEntry.Path, snapshotVersionSpec, RecursionType.OneLevel); Item[] items = itemSet.Items; foreach (Item childItem in items) { // Avoid the item itself. if (!VersionControlPath.Equals(childItem.ServerItem, mappingEntry.Path)) { pathsToGet.Add(childItem.ServerItem); } } } int countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize; int batchExecutionOrder = m_sessionLevelSnapshotChangeset; ChangeGroup batchGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotChangeset, batchExecutionOrder); foreach (string path in pathsToGet) { TraceManager.TraceInformation("Getting snapshot at changeset: {0}, path: {1}", m_sessionLevelSnapshotChangeset, path); ItemSet itemSet = m_tfsClient.GetItems(path, snapshotVersionSpec, RecursionType.Full); Item[] items = itemSet.Items; itemSet = null; TraceManager.TraceInformation("Snapshot contains {0} items", items.Length); for (int i = 0; i < items.Length; i++) { // We want to include the situation where a snapshot on a path is the same as the snapshot of the VC session. // In this situation, we want to include the item in the session snapshot changeset. // So we use changesetId + 1 as the reference changeset id. if (IsPathMapped(items[i].ServerItem, m_sessionLevelSnapshotChangeset + 1) == MappingResult.Mapped) { countDownToCreateNewChangeGroup--; if (countDownToCreateNewChangeGroup == 0) { TraceManager.TraceInformation("Saving {0} change actions", m_snapshotCheckinBatchSize); batchGroup.Save(); batchGroup.Actions.Clear(); batchGroup = null; batchExecutionOrder--; batchGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotChangeset, batchExecutionOrder); countDownToCreateNewChangeGroup = m_snapshotCheckinBatchSize; TraceManager.TraceInformation("Saved {0} change actions", m_snapshotCheckinBatchSize); } batchGroup.CreateAction( WellKnownChangeActionId.Add, new TfsMigrationItem(items[i]), null, items[i].ServerItem, null, null, TfsAnalysisAlgorithms.convertContentType(items[i].ItemType), null); } items[i] = null; // Dispose this object to reduce memory consumption. } } if (batchGroup.Actions.Count > 0) { int numRemainingItems = batchGroup.Actions.Count; TraceManager.TraceInformation("Saving {0} change actions", numRemainingItems); batchGroup.Save(); TraceManager.TraceInformation("Saved {0} change actions", numRemainingItems); } m_hwmDelta.Update(m_sessionLevelSnapshotChangeset); m_changeGroupService.PromoteDeltaToPending(); m_sessionlevelSnapshotCompleted = true; }
public virtual ReadOnlyCollection <LinkChangeGroup> GenerateNextLinkDeltaSlice( LinkService linkService, int maxDeltaSliceSize) { try { var linkChangeGroups = new List <LinkChangeGroup>(); if (null == ExtractLinkChangeActionsCallback) { return(linkChangeGroups.AsReadOnly()); } // load main Highwater Mark m_hwmLink.Reload(); DateTime hwmLinkValue = m_hwmLink.Value; string hwmLinkValueStr = hwmLinkValue.ToString(CultureInfo.InvariantCulture); // load Work Items for extracting links string sourceId = m_migrationSource.UniqueId; string storeName = m_migrationSource.WorkItemStore.StoreName; // Get items based on primary Highwater Mark TraceManager.TraceInformation(TfsWITAdapterResources.GettingModifiedItems, sourceId, storeName); IEnumerable <TfsMigrationWorkItem> items = m_migrationSource.WorkItemStore.GetItems(ref hwmLinkValueStr); TraceManager.TraceInformation(TfsWITAdapterResources.ReceivedModifiedItems, sourceId, storeName); // Record the updated HWM value DateTime newHwmLinkValue = Convert.ToDateTime(hwmLinkValueStr, CultureInfo.InvariantCulture); // store to be used to analyze deleted links WorkItemLinkStore store = new WorkItemLinkStore(new Guid(sourceId)); // extract links var inMaxDeltaSliceSize = maxDeltaSliceSize; foreach (TfsMigrationWorkItem tfsMigrationWorkItem in items) { if (tfsMigrationWorkItem.WorkItem == null) { continue; } TraceManager.TraceInformation("Generating linking delta for Work Item: {0}", tfsMigrationWorkItem.WorkItem.Id.ToString()); var perWorkItemlinkChangeGroups = new List <LinkChangeGroup>(); ExtractLinkChangeActionsCallback(tfsMigrationWorkItem, perWorkItemlinkChangeGroups, store); if (perWorkItemlinkChangeGroups.Count == 0) { TraceManager.TraceInformation("Number of links: {0}", 0); continue; } LinkChangeGroup consolidatedLinkChangeGroup = perWorkItemlinkChangeGroups[0]; for (int i = 1; i < perWorkItemlinkChangeGroups.Count; ++i) { foreach (LinkChangeAction action in perWorkItemlinkChangeGroups[i].Actions) { consolidatedLinkChangeGroup.AddChangeAction(action); } } TraceManager.TraceInformation("Number of links: {0}", consolidatedLinkChangeGroup.Actions.Count.ToString()); // VERY IMPORTANT: use the RelatedArtifactsStore to detect link deletion store.UpdatePerItemLinkChangeGroupsByCheckingRelatedItemRecords( tfsMigrationWorkItem.Uri, consolidatedLinkChangeGroup, this); if (consolidatedLinkChangeGroup.Actions.Count > 0) { linkChangeGroups.Add(consolidatedLinkChangeGroup); } maxDeltaSliceSize -= consolidatedLinkChangeGroup.Actions.Count; if (maxDeltaSliceSize <= 0) { // size limit reached - persist groups to DB linkService.AddChangeGroups(linkChangeGroups); linkChangeGroups.Clear(); maxDeltaSliceSize = inMaxDeltaSliceSize; } } // persist remaining groups to DB linkService.AddChangeGroups(linkChangeGroups); // clean up the returned link change group collection // when the caller (toolkit) receives an empty collection, it understands there is no more // delta to generate for the moment, and proceeds to next phase linkChangeGroups.Clear(); // update primary Highwater Mark m_hwmLink.Update(newHwmLinkValue); TraceManager.TraceInformation("Persisted WIT linking HWM: {0}", Toolkit.Constants.HwmDeltaLink); TraceManager.TraceInformation(TfsWITAdapterResources.UpdatedHighWatermark, hwmLinkValueStr); return(linkChangeGroups.AsReadOnly()); } catch (Exception exception) { ErrorManager errMgr = m_serviceContainer.GetService(typeof(ErrorManager)) as ErrorManager; errMgr.TryHandleException(exception); return(new List <LinkChangeGroup>().AsReadOnly()); } }
private void SetServerLinkChangeIds(List <LinkChangeAction> linkChangeActions) { if (linkChangeActions.Count == 0) { return; } m_hwmSubmittedLinkChangeId.Reload(); long hwmSubmittedValue = m_hwmSubmittedLinkChangeId.Value; Dictionary <int, List <LinkChangeAction> > linkChangeActionsByLowerId = new Dictionary <int, List <LinkChangeAction> >(); foreach (LinkChangeAction action in linkChangeActions) { int workItemIdKey = GetLowerWorkItemId(action); if (!linkChangeActionsByLowerId.ContainsKey(workItemIdKey)) { linkChangeActionsByLowerId.Add(workItemIdKey, new List <LinkChangeAction>()); } linkChangeActionsByLowerId[workItemIdKey].Add(action); } /* * TraceManager.TraceVerbose(String.Format( * "SetServerLinkChangeIds calling WorkItemServer.GetWorkItemLinkChanges to find Ids for {0} successful link actions starting with RowNumber {1}", * linkChangeActions.Count, hwmSubmittedValue)); */ Stopwatch stopwatch = Stopwatch.StartNew(); int serverLinkChangeIdsSet = 0; foreach (WorkItemLinkChange linkChange in WorkItemServer.GetWorkItemLinkChanges(Guid.NewGuid().ToString(), hwmSubmittedValue)) { int linkChangeKey = GetLowerWorkItemId(linkChange); List <LinkChangeAction> actions; if (linkChangeActionsByLowerId.TryGetValue(linkChangeKey, out actions)) { foreach (LinkChangeAction action in actions) { if (LinkChangeMatchesLinkAction(linkChange, action)) { action.ServerLinkChangeId = linkChange.RowVersion.ToString(); serverLinkChangeIdsSet++; hwmSubmittedValue = linkChange.RowVersion; // Don't break here because there could be more than one LinkChangeAction in the list that matches the WorkItemLinkChange // break; } } } } stopwatch.Stop(); TraceManager.TraceVerbose("Time to call GetWorkItemLinkChanges() and process return values: {0} seconds", stopwatch.Elapsed.TotalSeconds); if (serverLinkChangeIdsSet < linkChangeActions.Count) { // Look for any LinkChangeActions that did not get the ServerLinkChangeId set foreach (LinkChangeAction linkChangeAction in linkChangeActions) { if (linkChangeAction.ServerLinkChangeId == null) { string msg = String.Format( "Unable to set ServerLinkChangeId on at least one LinkChangeAction: {0} '{1}'->'{2}' ({3})", linkChangeAction.ChangeActionId == WellKnownChangeActionId.Add ? "Add" : "Delete", linkChangeAction.Link.SourceArtifact.Uri, linkChangeAction.Link.TargetArtifact.Uri, linkChangeAction.Link.LinkType.ReferenceName); TraceManager.TraceWarning(msg); break; } } } /* * else * { * TraceManager.TraceVerbose(String.Format("SetServerLinkChangeIds set values for {0} link actions ending with RowNumber {1}", * serverLinkChangeIdsSet, hwmSubmittedValue)); * } */ m_hwmSubmittedLinkChangeId.Update(hwmSubmittedValue); TraceManager.TraceInformation("Persisted WIT linking sequence HWM: {0} (MigrationSourceId: {1})", TfsConstants.HwmSubmittedLinkChangeId, m_hwmSubmittedLinkChangeId.SourceUniqueId.ToString()); TraceManager.TraceInformation(TfsWITAdapterResources.UpdatedHighWatermark, hwmSubmittedValue); }
private void generateSnapshotForVCSession() { foreach (var setting in m_configurationService.VcCustomSetting.Settings.Setting) { if (setting.SettingKey == "SnapshotStartPoint") { m_sessionLevelSnapshotTime = parseSnapShotStartPoint(setting.SettingValue); } } m_hwmDelta.Reload(); if (m_hwmDelta.Value >= m_sessionLevelSnapshotTime) { // We've already passed snapshot changeset Id, just return. m_sessionlevelSnapshotCompleted = true; return; } ChangeGroup snapshotGroup = createChangeGroupForSnapshot(m_sessionLevelSnapshotTime, 0); m_clearCaseServer.SetConfigSpecForSnapshotStartPoint(m_sessionLevelSnapshotTime); try { foreach (MappingEntry mappingEntry in m_configurationService.Filters) { if (mappingEntry.Cloak) { continue; } string localMappingPath = m_clearCaseServer.GetViewLocalPathFromServerPath(mappingEntry.Path); foreach (string subDirectory in Directory.GetDirectories(localMappingPath, "*", SearchOption.AllDirectories)) { string serverPath = m_clearCaseServer.GetServerPathFromViewLocalPath(subDirectory); snapshotGroup.CreateAction( WellKnownChangeActionId.Add, new ClearCaseMigrationItem( m_clearCaseServer.ViewName, m_clearCaseServer.ApplicationClass.get_Element(serverPath).Version.ExtendedPath, true), null, serverPath, null, null, WellKnownContentType.VersionControlledFolder.ReferenceName, null); } foreach (string subFile in Directory.GetFiles(localMappingPath, "*", SearchOption.AllDirectories)) { string serverPath = m_clearCaseServer.GetServerPathFromViewLocalPath(subFile); snapshotGroup.CreateAction( WellKnownChangeActionId.Add, new ClearCaseMigrationItem( m_clearCaseServer.ViewName, m_clearCaseServer.ApplicationClass.get_Element(serverPath).Version.ExtendedPath, true), null, serverPath, null, null, WellKnownContentType.VersionControlledFile.ReferenceName, null); } } } finally { m_clearCaseServer.ResetConfigSpec(); } snapshotGroup.Save(); m_hwmDelta.Update(m_sessionLevelSnapshotTime); m_changeGroupService.PromoteDeltaToPending(); m_sessionlevelSnapshotCompleted = true; }
public ReadOnlyCollection <LinkChangeGroup> GenerateNextLinkDeltaSlice( LinkService linkService, int maxDeltaSliceSize) { try { var linkChangeGroups = new List <LinkChangeGroup>(); if (null == ExtractLinkChangeActionsCallback) { return(linkChangeGroups.AsReadOnly()); } // load high watermark; as for CQ, we store local time for queries m_hwmLink.Reload(); DateTime hwmDeltaValue = m_hwmLink.Value; if (hwmDeltaValue.Equals(default(DateTime))) { hwmDeltaValue = new DateTime(1900, 1, 1); } hwmDeltaValue = hwmDeltaValue.AddSeconds(-1); // go back 1 second as we'll drop the millisec below string hwmDeltaValueStr = hwmDeltaValue.ToString(m_migrationContext.CQQueryDateTimeFormat, CultureInfo.InvariantCulture); // record current time to update HWM after processing DateTime newHwmValue = CQUtilityMethods.GetTimeForNewHighWaterMark(m_migrationContext.CQTimeOffsetFromServerHistoryTimesInMinutes); // store to be used for analysis WorkItemLinkStore store = new WorkItemLinkStore(m_configurationService.SourceId); // extract links var inMaxDeltaSliceSize = maxDeltaSliceSize; foreach (CQRecordFilter filter in m_filters) { CQRecordQueryBase recordQuery = CQRecordQueryFactory.CreateQuery(m_userSession, filter, hwmDeltaValueStr, this); foreach (ClearQuestOleServer.OAdEntity record in recordQuery) { // HACK HACK if (record == null) { continue; } // HACK HACK string recDispName = CQWrapper.GetEntityDisplayName(record); TraceManager.TraceInformation("Generating linking delta for CQ Record: {0}", recDispName); var perWorkItemlinkChangeGroups = new List <LinkChangeGroup>(); ExtractLinkChangeActionsCallback(m_userSession, record, perWorkItemlinkChangeGroups); if (perWorkItemlinkChangeGroups.Count == 0) { TraceManager.TraceInformation("Number of links: {0}", 0); continue; } LinkChangeGroup consolidatedLinkChangeGroup = perWorkItemlinkChangeGroups[0]; for (int i = 1; i < perWorkItemlinkChangeGroups.Count; ++i) { foreach (LinkChangeAction action in perWorkItemlinkChangeGroups[i].Actions) { consolidatedLinkChangeGroup.AddChangeAction(action); } } TraceManager.TraceInformation("Number of links: {0}", consolidatedLinkChangeGroup.Actions.Count.ToString()); // VERY IMPORTANT STEP: update the link delta to store string hostRecMigrItemId = UtilityMethods.CreateCQRecordMigrationItemId(record); store.UpdatePerItemLinkChangeGroupsByCheckingRelatedItemRecords( hostRecMigrItemId, consolidatedLinkChangeGroup, this); if (consolidatedLinkChangeGroup.Actions.Count > 0) { linkChangeGroups.Add(consolidatedLinkChangeGroup); } maxDeltaSliceSize -= consolidatedLinkChangeGroup.Actions.Count; if (maxDeltaSliceSize <= 0) { // size limit reached - persist groups to DB, then empty the slice and process next slice linkService.AddChangeGroups(linkChangeGroups); linkChangeGroups.Clear(); maxDeltaSliceSize = inMaxDeltaSliceSize; } } } // persist remaining groups to DB linkService.AddChangeGroups(linkChangeGroups); // clean up the returned link change group collection // when the caller (toolkit) receives an empty collection, it understands there is no more // delta to generate for the moment, and proceeds to next phase linkChangeGroups.Clear(); // update primary Highwater Mark m_hwmLink.Update(newHwmValue); TraceManager.TraceInformation("Persisted CQ linking HWM: {0}", ClearQuestConstants.CqLinkHwm); TraceManager.TraceInformation("Updated CQ linking HWM: {0}", newHwmValue.ToString()); return(linkChangeGroups.AsReadOnly()); } catch (Exception exception) { // [teyang] TODO CONFLICT HANDLING //MigrationConflict genericeConflict = WitGeneralConflictType.CreateConflict(exception); //var conflictManager = m_conflictManager.GetService(typeof(ConflictManager)) as ConflictManager; //Debug.Assert(null != conflictManager); //List<MigrationAction> resolutionActions; //ConflictResolutionResult resolveRslt = // conflictManager.TryResolveNewConflict(conflictManager.SourceId, genericeConflict, out resolutionActions); //Debug.Assert(!resolveRslt.Resolved); TraceManager.TraceException(exception); return(new List <LinkChangeGroup>().AsReadOnly()); } }
/// <summary> /// Process the change group. /// </summary> /// <param name="group"></param> /// <returns></returns> public ConversionResult ProcessChangeGroup(ChangeGroup group) { ConversionResult rslt; CCBatchingContext ctx = new CCBatchingContext(m_clearCaseServer, GetChangeComment(group), group, m_ccConfiguration.DownloadFolder, m_conflictManagementService, m_ccConfiguration, m_overrideTargetChange); int processedActionCount = 0; m_changeGroupHighWaterMark.Reload(); if (m_changeGroupHighWaterMark.Value == group.ChangeGroupId) { // Todo get the last action id from ClearCase history } try { foreach (MigrationAction action in group.Actions) { if (processedActionCount > 50000) { TraceManager.TraceInformation("Processed 50,000 actions"); processedActionCount = 0; } processedActionCount++; if (action.State != ActionState.Pending) { continue; } if (action.Action == WellKnownChangeActionId.Add) { if (string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlLabel.ReferenceName, StringComparison.Ordinal)) { ctx.CacheLabel(action); } else if (string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlLabelItem.ReferenceName, StringComparison.Ordinal) || string.Equals(action.ItemTypeReferenceName, WellKnownContentType.VersionControlRecursiveLabelItem.ReferenceName, StringComparison.Ordinal)) { ctx.CacheLabelItem(action); } else { // Todo handle branch and undelete seperately. if (ClearCasePath.IsVobRoot(ClearCasePath.GetFullPath(action.Path))) { TraceManager.TraceWarning("Skipped the change action that creates vob itself"); continue; } ctx.AddSingleItem(action, WellKnownChangeActionId.Add); } } else if ((action.Action == WellKnownChangeActionId.Branch) || (action.Action == WellKnownChangeActionId.BranchMerge) || (action.Action == WellKnownChangeActionId.Undelete)) { // Todo handle branch and undelete seperately. if (ClearCasePath.IsVobRoot(ClearCasePath.GetFullPath(action.Path))) { TraceManager.TraceWarning("Skipped the change action that creates vob itself"); continue; } ctx.AddSingleItem(action, WellKnownChangeActionId.Add); } else if (action.Action == WellKnownChangeActionId.Edit) { ctx.AddSingleItem(action, WellKnownChangeActionId.Edit); } else if (action.Action == WellKnownChangeActionId.Delete) { ctx.AddSingleItem(action, WellKnownChangeActionId.Delete); } else if (action.Action == WellKnownChangeActionId.Rename) { if (ClearCasePath.Equals(action.Path, action.FromPath)) { // Skip case-only rename. continue; } ctx.AddSingleItem(action, WellKnownChangeActionId.Rename); } else if (action.Action == WellKnownChangeActionId.Merge) { continue; } else if (action.Action == WellKnownChangeActionId.AddFileProperties) { ctx.AddSingleItem(action, WellKnownChangeActionId.AddFileProperties); } } rslt = new ConversionResult(m_configurationService.SourceId, m_configurationService.MigrationPeer); rslt.ChangeId = m_clearCaseServer.GetRelativePathFromVobAbsolutePath(ctx.Flush()); rslt.ItemConversionHistory.Add(new ItemConversionHistory(group.Name, string.Empty, rslt.ChangeId, string.Empty)); rslt.ContinueProcessing = true; m_changeGroupHighWaterMark.Update(group.ChangeGroupId); if (m_hwmLastSyncedTfsChangeset != null) { m_hwmLastSyncedTfsChangeset.Update(int.Parse(group.Name)); } } catch (Exception e) { // Undo any pending checkouts that would have been checked in by the call to ctx.Flush() if no exception occurred. // (If ctx.Flush() has already been called, this will just return.) // It will catch and log any exception as an error, but will not throw it so that the original exception is raised as the conflict. ctx.CancelCachedCheckouts(); if (!(e is MigrationUnresolvedConflictException)) { TraceManager.TraceInformation("Raising generic conflict for exception: {0}", e.Message); createGenericConflict(e, group); } rslt = new ConversionResult(Guid.Empty, group.SourceId); rslt.ContinueProcessing = false; } return(rslt); }