Skip to content

Commit

Permalink
PR 44: Updated to load test migration tools properly +semver:patch
Browse files Browse the repository at this point in the history
 - Updated to load test migration tools properly +semver:patch
  • Loading branch information
MrHinsh committed Aug 17, 2016
1 parent 5bd6a9e commit 4420ba1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
38 changes: 19 additions & 19 deletions TfsWitMigrator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,33 @@ static int Main(string[] args)
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.Listeners.Add(new TextWriterTraceListener(string.Format(@"{0}-{1}.log", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"), "MigrationRun"), "myListener"));
//////////////////////////////////////////////////
Trace.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
Trace.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
Trace.WriteLine(string.Format("Telemitery Enabled: {0}", Telemetry.Current.IsEnabled().ToString()));
Trace.WriteLine(string.Format("SessionID: {0}", Telemetry.Current.Context.Session.Id));
Trace.WriteLine(string.Format("User: {0}", Telemetry.Current.Context.User.Id));
Trace.WriteLine(string.Format("Start Time: {0}", startTime.ToUniversalTime()));
Trace.WriteLine("----------------------------------------------------------------");
Trace.WriteLine("------------------------------START-----------------------------");
Trace.WriteLine("----------------------------------------------------------------");
Trace.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, "vstsbulkeditor");
Trace.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), "vstsbulkeditor");
Trace.WriteLine(string.Format("Telemitery Enabled: {0}", Telemetry.Current.IsEnabled().ToString()), "vstsbulkeditor");
Trace.WriteLine(string.Format("SessionID: {0}", Telemetry.Current.Context.Session.Id), "vstsbulkeditor");
Trace.WriteLine(string.Format("User: {0}", Telemetry.Current.Context.User.Id), "vstsbulkeditor");
Trace.WriteLine(string.Format("Start Time: {0}", startTime.ToUniversalTime()), "vstsbulkeditor");
Trace.WriteLine("----------------------------------------------------------------", "vstsbulkeditor");
Trace.WriteLine("------------------------------START-----------------------------", "vstsbulkeditor");
Trace.WriteLine("----------------------------------------------------------------", "vstsbulkeditor");
//////////////////////////////////////////////////
int result = (int)Parser.Default.ParseArguments<InitOptions, RunOptions>(args).MapResult(
(InitOptions opts) => RunInitAndReturnExitCode(opts),
(RunOptions opts) => RunExecuteAndReturnExitCode(opts),
errs => 1);
//////////////////////////////////////////////////
Trace.WriteLine("----------------------------------------------------------------");
Trace.WriteLine("-------------------------------END------------------------------");
Trace.WriteLine("----------------------------------------------------------------");
Trace.WriteLine("----------------------------------------------------------------", "vstsbulkeditor");
Trace.WriteLine("-------------------------------END------------------------------", "vstsbulkeditor");
Trace.WriteLine("----------------------------------------------------------------", "vstsbulkeditor");
mainTimer.Stop();
Telemetry.Current.TrackEvent("ApplicationEnd", null,
new Dictionary<string, double> {
{ "ApplicationDuration", mainTimer.ElapsedMilliseconds }
});
Telemetry.Current.Flush();

Trace.WriteLine(string.Format("Duration: {0}", mainTimer.Elapsed.ToString("c")));
Trace.WriteLine(string.Format("End Time: {0}", startTime.ToUniversalTime()));
Trace.WriteLine(string.Format("Duration: {0}", mainTimer.Elapsed.ToString("c")), "vstsbulkeditor");
Trace.WriteLine(string.Format("End Time: {0}", startTime.ToUniversalTime()), "vstsbulkeditor");
return result;
}

Expand All @@ -89,7 +89,7 @@ private static object RunExecuteAndReturnExitCode(RunOptions opts)

if (!File.Exists(opts.ConfigFile))
{
Trace.WriteLine("The config file does not exist, nor doe the default 'vstsbulkeditor.json'. Use 'init' to create a configuration file first");
Trace.WriteLine("The config file does not exist, nor doe the default 'vstsbulkeditor.json'. Use 'init' to create a configuration file first", "vstsbulkeditor");
return 1;
}
else
Expand All @@ -102,11 +102,11 @@ private static object RunExecuteAndReturnExitCode(RunOptions opts)
new FieldMapConfigJsonConverter(),
new ProcessorConfigJsonConverter());
}
Trace.WriteLine("Config Loaded, creating engine");
Trace.WriteLine("Config Loaded, creating engine", "vstsbulkeditor");
MigrationEngine me = new MigrationEngine(ec);
Trace.WriteLine("Engine created, running...");
Trace.WriteLine("Engine created, running...", "vstsbulkeditor");
me.Run();
Trace.WriteLine("Run complete...");
Trace.WriteLine("Run complete...", "vstsbulkeditor");
return 0;
}

Expand All @@ -121,7 +121,7 @@ private static object RunInitAndReturnExitCode(InitOptions opts)
StreamWriter sw = new StreamWriter("vstsbulkeditor.json");
sw.WriteLine(json);
sw.Close();
Trace.WriteLine("New vstsbulkeditor.json file has been created");
Trace.WriteLine("New vstsbulkeditor.json file has been created", "vstsbulkeditor");
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace VSTS.DataBulkEditor.Engine.Configuration.Processing
public class TestPlansAndSuitsMigrationConfig : ITfsProcessingConfig
{
public bool Enabled { get; set; }
public string AreaIterationPath { get; set; }

public Type Processor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestPlansAndSuitsMigrationContext : MigrationContextBase
WorkItemStoreContext targetWitStore;
TestManagementContext targetTestStore;

WorkItemUpdateAreasAsTagsConfig config;
TestPlansAndSuitsMigrationConfig config;

public override string Name
{
Expand All @@ -30,7 +30,7 @@ public override string Name
}
}

public TestPlansAndSuitsMigrationContext(MigrationEngine me, WorkItemUpdateAreasAsTagsConfig config) : base(me, config)
public TestPlansAndSuitsMigrationContext(MigrationEngine me, TestPlansAndSuitsMigrationConfig config) : base(me, config)
{
sourceWitStore = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.None);
sourceTestStore = new TestManagementContext(me.Source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ internal override void InternalExecute()
tfsqc.AddParameter("TeamProject", me.Source.Name);
tfsqc.Query = string.Format(@"SELECT [System.Id], [System.Tags] FROM WorkItems WHERE [System.TeamProject] = @TeamProject {0} ORDER BY [System.ChangedDate] desc", _config.QueryBit);
WorkItemCollection sourceWIS = tfsqc.Execute();
Trace.WriteLine(string.Format("Migrate {0} work items?", sourceWIS.Count));
Trace.WriteLine(string.Format("Migrate {0} work items?", sourceWIS.Count),this.Name);
//////////////////////////////////////////////////
WorkItemStoreContext targetStore = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
Project destProject = targetStore.GetProject();
Trace.WriteLine(string.Format("Found target project as {0}", destProject.Name));
Trace.WriteLine(string.Format("Found target project as {0}", destProject.Name), this.Name);

int current = sourceWIS.Count;
int count = 0;
Expand All @@ -56,7 +56,7 @@ internal override void InternalExecute()
witstopwatch.Start();
WorkItem targetFound;
targetFound = targetStore.FindReflectedWorkItem(sourceWI, me.ReflectedWorkItemIdFieldName);
Trace.WriteLine(string.Format("{0} - Migrating: {1}-{2}", current, sourceWI.Id, sourceWI.Type.Name));
Trace.WriteLine(string.Format("{0} - Migrating: {1}-{2}", current, sourceWI.Id, sourceWI.Type.Name), this.Name);
if (targetFound == null)
{
WorkItem newwit = null;
Expand All @@ -72,12 +72,12 @@ internal override void InternalExecute()
ArrayList fails = newwit.Validate();
foreach (Field f in fails)
{
Trace.WriteLine(string.Format("{0} - Invalid: {1}-{2}-{3}", current, sourceWI.Id, sourceWI.Type.Name, f.ReferenceName));
Trace.WriteLine(string.Format("{0} - Invalid: {1}-{2}-{3}", current, sourceWI.Id, sourceWI.Type.Name, f.ReferenceName), this.Name);
}
}
else
{
Trace.WriteLine("...not supported");
Trace.WriteLine("...not supported", this.Name);
}

if (newwit != null)
Expand All @@ -88,22 +88,22 @@ internal override void InternalExecute()
if (_config.UpdateCreatedDate) { newwit.Fields["System.CreatedDate"].Value = sourceWI.Fields["System.CreatedDate"].Value; }
if (_config.UpdateCreatedBy) { newwit.Fields["System.CreatedBy"].Value = sourceWI.Fields["System.CreatedBy"].Value; }
newwit.Save();
Trace.WriteLine(string.Format("...Saved as {0}", newwit.Id));
Trace.WriteLine(string.Format("...Saved as {0}", newwit.Id), this.Name);
if (sourceWI.Fields.Contains(me.ReflectedWorkItemIdFieldName) && _config.UpdateSoureReflectedId)
{
sourceWI.Fields[me.ReflectedWorkItemIdFieldName].Value = targetStore.CreateReflectedWorkItemId(newwit);
}
sourceWI.Save();
Trace.WriteLine(string.Format("...and Source Updated {0}", sourceWI.Id));
Trace.WriteLine(string.Format("...and Source Updated {0}", sourceWI.Id), this.Name);
}
catch (Exception ex)
{
Trace.WriteLine("...FAILED to Save");
Trace.WriteLine("...FAILED to Save", this.Name);
foreach (Field f in newwit.Fields)
{
Trace.WriteLine(string.Format("{0} | {1}", f.ReferenceName, f.Value));
Trace.WriteLine(string.Format("{0} | {1}", f.ReferenceName, f.Value), this.Name);
}
Trace.WriteLine(ex.ToString());
Trace.WriteLine(ex.ToString(), this.Name);
}
}
}
Expand All @@ -122,7 +122,7 @@ internal override void InternalExecute()
count++;
TimeSpan average = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)));
Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)), this.Name);
}
//////////////////////////////////////////////////
stopwatch.Stop();
Expand All @@ -141,7 +141,7 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItem oldWi, Project destPr
Stopwatch fieldMappingTimer = new Stopwatch();

bool except = false;
Trace.Write("... Building");
Trace.Write("... Building", "WorkItemMigrationContext");
List<String> ignore = new List<string>();
ignore.Add("System.CreatedDate");
ignore.Add("System.CreatedBy");
Expand Down Expand Up @@ -175,7 +175,7 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItem oldWi, Project destPr
WorkItem newwit = destProject.WorkItemTypes[destType].NewWorkItem();
NewWorkItemTimer.Stop();
Telemetry.Current.TrackDependency("TeamService", "NewWorkItem", NewWorkItemstartTime, NewWorkItemTimer.Elapsed, true);
Trace.WriteLine(string.Format("Dependnacy: {0} - {1} - {2} - {3} - {4}", "TeamService", "NewWorkItem", NewWorkItemstartTime, NewWorkItemTimer.Elapsed, true));
Trace.WriteLine(string.Format("Dependnacy: {0} - {1} - {2} - {3} - {4}", "TeamService", "NewWorkItem", NewWorkItemstartTime, NewWorkItemTimer.Elapsed, true), "WorkItemMigrationContext");
newwit.Title = oldWi.Title;
newwit.State = oldWi.State;
switch (newwit.State)
Expand Down Expand Up @@ -234,17 +234,17 @@ private static WorkItem CreateAndPopulateWorkItem(WorkItem oldWi, Project destPr

if (except)
{
Trace.Write("...buildErrors");
Trace.WriteLine("...buildErrors", "WorkItemMigrationContext");
System.Threading.Thread.Sleep(1000);

}
else
{
Trace.Write("...buildComplete");
Trace.WriteLine("...buildComplete", "WorkItemMigrationContext");
}
fieldMappingTimer.Stop();
Telemetry.Current.TrackMetric( "FieldMappingTime", fieldMappingTimer.ElapsedMilliseconds);
Trace.WriteLine(string.Format("FieldMapOnNewWorkItem: {0} - {1}", NewWorkItemstartTime, fieldMappingTimer.Elapsed.ToString("c")));
Trace.WriteLine(string.Format("FieldMapOnNewWorkItem: {0} - {1}", NewWorkItemstartTime, fieldMappingTimer.Elapsed.ToString("c")), "WorkItemMigrationContext");
return newwit;
}

Expand Down
7 changes: 5 additions & 2 deletions TfsWitMigrator.Core/MigrationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ private void ProcessConfiguration(EngineConfiguration config)
{
foreach (IFieldMapConfig fieldmapConfig in config.FieldMaps)
{
Trace.WriteLine(string.Format("Adding FieldMap {0}", fieldmapConfig.FieldMap.Name), "MigrationEngine");
this.AddFieldMap(fieldmapConfig.WorkItemTypeName, (IFieldMap)Activator.CreateInstance(fieldmapConfig.FieldMap, fieldmapConfig));
}
}
foreach (string key in config.WorkItemTypeDefinition.Keys)
{
Trace.WriteLine(string.Format("Adding Work Item Type {0}", key), "MigrationEngine");
this.AddWorkItemTypeDefinition(key, new DescreteWitdMapper(config.WorkItemTypeDefinition[key]));
}
foreach (ITfsProcessingConfig processorConfig in config.Processors)
{
if (processorConfig.Enabled)
{
Trace.WriteLine(string.Format("Adding Processor {0}", processorConfig.Processor.Name), "MigrationEngine");
this.AddProcessor((ITfsProcessingContext)Activator.CreateInstance(processorConfig.Processor, this, processorConfig));
}
}
Expand Down Expand Up @@ -106,7 +109,7 @@ public ProcessingStatus Run()
Stopwatch engineTimer = new Stopwatch();
engineTimer.Start();
ProcessingStatus ps = ProcessingStatus.Complete;
Trace.WriteLine("Beginning run of {0} processors", processors.Count.ToString());
Trace.WriteLine(string.Format("Beginning run of {0} processors", processors.Count.ToString()), "MigrationEngine");
foreach (ITfsProcessingContext process in processors)
{
Stopwatch processorTimer = new Stopwatch();
Expand All @@ -117,7 +120,7 @@ public ProcessingStatus Run()
if (process.Status == ProcessingStatus.Failed)
{
ps = ProcessingStatus.Failed;
Trace.WriteLine("The Processor {0} entered the failed state...stopping run", process.Name);
Trace.WriteLine(string.Format("The Processor {0} entered the failed state...stopping run", process.Name), "MigrationEngine");
break;
}
}
Expand Down

0 comments on commit 4420ba1

Please sign in to comment.