Skip to content

Commit a6281af

Browse files
author
Ferran Pons Serra
committed
feat(kotlin): expose snapshot imageUri in the Kotlin SDK
Add imageUri to the domain SnapshotInfo and map it in SandboxModelConverter; the lifecycle client regenerates from the spec at build time. SnapshotInfo keeps a binary-compatibility constructor (with a default on name) so the pre-imageUri JVM constructor and its $default synthetic are preserved for already-compiled callers.
1 parent 77619ee commit a6281af

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/domain/models/sandboxes/SandboxModels.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,29 @@ class SnapshotInfo(
794794
val name: String? = null,
795795
val status: SnapshotStatus,
796796
val createdAt: OffsetDateTime,
797-
)
797+
/**
798+
* Portable OCI image reference for a Ready snapshot, usable to restore a sandbox (e.g. across
799+
* clusters). Populated once the snapshot reaches [SnapshotState.READY]; null otherwise.
800+
*/
801+
val imageUri: String? = null,
802+
) {
803+
/**
804+
* Binary-compatibility constructor preserving the pre-`imageUri` JVM signatures for
805+
* already-compiled callers; delegates [imageUri] to null.
806+
*
807+
* The default on [name] is deliberate: it makes the compiler emit the old
808+
* `(String, String, String?, SnapshotStatus, OffsetDateTime, int, DefaultConstructorMarker)`
809+
* synthetic `$default` constructor, so Kotlin call sites compiled against the previous
810+
* `SnapshotInfo` that omitted `name` keep resolving instead of hitting `NoSuchMethodError`.
811+
*/
812+
constructor(
813+
id: String,
814+
sandboxId: String,
815+
name: String? = null,
816+
status: SnapshotStatus,
817+
createdAt: OffsetDateTime,
818+
) : this(id, sandboxId, name, status, createdAt, null)
819+
}
798820

799821
class SnapshotFilter private constructor(
800822
val sandboxId: String?,

sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/infrastructure/adapters/converter/SandboxModelConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ internal object SandboxModelConverter {
410410
lastTransitionAt = this.status.lastTransitionAt,
411411
),
412412
createdAt = this.createdAt,
413+
imageUri = this.imageUri,
413414
)
414415
}
415416

sdks/sandbox/kotlin/sandbox/src/test/kotlin/com/alibaba/opensandbox/sandbox/infrastructure/adapters/service/SandboxesAdapterTest.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ class SandboxesAdapterTest {
369369
"message": null,
370370
"lastTransitionAt": "2023-01-01T10:00:00Z"
371371
},
372-
"createdAt": "2023-01-01T10:00:00Z"
372+
"createdAt": "2023-01-01T10:00:00Z",
373+
"imageUri": "registry.example.com/snapshots/snap-123:latest"
373374
}
374375
""".trimIndent()
375376
mockWebServer.enqueue(MockResponse().setBody(responseBody).setResponseCode(200))
@@ -378,6 +379,7 @@ class SandboxesAdapterTest {
378379

379380
assertEquals(snapshotId, result.id)
380381
assertEquals("sandbox-123", result.sandboxId)
382+
assertEquals("registry.example.com/snapshots/snap-123:latest", result.imageUri)
381383

382384
val request = mockWebServer.takeRequest()
383385
assertEquals("GET", request.method)

0 commit comments

Comments
 (0)