Merge pull request 'moved to json' (#7) from planner into main

This commit was merged in pull request #7.
This commit is contained in:
2026-02-24 15:01:33 +03:00
13 changed files with 23001 additions and 64 deletions

View File

@@ -23,11 +23,11 @@ public:
elements.push_back(new_line);
}
long getLength() const {
return (long)elements.size();
int getLength() const {
return (int)elements.size();
}
T* get(long i) {
T* get(int i) {
return elements[i];
}

View File

@@ -6,11 +6,11 @@
class CompilationSupervisor : public Supervisor<CompilationTask> {
public:
CompilationSupervisor() {
this->init("compilationTasks", 4);
this->init("compilationTasks.json");
}
CompilationTask* getTaskById(long task_id) {
for (long i = 0; i < getLength(); ++i) {
CompilationTask* getTaskById(int task_id) {
for (int i = 0; i < getLength(); ++i) {
CompilationTask* task = get(i);
if (task->getId() == task_id)
return task;

View File

@@ -2,13 +2,14 @@
#include "Task.h"
#include "Text.h"
#include "json.hpp"
class CompilationTask : public Task {
String test_id;
String test_name;
String makefile_text;
public:
void setTestId(String* test_id_in) {
test_id = String(test_id_in->getCharArray());
void setTestName(String* test_name_in) {
test_name = String(test_name_in->getCharArray());
}
void setMakefileText(String* makefile_text_in) {
@@ -16,22 +17,30 @@ public:
}
virtual void print() const {
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime, test_id.getCharArray());
printf("id=%ld; maxtime=%d; test_name=%s\n", id, maxtime, test_name.getCharArray());
printf("makefile_text=%s\n", makefile_text.getCharArray());
}
CompilationTask(Text* lines, int offset) :Task(lines, offset) {
setTestId(lines->get(offset + 2));
CompilationTask(Text* lines, int offset) : Task(lines, offset) {
setTestName(lines->get(offset + 2));
setMakefileText(lines->get(offset + 3));
setState(Waiting);
kernels = 1;
}
CompilationTask(const nlohmann::json& data) : Task(data) {
test_name = Utils::getValue<string>(data, "test_name");
makefile_text = Utils::getValue<string>(data, "makefile_text");
setState(Waiting);
kernels = 1;
}
virtual void prepareWorkspace() {
String makeFilePath = String(id) + "/Makefile";
File makeFileFile = File(makeFilePath, this->makefile_text);
String tests = userWorkspace + "/projects";
String testPath = tests + "/" + test_id;
String testPath = tests + "/" + test_name;
Utils::CopyDirectory_L(testPath, workspace);
}
virtual String getLaunchScriptText() {

View File

@@ -6,9 +6,10 @@
class RunSupervisor : public Supervisor<RunTask> {
public:
RunSupervisor(CompilationSupervisor* compilationSupervisor) {
this->init("runTasks", 8);
this->init("runTasks.json");
//проверить отмененные задачи.
for (long i = 0; i < getLength(); ++i) {
for (int i = 0; i < getLength(); ++i) {
RunTask* task = this->get(i);
CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId());
task->setState((parent->getState() == Done) ? Waiting : Canceled);

View File

@@ -3,7 +3,7 @@
#include "CompilationTask.h"
class RunTask : public Task {
long testcompilationtask_id;
int testcompilationtask_id;
String binary_name;
String matrix;
String environments;
@@ -23,34 +23,23 @@ public:
kernels
);
}
int setKernels(String* kernels_s) {
return kernels = atoi(kernels_s->getCharArray());
}
long setTestCompilationTaskId(String* id_s) {
return testcompilationtask_id = strtol(id_s->getCharArray(), NULL, 10);
}
long getTestCompilationTaskId() {
return testcompilationtask_id;
}
void setMatrix(String* matrix_in) {
matrix = String(matrix_in->getCharArray());
}
void setEnvironments(String* environments_in) {
environments = String(environments_in->getCharArray());
}
void setUsrPar(String* usr_par_in) {
usr_par = String(usr_par_in->getCharArray(), '|');
}
void setArgs(String* args_in) {
args = String(args_in->getCharArray());
}
void setParent(CompilationTask* parent_in) {
void setKernels(String* kernels_s) { kernels = atoi(kernels_s->getCharArray()); }
void setTestCompilationTaskId(String* id_s) { testcompilationtask_id = strtol(id_s->getCharArray(), NULL, 10); }
int getTestCompilationTaskId() { return testcompilationtask_id; }
void setMatrix(String* matrix_in) { matrix = String(matrix_in->getCharArray()); }
void setEnvironments(String* environments_in) { environments = String(environments_in->getCharArray()); }
void setUsrPar(String* usr_par_in) { usr_par = String(usr_par_in->getCharArray(), '|'); }
void setArgs(String* args_in) { args = String(args_in->getCharArray()); }
void setParent(CompilationTask* parent_in) {
parent = parent_in;
binary_name = "spf_" + packageId+"_"+String(id) + "_" + matrix.Replace(' ', '_');
}
CompilationTask* getParent() {
return parent;
}
CompilationTask* getParent() { return parent; }
RunTask(Text* lines, int offset) :Task(lines, offset) {
setTestCompilationTaskId(lines->get(offset + 2));
setMatrix(lines->get(offset + 3));
@@ -61,6 +50,16 @@ public:
//todo setStartCommand
}
RunTask(const nlohmann::json& data) : Task(data) {
testcompilationtask_id = Utils::getValue<int>(data, "compilation_task_id");
matrix = Utils::getValue<string>(data, "matrix");
environments = Utils::getValue<string>(data, "environments");
usr_par = Utils::getValue<string>(data, "usr_par");
args = Utils::getValue<string>(data, "args");
kernels = Utils::getValue<int>(data, "kernels");
//todo setStartCommand
}
String getLaunchScriptText() override {
String modules = userWorkspace + "/modules";
String starterCall = modules + "/starter";

View File

@@ -16,13 +16,11 @@ public:
String(const char* s, char ps) {
body = s;
for (long i = 0; i < getLength(); ++i)
for (int i = 0; i < getLength(); ++i)
body[i] = (s[i] == ps) ? '\n' : s[i];
}
String(int s) { body = to_string(s); }
String(long s) { body = to_string(s); }
String(long long s) { body = to_string(s); }
String (string s){ body = s;}
void println() const { printf("[%s]\n", body.c_str()); }

View File

@@ -4,18 +4,22 @@
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <math.h>
#include <thread>
#include <time.h>
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
#endif
#include "File.h"
#include "Task.h"
#include "Array.h"
#include "Utils.h"
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
#endif
#include <time.h>
#include "json.hpp"
enum SupervisorState {
WorkspacesCreation, //0
@@ -58,12 +62,13 @@ public:
for (auto& elem : this->getElements())
elem->print();
}
void init(const char* fileName, int recordSize) {
state = WorkspacesCreation;
File* packedTasks = new File(fileName);
Text* lines = packedTasks->readLines();
const long length = lines->getLength() / recordSize;
const int length = lines->getLength() / recordSize;
int offset = 0;
for (int i = 0; i < length; ++i) {
this->add(new T(lines, offset));
@@ -72,6 +77,31 @@ public:
delete packedTasks;
delete lines;
}
void init(const char* fileName) {
state = WorkspacesCreation;
std::ifstream file(fileName);
if (!file.is_open()) {
printf("can not open file %s\n", fileName);
exit(-1);
}
nlohmann::json data = nlohmann::json::parse(file);
file.close();
if (data.contains("tasks")) {
auto tasks = data["tasks"];
int length = tasks.size();
for (size_t i = 0; i < tasks.size(); ++i)
this->add(new T(tasks[i]));
}
else {
printf("can not fine object 'tasks'\n");
exit(-1);
}
}
void changeState() {
switch (this->state) {
case WorkspacesCreation:
@@ -170,7 +200,7 @@ public:
killed = false;
while (activeTasks) {
long oldActiveTasks = activeTasks;
int oldActiveTasks = activeTasks;
emptyKeys.clear();
toDel.clear();
@@ -279,7 +309,7 @@ public:
void saveState() {
saveState(getStatePrefix() + printState());
}
void saveProgress(long long persentDone) {
void saveProgress(size_t persentDone) {
FILE* f = fopen("progress", "w");
if (f) {
fprintf(f, "%lld", persentDone);

View File

@@ -1,6 +1,8 @@
#pragma once
#include <chrono>
#include <map>
#include <string>
#include "File.h"
#include "Utils.h"
@@ -38,7 +40,7 @@ enum TestType {
class Task {
protected:
long id;
int id;
int maxtime;
int kernels; //получение зависит от типа задачи.
@@ -101,22 +103,32 @@ public:
void setStart() { start_time = std::chrono::system_clock::now(); }
double getTotalTime() const { return total_time; }
long getId() { return id; }
long setId(String* id_s) {
int getId() { return id; }
int setId(String* id_s) {
return id = strtol(id_s->getCharArray(), NULL, 10);
}
int getMaxtime() { return maxtime; }
int setMaxtime(String* maxtime_s) {
return maxtime = atoi(maxtime_s->getCharArray());
}
int setMaxtime(String* maxtime_s) { return maxtime = atoi(maxtime_s->getCharArray()); }
const String& getWorkspace() { return workspace; }
TaskState getState() { return state; }
TaskState setState(TaskState state_in) { return state = state_in; }
Task(Text* lines, int offset) {
setId(lines->get(offset));
setMaxtime(lines->get(offset + 1));
workspace = packageWorkspace + "/" + String(id);
}
Task(const nlohmann::json& data) {
this->id = Utils::getValue<int>(data, "id");
this->maxtime = Utils::getValue<int>(data, "maxtime");
workspace = packageWorkspace + "/" + String(id);
}
virtual void print() const = 0;
//-
virtual void prepareWorkspace() {}
@@ -216,5 +228,5 @@ public:
}
}
//--
}
}
};

View File

@@ -9,7 +9,7 @@ public:
printf("text length=%ld\n", this->getLength());
auto elems = this->getElements();
for (long i = 0; i < elems.size(); ++i) {
for (int i = 0; i < elems.size(); ++i) {
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
// elements[i]->println();
}

View File

@@ -6,6 +6,7 @@
#include <time.h>
#include <chrono>
#include <thread>
#include "json.hpp"
#if __cplusplus >= 201703L
#include <filesystem>
@@ -112,11 +113,24 @@ public:
return res;
}
static String getFileName(const String& path){
static String getFileName(const String& path){
int start_i = path.getBody().find_last_of('/');
if (start_i != string::npos){
return String(path.getBody().substr(start_i+1));
}
return String();
}
template <typename T>
static T getValue(const nlohmann::json& data, const string& obj) {
T retval;
if (data.contains(obj))
retval = data[obj];
else {
printf("can not fine object '%s'\n", obj.c_str());
exit(-1);
}
return retval;
}
};

22874
src/files/json.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -115,7 +115,7 @@ int main(int argc, char ** argv)
("PATH="+PATH).println();
("LD_LIBRARY_PATH="+LD_LIBRARY_PATH).println();
//--
packageId =Utils::getFileName(packageWorkspace);
packageId = Utils::getFileName(packageWorkspace);
#if __cplusplus >= 201703L
std::filesystem::current_path(packageWorkspace.getCharArray());
#else

View File

@@ -1 +1 @@
24
25