Skip to content

Commit c47e772

Browse files
authored
Add support to VC to simplify the execution of 'loose scripts'. (#494)
1 parent b2167a0 commit c47e772

31 files changed

+1042
-239
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.6
1+
2.0.7

src/VirtualClient/VirtualClient.Contracts.UnitTests/VirtualClientLoggingExtensionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,11 +1429,11 @@ public async Task LogProcessDetailsExtensionWritesTheExpectedProcessInformationT
14291429
Assert.IsTrue(content.Contains($"Command : {expectedCommand} {expectedArguments}".TrimEnd(), StringComparison.Ordinal), "Command missing");
14301430
Assert.IsTrue(content.Contains($"Working Directory : {expectedWorkingDir}", StringComparison.Ordinal), "Working directory missing");
14311431
Assert.IsTrue(content.Contains($"Exit Code : {expectedExitCode}", StringComparison.Ordinal), "Exit code missing");
1432-
Assert.IsTrue(content.Contains($"##StandardOutput##", StringComparison.Ordinal), "Output delimiter missing");
14331432
Assert.IsFalse(content.Contains($"##GeneratedResults##", StringComparison.Ordinal), "Results delimiter unexpected");
14341433

14351434
if (!string.IsNullOrWhiteSpace(expectedStandardOutput))
14361435
{
1436+
Assert.IsTrue(content.Contains($"##StandardOutput##", StringComparison.Ordinal), "Output delimiter missing");
14371437
Assert.IsTrue(content.Contains(expectedStandardOutput, StringComparison.Ordinal), "Standard output missing");
14381438
}
14391439

@@ -1488,11 +1488,11 @@ public async Task LogProcessDetailsExtensionWritesTheExpectedProcessInformationT
14881488
Assert.IsTrue(content.Contains($"Command : {expectedCommand} {expectedArguments}".TrimEnd(), StringComparison.Ordinal), "Command missing");
14891489
Assert.IsTrue(content.Contains($"Working Directory : {expectedWorkingDir}", StringComparison.Ordinal), "Working directory missing");
14901490
Assert.IsTrue(content.Contains($"Exit Code : {expectedExitCode}", StringComparison.Ordinal), "Exit code missing");
1491-
Assert.IsTrue(content.Contains($"##StandardOutput##", StringComparison.Ordinal), "Output delimiter missing");
14921491
Assert.IsFalse(content.Contains($"##GeneratedResults##", StringComparison.Ordinal), "Results delimiter unexpected");
14931492

14941493
if (!string.IsNullOrWhiteSpace(expectedStandardOutput))
14951494
{
1495+
Assert.IsTrue(content.Contains($"##StandardOutput##", StringComparison.Ordinal), "Output delimiter missing");
14961496
Assert.IsTrue(content.Contains(expectedStandardOutput, StringComparison.Ordinal), "Standard output missing");
14971497
}
14981498

@@ -1549,11 +1549,11 @@ public async Task LogProcessDetailsToFileSystemAsyncExtensionWritesTheExpectedPr
15491549
Assert.IsTrue(content.Contains($"Command : {expectedCommand} {expectedArguments}".TrimEnd(), StringComparison.Ordinal), "Command missing");
15501550
Assert.IsTrue(content.Contains($"Working Directory : {expectedWorkingDir}", StringComparison.Ordinal), "Working directory missing");
15511551
Assert.IsTrue(content.Contains($"Exit Code : {expectedExitCode}", StringComparison.Ordinal), "Exit code missing");
1552-
Assert.IsTrue(content.Contains($"##StandardOutput##", StringComparison.Ordinal), "Output delimiter missing");
15531552
Assert.IsTrue(content.Contains($"##GeneratedResults##", StringComparison.Ordinal), "Results delimiter missing");
15541553

15551554
if (!string.IsNullOrWhiteSpace(expectedStandardOutput))
15561555
{
1556+
Assert.IsTrue(content.Contains($"##StandardOutput##", StringComparison.Ordinal), "Output delimiter missing");
15571557
Assert.IsTrue(content.Contains(expectedStandardOutput, StringComparison.Ordinal), "Standard output missing");
15581558
}
15591559

src/VirtualClient/VirtualClient.Contracts/ComponentFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ private static VirtualClientComponent CreateComponent(
102102
bool? logToFile = null)
103103
{
104104
VirtualClientComponent component = component = (VirtualClientComponent)Activator.CreateInstance(type, dependencies, componentDescription.Parameters);
105+
component.ComponentType = componentDescription.ComponentType;
105106
component.ExecutionSeed = randomizationSeed;
106107

107108
// Metadata is merged at each level down the hierarchy. Metadata at higher levels
@@ -164,6 +165,8 @@ private static VirtualClientComponent CreateComponent(
164165
failFast,
165166
logToFile);
166167

168+
childComponent.ComponentType = componentDescription.ComponentType;
169+
167170
componentCollection.Add(childComponent);
168171
}
169172

src/VirtualClient/VirtualClient.Contracts/ComponentTypeCache.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace VirtualClient.Contracts
1515
/// <summary>
1616
/// Provides a cache for object types associated with Virtual Client.
1717
/// </summary>
18-
public class ComponentTypeCache : List<ComponentType>
18+
public class ComponentTypeCache : List<CachedComponentType>
1919
{
2020
/// <summary>
2121
/// Lock object used to ensure single-threaded access to the cache when
@@ -169,7 +169,7 @@ private void CacheProviderTypes(Assembly componentAssembly)
169169
{
170170
if (!this.Any(type => type.Type == componentType))
171171
{
172-
this.Add(new ComponentType(componentType));
172+
this.Add(new CachedComponentType(componentType));
173173
}
174174
}
175175
}
@@ -180,12 +180,12 @@ private void CacheProviderTypes(Assembly componentAssembly)
180180
/// <summary>
181181
/// Represents a cached component type.
182182
/// </summary>
183-
public class ComponentType
183+
public class CachedComponentType
184184
{
185185
/// <summary>
186-
/// Initializes a new instance of the <see cref="ComponentType"/> class.
186+
/// Initializes a new instance of the <see cref="CachedComponentType"/> class.
187187
/// </summary>
188-
public ComponentType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
188+
public CachedComponentType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
189189
{
190190
type.ThrowIfNull(nameof(type));
191191
this.Type = type;

src/VirtualClient/VirtualClient.Contracts/Enumerations.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
33

44
namespace VirtualClient
55
{
6+
/// <summary>
7+
/// Enumeration defines the type of profile component.
8+
/// </summary>
9+
public enum ComponentType : int
10+
{
11+
/// <summary>
12+
/// Undefined component type.
13+
/// </summary>
14+
Undefined = 0,
15+
16+
/// <summary>
17+
/// Profile action.
18+
/// </summary>
19+
Action = 1,
20+
21+
/// <summary>
22+
/// Profile dependency.
23+
/// </summary>
24+
Dependency = 2,
25+
26+
/// <summary>
27+
/// Profile monitor.
28+
/// </summary>
29+
Monitor = 3
30+
}
31+
632
/// <summary>
733
/// Enumeration describes error reasons. Note that error reasons with
834
/// a value greater than or equal to 500 indicate failures for which will

src/VirtualClient/VirtualClient.Contracts/ExecutionProfile.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ public ExecutionProfile(
6262
? new Dictionary<string, IConvertible>(parameters, StringComparer.OrdinalIgnoreCase)
6363
: new Dictionary<string, IConvertible>(StringComparer.OrdinalIgnoreCase);
6464

65+
if (this.Actions?.Any() == true)
66+
{
67+
this.Actions.ForEach(action => action.ComponentType = ComponentType.Action);
68+
}
69+
70+
if (this.Dependencies?.Any() == true)
71+
{
72+
this.Dependencies.ForEach(dependency => dependency.ComponentType = ComponentType.Dependency);
73+
}
74+
75+
if (this.Monitors?.Any() == true)
76+
{
77+
this.Monitors.ForEach(monitor => monitor.ComponentType = ComponentType.Monitor);
78+
}
6579
}
6680

6781
/// <summary>

src/VirtualClient/VirtualClient.Contracts/ExecutionProfileElement.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public ExecutionProfileElement(ExecutionProfileElementYamlShim other)
6161
{
6262
}
6363

64+
/// <summary>
65+
/// The type of profile component (e.g. Action, Dependency, Monitor).
66+
/// </summary>
67+
[JsonIgnore]
68+
public ComponentType ComponentType { get; internal set; }
69+
6470
/// <summary>
6571
/// The name of this element
6672
/// </summary>

src/VirtualClient/VirtualClient.Contracts/ExecutionProfileElementYamlShim.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public ExecutionProfileElementYamlShim(ExecutionProfileElement other)
5050
}
5151
}
5252

53+
/// <summary>
54+
/// The type of profile component (e.g. Action, Dependency, Monitor).
55+
/// </summary>
56+
[YamlIgnore]
57+
public ComponentType ComponentType { get; internal set; }
58+
5359
/// <summary>
5460
/// The type of this element
5561
/// </summary>

src/VirtualClient/VirtualClient.Contracts/ExecutionProfileYamlShim.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ public ExecutionProfileYamlShim(ExecutionProfile other)
6767
{
6868
this.Parameters.AddRange(other.Parameters);
6969
}
70+
71+
if (this.Actions?.Any() == true)
72+
{
73+
this.Actions.ForEach(action => action.ComponentType = ComponentType.Action);
74+
}
75+
76+
if (this.Dependencies?.Any() == true)
77+
{
78+
this.Dependencies.ForEach(dependency => dependency.ComponentType = ComponentType.Dependency);
79+
}
80+
81+
if (this.Monitors?.Any() == true)
82+
{
83+
this.Monitors.ForEach(monitor => monitor.ComponentType = ComponentType.Monitor);
84+
}
7085
}
7186

7287
/// <summary>

src/VirtualClient/VirtualClient.Contracts/VirtualClientComponent.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public Guid? ClientRequestId
170170
}
171171
}
172172

173+
/// <summary>
174+
/// The type of component (Action, Dependency, Monitor).
175+
/// </summary>
176+
public ComponentType ComponentType { get; set; }
177+
173178
/// <summary>
174179
/// The CPU/processor architecture (e.g. amd64, arm).
175180
/// </summary>
@@ -230,6 +235,24 @@ public EnvironmentLayout Layout
230235
}
231236
}
232237

238+
/// <summary>
239+
/// The name of the directory/folder to which log files should be
240+
/// written (e.g. geekbench -> ./logs/geekbench).
241+
/// </summary>
242+
public string LogFolderName
243+
{
244+
get
245+
{
246+
this.Parameters.TryGetValue(nameof(VirtualClientComponent.LogFolderName), out IConvertible logDirectoryName);
247+
return logDirectoryName?.ToString();
248+
}
249+
250+
protected set
251+
{
252+
this.Parameters[nameof(this.LogFolderName)] = value;
253+
}
254+
}
255+
233256
/// <summary>
234257
/// The Logger for this component
235258
/// </summary>
@@ -687,7 +710,6 @@ await this.Logger.LogMessageAsync($"{this.TypeName}.Execute", telemetryContext,
687710
}
688711

689712
await this.CleanupAsync(telemetryContext, cancellationToken);
690-
691713
});
692714
}
693715
}

0 commit comments

Comments
 (0)