Package sh.createos.jenkins.sandbox
Class CreateOSApiClient
java.lang.Object
sh.createos.jenkins.sandbox.CreateOSApiClient
HTTP client for the CreateOS Sandbox control plane API.
Uses Java's built-in HttpClient (no external dependencies). All responses follow JSend format: { "status": "success", "data": {...} }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult from a CreateOS exec call.static final recordIdentity of one sandbox as the list endpoint reports it. -
Constructor Summary
ConstructorsConstructorDescriptionCreateOSApiClient(String baseUrl, String apiKey) Creates a client for the given CreateOS API endpoint and API key. -
Method Summary
Modifier and TypeMethodDescriptioncreateSandbox(CreateOSSandboxRequest request) Create a new sandbox and return its ID.voiddestroySandbox(String sandboxId) Destroy a sandbox.voiddownloadFile(String sandboxId, String remotePath, OutputStream output) Downloads raw bytes from an absolute path inside the sandbox.getSandboxStatus(String sandboxId) Get the current status of a sandbox.booleanReports whether a sandbox is still running.Lists every sandbox visible to this API key.com.fasterxml.jackson.databind.JsonNodeRun a bash script inside a sandbox and return once it exits.runShellScript(String sandboxId, String script, PrintStream log, boolean collectStdout) Runs a shell script inside the sandbox and streams output into the Jenkins log.voidVerify that this API key can access the CreateOS sandbox endpoint.voiduploadFile(String sandboxId, String remotePath, InputStream input) Uploads raw bytes to an absolute path inside the sandbox.voidwaitForRunning(String sandboxId, Duration timeout) Poll until sandbox reaches "running" state.
-
Constructor Details
-
CreateOSApiClient
Creates a client for the given CreateOS API endpoint and API key.
-
-
Method Details
-
testConnection
Verify that this API key can access the CreateOS sandbox endpoint.- Throws:
IOException
-
createSandbox
Create a new sandbox and return its ID.POST /v1/sandboxes
- Throws:
IOException
-
getSandboxStatus
Get the current status of a sandbox.- Throws:
IOException
-
isRunning
Reports whether a sandbox is still running.Any failure to answer counts as "not running". This backs decisions about adopting a sandbox the controller believes it owns, and treating an unreachable or deleted sandbox as alive would attach an agent to nothing.
-
listSandboxes
Lists every sandbox visible to this API key.- Throws:
IOException
-
runBash
public com.fasterxml.jackson.databind.JsonNode runBash(String sandboxId, String script) throws IOException Run a bash script inside a sandbox and return once it exits.POST /v1/sandboxes/{id}/exec Body: { "cmd": "bash", "args": ["-c", "..."] }
- Throws:
IOException
-
runShellScript
public CreateOSApiClient.ExecResult runShellScript(String sandboxId, String script, PrintStream log, boolean collectStdout) throws IOException Runs a shell script inside the sandbox and streams output into the Jenkins log.- Throws:
IOException
-
uploadFile
Uploads raw bytes to an absolute path inside the sandbox.- Throws:
IOException
-
downloadFile
public void downloadFile(String sandboxId, String remotePath, OutputStream output) throws IOException Downloads raw bytes from an absolute path inside the sandbox.- Throws:
IOException
-
destroySandbox
Destroy a sandbox.DELETE /v1/sandboxes/{id}
- Throws:
IOException
-
waitForRunning
public void waitForRunning(String sandboxId, Duration timeout) throws IOException, InterruptedException Poll until sandbox reaches "running" state.- Throws:
IOExceptionInterruptedException
-