2023-06-26 11:58:41 +00:00
using ArgsUniform ;
2023-06-22 08:33:21 +00:00
using DistTestCore.Codex ;
2023-08-13 07:07:23 +00:00
using DistTestCore.Metrics ;
2023-06-22 08:17:12 +00:00
namespace CodexNetDeployer
2023-06-22 07:51:25 +00:00
{
public class Configuration
{
2023-06-29 14:03:45 +00:00
public const int SecondsIn1Day = 24 * 60 * 60 ;
2023-08-23 06:29:16 +00:00
public const int TenMinutes = 10 * 60 ;
2023-06-29 14:03:45 +00:00
2023-06-27 06:29:39 +00:00
[Uniform("kube-config", "kc", "KUBECONFIG", false, "Path to Kubeconfig file. Use 'null' (default) to use local cluster.")]
public string KubeConfigFile { get ; set ; } = "null" ;
2023-06-26 11:58:41 +00:00
[Uniform("kube-namespace", "kn", "KUBENAMESPACE", true, "Kubernetes namespace to be used for deployment.")]
public string KubeNamespace { get ; set ; } = string . Empty ;
[Uniform("nodes", "n", "NODES", true, "Number of Codex nodes to be created.")]
public int? NumberOfCodexNodes { get ; set ; }
[Uniform("validators", "v", "VALIDATORS", true, "Number of Codex nodes that will be validating.")]
public int? NumberOfValidators { get ; set ; }
2023-06-29 09:05:58 +00:00
[Uniform("storage-quota", "sq", "STORAGEQUOTA", true, "Storage quota in megabytes used by each Codex node.")]
2023-06-26 11:58:41 +00:00
public int? StorageQuota { get ; set ; }
2023-06-22 07:51:25 +00:00
2023-06-29 09:05:58 +00:00
[Uniform("storage-sell", "ss", "STORAGESELL", true, "Number of megabytes of storage quota to make available for selling.")]
public int? StorageSell { get ; set ; }
2023-06-26 11:58:41 +00:00
[Uniform("log-level", "l", "LOGLEVEL", true, "Log level used by each Codex node. [Trace, Debug*, Info, Warn, Error] ")]
2023-06-27 06:29:39 +00:00
public CodexLogLevel CodexLogLevel { get ; set ; } = CodexLogLevel . Debug ;
2023-06-26 11:58:41 +00:00
2023-06-28 06:48:46 +00:00
[Uniform("test-tokens", "tt", "TESTTOKENS", true, "Initial amount of test-tokens minted for each Codex node.")]
public int InitialTestTokens { get ; set ; } = int . MaxValue ;
[Uniform("min-price", "mp", "MINPRICE", true, "Minimum price for the storage space for which contracts will be accepted.")]
public int MinPrice { get ; set ; }
[Uniform("max-collateral", "mc", "MAXCOLLATERAL", true, "Maximum collateral that will be placed for the total storage space.")]
public int MaxCollateral { get ; set ; }
[Uniform("max-duration", "md", "MAXDURATION", true, "Maximum duration in seconds for contracts which will be accepted.")]
public int MaxDuration { get ; set ; }
2023-06-29 14:03:45 +00:00
[Uniform("block-ttl", "bt", "BLOCKTTL", false, "Block timeout in seconds. Default is 24 hours.")]
public int BlockTTL { get ; set ; } = SecondsIn1Day ;
2023-07-11 08:59:41 +00:00
2023-08-23 06:29:16 +00:00
[Uniform("block-mi", "bmi", "BLOCKMI", false, "Block maintenance interval in seconds. Default is 10 minutes.")]
public int BlockMI { get ; set ; } = TenMinutes ;
[Uniform("block-mn", "bmn", "BLOCKMN", false, "Number of blocks maintained per interval. Default is 1000 blocks.")]
public int BlockMN { get ; set ; } = 1000 ;
2023-08-13 07:07:23 +00:00
[Uniform("metrics", "m", "METRICS", false, "[None*, Record, Dashboard] . Determines if metrics will be recorded and if a dashboard service will be created . ")]
public MetricsMode Metrics { get ; set ; } = MetricsMode . None ;
2023-08-07 13:51:44 +00:00
[ Uniform ( "teststype-podlabel" , "ttpl" , "TESTSTYPE-PODLABEL" , false , "Each kubernetes pod will be created with a label 'teststype' with value 'continuous'. " +
"set this option to override the label value." ) ]
2023-08-10 12:31:08 +00:00
public string TestsTypePodLabel { get ; set ; } = "continuous-tests" ;
2023-07-11 12:56:40 +00:00
2023-06-22 07:51:25 +00:00
public List < string > Validate ( )
{
var errors = new List < string > ( ) ;
ForEachProperty (
onString : ( n , v ) = > StringIsSet ( n , v , errors ) ,
onInt : ( n , v ) = > IntIsOverZero ( n , v , errors ) ) ;
2023-06-22 13:58:18 +00:00
if ( NumberOfValidators > NumberOfCodexNodes )
{
errors . Add ( $"{nameof(NumberOfValidators)} ({NumberOfValidators}) may not be greater than {nameof(NumberOfCodexNodes)} ({NumberOfCodexNodes})." ) ;
}
2023-06-29 09:05:58 +00:00
if ( StorageSell . HasValue & & StorageQuota . HasValue & & StorageSell . Value > = StorageQuota . Value )
{
errors . Add ( "StorageSell cannot be greater than or equal to StorageQuota." ) ;
}
2023-06-22 13:58:18 +00:00
2023-06-22 07:51:25 +00:00
return errors ;
}
private void ForEachProperty ( Action < string , string > onString , Action < string , int? > onInt )
{
var properties = GetType ( ) . GetProperties ( ) ;
foreach ( var p in properties )
{
if ( p . PropertyType = = typeof ( string ) ) onString ( p . Name , ( string ) p . GetValue ( this ) ! ) ;
if ( p . PropertyType = = typeof ( int? ) ) onInt ( p . Name , ( int? ) p . GetValue ( this ) ! ) ;
2023-06-28 06:48:46 +00:00
if ( p . PropertyType = = typeof ( int ) ) onInt ( p . Name , ( int ) p . GetValue ( this ) ! ) ;
2023-06-22 07:51:25 +00:00
}
}
private static void IntIsOverZero ( string variable , int? value , List < string > errors )
{
if ( value = = null | | value . Value < 1 )
{
2023-06-27 06:29:39 +00:00
errors . Add ( $"{variable} must be set and must be greater than 0." ) ;
2023-06-22 07:51:25 +00:00
}
}
private static void StringIsSet ( string variable , string value , List < string > errors )
{
if ( string . IsNullOrWhiteSpace ( value ) )
{
2023-06-27 06:29:39 +00:00
errors . Add ( $"{variable} must be set." ) ;
2023-06-22 07:51:25 +00:00
}
}
}
}