2
0
mirror of synced 2025-02-02 19:53:29 +00:00

Removes rest server

This commit is contained in:
benbierens 2024-09-12 14:42:19 +02:00
parent 8e018cbae9
commit a41272f160
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
17 changed files with 1 additions and 829 deletions

View File

@ -1,24 +0,0 @@
name: Docker - AutoClientCenter
on:
push:
branches:
- master
tags:
- 'v*.*.*'
paths:
- 'Tools/AutoClientCenter/**'
- '!Tools/AutoClientCenter/Dockerfile'
- .github/workflows/docker-autoclientcenter.yml
- .github/workflows/docker-reusable.yml
workflow_dispatch:
jobs:
build-and-push:
name: Build and Push
uses: ./.github/workflows/docker-reusable.yml
with:
docker_file: Tools/AutoClientCenter/Dockerfile
docker_repo: codexstorage/codex-autoclientcenter
secrets: inherit

View File

@ -5,7 +5,7 @@ namespace AutoClient
public class Configuration
{
[Uniform("codex-endpoints", "ce", "CODEXENDPOINTS", false, "Codex endpoints. Semi-colon separated. (default 'http://localhost:8080')")]
public string CodexEndpoints { get; set; } = "http://localhost";
public string CodexEndpoints { get; set; } = "http://localhost:8080";
[Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")]
public string DataPath { get; set; } = "datapath";

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>80f55fc5-9f8f-4bb4-89bc-314ed7379c5f</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Framework\Utils\Utils.csproj" />
<ProjectReference Include="..\..\ProjectPlugins\CodexContractsPlugin\CodexContractsPlugin.csproj" />
</ItemGroup>
</Project>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -1,6 +0,0 @@
@AutoClientCenter_HostAddress = http://localhost:5185
GET {{AutoClientCenter_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -1,76 +0,0 @@
namespace AutoClientCenter
{
public class CidRepo
{
private readonly Random random = new Random();
private readonly object _lock = new object();
private readonly List<CidEntry> entries = new List<CidEntry>();
public void Add(string cid, long knownSize)
{
lock (_lock)
{
entries.Add(new CidEntry(cid, knownSize));
}
}
public void AddEncoded(string originalCid, string encodedCid)
{
lock (_lock)
{
var entry = entries.SingleOrDefault(e => e.Cid == originalCid);
if (entry == null) return;
entry.Encoded = encodedCid;
}
}
public void Assign(AcDownloadStep downloadStep)
{
lock (_lock)
{
while (true)
{
if (!entries.Any()) return;
var i = random.Next(0, entries.Count);
var entry = entries[i];
if (entry.CreatedUtc < (DateTime.UtcNow + TimeSpan.FromHours(18)))
{
entries.RemoveAt(i);
}
else
{
downloadStep.Cid = entry.Cid;
return;
}
}
}
}
public long? GetSizeKbsForCid(string cid)
{
lock (_lock)
{
var entry = entries.SingleOrDefault(e => e.Cid == cid);
if (entry == null) return null;
return entry.KnownSize;
}
}
}
public class CidEntry
{
public CidEntry(string cid, long knownSize)
{
Cid = cid;
KnownSize = knownSize;
}
public string Cid { get; }
public string Encoded { get; set; } = string.Empty;
public long KnownSize { get; }
public DateTime CreatedUtc { get; } = DateTime.UtcNow;
}
}

View File

@ -1,28 +0,0 @@
using Microsoft.AspNetCore.Mvc;
namespace AutoClientCenter.Controllers
{
[ApiController]
[Route("[controller]")]
public class ConfigController : ControllerBase
{
private readonly ITaskService taskService;
public ConfigController(ITaskService taskService)
{
this.taskService = taskService;
}
[HttpGet("Stats")]
public AcStats Get()
{
return taskService.GetStats();
}
[HttpPost("Set")]
public void Post([FromBody] AcTasks tasks)
{
taskService.SetConfig(tasks);
}
}
}

View File

@ -1,35 +0,0 @@
using Microsoft.AspNetCore.Mvc;
namespace AutoClientCenter.Controllers
{
[ApiController]
[Route("[controller]")]
public class TasksController : ControllerBase
{
private readonly ITaskService taskService;
private static readonly object processLock = new object();
public TasksController(ITaskService taskService)
{
this.taskService = taskService;
}
[HttpGet]
public AcTasks Get()
{
return taskService.GetTasks();
}
[HttpPost("Results")]
public void Post([FromBody] AcTaskStep[] taskSteps)
{
Task.Run(() =>
{
lock (processLock)
{
taskService.ProcessResults(taskSteps);
}
});
}
}
}

View File

@ -1,23 +0,0 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Tools/AutoClientCenter/AutoClientCenter.csproj", "AutoClientCenter/"]
RUN dotnet restore "./Tools/AutoClientCenter/AutoClientCenter.csproj"
COPY . .
WORKDIR "/src/Tools/AutoClientCenter"
RUN dotnet build "./AutoClientCenter.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./AutoClientCenter.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AutoClientCenter.dll"]

View File

@ -1,60 +0,0 @@
namespace AutoClientCenter
{
public class AcTasks
{
public int StartTaskEverySeconds { get; set; }
public AcTask[] Tasks { get; set; } = Array.Empty<AcTask>();
}
public class AcTask
{
public int ChanceWeight { get; set; }
public AcTaskStep[] Steps { get; set; } = Array.Empty<AcTaskStep>();
}
public class AcTaskStep
{
public string Id { get; set; } = string.Empty;
public AcUploadStep? UploadStep { get; set; }
public AcStoreStep? StoreStep { get; set; }
public AcDownloadStep? DownloadStep { get; set; }
public string? ResultErrorMsg { get; set; }
}
public class AcUploadStep
{
public long SizeInBytes { get; set; }
public string? ResultCid { get; set; }
}
public class AcStoreStep
{
public int ContractDurationMinutes { get; set; }
public int ContractExpiryMinutes { get; set; }
public int NumHosts { get; set; }
public int HostTolerance { get; set; }
public int Price { get; set; }
public int RequiredCollateral { get; set; }
public string? ResultPurchaseId { get; set; }
public string? ResultOriginalCid { get; set; }
public string? ResultEncodedCid { get; set; }
}
public class AcDownloadStep
{
public string Cid { get; set; } = string.Empty;
public long ResultDownloadTimeMilliseconds { get; set; }
}
public class AcStats
{
public DateTime ServiceStartUtc { get; set; } = DateTime.MinValue;
public int TotalUploads { get; set; }
public int TotalUploadsFailed { get; set; }
public int TotalDownloads { get; set; }
public long[] DownloadTimesMillisecondsPerKb { get; set; } = Array.Empty<long>();
public int TotalDownloadsFailed { get; set; }
public int TotalContractsStarted { get; set; }
public int TotalContractStartsFailed { get; set; }
}
}

View File

@ -1,43 +0,0 @@
namespace AutoClientCenter
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var listenPort = Environment.GetEnvironmentVariable("APIPORT");
if (string.IsNullOrEmpty(listenPort)) listenPort = "31090";
builder.WebHost.ConfigureKestrel((context, options) =>
{
options.ListenAnyIP(Convert.ToInt32(listenPort));
});
builder.Services.AddSingleton<ITaskService>(new TaskService());
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
Console.WriteLine("AutoClientCenter listening on port " + listenPort);
app.Run();
}
}
}

View File

@ -1,52 +0,0 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5185"
},
"https": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7077;http://localhost:5185"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50475",
"sslPort": 44395
}
}
}

View File

@ -1,116 +0,0 @@
namespace AutoClientCenter
{
public interface ITaskService
{
AcStats GetStats();
AcTasks GetTasks();
void ProcessResults(AcTaskStep[] taskSteps);
void SetConfig(AcTasks tasks);
}
public class TaskService : ITaskService
{
private readonly CidRepo cidRepo = new CidRepo();
private readonly List<long> downloadTimes = new List<long>();
private readonly AcStats stats = new AcStats
{
ServiceStartUtc = DateTime.UtcNow,
};
private AcTasks tasks = new AcTasks
{
StartTaskEverySeconds = Convert.ToInt32(TimeSpan.FromHours(8).TotalSeconds),
Tasks = Array.Empty<AcTask>()
};
public AcStats GetStats()
{
stats.DownloadTimesMillisecondsPerKb = downloadTimes.ToArray();
return stats;
}
public AcTasks GetTasks()
{
foreach (var task in tasks.Tasks)
{
foreach (var step in task.Steps)
{
if (step.DownloadStep != null) cidRepo.Assign(step.DownloadStep);
}
}
return tasks;
}
public void SetConfig(AcTasks newTasks)
{
if (newTasks.StartTaskEverySeconds < (10 * 60)) return;
foreach (var task in newTasks.Tasks)
{
if (task.ChanceWeight < 1) return;
foreach (var step in task.Steps)
{
if (string.IsNullOrWhiteSpace(step.Id)) return;
if (step.UploadStep == null && step.StoreStep == null && step.DownloadStep == null) return;
}
}
tasks = newTasks;
}
public void ProcessResults(AcTaskStep[] taskSteps)
{
foreach (var step in taskSteps) ProcessResults(step);
}
private void ProcessResults(AcTaskStep step)
{
ProcessResult(step.UploadStep);
ProcessResult(step.StoreStep);
ProcessResult(step.DownloadStep);
}
private void ProcessResult(AcUploadStep? uploadStep)
{
if (uploadStep == null) return;
if (string.IsNullOrWhiteSpace(uploadStep.ResultCid))
{
stats.TotalUploadsFailed++;
}
else
{
stats.TotalUploads++;
cidRepo.Add(uploadStep.ResultCid, uploadStep.SizeInBytes);
}
}
private void ProcessResult(AcStoreStep? storeStep)
{
if (storeStep == null) return;
if (string.IsNullOrWhiteSpace(storeStep.ResultOriginalCid) ||
string.IsNullOrWhiteSpace(storeStep.ResultEncodedCid) ||
string.IsNullOrWhiteSpace(storeStep.ResultPurchaseId))
{
stats.TotalContractStartsFailed++;
}
else
{
stats.TotalContractsStarted++;
cidRepo.AddEncoded(storeStep.ResultOriginalCid, storeStep.ResultEncodedCid);
}
}
private void ProcessResult(AcDownloadStep? downloadStep)
{
if (downloadStep == null) return;
var kbs = cidRepo.GetSizeKbsForCid(downloadStep.Cid);
if (kbs == null) return;
var milliseconds = downloadStep.ResultDownloadTimeMilliseconds;
var millisecondsPerKb = milliseconds / kbs.Value;
downloadTimes.Add(millisecondsPerKb);
}
}
}

View File

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -1,311 +0,0 @@
{
"openapi": "3.0.1",
"info": {
"title": "AutoClientCenter",
"version": "1.0"
},
"paths": {
"/Config/Stats": {
"get": {
"tags": [
"Config"
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/AcStats"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/AcStats"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/AcStats"
}
}
}
}
}
}
},
"/Config/Set": {
"post": {
"tags": [
"Config"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AcTasks"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/AcTasks"
}
},
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/AcTasks"
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/Tasks": {
"get": {
"tags": [
"Tasks"
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/AcTasks"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/AcTasks"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/AcTasks"
}
}
}
}
}
}
},
"/Tasks/Results": {
"post": {
"tags": [
"Tasks"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AcTaskStep"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AcTaskStep"
}
}
},
"application/*+json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AcTaskStep"
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
}
},
"components": {
"schemas": {
"AcDownloadStep": {
"type": "object",
"properties": {
"cid": {
"type": "string",
"nullable": true
},
"resultDownloadTimeMilliseconds": {
"type": "integer",
"format": "int64"
}
},
"additionalProperties": false
},
"AcStats": {
"type": "object",
"properties": {
"serviceStartUtc": {
"type": "string",
"format": "date-time"
},
"totalUploads": {
"type": "integer",
"format": "int32"
},
"totalUploadsFailed": {
"type": "integer",
"format": "int32"
},
"totalDownloads": {
"type": "integer",
"format": "int32"
},
"downloadTimesMillisecondsPerKb": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"nullable": true
},
"totalDownloadsFailed": {
"type": "integer",
"format": "int32"
},
"totalContractsStarted": {
"type": "integer",
"format": "int32"
},
"totalContractStartsFailed": {
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false
},
"AcStoreStep": {
"type": "object",
"properties": {
"contractDurationMinutes": {
"type": "integer",
"format": "int32"
},
"contractExpiryMinutes": {
"type": "integer",
"format": "int32"
},
"numHosts": {
"type": "integer",
"format": "int32"
},
"hostTolerance": {
"type": "integer",
"format": "int32"
},
"price": {
"type": "integer",
"format": "int32"
},
"requiredCollateral": {
"type": "integer",
"format": "int32"
},
"resultPurchaseId": {
"type": "string",
"nullable": true
},
"resultOriginalCid": {
"type": "string",
"nullable": true
},
"resultEncodedCid": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"AcTask": {
"type": "object",
"properties": {
"chanceWeight": {
"type": "integer",
"format": "int32"
},
"steps": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AcTaskStep"
},
"nullable": true
}
},
"additionalProperties": false
},
"AcTaskStep": {
"type": "object",
"properties": {
"id": {
"type": "string",
"nullable": true
},
"uploadStep": {
"$ref": "#/components/schemas/AcUploadStep"
},
"storeStep": {
"$ref": "#/components/schemas/AcStoreStep"
},
"downloadStep": {
"$ref": "#/components/schemas/AcDownloadStep"
},
"resultErrorMsg": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
},
"AcTasks": {
"type": "object",
"properties": {
"startTaskEverySeconds": {
"type": "integer",
"format": "int32"
},
"tasks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AcTask"
},
"nullable": true
}
},
"additionalProperties": false
},
"AcUploadStep": {
"type": "object",
"properties": {
"sizeInBytes": {
"type": "integer",
"format": "int64"
},
"resultCid": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
}
}
}

View File

@ -76,8 +76,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TranscriptAnalysis", "Tools
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MarketInsights", "Tools\MarketInsights\MarketInsights.csproj", "{004614DF-1C65-45E3-882D-59AE44282573}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoClientCenter", "Tools\AutoClientCenter\AutoClientCenter.csproj", "{9290DA91-F120-4DBC-94B7-CFC3CE41AF4A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -204,10 +202,6 @@ Global
{004614DF-1C65-45E3-882D-59AE44282573}.Debug|Any CPU.Build.0 = Debug|Any CPU
{004614DF-1C65-45E3-882D-59AE44282573}.Release|Any CPU.ActiveCfg = Release|Any CPU
{004614DF-1C65-45E3-882D-59AE44282573}.Release|Any CPU.Build.0 = Release|Any CPU
{9290DA91-F120-4DBC-94B7-CFC3CE41AF4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9290DA91-F120-4DBC-94B7-CFC3CE41AF4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9290DA91-F120-4DBC-94B7-CFC3CE41AF4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9290DA91-F120-4DBC-94B7-CFC3CE41AF4A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -243,7 +237,6 @@ Global
{870DDFBE-D7ED-4196-9681-13CA947BDEA6} = {81AE04BC-CBFA-4E6F-B039-8208E9AFAAE7}
{C0EEBD32-23CB-45EC-A863-79FB948508C8} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3}
{004614DF-1C65-45E3-882D-59AE44282573} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3}
{9290DA91-F120-4DBC-94B7-CFC3CE41AF4A} = {7591C5B3-D86E-4AE4-8ED2-B272D17FE7E3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {237BF0AA-9EC4-4659-AD9A-65DEB974250C}