// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using EpicGames.Horde.Common;
#pragma warning disable CA2227
namespace EpicGames.Horde.Compute
{
///
/// Requirements for a compute task to be assigned an agent
///
public class Requirements
{
///
/// Pool of machines to draw from
///
public string? Pool { get; set; }
///
/// Condition string to be evaluated against the machine spec, eg. cpu-cores >= 10 && ram.mb >= 200 && pool == 'worker'
///
public Condition? Condition { get; set; }
///
/// Properties required from the remote machine
///
public HashSet Properties { get; set; } = new HashSet();
///
/// Resources used by the process
///
public Dictionary Resources { get; } = new Dictionary();
///
/// Whether we require exclusive access to the device
///
public bool Exclusive { get; set; }
///
/// Default constructor
///
public Requirements()
{
}
///
/// Construct a requirements object with a condition
///
/// Condition for matching machines to execute the work
public Requirements(Condition? condition)
{
Condition = condition;
}
///
public override string ToString()
{
List list = new List();
if (Pool != null)
{
list.Add($"Pool:{Pool}");
}
if (Condition != null)
{
list.Add($"\"{Condition}\"");
}
foreach ((string name, ResourceRequirements allocation) in Resources)
{
list.Add($"{name}: {allocation.Min}-{allocation.Max}");
}
if (Exclusive)
{
list.Add("Exclusive");
}
return String.Join(", ", list);
}
}
///
/// Specifies requirements for resource allocation
///
public class ResourceRequirements
{
///
/// Minimum allocation of the requested resource
///
public int Min { get; set; } = 1;
///
/// Maximum allocation of the requested resource. Allocates as much as possible unless capped.
///
public int? Max { get; set; }
}
}