Runner register labels during configuration (#130)

* Runners will add os and architecture labels during registration

* support github.localhost for dev.
This commit is contained in:
Tingluo Huang
2019-10-17 16:33:43 -04:00
committed by Christopher Johnson
parent 2f261f2c31
commit f5f14d4811
16 changed files with 52 additions and 408 deletions

View File

@@ -55,14 +55,9 @@ namespace GitHub.DistributedTask.WebApi
m_properties = new PropertiesCollection(agentToBeCloned.m_properties);
}
if (agentToBeCloned.m_systemCapabilities != null && agentToBeCloned.m_systemCapabilities.Count > 0)
if (agentToBeCloned.m_labels != null && agentToBeCloned.m_labels.Count > 0)
{
m_systemCapabilities = new Dictionary<String, String>(agentToBeCloned.m_systemCapabilities, StringComparer.OrdinalIgnoreCase);
}
if (agentToBeCloned.m_userCapabilities != null && agentToBeCloned.m_userCapabilities.Count > 0)
{
m_userCapabilities = new Dictionary<String, String>(agentToBeCloned.m_userCapabilities, StringComparer.OrdinalIgnoreCase);
m_labels = new HashSet<string>(agentToBeCloned.m_labels, StringComparer.OrdinalIgnoreCase);
}
if (agentToBeCloned.PendingUpdate != null)
@@ -152,32 +147,17 @@ namespace GitHub.DistributedTask.WebApi
}
/// <summary>
/// System-defined capabilities supported by this agent's host.
/// The labels of the runner
/// </summary>
public IDictionary<String, String> SystemCapabilities
public ISet<string> Labels
{
get
{
if (m_systemCapabilities == null)
if (m_labels == null)
{
m_systemCapabilities = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
m_labels = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
}
return m_systemCapabilities;
}
}
/// <summary>
/// User-defined capabilities supported by this agent's host.
/// </summary>
public IDictionary<String, String> UserCapabilities
{
get
{
if (m_userCapabilities == null)
{
m_userCapabilities = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
}
return m_userCapabilities;
return m_labels;
}
}
@@ -214,10 +194,7 @@ namespace GitHub.DistributedTask.WebApi
[DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Properties")]
private PropertiesCollection m_properties;
[DataMember(IsRequired = false, EmitDefaultValue = false, Name = "SystemCapabilities")]
private Dictionary<String, String> m_systemCapabilities;
[DataMember(IsRequired = false, EmitDefaultValue = false, Name = "UserCapabilities")]
private Dictionary<String, String> m_userCapabilities;
[DataMember(IsRequired = false, EmitDefaultValue = false, Name = "Labels")]
private HashSet<string> m_labels;
}
}

View File

@@ -246,8 +246,7 @@ namespace GitHub.DistributedTask.WebApi
PlanType = hubName,
ScopeId = scopeIdentifier,
PlanId = planId,
JobId = jobId,
Demands = demands,
JobId = jobId
};
return QueueAgentRequestByPoolAsync(poolId, request, userState, cancellationToken);

View File

@@ -35,7 +35,6 @@ namespace GitHub.DistributedTask.WebApi
this.PoolId = requestToBeCloned.PoolId;
this.JobId = requestToBeCloned.JobId;
this.JobName = requestToBeCloned.JobName;
this.Demands = new List<Demand>(requestToBeCloned.Demands ?? new Demand[0]);
this.LockToken = requestToBeCloned.LockToken;
this.ExpectedDuration = requestToBeCloned.ExpectedDuration;
this.OrchestrationId = requestToBeCloned.OrchestrationId;
@@ -68,6 +67,11 @@ namespace GitHub.DistributedTask.WebApi
{
this.AgentSpecification = new JObject(requestToBeCloned.AgentSpecification);
}
if (requestToBeCloned.Labels != null)
{
this.Labels = new HashSet<string>(requestToBeCloned.Labels, StringComparer.OrdinalIgnoreCase);
}
}
/// <summary>
@@ -229,6 +233,7 @@ namespace GitHub.DistributedTask.WebApi
/// </summary>
/// <value></value>
[DataMember(Order = 16, EmitDefaultValue = false)]
[Obsolete("No more demands, use labels", true)]
public IList<Demand> Demands
{
get;
@@ -386,6 +391,13 @@ namespace GitHub.DistributedTask.WebApi
set;
}
[DataMember(Order = 33, EmitDefaultValue = false)]
public ISet<string> Labels
{
get;
set;
}
[IgnoreDataMember]
internal Guid? LockToken
{

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace GitHub.DistributedTask.WebApi
@@ -27,29 +26,6 @@ namespace GitHub.DistributedTask.WebApi
this.OwnerName = ownerName;
}
/// <summary>
/// Initializes a new <c>TaskAgentSession</c> isntance with the specified owner name, agent, and capabilities.
/// </summary>
/// <param name="ownerName">The name of the owner for this session. This should typically be the agent machine</param>
/// <param name="agent">The target agent for the session</param>
/// <param name="systemCapabilities">A collection of capabilities to publish on session creation</param>
public TaskAgentSession(
String ownerName,
TaskAgentReference agent,
IDictionary<String, String> systemCapabilities)
{
this.Agent = agent;
this.OwnerName = ownerName;
foreach (var capability in systemCapabilities)
{
if (capability.Value != null)
{
this.SystemCapabilities.Add(capability.Key, capability.Value);
}
}
}
/// <summary>
/// Gets the unique identifier for this session.
/// </summary>
@@ -89,33 +65,5 @@ namespace GitHub.DistributedTask.WebApi
get;
set;
}
/// <summary>
/// Gets the collection of system capabilities used for this session.
/// </summary>
public IDictionary<String, String> SystemCapabilities
{
get
{
if (m_systemCapabilities == null)
{
m_systemCapabilities = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
}
return m_systemCapabilities;
}
}
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
if (m_systemCapabilities?.Count == 0)
{
m_systemCapabilities = null;
}
}
[DataMember(IsRequired = false, EmitDefaultValue = false, Name = "SystemCapabilities")]
private IDictionary<String, String> m_systemCapabilities;
}
}