44026d0a70
- http_client.{h,cpp}: TCP plain (copia de registry_dashboard, sin SSL).
- data_http.{h,cpp}: API DAG (list/get/runs/trigger) + parser nlohmann/json.
- vendor/nlohmann/json.hpp: vendored.
- main.cpp: panel "Fetch /api/dags" demo, lista DAGs con schedule.
- CMakeLists.txt: anade http_client.cpp + data_http.cpp.
Build verificado. WS y tabs (data_table::render) en commits siguientes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
#pragma once
|
|
|
|
// Cliente HTTP REST contra apps/dag_engine (Go backend).
|
|
// Endpoints: /api/dags, /api/runs, /api/dags/{name}/run (issue 0095).
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace dag_ui {
|
|
|
|
// --- Modelo de datos (mirror JSON shape de apps/dag_engine) ---
|
|
|
|
struct DagInfo {
|
|
std::string name;
|
|
std::string description;
|
|
std::vector<std::string> schedule; // cron expressions
|
|
std::vector<std::string> tags;
|
|
std::string type;
|
|
std::string file_path;
|
|
bool valid = false;
|
|
// last_run inlined fields (extracted from nested object on load)
|
|
bool has_last_run = false;
|
|
std::string last_run_id;
|
|
std::string last_run_status;
|
|
std::string last_run_started_at;
|
|
std::string last_run_finished_at;
|
|
};
|
|
|
|
struct DagRunRow {
|
|
std::string id;
|
|
std::string dag_name;
|
|
std::string dag_path;
|
|
std::string status; // pending|running|success|failed|cancelled
|
|
std::string trigger; // manual|cron|api
|
|
std::string started_at;
|
|
std::string finished_at;
|
|
std::string error;
|
|
};
|
|
|
|
struct DagStepRow {
|
|
std::string id;
|
|
std::string run_id;
|
|
std::string step_name;
|
|
std::string status;
|
|
int exit_code = 0;
|
|
std::string stdout_text;
|
|
std::string stderr_text;
|
|
std::string started_at;
|
|
std::string finished_at;
|
|
long long duration_ms = 0;
|
|
std::string error;
|
|
};
|
|
|
|
struct DagRunDetail {
|
|
DagRunRow run;
|
|
std::vector<DagStepRow> steps;
|
|
};
|
|
|
|
struct DagDetail {
|
|
DagInfo info;
|
|
std::vector<DagRunRow> recent_runs;
|
|
std::string validation_error; // empty if valid
|
|
};
|
|
|
|
// --- API ---
|
|
// api_url: "http://127.0.0.1:8090". Todas las funciones blocking, devuelven
|
|
// false si la red falla o el status no es 2xx. Errores van a stderr.
|
|
|
|
bool list_dags_http(const std::string& api_url, std::vector<DagInfo>& out);
|
|
|
|
bool get_dag_http(const std::string& api_url, const std::string& name,
|
|
DagDetail& out);
|
|
|
|
bool list_runs_http(const std::string& api_url, const std::string& dag_name,
|
|
int limit, std::vector<DagRunRow>& out);
|
|
|
|
bool get_run_http(const std::string& api_url, const std::string& run_id,
|
|
DagRunDetail& out);
|
|
|
|
// Devuelve el run_id en out_run_id si HTTP 202.
|
|
bool trigger_dag_http(const std::string& api_url, const std::string& name,
|
|
std::string& out_run_id, std::string& out_error);
|
|
|
|
} // namespace dag_ui
|