Skip to content

Commit ba46b11

Browse files
authored
Merge pull request #76 from ninan-nn/feature/refacotr_sandbox_uuid
Refactor Sandbox Id
2 parents ad5e4ad + 73f7275 commit ba46b11

File tree

55 files changed

+167
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+167
-199
lines changed

sdks/code-interpreter/kotlin/code-interpreter/src/main/kotlin/com/alibaba/opensandbox/codeinterpreter/CodeInterpreter.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.alibaba.opensandbox.sandbox.domain.exceptions.SandboxException
2424
import com.alibaba.opensandbox.sandbox.domain.exceptions.SandboxInternalException
2525
import com.alibaba.opensandbox.sandbox.domain.models.execd.DEFAULT_EXECD_PORT
2626
import org.slf4j.LoggerFactory
27-
import java.util.UUID
2827

2928
/**
3029
* Code Interpreter SDK providing secure, isolated code execution capabilities.
@@ -92,7 +91,7 @@ class CodeInterpreter internal constructor(
9291
/**
9392
* Gets the unique identifier of this code interpreter (same as underlying sandbox ID).
9493
*/
95-
val id: UUID get() = sandbox.id
94+
val id: String get() = sandbox.id
9695

9796
/**
9897
* Provides access to file system operations within the sandbox.

sdks/code-interpreter/kotlin/code-interpreter/src/test/kotlin/com/alibaba/opensandbox/codeinterpreter/CodeInterpreterTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import org.junit.jupiter.api.Assertions.assertSame
3131
import org.junit.jupiter.api.BeforeEach
3232
import org.junit.jupiter.api.Test
3333
import org.junit.jupiter.api.extension.ExtendWith
34-
import java.util.UUID
3534

3635
@ExtendWith(MockKExtension::class)
3736
class CodeInterpreterTest {
@@ -42,7 +41,7 @@ class CodeInterpreterTest {
4241
lateinit var codeService: Codes
4342

4443
private lateinit var codeInterpreter: CodeInterpreter
45-
private val sandboxId = UUID.randomUUID()
44+
private val sandboxId = "sandbox-id"
4645

4746
@BeforeEach
4847
fun setUp() {

sdks/code-interpreter/python/src/code_interpreter/code_interpreter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"""
2323

2424
import logging
25-
from uuid import UUID
2625

2726
from opensandbox.exceptions import (
2827
InvalidArgumentException,
@@ -110,12 +109,12 @@ def sandbox(self) -> Sandbox:
110109
return self._sandbox
111110

112111
@property
113-
def id(self) -> UUID:
112+
def id(self) -> str:
114113
"""
115114
Gets the unique identifier of this code interpreter (same as underlying sandbox ID).
116115
117116
Returns:
118-
UUID of the code interpreter/sandbox
117+
ID of the code interpreter/sandbox
119118
"""
120119
return self._sandbox.id
121120

sdks/code-interpreter/python/src/code_interpreter/sync/code_interpreter.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"""
1919

2020
import logging
21-
from uuid import UUID
2221

2322
from opensandbox.constants import DEFAULT_EXECD_PORT
2423
from opensandbox.exceptions import (
@@ -93,12 +92,12 @@ def sandbox(self) -> SandboxSync:
9392
return self._sandbox
9493

9594
@property
96-
def id(self) -> UUID:
95+
def id(self) -> str:
9796
"""
9897
Gets the unique identifier of this code interpreter (same as underlying sandbox ID).
9998
10099
Returns:
101-
UUID of the code interpreter/sandbox
100+
ID of the code interpreter/sandbox
102101
"""
103102
return self._sandbox.id
104103

sdks/code-interpreter/python/tests/test_code_interpreter_create_and_delegation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class _FakeSandbox:
2525
def __init__(self) -> None:
26-
self._id = __import__("uuid").uuid4()
26+
self._id = str(__import__("uuid").uuid4())
2727
self.connection_config = ConnectionConfig(protocol="http")
2828
self.files = object()
2929
self.commands = object()

sdks/sandbox/kotlin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ PagedSandboxInfos sandboxes = manager.listSandboxInfos(
196196
sandboxes.getSandboxInfos().forEach(info -> {
197197
System.out.println("Found sandbox: " + info.getId());
198198
// Perform admin actions
199-
manager.killSandbox(UUID.fromString(info.getId()));
199+
manager.killSandbox(info.getId());
200200
});
201201

202202
// Try-with-resources will automatically call manager.close()

sdks/sandbox/kotlin/README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ PagedSandboxInfos sandboxes = manager.listSandboxInfos(
197197
sandboxes.getSandboxInfos().forEach(info -> {
198198
System.out.println("Found sandbox: " + info.getId());
199199
// 执行管理操作
200-
manager.killSandbox(UUID.fromString(info.getId()));
200+
manager.killSandbox(info.getId());
201201
});
202202

203203
// Try-with-resources 会自动调用 manager.close()

sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/Sandbox.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import com.alibaba.opensandbox.sandbox.infrastructure.factory.AdapterFactory
3636
import org.slf4j.LoggerFactory
3737
import java.time.Duration
3838
import java.time.OffsetDateTime
39-
import java.util.UUID
4039

4140
/**
4241
* Main entrypoint for the Open Sandbox SDK providing secure, isolated execution environments.
@@ -76,7 +75,7 @@ import java.util.UUID
7675
*
7776
*/
7877
class Sandbox internal constructor(
79-
val id: UUID,
78+
val id: String,
8079
private val sandboxService: Sandboxes,
8180
private val fileSystemService: Filesystem,
8281
private val commandService: Commands,
@@ -147,11 +146,11 @@ class Sandbox internal constructor(
147146
* Initialization result indicating the type of sandbox being initialized.
148147
*/
149148
private sealed class InitializationResult {
150-
abstract val id: UUID
149+
abstract val id: String
151150

152-
data class NewSandbox(override val id: UUID) : InitializationResult()
151+
data class NewSandbox(override val id: String) : InitializationResult()
153152

154-
data class ExistingSandbox(override val id: UUID) : InitializationResult()
153+
data class ExistingSandbox(override val id: String) : InitializationResult()
155154
}
156155

157156
/**
@@ -310,7 +309,7 @@ class Sandbox internal constructor(
310309
* @throws SandboxException if connection fails
311310
*/
312311
private fun connect(
313-
sandboxId: UUID,
312+
sandboxId: String,
314313
connectionConfig: ConnectionConfig,
315314
healthCheck: ((Sandbox) -> Boolean)? = null,
316315
connectTimeout: Duration,
@@ -347,7 +346,7 @@ class Sandbox internal constructor(
347346
* @throws SandboxException if resume or readiness check fails
348347
*/
349348
private fun resume(
350-
sandboxId: UUID,
349+
sandboxId: String,
351350
connectionConfig: ConnectionConfig,
352351
healthCheck: ((Sandbox) -> Boolean)? = null,
353352
resumeTimeout: Duration,
@@ -561,7 +560,7 @@ class Sandbox internal constructor(
561560
/**
562561
* Sandbox ID to connect to
563562
*/
564-
private var sandboxId: UUID? = null
563+
private var sandboxId: String? = null
565564

566565
/**
567566
* Connection config
@@ -593,11 +592,11 @@ class Sandbox internal constructor(
593592
/**
594593
* Sets the sandbox ID to connect to.
595594
*
596-
* @param sandboxId UUID string of the existing sandbox
595+
* @param sandboxId ID of the existing sandbox
597596
* @return This connector for method chaining
598597
* @throws InvalidArgumentException if sandboxId is blank
599598
*/
600-
fun sandboxId(sandboxId: UUID): Connector {
599+
fun sandboxId(sandboxId: String): Connector {
601600
this.sandboxId = sandboxId
602601
return this
603602
}
@@ -1098,7 +1097,7 @@ class Sandbox internal constructor(
10981097
/**
10991098
* Sandbox ID to resume
11001099
*/
1101-
private var sandboxId: UUID? = null
1100+
private var sandboxId: String? = null
11021101

11031102
/**
11041103
* Connection config
@@ -1130,10 +1129,10 @@ class Sandbox internal constructor(
11301129
/**
11311130
* Sets the sandbox ID to resume.
11321131
*
1133-
* @param sandboxId UUID of the paused sandbox
1132+
* @param sandboxId ID of the paused sandbox
11341133
* @return This resumer for method chaining
11351134
*/
1136-
fun sandboxId(sandboxId: UUID): Resumer {
1135+
fun sandboxId(sandboxId: String): Resumer {
11371136
this.sandboxId = sandboxId
11381137
return this
11391138
}

sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/SandboxManager.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import com.alibaba.opensandbox.sandbox.infrastructure.factory.AdapterFactory
2828
import org.slf4j.LoggerFactory
2929
import java.time.Duration
3030
import java.time.OffsetDateTime
31-
import java.util.UUID
3231

3332
/**
3433
* Sandbox management interface for administrative operations and monitoring sandbox instances.
@@ -56,7 +55,7 @@ import java.util.UUID
5655
* )
5756
*
5857
* // Individual operations
59-
* val sandboxId = UUID.fromString("sandbox-id")
58+
* val sandboxId = "sandbox-id"
6059
* manager.getSandboxInfo(sandboxId)
6160
* manager.pauseSandbox(sandboxId)
6261
* manager.resumeSandbox(sandboxId)
@@ -105,7 +104,7 @@ class SandboxManager internal constructor(
105104
* @return SandboxInfo for the specified sandbox
106105
* @throws SandboxException if the operation fails
107106
*/
108-
fun getSandboxInfo(sandboxId: UUID): SandboxInfo {
107+
fun getSandboxInfo(sandboxId: String): SandboxInfo {
109108
logger.debug("Getting info for sandbox: {}", sandboxId)
110109
return sandboxService.getSandboxInfo(sandboxId)
111110
}
@@ -116,7 +115,7 @@ class SandboxManager internal constructor(
116115
* @param sandboxId Sandbox ID to terminate
117116
* @throws SandboxException if the operation fails
118117
*/
119-
fun killSandbox(sandboxId: UUID) {
118+
fun killSandbox(sandboxId: String) {
120119
logger.info("Terminating sandbox: {}", sandboxId)
121120
sandboxService.killSandbox(sandboxId)
122121
logger.info("Successfully terminated sandbox: {}", sandboxId)
@@ -132,7 +131,7 @@ class SandboxManager internal constructor(
132131
* @throws SandboxException if the operation fails
133132
*/
134133
fun renewSandbox(
135-
sandboxId: UUID,
134+
sandboxId: String,
136135
timeout: Duration,
137136
): SandboxRenewResponse {
138137
logger.info("Renew expiration for sandbox {} to {}", sandboxId, OffsetDateTime.now().plus(timeout))
@@ -145,7 +144,7 @@ class SandboxManager internal constructor(
145144
* @param sandboxId Sandbox ID to pause
146145
* @throws SandboxException if the operation fails
147146
*/
148-
fun pauseSandbox(sandboxId: UUID) {
147+
fun pauseSandbox(sandboxId: String) {
149148
logger.info("Pausing sandbox: {}", sandboxId)
150149
sandboxService.pauseSandbox(sandboxId)
151150
}
@@ -156,7 +155,7 @@ class SandboxManager internal constructor(
156155
* @param sandboxId Sandbox ID to resume
157156
* @throws SandboxException if the operation fails
158157
*/
159-
fun resumeSandbox(sandboxId: UUID) {
158+
fun resumeSandbox(sandboxId: String) {
160159
logger.info("Resuming sandbox: {}", sandboxId)
161160
sandboxService.resumeSandbox(sandboxId)
162161
}

sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/config/ConnectionConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ConnectionConfig private constructor(
5050
private const val ENV_DOMAIN = "OPEN_SANDBOX_DOMAIN"
5151

5252
private const val DEFAULT_USER_AGENT = "OpenSandbox-Kotlin-SDK/1.0.1"
53+
private const val API_VERSION = "v1"
5354

5455
@JvmStatic
5556
fun builder(): Builder = Builder()
@@ -69,7 +70,7 @@ class ConnectionConfig private constructor(
6970
if (currentDomain.startsWith("http://") || currentDomain.startsWith("https://")) {
7071
return currentDomain
7172
}
72-
return "$protocol://$currentDomain"
73+
return "$protocol://$currentDomain/$API_VERSION"
7374
}
7475

7576
/**

0 commit comments

Comments
 (0)