Skip to content

Commit

Permalink
Add support for specifying column variants in a ColumnConfiguration (#…
Browse files Browse the repository at this point in the history
…379)

* Add support for specifying column variants in a ColumnConfiguration

* Consolidate ctors

* Fix typo

* Refactor upgrade logic

* Rename namespace to Latest

* Add typecast to while loop

* Remove cycle check

* Add check to PreviousPrebuiltConfigurationBase
  • Loading branch information
mslukebo authored Oct 24, 2024
1 parent d46753d commit e4e94fa
Show file tree
Hide file tree
Showing 17 changed files with 335 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Performance.Testing;
using Microsoft.Performance.Testing.SDK;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ColumnConfiguration = Microsoft.Performance.SDK.Runtime.DTO.Latest.ColumnConfiguration;
using TableConfiguration = Microsoft.Performance.SDK.Processing.TableConfiguration;

namespace Microsoft.Performance.SDK.Runtime.Tests
Expand Down Expand Up @@ -286,7 +287,7 @@ private DTO.PreV1.TableConfiguration BuildPreV1TableConfig()
StartTimeColumnGuid = Guid.NewGuid(),
StartTimeColumnName = testStr()
}, 3).ToArray(),
Columns = Enumerable.Repeat(new DTO.ColumnConfiguration()
Columns = Enumerable.Repeat(new DTO.V1_0.ColumnConfiguration()
{
Metadata = new DTO.ColumnMetadata()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Microsoft.Performance.SDK.Runtime/DTO/DTOExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Performance.SDK.Runtime.DTO.Enums;
using Microsoft.Performance.SDK.Runtime.DTO.Latest;

namespace Microsoft.Performance.SDK.Runtime.DTO
{
Expand Down Expand Up @@ -431,7 +432,8 @@ private static Microsoft.Performance.SDK.Processing.ColumnConfiguration ConvertT

var columnConfiguration = new Microsoft.Performance.SDK.Processing.ColumnConfiguration(
dto.Metadata.ConvertToSdk(),
dto.DisplayHints.ConvertToSdk());
dto.DisplayHints.ConvertToSdk(),
dto.VariantGuid);
return columnConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Performance.SDK.Runtime.DTO
namespace Microsoft.Performance.SDK.Runtime.DTO.Latest
{
[DataContract]
internal class ColumnConfiguration
Expand All @@ -14,6 +15,12 @@ internal class ColumnConfiguration
[DataMember]
public ColumnMetadata Metadata { get; set; }

/// <summary>
/// The unique identifier of the column variant to use.
/// </summary>
[DataMember]
public Guid? VariantGuid { get; set; }

/// <summary>
/// UI hints for displaying the column.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

using System.Runtime.Serialization;

namespace Microsoft.Performance.SDK.Runtime.DTO
namespace Microsoft.Performance.SDK.Runtime.DTO.Latest
{
[DataContract]
internal class PrebuiltConfigurations
: PrebuiltConfigurationsBase
{
internal static readonly double DTOVersion = 1.0;
internal static readonly double DTOVersion = 1.3;

public PrebuiltConfigurations()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Runtime.Serialization;
using Microsoft.Performance.SDK.Runtime.DTO.Enums;

namespace Microsoft.Performance.SDK.Runtime.DTO
namespace Microsoft.Performance.SDK.Runtime.DTO.Latest
{
[DataContract]
internal class TableConfiguration
Expand Down Expand Up @@ -93,7 +93,7 @@ internal class TableConfiguration
/// Columns that may appear in the table.
/// </summary>
[DataMember(Order = 14)]
public IEnumerable<Runtime.DTO.ColumnConfiguration> Columns { get; set; }
public IEnumerable<ColumnConfiguration> Columns { get; set; }

/// <summary>
/// The roles and their associated column entries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Runtime.Serialization;

namespace Microsoft.Performance.SDK.Runtime.DTO
namespace Microsoft.Performance.SDK.Runtime.DTO.Latest
{
[DataContract]
internal class TableConfigurations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace Microsoft.Performance.SDK.Runtime.DTO.PreV1
{
[DataContract]
internal class PrebuiltConfigurations
: PrebuiltConfigurationsBase,
ISupportUpgrade<DTO.PrebuiltConfigurations>
: PreviousPrebuiltConfigurationBase<V1_0.PrebuiltConfigurations>
{
internal static readonly double DTOVersion = 0.1;

Expand All @@ -21,9 +20,9 @@ public PrebuiltConfigurations()
[DataMember(Order = 2)]
public TableConfigurations[] Tables { get; set; }

public DTO.PrebuiltConfigurations Upgrade()
protected override V1_0.PrebuiltConfigurations UpgradeToNext()
{
return new DTO.PrebuiltConfigurations()
return new V1_0.PrebuiltConfigurations()
{
Tables = this.Tables.Select(configs => configs.Upgrade()).ToArray()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Performance.SDK.Runtime.DTO.PreV1
{
[DataContract]
internal class TableConfiguration
: ISupportUpgrade<DTO.TableConfiguration>
: ISupportUpgrade<V1_0.TableConfiguration>
{
/// <summary>
/// The table name.
Expand Down Expand Up @@ -100,15 +100,15 @@ internal class TableConfiguration
/// Columns that may appear in the table.
/// </summary>
[DataMember(Order = 15)]
public IEnumerable<Runtime.DTO.ColumnConfiguration> Columns { get; set; }
public IEnumerable<V1_0.ColumnConfiguration> Columns { get; set; }

/// <summary>
/// The roles and their associated column entries.
/// </summary>
[DataMember(Order = 16)]
public IDictionary<ColumnRole, ColumnRoleEntry> ColumnRoles { get; set; }

public DTO.TableConfiguration Upgrade()
public V1_0.TableConfiguration Upgrade()
{
var newColumnRoles = new Dictionary<string, ColumnRoleEntry>(this.ColumnRoles.Count);

Expand Down Expand Up @@ -163,7 +163,7 @@ public DTO.TableConfiguration Upgrade()
}
}

return new DTO.TableConfiguration()
return new V1_0.TableConfiguration()
{
Name = this.Name,
ChartType = this.ChartType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Performance.SDK.Runtime.DTO.PreV1
{
[DataContract]
internal class TableConfigurations
: ISupportUpgrade<DTO.TableConfigurations>
: ISupportUpgrade<V1_0.TableConfigurations>
{
[DataMember(Order = 1)]
public Guid TableId { get; set; }
Expand All @@ -20,9 +20,9 @@ internal class TableConfigurations
[DataMember(Order = 3)]
public TableConfiguration[] Configurations { get; set; }

public DTO.TableConfigurations Upgrade()
public V1_0.TableConfigurations Upgrade()
{
return new DTO.TableConfigurations()
return new V1_0.TableConfigurations()
{
TableId = this.TableId,
DefaultConfigurationName = this.DefaultConfigurationName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Runtime.Serialization;

namespace Microsoft.Performance.SDK.Runtime.DTO;

[DataContract]
internal abstract class PreviousPrebuiltConfigurationBase<TNext>
: PrebuiltConfigurationsBase,
ISupportUpgrade<PrebuiltConfigurationsBase>
where TNext : PrebuiltConfigurationsBase
{
public PrebuiltConfigurationsBase Upgrade()
{
var next = UpgradeToNext();
if (next.Version <= this.Version)
{
throw new InvalidOperationException(
$"Cannot upgrade to a version less than or equal to the current version. Current version: {this.Version}, Next version: {next.Version}");
}

return next;
}

/// <summary>
/// Upgrade the current configuration to the next version. The version number
/// of the returned configuration MUST be greater than this instance's version number.
/// </summary>
/// <returns>
/// The upgraded configuration.
/// </returns>
protected abstract TNext UpgradeToNext();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Runtime.Serialization.Json;
using System.Text;
using Microsoft.Performance.SDK.Processing;
using Microsoft.Performance.SDK.Runtime.DTO.Latest;
using TableConfigurations = Microsoft.Performance.SDK.Runtime.DTO.Latest.TableConfigurations;

namespace Microsoft.Performance.SDK.Runtime.DTO
{
Expand All @@ -27,6 +29,7 @@ public class TableConfigurationsSerializer

return assembly.GetTypes()
.Where(type => type.IsSubclassOf(typeof(PrebuiltConfigurationsBase)))
.Where(type => type.IsConcrete())
.Select(type => (((PrebuiltConfigurationsBase)Activator.CreateInstance(type)).Version, type)).ToArray();
});

Expand Down Expand Up @@ -94,15 +97,19 @@ public class TableConfigurationsSerializer

var desrailizedObject = serializer.ReadObject(stream);

if (desrailizedObject is ISupportUpgrade<PrebuiltConfigurations> supportUpgrade)
if (desrailizedObject is not PrebuiltConfigurationsBase configurationsBase)
{
prebuiltConfigurations = supportUpgrade.Upgrade();
return Enumerable.Empty<Processing.TableConfigurations>();
}
else if (desrailizedObject is PrebuiltConfigurations latestConfigs)

while (configurationsBase is not PrebuiltConfigurations &&
configurationsBase is ISupportUpgrade<PrebuiltConfigurationsBase> upgradeable)
{
prebuiltConfigurations = latestConfigs;
configurationsBase = upgradeable.Upgrade();
}

prebuiltConfigurations = configurationsBase as PrebuiltConfigurations;

if (prebuiltConfigurations == null)
{
return Enumerable.Empty<Processing.TableConfigurations>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Runtime.Serialization;

namespace Microsoft.Performance.SDK.Runtime.DTO.V1_0
{
[DataContract]
internal class ColumnConfiguration
: ISupportUpgrade<Latest.ColumnConfiguration>
{
/// <summary>
/// Metadata describing the column.
/// </summary>
[DataMember]
public ColumnMetadata Metadata { get; set; }

/// <summary>
/// UI hints for displaying the column.
/// </summary>
[DataMember]
public UIHints DisplayHints { get; set; }

public Latest.ColumnConfiguration Upgrade()
{
return new Latest.ColumnConfiguration()
{
Metadata = this.Metadata,
VariantGuid = null,
DisplayHints = this.DisplayHints,
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Linq;
using System.Runtime.Serialization;

namespace Microsoft.Performance.SDK.Runtime.DTO.V1_0
{
[DataContract]
internal class PrebuiltConfigurations
: PreviousPrebuiltConfigurationBase<Latest.PrebuiltConfigurations>
{
internal static readonly double DTOVersion = 1.0;

public PrebuiltConfigurations()
{
this.Version = DTOVersion;
}

[DataMember(Order = 2)]
public TableConfigurations[] Tables { get; set; }

protected override Latest.PrebuiltConfigurations UpgradeToNext()
{
return new Latest.PrebuiltConfigurations()
{
Tables = this.Tables.Select(configs => configs.Upgrade()).ToArray()
};
}
}
}
Loading

0 comments on commit e4e94fa

Please sign in to comment.