summaryrefslogtreecommitdiff
path: root/src/marlin.agents.shell
diff options
context:
space:
mode:
Diffstat (limited to 'src/marlin.agents.shell')
-rw-r--r--src/marlin.agents.shell/MarlinApiClient.cs38
-rw-r--r--src/marlin.agents.shell/Program.cs21
-rw-r--r--src/marlin.agents.shell/marlin.agents.shell.csproj4
3 files changed, 62 insertions, 1 deletions
diff --git a/src/marlin.agents.shell/MarlinApiClient.cs b/src/marlin.agents.shell/MarlinApiClient.cs
new file mode 100644
index 0000000..aa4f013
--- /dev/null
+++ b/src/marlin.agents.shell/MarlinApiClient.cs
@@ -0,0 +1,38 @@
+namespace marlin.agents.shell;
+
+using System.Net.Http.Json;
+using core.models;
+
+public class MarlinApiClient
+{
+ private readonly HttpClient _http;
+
+ public MarlinApiClient(string baseUrl, Guid agentId, string agentToken)
+ {
+ _http = new HttpClient { BaseAddress = new Uri(baseUrl) };
+ _http.DefaultRequestHeaders.Add("Agent", $"{agentId} {agentToken}");
+ }
+
+ public static MarlinApiClient FromEnvironment()
+ {
+ var baseUrl = RequireEnv("MARLIN_API_BASE_URL");
+ var agentId = RequireEnv("MARLIN_AGENT_ID");
+ var agentToken = RequireEnv("MARLIN_AGENT_TOKEN");
+
+ return new MarlinApiClient(baseUrl, Guid.Parse(agentId), agentToken);
+ }
+
+ private static string RequireEnv(string name) =>
+ Environment.GetEnvironmentVariable(name)
+ ?? throw new InvalidOperationException($"Missing required environment variable: {name}");
+
+ public async Task<AgentConfiguration> Handshake(AgentStatus status, CancellationToken ct = default)
+ {
+ var response = await _http.PostAsJsonAsync("api/dispatch/handshake", status, ct);
+ response.EnsureSuccessStatusCode();
+ return (await response.Content.ReadFromJsonAsync<AgentConfiguration>(ct))!;
+ }
+
+ public async Task<DispatchJob?> QueueNextJob(CancellationToken ct = default)
+ => await _http.GetFromJsonAsync<DispatchJob?>("api/dispatch/queue", ct);
+}
diff --git a/src/marlin.agents.shell/Program.cs b/src/marlin.agents.shell/Program.cs
index 837131c..02a0bc9 100644
--- a/src/marlin.agents.shell/Program.cs
+++ b/src/marlin.agents.shell/Program.cs
@@ -1 +1,20 @@
-Console.WriteLine("Hello, World!"); \ No newline at end of file
+using System.Runtime.InteropServices;
+using marlin.agents.shell;
+using marlin.core.models;
+
+DotNetEnv.Env.NoClobber().TraversePath().Load();
+
+var client = MarlinApiClient.FromEnvironment();
+
+var capabilities = new CapabilitySet();
+capabilities.Items.Add(KnownCapabilities.Architecture, RuntimeInformation.OSArchitecture.ToString());
+capabilities.Items.Add(KnownCapabilities.CoreCount, Environment.ProcessorCount.ToString());
+capabilities.Items.Add(KnownCapabilities.Memory, (GC.GetGCMemoryInfo().TotalAvailableMemoryBytes / (1024 * 1024)).ToString());
+var status = new AgentStatus(capabilities);
+
+AgentConfiguration config = await client.Handshake(status);
+Console.WriteLine($"IAM: {config.Name}");
+Console.WriteLine($"MCJ: {config.MaxConcurrentJobs}");
+
+var job = await client.QueueNextJob();
+Console.WriteLine(job == null ? "No pending jobs." : $"Claimed job {job.Id}: {job.Recipe}");
diff --git a/src/marlin.agents.shell/marlin.agents.shell.csproj b/src/marlin.agents.shell/marlin.agents.shell.csproj
index cd0016d..ff86d63 100644
--- a/src/marlin.agents.shell/marlin.agents.shell.csproj
+++ b/src/marlin.agents.shell/marlin.agents.shell.csproj
@@ -8,6 +8,10 @@
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="DotNetEnv" Version="3.2.0" />
+ </ItemGroup>
+
+ <ItemGroup>
<ProjectReference Include="..\marlin.core\marlin.core.csproj" />
</ItemGroup>