Compare commits
3 Commits
2b0f534f5d
...
1f8ebdc9a2
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f8ebdc9a2 | |||
| 39ee78da3d | |||
| 12a6a1f076 |
7
.idea/workspace.xml
generated
7
.idea/workspace.xml
generated
@@ -8,9 +8,14 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Repository/Server/ServerCode.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Repository/Server/ServerCode.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/GlobalData/Tasks/TaskState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/GlobalData/Tasks/TaskState.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/TestingSystem/Common/TestingServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/Common/TestingServer.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/TestingSystem/DVM/TestsSupervisor_2022.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/DVM/TestsSupervisor_2022.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/RemoteInitialiseUser.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Visual_DVM_2021/Passes/All/RemoteInitialiseUser.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/files/Planner/Planner.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Planner.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/files/Planner/RunTask.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/RunTask.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/files/Planner/Supervisor.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Supervisor.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/files/Planner/Task.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/files/Planner/Task.h" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
|
||||
template <class T>
|
||||
class Array {
|
||||
private:
|
||||
std::vector<T*> elements;
|
||||
|
||||
public:
|
||||
Array() { }
|
||||
|
||||
virtual ~Array() {
|
||||
for (auto& elem : elements)
|
||||
delete elem;
|
||||
elements.clear();
|
||||
}
|
||||
|
||||
void add(T* new_line) {
|
||||
elements.push_back(new_line);
|
||||
}
|
||||
|
||||
long getLength() const {
|
||||
return (long)elements.size();
|
||||
}
|
||||
|
||||
T* get(long i) {
|
||||
return elements[i];
|
||||
}
|
||||
|
||||
const std::vector<T*>& getElements() const {
|
||||
return elements;
|
||||
}
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Supervisor.h"
|
||||
#include "CompilationTask.h"
|
||||
|
||||
class CompilationSupervisor : public Supervisor<CompilationTask> {
|
||||
public:
|
||||
CompilationSupervisor() {
|
||||
this->init("compilationTasks", 4);
|
||||
}
|
||||
CompilationTask* getTaskById(long task_id) {
|
||||
for (long i = 0; i < getLength(); ++i) {
|
||||
CompilationTask* task = get(i);
|
||||
if (task->getId() == task_id)
|
||||
return task;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual String getStatePrefix() {
|
||||
return String("Compilation");
|
||||
}
|
||||
};
|
||||
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Task.h"
|
||||
#include "Text.h"
|
||||
|
||||
class CompilationTask : public Task {
|
||||
String test_id;
|
||||
String makefile_text;
|
||||
public:
|
||||
void setTestId(String* test_id_in) {
|
||||
test_id = String(test_id_in->getCharArray());
|
||||
}
|
||||
void setMakefileText(String* makefile_text_in) {
|
||||
makefile_text = String(makefile_text_in->getCharArray(), '|');
|
||||
}
|
||||
virtual void print() const {
|
||||
printf("id=%ld; maxtime=%d; test_id=%s\n", id, maxtime,
|
||||
test_id.getCharArray());
|
||||
printf("makefile_text=%s\n", makefile_text.getCharArray());
|
||||
}
|
||||
|
||||
CompilationTask(Text* lines, int offset) :Task(lines, offset) {
|
||||
setTestId(lines->get(offset + 2));
|
||||
setMakefileText(lines->get(offset + 3));
|
||||
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 copyCommand = "cp -r " + String::DQuotes(testPath + "/.") + " " + String::DQuotes(workspace);
|
||||
system(copyCommand.getCharArray());
|
||||
}
|
||||
virtual String getLaunchScriptText() {
|
||||
String modules = userWorkspace + "/modules";
|
||||
String starterCall = modules + "/starter";
|
||||
String launcherCall = modules + "/launcher";
|
||||
return String::DQuotes(starterCall) + " " +
|
||||
String::DQuotes(launcherCall) + " " +
|
||||
String(maxtime) + " " +
|
||||
String::DQuotes("") + " " +
|
||||
"make -j -f Makefile";
|
||||
}
|
||||
virtual void analyseResults() {
|
||||
String binary = workspace + "/0";
|
||||
state = Utils::Exists(binary) ? Done : DoneWithErrors;
|
||||
}
|
||||
};
|
||||
@@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
#include "String.h"
|
||||
#include "Text.h"
|
||||
|
||||
class File {
|
||||
FILE* ptr;
|
||||
public:
|
||||
File(String* name) {
|
||||
ptr = fopen(name->getCharArray(), "r");
|
||||
}
|
||||
File(const char* name) {
|
||||
ptr = fopen(name, "r");
|
||||
}
|
||||
File(const String& name, const String& text) {
|
||||
ptr = fopen(name.getCharArray(), "w");
|
||||
fprintf(ptr, "%s\n", text.getCharArray());
|
||||
}
|
||||
~File() {
|
||||
Close();
|
||||
}
|
||||
void Close() {
|
||||
if (ptr != NULL) {
|
||||
fclose(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
Text* readLines() {
|
||||
Text* lines = new Text();
|
||||
int c;
|
||||
String* line = NULL;
|
||||
bool lineStarted = false;
|
||||
do {
|
||||
c = fgetc(ptr);
|
||||
if (lineStarted) {
|
||||
switch (c) {
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
case EOF:
|
||||
lines->add(line);
|
||||
line = NULL;
|
||||
lineStarted = false;
|
||||
break;
|
||||
default:
|
||||
line->addChar((char)c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (c) {
|
||||
case '\r':
|
||||
break;
|
||||
case '\n':
|
||||
line = new String();
|
||||
lines->add(line);
|
||||
line = NULL;
|
||||
break;
|
||||
case EOF:
|
||||
break;
|
||||
default:
|
||||
line = new String();
|
||||
line->addChar((char)c);
|
||||
lineStarted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (c != EOF);
|
||||
return lines;
|
||||
}
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
|
||||
String userWorkspace;
|
||||
String packageWorkspace;
|
||||
int maxKernels;
|
||||
int busyKernels;
|
||||
int freeKernels;
|
||||
String dvm_drv;
|
||||
@@ -1,134 +0,0 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
using namespace std;
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <filesystem>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "CompilationSupervisor.h"
|
||||
#include "RunSupervisor.h"
|
||||
#include "Global.h"
|
||||
#include <signal.h>
|
||||
|
||||
//https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D0%BB_(Unix)
|
||||
void hdl(int sig)
|
||||
{
|
||||
String file_name = "GOT_SIGNAL_AT_"+ String(Utils::getAbsoluteTime());
|
||||
FILE * res = fopen(file_name.getCharArray(),"w");
|
||||
fprintf(res,"%d\n", sig);
|
||||
fclose(res);
|
||||
}
|
||||
void set_handlers() {
|
||||
#ifndef _WIN32
|
||||
struct sigaction act;
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = hdl;
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
//---
|
||||
sigaddset(&set, SIGABRT);
|
||||
sigaddset(&set, SIGALRM);
|
||||
sigaddset(&set, SIGBUS);
|
||||
sigaddset(&set, SIGVTALRM);
|
||||
sigaddset(&set, SIGFPE);
|
||||
sigaddset(&set, SIGHUP);
|
||||
sigaddset(&set, SIGILL);
|
||||
sigaddset(&set, SIGINT);
|
||||
sigaddset(&set, SIGPIPE);
|
||||
sigaddset(&set, SIGQUIT);
|
||||
sigaddset(&set, SIGSEGV);
|
||||
sigaddset(&set, SIGTERM);
|
||||
sigaddset(&set, SIGTSTP);
|
||||
sigaddset(&set, SIGTTIN);
|
||||
sigaddset(&set, SIGTTOU);
|
||||
sigaddset(&set, SIGUSR1);
|
||||
sigaddset(&set, SIGUSR2);
|
||||
sigaddset(&set, SIGPOLL);
|
||||
sigaddset(&set, SIGPROF);
|
||||
sigaddset(&set, SIGSYS);
|
||||
sigaddset(&set, SIGTRAP);
|
||||
//sigaddset(&set, SIGURG);
|
||||
//sigaddset(&set, SIGCHLD);
|
||||
//sigaddset(&set, SIGCONT);
|
||||
sigaddset(&set, SIGVTALRM);
|
||||
sigaddset(&set, SIGXCPU);
|
||||
sigaddset(&set, SIGXFSZ);
|
||||
//---
|
||||
act.sa_mask = set;
|
||||
//---
|
||||
sigaction(SIGABRT, &act, 0);
|
||||
sigaction(SIGALRM, &act, 0);
|
||||
sigaction(SIGBUS, &act, 0);
|
||||
sigaction(SIGVTALRM, &act, 0);
|
||||
sigaction(SIGFPE, &act, 0);
|
||||
sigaction(SIGHUP, &act, 0);
|
||||
sigaction(SIGILL, &act, 0);
|
||||
sigaction(SIGINT, &act, 0);
|
||||
sigaction(SIGPIPE, &act, 0);
|
||||
sigaction(SIGQUIT, &act, 0);
|
||||
sigaction(SIGSEGV, &act, 0);
|
||||
sigaction(SIGTERM, &act, 0);
|
||||
sigaction(SIGTSTP, &act, 0);
|
||||
sigaction(SIGTTIN, &act, 0);
|
||||
sigaction(SIGTTOU, &act, 0);
|
||||
sigaction(SIGUSR1, &act, 0);
|
||||
sigaction(SIGUSR2, &act, 0);
|
||||
sigaction(SIGPOLL, &act, 0);
|
||||
sigaction(SIGPROF, &act, 0);
|
||||
sigaction(SIGSYS, &act, 0);
|
||||
sigaction(SIGTRAP, &act, 0);
|
||||
sigaction(SIGVTALRM, &act, 0);
|
||||
sigaction(SIGXCPU, &act, 0);
|
||||
sigaction(SIGXFSZ, &act, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
//+
|
||||
set_handlers();
|
||||
//-
|
||||
userWorkspace = String(argv[1]);
|
||||
packageWorkspace = String(argv[2]);
|
||||
maxKernels = atoi(argv[3]);
|
||||
dvm_drv = String(argv[4]);
|
||||
//--
|
||||
freeKernels = maxKernels;
|
||||
busyKernels= 0;
|
||||
//--
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
std::filesystem::current_path(packageWorkspace.getCharArray());
|
||||
#else
|
||||
chdir(packageWorkspace.getCharArray());
|
||||
#endif
|
||||
|
||||
userWorkspace.println();
|
||||
packageWorkspace.println();
|
||||
printf("%d\n", maxKernels);
|
||||
#ifndef _WIN32
|
||||
int pid = getpid();
|
||||
#else
|
||||
int pid = _getpid();
|
||||
#endif
|
||||
|
||||
printf("PID=%d\n", pid);
|
||||
File pidFile("PID", String(pid));
|
||||
pidFile.Close();
|
||||
//---
|
||||
File startFile("STARTED", "+");
|
||||
startFile.Close();
|
||||
//---
|
||||
printf(">>>>\n");
|
||||
CompilationSupervisor * compilationSupervisor = new CompilationSupervisor();
|
||||
printf("%ld\n", compilationSupervisor->getLength());
|
||||
compilationSupervisor->Do();
|
||||
|
||||
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
|
||||
printf("%ld\n", runSupervisor->getLength());
|
||||
runSupervisor->print();
|
||||
runSupervisor->DoWithSchedule(maxKernels);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CompilationSupervisor.h"
|
||||
#include "RunTask.h"
|
||||
|
||||
class RunSupervisor : public Supervisor<RunTask> {
|
||||
public:
|
||||
RunSupervisor(CompilationSupervisor* compilationSupervisor) {
|
||||
this->init("runTasks", 8);
|
||||
//проверить отмененные задачи.
|
||||
for (long i = 0; i < getLength(); ++i) {
|
||||
RunTask* task = this->get(i);
|
||||
CompilationTask* parent = compilationSupervisor->getTaskById(task->getTestCompilationTaskId());
|
||||
task->setState((parent->getState() == Done) ? Waiting : Canceled);
|
||||
task->setParent(parent);
|
||||
printf("id=%ld; parent_id = %ld; state=%s\n",
|
||||
task->getId(),
|
||||
task->getParent()->getId(),
|
||||
task->printState().getCharArray());
|
||||
}
|
||||
}
|
||||
virtual String getStatePrefix() {
|
||||
return String("Running");
|
||||
}
|
||||
|
||||
/*
|
||||
virtual void Finalize(){
|
||||
this->state = Archivation;
|
||||
saveState();
|
||||
printf("Archivation started\n");
|
||||
Utils::ZipFolder(String("./"),String("archive.zip"));
|
||||
printf("Archivation ended\n");
|
||||
}
|
||||
*/
|
||||
};
|
||||
@@ -1,96 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CompilationTask.h"
|
||||
|
||||
class RunTask : public Task {
|
||||
long testcompilationtask_id;
|
||||
String binary_name;
|
||||
String matrix;
|
||||
String environments;
|
||||
String usr_par;
|
||||
String args;
|
||||
CompilationTask* parent;
|
||||
public:
|
||||
virtual void print() const {
|
||||
printf("id=%ld; maxtime=%d; testcompilationtask_id=%ld; matrix=%s; environments=%s; usr_par=%s; args=%s kernels=%d\n",
|
||||
id,
|
||||
maxtime,
|
||||
testcompilationtask_id,
|
||||
matrix.getCharArray(),
|
||||
environments.getCharArray(),
|
||||
usr_par.getCharArray(),
|
||||
args.getCharArray(),
|
||||
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) {
|
||||
parent = parent_in;
|
||||
binary_name = "spf_" + String(id) + "_" + matrix.Replace(' ', '_');
|
||||
}
|
||||
CompilationTask* getParent() {
|
||||
return parent;
|
||||
}
|
||||
RunTask(Text* lines, int offset) :Task(lines, offset) {
|
||||
setTestCompilationTaskId(lines->get(offset + 2));
|
||||
setMatrix(lines->get(offset + 3));
|
||||
setEnvironments(lines->get(offset + 4));
|
||||
setUsrPar(lines->get(offset + 5));
|
||||
setArgs(lines->get(offset + 6));
|
||||
setKernels(lines->get(offset + 7));
|
||||
}
|
||||
|
||||
virtual String getLaunchScriptText() {
|
||||
String modules = userWorkspace + "/modules";
|
||||
String starterCall = modules + "/starter";
|
||||
String launcherCall = modules + "/launcher";
|
||||
//-
|
||||
String dvm_start = String::DQuotes(dvm_drv) + " run ";
|
||||
if (!matrix.isEmpty())
|
||||
dvm_start = dvm_start + matrix + " ";
|
||||
dvm_start = dvm_start + String::DQuotes("./" + binary_name);
|
||||
if (!args.isEmpty())
|
||||
dvm_start = dvm_start + " " + args;
|
||||
return String::DQuotes(starterCall) + " " +
|
||||
String::DQuotes(launcherCall) + " " +
|
||||
String(maxtime) + " " +
|
||||
String::DQuotes("killall -SIGKILL " + binary_name) + " " +
|
||||
dvm_start;
|
||||
}
|
||||
virtual void prepareWorkspace() {
|
||||
String binary_src = parent->getWorkspace() + "/0";
|
||||
String binary_dst = workspace + "/" + binary_name;
|
||||
Utils::Copy(binary_src, binary_dst);
|
||||
if (!usr_par.isEmpty()) {
|
||||
String parPath = String(id) + "/usr.par";
|
||||
File parFile = File(parPath, usr_par);
|
||||
}
|
||||
}
|
||||
virtual String getStartCommand() {
|
||||
String res = workspace + "/run";
|
||||
if (!environments.isEmpty())
|
||||
res = environments + " " + res;
|
||||
printf("START %ld: %s\n", id, res.getCharArray());
|
||||
return res;
|
||||
}
|
||||
};
|
||||
226
Planner/String.h
226
Planner/String.h
@@ -1,226 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
class String {
|
||||
friend String operator+(const String& a, const String& b);
|
||||
long length;
|
||||
char* body;
|
||||
public:
|
||||
String() {
|
||||
length = 0;
|
||||
body = new char[1];
|
||||
body[0] = '\0';
|
||||
}
|
||||
|
||||
String(const char* s) {
|
||||
length = (long)strlen(s);
|
||||
body = new char[length + 1];
|
||||
for (long i = 0; i < length; ++i)
|
||||
body[i] = s[i];
|
||||
body[length] = '\0';
|
||||
}
|
||||
String(const char* s, char ps) {
|
||||
length = (long)strlen(s);
|
||||
body = new char[length + 1];
|
||||
for (long i = 0; i < length; ++i) {
|
||||
body[i] = (s[i] == ps) ? '\n' : s[i];
|
||||
}
|
||||
body[length] = '\0';
|
||||
}
|
||||
~String() {
|
||||
if (body != NULL) {
|
||||
delete[] body;
|
||||
}
|
||||
}
|
||||
void println() const {
|
||||
printf("[%s]\n", body);
|
||||
}
|
||||
void addChar(char c) {
|
||||
char* buf = new char[length + 2];
|
||||
for (long i = 0; i < length; ++i) {
|
||||
buf[i] = body[i];
|
||||
}
|
||||
buf[length] = c;
|
||||
|
||||
length++;
|
||||
//--
|
||||
buf[length] = '\0';
|
||||
delete[] body;
|
||||
body = buf;
|
||||
buf = NULL;
|
||||
}
|
||||
char* getCharArray() const {
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
String(int s) {
|
||||
length = 0;
|
||||
body = new char[1];
|
||||
body[0] = '\0';
|
||||
if (s >= 0) {
|
||||
int s_ = s;
|
||||
int size = 1;
|
||||
while (s_ >= 10) {
|
||||
s_ = s_ / 10;
|
||||
size++;
|
||||
}
|
||||
length = size;
|
||||
body = new char[size + 1];
|
||||
sprintf(body, "%d", s);
|
||||
}
|
||||
}
|
||||
|
||||
String(long s) : String((long long)s) { }
|
||||
|
||||
String(long long s) {
|
||||
length = 0;
|
||||
body = new char[1];
|
||||
body[0] = '\0';
|
||||
if (s >= 0) {
|
||||
long long s_ = s;
|
||||
long size = 1;
|
||||
while (s_ >= 10) {
|
||||
s_ = s_ / 10;
|
||||
size++;
|
||||
}
|
||||
length = size;
|
||||
body = new char[size + 1];
|
||||
sprintf(body, "%lld", s);
|
||||
}
|
||||
}
|
||||
|
||||
const String& operator=(const String& s) {
|
||||
if (body != NULL)
|
||||
delete[] body;
|
||||
length = s.length;
|
||||
body = new char[length + 1];
|
||||
for (long i = 0; i < length; ++i)
|
||||
body[i] = s.body[i];
|
||||
body[length] = '\0';
|
||||
return *this;
|
||||
}
|
||||
|
||||
static String DQuotes(const String& s) {
|
||||
String res;
|
||||
res.length = s.length + 2;
|
||||
res.body = new char[res.length + 1];
|
||||
res.body[0] = '"';
|
||||
res.body[res.length - 1] = '"';
|
||||
res.body[res.length] = '\0';
|
||||
for (long i = 0; i < s.length; ++i)
|
||||
res.body[i + 1] = s.body[i];
|
||||
return res;
|
||||
}
|
||||
|
||||
String Replace(char f, char t) {
|
||||
String res;
|
||||
res.length = length;
|
||||
res.body = new char[length];
|
||||
res.body[length] = '\0';
|
||||
for (long i = 0; i < length; ++i)
|
||||
res.body[i] = (body[i] == f) ? t : body[i];
|
||||
return res;
|
||||
}
|
||||
String Remove(char f) {
|
||||
String res;
|
||||
for (long i = 0; i < length; ++i) {
|
||||
if (body[i] != f)
|
||||
res.addChar(body[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
bool isEmpty() const {
|
||||
return length == 0;
|
||||
}
|
||||
bool contains(const String& s) const {
|
||||
bool res = false;
|
||||
bool search_on = false;
|
||||
if (s.isEmpty()) return true;
|
||||
if (s.length > length) return false;
|
||||
long k = 0;
|
||||
long start = -1;
|
||||
for (long i = 0; i < length; ++i) {
|
||||
if (search_on) {
|
||||
if (k < s.length) {
|
||||
if (body[i] == s.body[k]) {
|
||||
k++;
|
||||
}
|
||||
else {
|
||||
//обрыв поиска.
|
||||
search_on = false;
|
||||
k = 0;
|
||||
start = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//printf("starts with %ld", start);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (body[i] == s.body[0]) {
|
||||
k = 1;
|
||||
start = i;
|
||||
search_on = true;
|
||||
//printf("search started %d\n", start);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (search_on) {
|
||||
//printf("starts with %ld\n", start);
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
String toUpper() {
|
||||
String res = String(this->getCharArray());
|
||||
for (long i = 0; i < length; ++i)
|
||||
res.body[i] = toupper(body[i]);
|
||||
res.println();
|
||||
return res;
|
||||
}
|
||||
long getLength() {
|
||||
return length;
|
||||
}
|
||||
bool operator==(const String& s) const {
|
||||
if (length != s.length) return false;
|
||||
for (long i = 0; i < length; ++i) {
|
||||
if (body[i] != s.body[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/* регистр.
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int main(void) {
|
||||
FILE * f;
|
||||
int c;
|
||||
|
||||
if ( ! ( f = fopen("file.txt", "r") ) )
|
||||
return -1;
|
||||
|
||||
while ( ( c = fgetc(f) ) != EOF )
|
||||
putchar( isupper(c) ? tolower(c) : toupper(c) );
|
||||
|
||||
return ( fclose(f) );
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
String operator+(const String& a, const String& b) {
|
||||
String res = String();
|
||||
res.length = a.length + b.length;
|
||||
res.body = new char[res.length + 1];
|
||||
for (long i = 0; i < a.length; ++i)
|
||||
res.body[i] = a.body[i];
|
||||
for (long i = 0; i < b.length; ++i)
|
||||
res.body[i + a.length] = b.body[i];
|
||||
res.body[res.length] = '\0';
|
||||
return res;
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include "File.h"
|
||||
#include "Task.h"
|
||||
#include "Array.h"
|
||||
|
||||
enum SupervisorState {
|
||||
WorkspacesCreation, //0
|
||||
Preparation, //1
|
||||
Execution, //2
|
||||
Archivation, //3
|
||||
End //4
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class Supervisor : public Array <T> {
|
||||
protected:
|
||||
SupervisorState state;
|
||||
public:
|
||||
virtual String getStatePrefix() {
|
||||
return String("");
|
||||
}
|
||||
String printState() {
|
||||
switch (state) {
|
||||
case WorkspacesCreation:
|
||||
return String("WorkspacesCreation");
|
||||
case Preparation:
|
||||
return String("Preparation");
|
||||
case Execution:
|
||||
return String("Execution");
|
||||
case Archivation:
|
||||
return String("Archivation");
|
||||
case End:
|
||||
return String("End");
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
//-
|
||||
void print() {
|
||||
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;
|
||||
int offset = 0;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
this->add(new T(lines, offset));
|
||||
offset += recordSize;
|
||||
}
|
||||
delete packedTasks;
|
||||
delete lines;
|
||||
}
|
||||
|
||||
void changeState() {
|
||||
switch (this->state) {
|
||||
case WorkspacesCreation:
|
||||
this->state = Preparation;
|
||||
saveState();
|
||||
break;
|
||||
case Preparation:
|
||||
this->state = Execution;
|
||||
saveState();
|
||||
break;
|
||||
case Execution:
|
||||
Finalize();
|
||||
this->state = End;
|
||||
saveState();
|
||||
break;
|
||||
default:
|
||||
this->state = End;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Do() {
|
||||
saveState();
|
||||
long activeCount = 0;
|
||||
//todo обязательно убрать отладочную печать.
|
||||
printf("tasks count = %ld\n", this->getLength());
|
||||
while (this->state != End) {
|
||||
// printf("state=%d\n", this->state);
|
||||
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
|
||||
activeCount = 0;
|
||||
for (long i = 0; i < this->getLength(); ++i) {
|
||||
T* task = this->get(i);
|
||||
switch (this->state) {
|
||||
case WorkspacesCreation:
|
||||
if (task->getState() == Waiting) {
|
||||
activeCount++;
|
||||
task->createWorkspace();
|
||||
task->setState(WorkspaceCreated);
|
||||
}
|
||||
break;
|
||||
case Preparation:
|
||||
if (task->getState() == WorkspaceCreated) {
|
||||
activeCount++;
|
||||
task->prepareWorkspace();
|
||||
task->createLaunchScript();
|
||||
task->setState(WorkspaceReady);
|
||||
}
|
||||
break;
|
||||
case Execution:
|
||||
if (task->getState() == WorkspaceReady) {
|
||||
activeCount++;
|
||||
task->Start();
|
||||
}
|
||||
else if (task->getState() == Running) {
|
||||
activeCount++;
|
||||
task->Check();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// printf("id = %ld; state = %d\n", task->getId(), task->getState());
|
||||
break;
|
||||
}
|
||||
}
|
||||
// printf("active count = %d\n", activeCount);
|
||||
if (activeCount == 0)
|
||||
changeState();
|
||||
Utils::Sleep(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DoWithSchedule(int maxKernels) {
|
||||
saveState();
|
||||
|
||||
// подготовка тестов
|
||||
while (this->state != Execution) {
|
||||
for (auto& task : this->getElements()) {
|
||||
switch (this->state) {
|
||||
case WorkspacesCreation:
|
||||
if (task->getState() == Waiting) {
|
||||
task->createWorkspace();
|
||||
task->setState(WorkspaceCreated);
|
||||
}
|
||||
break;
|
||||
case Preparation:
|
||||
if (task->getState() == WorkspaceCreated) {
|
||||
task->prepareWorkspace();
|
||||
task->createLaunchScript();
|
||||
task->setState(WorkspaceReady);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//printf("id = %ld; state = %d\n", task->getId(), task->getState());
|
||||
break;
|
||||
}
|
||||
}
|
||||
changeState();
|
||||
}
|
||||
|
||||
map<int, queue<T*>, std::greater<int>> sortedByKernelNeeds;
|
||||
|
||||
long activeTasks = 0;
|
||||
long done = 0;
|
||||
for (auto& task : this->getElements()) {
|
||||
if (task->getState() == WorkspaceReady) {
|
||||
activeTasks++;
|
||||
sortedByKernelNeeds[task->getKernels()].push(task);
|
||||
}
|
||||
}
|
||||
|
||||
printf("total tasks count = %ld, active task count %ld, maxkernels %d\n", this->getLength(), activeTasks, maxKernels);
|
||||
|
||||
int busyKernels = 0;
|
||||
set<T*> activeTaskSet;
|
||||
bool ignoreCheck = true;
|
||||
|
||||
while (activeTasks) {
|
||||
long oldActiveTasks = activeTasks;
|
||||
vector<int> emptyKeys;
|
||||
|
||||
//ставим задачи от больших к меньшему по ядрам
|
||||
for (auto& elem : sortedByKernelNeeds) {
|
||||
int freeKernels = maxKernels - busyKernels;
|
||||
int kernelsNeeded = elem.first;
|
||||
|
||||
while (kernelsNeeded <= freeKernels && elem.second.size()) {
|
||||
T* task = elem.second.front();
|
||||
elem.second.pop();
|
||||
|
||||
activeTaskSet.insert(task);
|
||||
task->Start(ignoreCheck);
|
||||
printf("start task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||
|
||||
busyKernels += task->getKernels();
|
||||
freeKernels = maxKernels - busyKernels;
|
||||
}
|
||||
|
||||
if (elem.second.size() == 0)
|
||||
emptyKeys.push_back(kernelsNeeded);
|
||||
|
||||
//если ядер не осталось, то нет смысла дальше смотреть
|
||||
if (freeKernels == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// очищаем от пустых ключей
|
||||
for (auto& empty : emptyKeys)
|
||||
sortedByKernelNeeds.erase(empty);
|
||||
|
||||
// проверяем нет ли завершившихся задач
|
||||
for (auto it = activeTaskSet.begin(); it != activeTaskSet.end(); )
|
||||
{
|
||||
T* task = *(it);
|
||||
|
||||
if (task->Check()) {
|
||||
it++;
|
||||
activeTaskSet.erase(task);
|
||||
activeTasks--;
|
||||
done++;
|
||||
busyKernels -= task->getKernels();
|
||||
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||
|
||||
continue;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
if (oldActiveTasks != activeTasks)
|
||||
printf("done %ld / %ld\n", done, this->getLength());
|
||||
}
|
||||
|
||||
changeState();
|
||||
}
|
||||
|
||||
virtual void Finalize() {}
|
||||
|
||||
void saveState() {
|
||||
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
|
||||
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
|
||||
//printf("stateFile=<%s>\n", stateFile.getCharArray());
|
||||
File(stateFile, Utils::getDate());
|
||||
}
|
||||
};
|
||||
191
Planner/Task.h
191
Planner/Task.h
@@ -1,191 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "File.h"
|
||||
#include "Utils.h"
|
||||
#include "Global.h"
|
||||
|
||||
enum TaskState {
|
||||
Inactive, //0
|
||||
Waiting, //1
|
||||
WorkspaceCreated, //2
|
||||
WorkspaceReady, //3
|
||||
Running, //4
|
||||
Canceled, //5
|
||||
Finished, //6
|
||||
FinishedAbortedByTimeout, //7
|
||||
FinishedAbortedByUser, //8
|
||||
Done, //9
|
||||
DoneWithErrors, //10
|
||||
AbortedByTimeout, //11
|
||||
AbortedByUser, //12
|
||||
Crushed, //13
|
||||
WrongTestFormat, //14
|
||||
InternalError, //15
|
||||
Queued, //16
|
||||
NoSuchTask, //17
|
||||
FailedToQueue, //18
|
||||
AbortingByUser //19
|
||||
};
|
||||
|
||||
enum TestType {
|
||||
Default, //0
|
||||
Correctness, //1
|
||||
Performance, //2
|
||||
};
|
||||
|
||||
class Task {
|
||||
protected:
|
||||
long id;
|
||||
|
||||
int maxtime;
|
||||
int kernels; //получение зависит от типа задачи.
|
||||
String workspace;
|
||||
TaskState state;
|
||||
std::chrono::system_clock::time_point start_time;
|
||||
|
||||
public:
|
||||
String printState() {
|
||||
switch (state) {
|
||||
case Inactive:
|
||||
return String("Inactive");
|
||||
case Waiting:
|
||||
return String("Waiting");
|
||||
case WorkspaceCreated:
|
||||
return String("WorkspaceCreated");
|
||||
case WorkspaceReady:
|
||||
return String("WorkspaceReady");
|
||||
case Running:
|
||||
return String("Running");
|
||||
case Canceled:
|
||||
return String("Canceled");
|
||||
case Finished:
|
||||
return String("Finished");
|
||||
case FinishedAbortedByTimeout:
|
||||
return String("FinishedAbortedByTimeout");
|
||||
case FinishedAbortedByUser:
|
||||
return String("FinishedAbortedByUser");
|
||||
case Done:
|
||||
return String("Done");
|
||||
case DoneWithErrors:
|
||||
return String("DoneWithErrors");
|
||||
case AbortedByTimeout:
|
||||
return String("AbortedByTimeout");
|
||||
case AbortedByUser:
|
||||
return String("AbortedByUser");
|
||||
case Crushed:
|
||||
return String("Crushed");
|
||||
case WrongTestFormat:
|
||||
return String("WrongTestFormat");
|
||||
case InternalError:
|
||||
return String("InternalError");
|
||||
case Queued:
|
||||
return String("Queued");
|
||||
case NoSuchTask:
|
||||
return String("NoSuchTask");
|
||||
case FailedToQueue:
|
||||
return String("FailedToQueue");
|
||||
case AbortingByUser:
|
||||
return String("AbortingByUser");
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
//-------------->>
|
||||
void setStart() { start_time = std::chrono::system_clock::now(); }
|
||||
|
||||
long getId() { return id; }
|
||||
long 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());
|
||||
}
|
||||
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);
|
||||
}
|
||||
virtual void print() const = 0;
|
||||
//-
|
||||
virtual void prepareWorkspace() {}
|
||||
virtual String getLaunchScriptText() = 0;
|
||||
virtual String getStartCommand() {
|
||||
return workspace + "/run";
|
||||
}
|
||||
|
||||
void createWorkspace() {
|
||||
Utils::Mkdir(workspace);
|
||||
}
|
||||
void createLaunchScript() {
|
||||
String launchScriptPath = workspace + "/run";
|
||||
String launchScriptText =
|
||||
String("cd ") + String::DQuotes(workspace) + "\n" +
|
||||
getLaunchScriptText();
|
||||
File launchScriptFile = File(launchScriptPath, launchScriptText);
|
||||
Utils::Chmod(launchScriptPath);
|
||||
}
|
||||
|
||||
int getKernels() const { return kernels; }
|
||||
|
||||
void Start(bool dontCheck = false) {
|
||||
if (kernels <= freeKernels || dontCheck) {
|
||||
setStart();
|
||||
system(getStartCommand().getCharArray());
|
||||
state = Running;
|
||||
//-
|
||||
busyKernels = Utils::min(busyKernels + kernels, maxKernels);
|
||||
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
||||
//-
|
||||
}
|
||||
}
|
||||
|
||||
//return 'true' if done, 'false' - if running
|
||||
virtual bool Check() {
|
||||
if (Utils::Exists(workspace + "/DONE"))
|
||||
analyseResults();
|
||||
else {
|
||||
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
||||
state = AbortedByTimeout;
|
||||
//todo определить по интервалу времени на всякий случай.
|
||||
}
|
||||
else if (Utils::Exists(workspace + "/INTERRUPT")) {
|
||||
state = AbortedByUser;
|
||||
}
|
||||
else {
|
||||
auto end_time = std::chrono::system_clock::now();
|
||||
std::chrono::duration<double> diff_time = end_time - start_time;
|
||||
|
||||
if (maxtime * 1.1 < diff_time.count()) {
|
||||
printf("SET STATUS ABORTED by timer to %ld with time %f sec / %f sec", id, diff_time.count(), maxtime * 1.1);
|
||||
state = AbortedByTimeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state != Running) {
|
||||
//-
|
||||
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
||||
freeKernels = Utils::max(0, maxKernels - busyKernels);
|
||||
//-
|
||||
saveState();
|
||||
}
|
||||
|
||||
return (state != Running);
|
||||
}
|
||||
|
||||
virtual void analyseResults() {
|
||||
state = Finished;
|
||||
}
|
||||
|
||||
virtual void saveState() {
|
||||
String stateFile = workspace + "/TaskState";
|
||||
File tmp(stateFile, printState());
|
||||
}
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
#include "Array.h"
|
||||
|
||||
class Text : public Array<String> {
|
||||
public:
|
||||
void Print() const {
|
||||
printf("text length=%ld\n", this->getLength());
|
||||
|
||||
auto elems = this->getElements();
|
||||
for (long i = 0; i < elems.size(); ++i) {
|
||||
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
|
||||
// elements[i]->println();
|
||||
}
|
||||
}
|
||||
|
||||
bool hasMatch(const String& s) const {
|
||||
|
||||
for (auto& elem : this->getElements()) {
|
||||
if (s.contains(*elem)) {
|
||||
//printf("match: [%s]\n", elements[i]->getCharArray());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//printf("no matches for [%s]\n", s.getCharArray());
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
#include "String.h"
|
||||
|
||||
class Utils {
|
||||
public:
|
||||
static int max(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
static int min(int a, int b) {
|
||||
return (a > b) ? b : a;
|
||||
}
|
||||
static void Mkdir(const String& path) {
|
||||
#if __cplusplus >= 201703L
|
||||
std::filesystem::create_directory(path.getCharArray());
|
||||
#else
|
||||
mkdir(path.getCharArray(), 0777);
|
||||
#endif
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
||||
static void Chmod(const String& path) {
|
||||
String command = "chmod 777 " + String::DQuotes(path);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
||||
static bool Exists(const String& path) {
|
||||
struct stat buffer;
|
||||
return (stat(path.getCharArray(), &buffer) == 0);
|
||||
}
|
||||
|
||||
//in seconds
|
||||
static void Sleep(int s) {
|
||||
std::chrono::seconds timespan(s);
|
||||
std::this_thread::sleep_for(timespan);
|
||||
}
|
||||
static void Copy(const String& src, const String& dst) {
|
||||
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
static time_t getAbsoluteTime() {
|
||||
return time(NULL);
|
||||
}
|
||||
static String getDate() {
|
||||
auto ttime = time(NULL);
|
||||
String res(ctime(&ttime));
|
||||
return res;
|
||||
}
|
||||
static void ZipFolder(const String& src, const String& dst) {
|
||||
String command = "zip -r " + String::DQuotes(dst) + " " + String::DQuotes(src);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
};
|
||||
@@ -67,7 +67,7 @@ public enum TaskState implements StatusEnum {
|
||||
case Canceled:
|
||||
return "отменена";
|
||||
case InternalError:
|
||||
return "внутренняя ошибка";
|
||||
return "отсутствует файл состояния";
|
||||
case WrongTestFormat:
|
||||
return "неверный формат";
|
||||
case FailedToQueue:
|
||||
|
||||
@@ -402,11 +402,11 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
public void UpdateTestTasks() throws Exception {
|
||||
Vector<TestCompilationTask> compilationTasks = (Vector<TestCompilationTask>) request.object;
|
||||
account_db.BeginTransaction();
|
||||
//сами задачи на компиляцию не сохраняем. незачем.
|
||||
for (TestCompilationTask compilationTask : compilationTasks) {
|
||||
compilationTask.ChangeDate = new Date().getTime();
|
||||
account_db.Update(compilationTask);
|
||||
account_db.Delete(compilationTask);
|
||||
for (TestRunTask runTask : compilationTask.runTasks) {
|
||||
compilationTask.ChangeDate = new Date().getTime();
|
||||
runTask.ChangeDate = new Date().getTime();
|
||||
account_db.Update(runTask);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import TestingSystem.DVM.Tasks.TestRunTask;
|
||||
import TestingSystem.DVM.Tasks.TestTask;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackage;
|
||||
import TestingSystem.DVM.TasksPackage.TasksPackageState;
|
||||
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -37,7 +38,6 @@ public class TestsSupervisor_2022 {
|
||||
connection = connection_in;
|
||||
tasksPackage = tasksPackage_in;
|
||||
compilationTasks = tasks_in;
|
||||
planner.Print(getClass().getSimpleName() + ": найдено задач на компиляцию: " + compilationTasks.size());
|
||||
packageRemoteWorkspace = new RemoteFile(tasksPackage.user_workspace + "/tests", String.valueOf(tasksPackage.id), true);
|
||||
packageLocalWorkspace = new File(Global.PackagesDirectory, String.valueOf(tasksPackage.id));
|
||||
}
|
||||
@@ -170,53 +170,12 @@ public class TestsSupervisor_2022 {
|
||||
}
|
||||
public void DownloadResults() throws Exception {
|
||||
Utils.CheckDirectory(packageLocalWorkspace);
|
||||
for (TestCompilationTask testCompilationTask : compilationTasks) {
|
||||
//------------>>>
|
||||
if (TryDownloadTask(testCompilationTask)) {
|
||||
for (TestRunTask testRunTask : testCompilationTask.runTasks) {
|
||||
TryDownloadTask(testRunTask);
|
||||
}
|
||||
} else {
|
||||
//задача на компиляцию не состоялась. значит и все ее задачи на запуск тоже.
|
||||
for (TestRunTask testRunTask : testCompilationTask.runTasks) {
|
||||
testRunTask.state = TaskState.Canceled;
|
||||
planner.UpdateTask(testRunTask);
|
||||
}
|
||||
}
|
||||
//--->>>>>>>>>
|
||||
}
|
||||
}
|
||||
public boolean TryDownloadTask(TestTask testTask) throws Exception {
|
||||
if (
|
||||
!testTask.state.equals(TaskState.ResultsDownloaded) &&
|
||||
!testTask.state.equals(TaskState.Canceled)
|
||||
) {
|
||||
File taskLocalWorkspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), String.valueOf(testTask.id)).toFile();
|
||||
RemoteFile taskRemoteWorkspace = new RemoteFile(packageRemoteWorkspace.full_name, String.valueOf(testTask.id));
|
||||
Utils.CheckDirectory(taskLocalWorkspace);
|
||||
if (connection.Exists(packageRemoteWorkspace.full_name, String.valueOf(testTask.id))) {
|
||||
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, Constants.out_file);
|
||||
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, Constants.err_file);
|
||||
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, Constants.time_file);
|
||||
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, "TaskState");
|
||||
if (testTask instanceof TestRunTask)
|
||||
CheckTaskFile(taskRemoteWorkspace, taskLocalWorkspace, "sts.gz+");
|
||||
testTask.state = TaskState.ResultsDownloaded;
|
||||
planner.UpdateTask(testTask);
|
||||
return true;
|
||||
} else {
|
||||
testTask.state = TaskState.Canceled;
|
||||
planner.UpdateTask(testTask);
|
||||
return false;
|
||||
//нет раб пространства. значит задача не выполнялась.
|
||||
}
|
||||
} else return true;
|
||||
}
|
||||
public void CheckTaskFile(RemoteFile taskRemoteWorkspace, File taskLocalWorkspace, String fileName) throws Exception {
|
||||
RemoteFile rFile = new RemoteFile(taskRemoteWorkspace.full_name, fileName);
|
||||
File lFile = Paths.get(taskLocalWorkspace.getAbsolutePath(), fileName).toFile();
|
||||
if (connection.Exists(taskRemoteWorkspace.full_name, fileName)) {
|
||||
connection.getSingleFile(rFile, lFile, 0);
|
||||
RemoteFile remote_results_archive = new RemoteFile(packageRemoteWorkspace.full_name, "results.zip");
|
||||
File results_archive = new File(packageLocalWorkspace, "results.zip");
|
||||
if (connection.Exists(packageRemoteWorkspace.full_name, "results.zip")) {
|
||||
connection.getSingleFile(remote_results_archive, results_archive, 0);
|
||||
UnzipFolderPass unzipFolderPass = new UnzipFolderPass();
|
||||
unzipFolderPass.Do(results_archive.getAbsolutePath(), packageLocalWorkspace.getAbsolutePath(), false);
|
||||
}
|
||||
}
|
||||
public void AnalyseResults() throws Exception {
|
||||
@@ -226,7 +185,6 @@ public class TestsSupervisor_2022 {
|
||||
for (TestCompilationTask testCompilationTask : compilationTasks) {
|
||||
ct_count++;
|
||||
if (CheckTask(testCompilationTask)) {
|
||||
// planner.UpdateTask(testCompilationTask);
|
||||
for (TestRunTask testRunTask : testCompilationTask.runTasks) {
|
||||
rt_count++;
|
||||
testRunTask.compilation_state = testCompilationTask.state;
|
||||
@@ -237,7 +195,6 @@ public class TestsSupervisor_2022 {
|
||||
} else {
|
||||
CheckTask(testRunTask);
|
||||
}
|
||||
// planner.UpdateTask(testRunTask);
|
||||
if (testRunTask.state.equals(TaskState.Finished)) {
|
||||
//анализ задачи на запуск.
|
||||
List<String> output_lines = Arrays.asList(testRunTask.output.split("\n"));
|
||||
@@ -261,55 +218,33 @@ public class TestsSupervisor_2022 {
|
||||
testRunTask.progress = results.getValue();
|
||||
testRunTask.CleanTime = Utils.parseCleanTime(testRunTask.output);
|
||||
}
|
||||
File local_sts_text = Utils.getTempFileName("sts_text");
|
||||
Vector<ChannelSftp.LsEntry> files = connection.sftpChannel.ls(testRunTask.remote_workspace);
|
||||
for (ChannelSftp.LsEntry file : files) {
|
||||
if (file.getFilename().equals("sts.gz+")) {
|
||||
RemoteFile remote_sts = new RemoteFile(
|
||||
testRunTask.remote_workspace, file.getFilename(), false);
|
||||
RemoteFile remote_sts_text = new RemoteFile(
|
||||
testRunTask.remote_workspace, "statistic.txt", false);
|
||||
try {
|
||||
connection.ShellCommand(Utils.DQuotes(tasksPackage.dvm_drv) + " pa " +
|
||||
Utils.DQuotes(remote_sts.full_name) + " " + Utils.DQuotes(remote_sts_text.full_name));
|
||||
connection.getSingleFile(remote_sts_text, local_sts_text, 10240);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (local_sts_text.exists()) {
|
||||
try {
|
||||
testRunTask.statistic = FileUtils.readFileToString(local_sts_text, Charset.defaultCharset());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//planner.UpdateTask(testRunTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("ct_count=" + ct_count + " rt count=" + rt_count);
|
||||
//теперь обновить их единым списком.
|
||||
//теперь обновить их единым списком, и удалить задачи на компиляцию.
|
||||
planner.ServerCommand(ServerCode.UpdateTestTasks, compilationTasks);
|
||||
|
||||
}
|
||||
public boolean CheckTask(TestTask testTask) throws Exception {
|
||||
if (testTask.state.equals(TaskState.ResultsDownloaded)) {
|
||||
File taskWorkspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), String.valueOf(testTask.id)).toFile();
|
||||
File taskWorkspace = Paths.get(packageLocalWorkspace.getAbsolutePath(), "results", String.valueOf(testTask.id)).toFile();
|
||||
if (taskWorkspace.exists()) {
|
||||
System.out.println("id=" + testTask.id + ": path=" + taskWorkspace.getAbsolutePath());
|
||||
File stateFile = Paths.get(taskWorkspace.getAbsolutePath(), "TaskState").toFile();
|
||||
File outFile = Paths.get(taskWorkspace.getAbsolutePath(), Constants.out_file).toFile();
|
||||
File errFile = Paths.get(taskWorkspace.getAbsolutePath(), Constants.err_file).toFile();
|
||||
File timeFile = Paths.get(taskWorkspace.getAbsolutePath(), Constants.time_file).toFile();
|
||||
File stateFile = new File(taskWorkspace, "TaskState");
|
||||
File outFile = new File(taskWorkspace, Constants.out_file);
|
||||
File errFile = new File(taskWorkspace.getAbsolutePath(), Constants.err_file);
|
||||
File timeFile = new File(taskWorkspace.getAbsolutePath(), Constants.time_file);
|
||||
File stsFile = new File(taskWorkspace.getAbsolutePath(), "statistic.txt");
|
||||
if (outFile.exists())
|
||||
testTask.output = FileUtils.readFileToString(outFile);
|
||||
if (errFile.exists())
|
||||
testTask.errors = FileUtils.readFileToString(errFile);
|
||||
if (timeFile.exists())
|
||||
testTask.Time = Double.parseDouble(Utils.ReadAllText(timeFile));
|
||||
if ((testTask instanceof TestRunTask) && stsFile.exists()) {
|
||||
TestRunTask testRunTask = (TestRunTask) testTask;
|
||||
testRunTask.statistic = FileUtils.readFileToString(stsFile);
|
||||
}
|
||||
if (stateFile.exists()) {
|
||||
String stateText = FileUtils.readFileToString(stateFile, Charset.defaultCharset()).replace("\n", "");
|
||||
testTask.state = TaskState.valueOf(stateText);
|
||||
@@ -319,3 +254,4 @@ public class TestsSupervisor_2022 {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ int main(int argc, char ** argv)
|
||||
printf(">>>>\n");
|
||||
CompilationSupervisor * compilationSupervisor = new CompilationSupervisor();
|
||||
printf("%ld\n", compilationSupervisor->getLength());
|
||||
compilationSupervisor->Do();
|
||||
compilationSupervisor->DoWithSchedule(maxKernels);
|
||||
|
||||
RunSupervisor * runSupervisor = new RunSupervisor(compilationSupervisor);
|
||||
printf("%ld\n", runSupervisor->getLength());
|
||||
|
||||
@@ -93,18 +93,12 @@ public:
|
||||
printf("START %ld: %s\n", id, res.getCharArray());
|
||||
return res;
|
||||
}
|
||||
|
||||
virtual void copyResults(const String& pathRes) {
|
||||
String resultPath(packageWorkspace + "/" + pathRes + "/" + getId());
|
||||
|
||||
Utils::Mkdir(resultPath);
|
||||
|
||||
Utils::Copy(workspace + "/out.txt", resultPath + "/out.txt");
|
||||
Utils::Copy(workspace + "/err.txt", resultPath + "/err.txt");
|
||||
|
||||
virtual String copyResults(const String& pathRes) {
|
||||
String resultPath = Task::copyResults(pathRes);
|
||||
if (Utils::Exists(workspace + "/sts.gz+")) {
|
||||
String dvm_start = String::DQuotes(dvm_drv) + " pa " + String::DQuotes(String(getId()) + "/sts.gz+") + " " + String::DQuotes(resultPath + "/statistic.txt");
|
||||
system(dvm_start.getCharArray());
|
||||
}
|
||||
return resultPath;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,7 +60,6 @@ public:
|
||||
delete packedTasks;
|
||||
delete lines;
|
||||
}
|
||||
|
||||
void changeState() {
|
||||
switch (this->state) {
|
||||
case WorkspacesCreation:
|
||||
@@ -81,60 +80,8 @@ public:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Do() {
|
||||
saveState();
|
||||
long activeCount = 0;
|
||||
//todo обязательно убрать отладочную печать.
|
||||
printf("tasks count = %ld\n", this->getLength());
|
||||
while (this->state != End) {
|
||||
// printf("state=%d\n", this->state);
|
||||
// printf("max=%d; busy=%d; free=%d\n", maxKernels, busyKernels, freeKernels);
|
||||
activeCount = 0;
|
||||
for (long i = 0; i < this->getLength(); ++i) {
|
||||
T* task = this->get(i);
|
||||
switch (this->state) {
|
||||
case WorkspacesCreation:
|
||||
if (task->getState() == Waiting) {
|
||||
activeCount++;
|
||||
task->createWorkspace();
|
||||
task->setState(WorkspaceCreated);
|
||||
}
|
||||
break;
|
||||
case Preparation:
|
||||
if (task->getState() == WorkspaceCreated) {
|
||||
activeCount++;
|
||||
task->prepareWorkspace();
|
||||
task->createLaunchScript();
|
||||
task->setState(WorkspaceReady);
|
||||
}
|
||||
break;
|
||||
case Execution:
|
||||
if (task->getState() == WorkspaceReady) {
|
||||
activeCount++;
|
||||
task->Start();
|
||||
}
|
||||
else if (task->getState() == Running) {
|
||||
activeCount++;
|
||||
task->Check();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// printf("id = %ld; state = %d\n", task->getId(), task->getState());
|
||||
break;
|
||||
}
|
||||
}
|
||||
// printf("active count = %d\n", activeCount);
|
||||
if (activeCount == 0)
|
||||
changeState();
|
||||
Utils::Sleep(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DoWithSchedule(int maxKernels) {
|
||||
saveState();
|
||||
|
||||
// подготовка тестов
|
||||
while (this->state != Execution) {
|
||||
for (auto& task : this->getElements()) {
|
||||
@@ -179,7 +126,7 @@ public:
|
||||
|
||||
String pathRes("results");
|
||||
Utils::Mkdir(pathRes);
|
||||
string buf;
|
||||
//string buf;
|
||||
|
||||
while (activeTasks) {
|
||||
long oldActiveTasks = activeTasks;
|
||||
@@ -227,7 +174,7 @@ public:
|
||||
busyKernels -= task->getKernels();
|
||||
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
|
||||
|
||||
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
|
||||
//buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
|
||||
task->copyResults(pathRes);
|
||||
continue;
|
||||
}
|
||||
@@ -240,8 +187,8 @@ public:
|
||||
|
||||
changeState();
|
||||
|
||||
String outFile(pathRes + "/info.txt");
|
||||
File tmp(outFile, String(buf.c_str()));
|
||||
//String outFile(pathRes + "/info.txt");
|
||||
//File tmp(outFile, String(buf.c_str()));
|
||||
|
||||
Utils::ZipFolder(pathRes, pathRes + ".zip");
|
||||
}
|
||||
|
||||
@@ -198,5 +198,13 @@ public:
|
||||
File tmp(stateFile, printState());
|
||||
}
|
||||
|
||||
virtual void copyResults(const String& path) { }
|
||||
virtual String copyResults(const String& pathRes) {
|
||||
String resultPath(packageWorkspace + "/" + pathRes + "/" + getId());
|
||||
Utils::Mkdir(resultPath);
|
||||
Utils::Copy(workspace + "/TaskState", resultPath + "/TaskState");
|
||||
Utils::Copy(workspace + "/out.txt", resultPath + "/out.txt");
|
||||
Utils::Copy(workspace + "/err.txt", resultPath + "/err.txt");
|
||||
Utils::Copy(workspace + "/total_time", resultPath + "/total_time");
|
||||
return resultPath;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user