2023-04-14 07:54:07 +00:00
using KubernetesWorkflow ;
namespace DistTestCore.Marketplace
{
2023-04-18 11:45:48 +00:00
public class GethCompanionNodeStarter : BaseStarter
2023-04-14 07:54:07 +00:00
{
public GethCompanionNodeStarter ( TestLifecycle lifecycle , WorkflowCreator workflowCreator )
2023-04-18 11:45:48 +00:00
: base ( lifecycle , workflowCreator )
2023-04-14 07:54:07 +00:00
{
}
2023-04-24 12:09:23 +00:00
public GethCompanionNodeInfo [ ] StartCompanionNodesFor ( CodexSetup codexSetup , MarketplaceNetwork marketplace )
2023-04-14 07:54:07 +00:00
{
2023-04-18 11:45:48 +00:00
LogStart ( $"Initializing companions for {codexSetup.NumberOfNodes} Codex nodes." ) ;
2023-04-14 07:54:07 +00:00
2023-04-24 12:09:23 +00:00
var startupConfig = CreateCompanionNodeStartupConfig ( marketplace . Bootstrap ) ;
2023-04-14 07:54:07 +00:00
var workflow = workflowCreator . CreateWorkflow ( ) ;
var containers = workflow . Start ( codexSetup . NumberOfNodes , Location . Unspecified , new GethContainerRecipe ( ) , startupConfig ) ;
if ( containers . Containers . Length ! = codexSetup . NumberOfNodes ) throw new InvalidOperationException ( "Expected a Geth companion node to be created for each Codex node. Test infra failure." ) ;
2023-04-19 07:19:06 +00:00
var result = containers . Containers . Select ( c = > CreateCompanionInfo ( workflow , c ) ) . ToArray ( ) ;
2023-04-14 07:54:07 +00:00
2023-04-24 12:09:23 +00:00
foreach ( var node in result )
{
EnsureCompanionNodeIsSynced ( node , marketplace ) ;
}
2023-04-19 07:19:06 +00:00
LogEnd ( $"Initialized {codexSetup.NumberOfNodes} companion nodes. Their accounts: [{string.Join(" , ", result.Select(c => c.Account))}]" ) ;
return result ;
2023-04-14 07:54:07 +00:00
}
private GethCompanionNodeInfo CreateCompanionInfo ( StartupWorkflow workflow , RunningContainer container )
{
2023-04-18 08:22:11 +00:00
var extractor = new ContainerInfoExtractor ( workflow , container ) ;
2023-04-14 07:54:07 +00:00
var account = extractor . ExtractAccount ( ) ;
2023-04-24 12:09:23 +00:00
var privKey = extractor . ExtractPrivateKey ( ) ;
return new GethCompanionNodeInfo ( container , account , privKey ) ;
}
private void EnsureCompanionNodeIsSynced ( GethCompanionNodeInfo node , MarketplaceNetwork marketplace )
{
var interaction = node . StartInteraction ( lifecycle . Log ) ;
interaction . EnsureSynced ( marketplace . Marketplace . Address , marketplace . Marketplace . Abi ) ;
2023-04-14 07:54:07 +00:00
}
private StartupConfig CreateCompanionNodeStartupConfig ( GethBootstrapNodeInfo bootstrapNode )
{
var config = new StartupConfig ( ) ;
2023-04-19 05:59:28 +00:00
config . Add ( new GethStartupConfig ( false , bootstrapNode ) ) ;
2023-04-14 07:54:07 +00:00
return config ;
}
}
}