Skip to content

Commit

Permalink
Prompt user for device creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tokou committed Aug 27, 2024
1 parent 4f39257 commit 75f01a3
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,32 @@ class TestCommand : Callable<Int> {

val connectedDevices = DeviceService.listConnectedDevices()
initialActiveDevices.addAll(connectedDevices.map { it.instanceId }.toSet())
val effectiveShards = shards.coerceAtMost(plan.flowsToRun.size)
var effectiveShards = shards.coerceAtMost(plan.flowsToRun.size)

// Collect device configurations for missing shards, if any
val availableDevices = if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size
val missingDevices = effectiveShards - availableDevices
if (missingDevices > 0) {
val message = """
Found $availableDevices active devices.
Need to create or start $missingDevices more for $effectiveShards shards. Continue? y/n
""".trimIndent()
PrintUtils.message(message)
val str = readlnOrNull()?.lowercase()
val granted = str?.isBlank() == true || str == "y" || str == "yes"
if (!granted) {
PrintUtils.message("Continuing with only $availableDevices shards.")
effectiveShards = availableDevices
}
}
val missingDevicesConfigs = (availableDevices until effectiveShards).mapNotNull { shardIndex ->
PrintUtils.message("Creating device for shard ${shardIndex + 1}:")
PickDeviceView.requestDeviceOptions()
}.toMutableList()

val chunkPlans = plan.flowsToRun
.withIndex()
.groupBy { it.index % shards }
.groupBy { it.index % effectiveShards }
.map { (shardIndex, files) ->
ExecutionPlan(
files.map { it.value },
Expand All @@ -202,15 +224,6 @@ class TestCommand : Callable<Int> {
)
}

// Collect device configurations for missing shards, if any
val availableDevices = if (deviceIds.isNotEmpty()) deviceIds.size else initialActiveDevices.size
val missingDevices = effectiveShards - availableDevices
val missingDevicesConfigs = (0 until missingDevices).map { shardIndex ->
PrintUtils.message("------------------ Shard ${shardIndex + 1} ------------------")
// Collect device configurations here, one per shard
PickDeviceView.requestDeviceOptions()
}.toMutableList()

val barrier = CountDownLatch(effectiveShards)

logger.info("Running $effectiveShards shards on $availableDevices available devices and ${missingDevicesConfigs.size} created devices.")
Expand Down

0 comments on commit 75f01a3

Please sign in to comment.