Commit 1e8c07f9 authored by Aivan_2008's avatar Aivan_2008
Browse files

1. Deplloy updates

2. New Rpc commands for deployment added

--HG--
branch : DeploymentQt
parent bf1abd3bb7a9
......@@ -501,6 +501,19 @@ int Rpc_GetChannelName(int server_index, int channel_index, const char* &result,
return 0;
}
int Rpc_GetLastError(int server_index, const char* &result, int timeout)
{
RDK::USerStorageXML request,response;
int res=ProcessSimpleCommand("GetLastError", server_index, -1, timeout, request, response);
if(res)
return res;
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
result=res_string.c_str();
return 0;
}
int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, int& dp_cap, int timeout)
{
RDK::USerStorageXML request,response;
......@@ -582,9 +595,16 @@ int Rpc_DeployProject(int server_index, int task_index, int &resp, int timeout)
return res;
}
int Rpc_OpenDeployedProject(int server_index, int timeout)
{
int Rpc_PrepareProject(int server_index, const char* &verbose_response, int timeout)
{
RDK::USerStorageXML request,response;
return ProcessSimpleCommand("OpenDeployedProject", server_index, -1, timeout, request, response);
return ProcessSimpleCommand("PrepareProject", server_index, -1, timeout, request, response);
}
int Rpc_OpenPreparedProject(int server_index, const char* &verbose_response, int timeout)
{
RDK::USerStorageXML request,response;
return ProcessSimpleCommand("OpenPreparedProject", server_index, -1, timeout, request, response);
}
......@@ -97,12 +97,16 @@ int Rpc_GetDeploymentState(int server_index, int &dp_state, int& dp_progress, i
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout);
int Rpc_GetLastError(int server_index, const char* &result, int timeout);
int Rpc_SaveProject(int server_index, int timeout);
int Rpc_LoadProject(int server_index, const char* project_path, int timeout);
int Rpc_DeployProject(int server_index, int task_index, int &resp, int timeout=-1);
int Rpc_OpenDeployedProject(int server_index, int timeout);
int Rpc_PrepareProject(int server_index, const char* &verbose_response, int timeout);
int Rpc_OpenPreparedProject(int server_index, const char* &verbose_response, int timeout);
#endif // RDKQTCPCLIENTLIB_H
......@@ -55,11 +55,6 @@ void UProjectDeployProcessingThread::SetDownloadTempPath(const QString& path)
downloadTempPath = path;
}
void UProjectDeployProcessingThread::SetDeploymentTempPath(const QString& path)
{
deploymentTempPath = path;
}
void UProjectDeployProcessingThread::SetFtpRemoteBasePath(const QString& path)
{
ftpRemoteBasePath = path;
......@@ -126,11 +121,6 @@ QString UProjectDeployProcessingThread::GetDownloadTempPath()
return downloadTempPath;
}
QString UProjectDeployProcessingThread::GetDeploymentTempPath()
{
return deploymentTempPath;
}
DeploymentState UProjectDeployProcessingThread::GetDeploymentState()
{
return deploymentState;
......@@ -223,7 +213,7 @@ void UProjectDeployProcessingThread::run()
// ,
}
deploymentState = DS_Finished;
deploymentState = DS_DeployFinished;
}
......@@ -779,7 +769,8 @@ bool UProjectDeployProcessingThread::VerifyData()
// --------------------------
UProjectDeployerQt::UProjectDeployerQt(void):
db(NULL),
deployProcessingThread(NULL)
deployProcessingThread(NULL),
deploymentState(DS_NULL)
{
// curl,
// ?
......@@ -837,6 +828,8 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
return 20;
}
deploymentState=DS_NULL;
if(!DestroyProcessingThread())
{
lastError = "Deployment thread exists and cannot be destroyed";
......@@ -1014,9 +1007,9 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
return 7;
}
task_src_path = q.value(0).toString();
QString abs_src_path = task_src_path;
abs_src_path.replace("{Database}", database_path);
QFileInfo qfi_src_file(abs_src_path);
task_src_fullpath = task_src_path;
task_src_fullpath.replace("{Database}", database_path);
QFileInfo qfi_src_file(task_src_fullpath);
if(!qfi_src_file.exists())
{
task_src_download_required = true;
......@@ -1039,10 +1032,10 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
}
task_src_path = q.value(0).toString();
int frame_length = q.value(1).toInt();
QString abs_src_path = task_src_path;
abs_src_path.replace("{Database}", database_path);
task_src_fullpath = task_src_path;
task_src_fullpath.replace("{Database}", database_path);
//QFileInfo qfi_src_file(abs_src_path);
QDir seq_dir(abs_src_path);
QDir seq_dir(task_src_fullpath);
if(seq_dir.exists())
{
QStringList ldr = seq_dir.entryList(QDir::Filter::NoDotAndDotDot|QDir::Filter::Files);
......@@ -1070,9 +1063,6 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
// , {Database}/...
download_temp_path = database_path+"/Temp";
//, zip ,
deployment_temp_path = database_path+"/Deploy";
if(deployProcessingThread)
{
......@@ -1083,32 +1073,39 @@ int UProjectDeployerQt::StartProjectDeployment(int task_id)
}
}
deployProcessingThread = new UProjectDeployProcessingThread();
deployProcessingThread->SetDatabasePath(database_path);
deployProcessingThread->SetDeploymentState(DS_Unknown);
deployProcessingThread->SetDeploymentTempPath(deployment_temp_path);
deployProcessingThread->SetDownloadTempPath(download_temp_path);
if(ftp_remote_path!="")
if(task_template_download_required||task_weights_download_required||
task_script_download_required||task_src_download_required)
{
deployProcessingThread->SetFtpRemoteBasePath(QString(ftp_remote_path.c_str()));
deployProcessingThread = new UProjectDeployProcessingThread();
deployProcessingThread->SetDatabasePath(database_path);
deployProcessingThread->SetDeploymentState(DS_Unknown);
deployProcessingThread->SetDownloadTempPath(download_temp_path);
if(ftp_remote_path!="")
{
deployProcessingThread->SetFtpRemoteBasePath(QString(ftp_remote_path.c_str()));
}
else
{
qDebug("Empty ftp_remote_path on deploy processing stage");
}
std::cout<<"Initialize deployment thread: ttdr="<<task_template_download_required<<" atf="<<abs_template_file.toUtf8().constData()<<
" twdr="<<task_weights_download_required<<" twp="<<task_weights_path.toUtf8().constData()<<" tsdr="<<task_script_download_required<<
" tsp="<<task_script_path.toUtf8().constData()<<" tsrcdr="<<task_src_download_required<<" tst="<<task_src_type<<" tsp="<<task_src_path.toUtf8().constData();
deployProcessingThread->PrepareProjectDeployment(task_template_download_required, task_template_path,
task_weights_download_required, task_weights_path,
task_script_download_required, task_script_path,
task_src_download_required, task_src_type, task_src_path);
deployProcessingThread->RunProjectDeployment();
}
else
{
qDebug("Empty ftp_remote_path on deploy processing stage");
// , , ?
this->deploymentState = DS_DeployFinished;
}
std::cout<<"Initialize deployment thread: ttdr="<<task_template_download_required<<" atf="<<abs_template_file.toUtf8().constData()<<
" twdr="<<task_weights_download_required<<" twp="<<task_weights_path.toUtf8().constData()<<" tsdr="<<task_script_download_required<<
" tsp="<<task_script_path.toUtf8().constData()<<" tsrcdr="<<task_src_download_required<<" tst="<<task_src_type<<" tsp="<<task_src_path.toUtf8().constData();
deployProcessingThread->PrepareProjectDeployment(task_template_download_required, task_template_path,
task_weights_download_required, task_weights_path,
task_script_download_required, task_script_path,
task_src_download_required, task_src_type, task_src_path);
deployProcessingThread->RunProjectDeployment();
lastError = "";
return 0;
}
......@@ -1164,23 +1161,27 @@ std::string UProjectDeployerQt::GetLastError()
std::string le = "";
if(lastError!="")
{
le = "UProjectDeployerQt lastError="+lastError+" ";
le = std::string("UProjectDeployerQt lastError=")+lastError+std::string(" ");
}
if(deployProcessingThread==NULL)
{
le+="DeployProcessingThread lastError: Deploy thread not exists. ";
if(le=="")
le=le+std::string("DeployProcessingThread lastError: Deploy thread not exists. ");
}
else
{
return le+="DeployProcessingThread lastError: "+deployProcessingThread->GetLastError();
std::string dtle = deployProcessingThread->GetLastError();
if(dtle!="")
le=le+std::string("DeployProcessingThread lastError: ")+dtle;
}
return le;
}
int UProjectDeployerQt::GetDeploymentState()
{
if(deployProcessingThread==NULL)
{
return DeploymentState::DS_NULL;
return deploymentState;
}
else
{
......@@ -1233,10 +1234,232 @@ int UProjectDeployerQt::GetStageProgress()
}
}
/// :
/// 1.
/// 2. ?
/// 3.
int UProjectDeployerQt::PrepareProject(std::string &response)
{
lastError="";
if(this->deploymentState!=DS_DeployFinished)
{
response = "Project deployment is not opened, can't start preparations";
lastError=response;
return 1;
}
this->deploymentState = DS_CopyProject;
if(CopyProjectToTempFolder()!=0)
{
this->deploymentState=DS_Error;
response = "error during copying";
lastError=response;
return 1;
}
this->deploymentState=DS_PrepareProject;
if(OpenProjectMockMode()!=0)
{
this->deploymentState=DS_Error;
response = "error during opening in mock mode";
lastError=response;
return 1;
}
if(SetupProjectMockParameters()!=0)
{
this->deploymentState=DS_Error;
response = "error during mock parameters setup";
lastError=response;
return 1;
}
if(CloseMockProject()!=0)
{
this->deploymentState=DS_Error;
response = "error during mocked project closing";
lastError=response;
return 1;
}
this->deploymentState=DS_ProjectPrepared;
response = "project prepared successfully";
lastError=response;
return 0;
}
///
int UProjectDeployerQt::OpenPreparedProject(std::string &response)
{
if(this->deploymentState!=DS_ProjectPrepared)
{
response = "Project is not prepared yet";
lastError=response;
return 1;
}
deploymentState = DS_OpenProject;
// -
//RDK::Sleep(3);
Application->SetStorageBuildMode(1);
QString pdpath = GetTempProjectDeploymentPath().c_str();
QString project_path = pdpath+"/project_full.ini";
if(!Application->OpenProject(project_path.toUtf8().constData()))
{
lastError="UApplication OpenProject normally error";
return 1;
}
////
deploymentState = DS_ProjectOpened;
response = "project opened successfully";
lastError=response;
return 0;
}
// --------------------------
//
// --------------------------
/// ,
int UProjectDeployerQt::CopyProjectToTempFolder()
{
QString pdpath = GetTempProjectDeploymentPath().c_str();
if(pdpath=="")
{
lastError="project temporary deployment path empty - cannot copy";
return 1;
}
QString abs_ttp = task_template_path;
QString db_p = Application->GetDatabaseMainPath().c_str();
abs_ttp.replace("{Database}", db_p);
QFileInfo fi(abs_ttp);
QDir src_dir(fi.absoluteDir());
QStringList files_dirs = src_dir.entryList(QDir::Filter::NoDotAndDotDot|QDir::Filter::Files);
//
for(QString fn:files_dirs)
{
QFile::copy(src_dir.path()+"/"+fn, pdpath+"/"+fn);
}
QDir pddir(pdpath);
//
pddir.mkdir("EventsLog");
//..
pddir.mkdir("Results");
//RDK::Sleep(3);
return 0;
}
///
int UProjectDeployerQt::OpenProjectMockMode()
{
//
Application->CreateSaveMockLibs();
//
Application->SetStorageBuildMode(3);
QString pdpath = GetTempProjectDeploymentPath().c_str();
QString project_path = pdpath+"/project_full.ini";
if(!Application->OpenProject(project_path.toUtf8().constData()))
{
lastError="UApplication OpenProject Mock Components error";
return 1;
}
return 0;
}
///
int UProjectDeployerQt::SetupProjectMockParameters()
{
RDK::Sleep(3);
RDK::UELockPtr<RDK::UContainer> model = RDK::GetModelLock(0);
if(!model) return 1;
//
RDK::UEPtr<RDK::UContainer> video_cont;
RDK::UEPtr<RDK::UContainer> imseq_cont;
std::vector<std::string> vid_names;
vid_names = model->GetComponentsNameByClassName("TCaptureOpenCV", vid_names);
std::vector<std::string> imseq_names;
imseq_names = model->GetComponentsNameByClassName("TCaptureImageSequence", imseq_names);
if(task_src_type==0)//TODO: -
{
if(vid_names.empty())
{
// -
lastError="Model does not contain video data source, fix project file/task parameters";
return 1;
}
video_cont = model->GetComponentL(vid_names[0]);
bool *video_Activity = video_cont->AccessPropertyData<bool>("Activity");
bool *video_EnableCapture = video_cont->AccessPropertyData<bool>("EnableCapture");
std::string *video_CameraPath = video_cont->AccessPropertyData<std::string>("CameraPath");
*video_Activity = true;
*video_EnableCapture = true;
*video_CameraPath = task_src_fullpath.toUtf8().constData();
if(!imseq_names.empty())
{
imseq_cont = model->GetComponentL(imseq_names[0]);
bool *act = imseq_cont->AccessPropertyData<bool>("Activity");
*act = false;
}
}
else if(task_src_type==1)//TODO: -
{
if(imseq_names.empty())
{
// -
lastError="Model does not contain image sequence data source, fix project file/task parameters";
return 1;
}
}
else
{
// ,
lastError="Video source type has undefined value";
return 1;
}
/*
if(cont)
{
std::map<std::string, RTV::RTVAlarmPlan> *schedules =
cont->AccessPropertyData<std::map<std::string, RTV::RTVAlarmPlan> >(schedulesPropertyName.toLocal8Bit().constData());
int stepCounter = 0;
for(std::map<std::string, RTV::RTVAlarmPlan>::iterator i = schedules->begin();
i != schedules->end(); ++i, ++stepCounter)
{
ui->tableWidgetSchedule->insertRow(stepCounter);
ui->tableWidgetSchedule->setItem(stepCounter, 0, new QTableWidgetItem(QString::fromLocal8Bit(i->first.c_str())));
ui->tableWidgetSchedule->setItem(stepCounter, 1, new QTableWidgetItem(QString::number(i->second.StartTime)));
ui->tableWidgetSchedule->setItem(stepCounter, 2, new QTableWidgetItem(QString::number(i->second.StopTime)));
for(int checkBoxIterator = 0; checkBoxIterator < 8; ++checkBoxIterator)
{
QCheckBox *checkBox = new QCheckBox();
if(i->second.DaysOfWeek & 1 << checkBoxIterator)
checkBox->setChecked(true);
ui->tableWidgetSchedule->setCellWidget(stepCounter, checkBoxIterator + 3, checkBox);
}
}
}
*/
return 0;
}
///
int UProjectDeployerQt::CloseMockProject()
{
//RDK::Sleep(3);
Application->SaveProject();
Application->CloseProject();
return 0;
}
/// ,
......
......@@ -52,7 +52,12 @@ enum DeploymentState
DS_UnpackScripts=7,
DS_DownloadData=8,
DS_UnpackData=9,
DS_Finished=10,
DS_DeployFinished=10,
DS_CopyProject=11,
DS_PrepareProject=12,
DS_ProjectPrepared=13,
DS_OpenProject=14,
DS_ProjectOpened=15,
DS_Error=100
};
......@@ -68,7 +73,6 @@ public:
void SetDatabasePath(const QString& path);
void SetDownloadTempPath(const QString& path);
void SetDeploymentTempPath(const QString& path);
void SetFtpRemoteBasePath(const QString& path);
void SetDeploymentState(const DeploymentState& state);
void SetDeploymentProgress(const int &progress);
......@@ -84,7 +88,6 @@ public:
///Get
QString GetDatabasePath();
QString GetFtpRemoteBasePath();
QString GetDeploymentTempPath();
QString GetDownloadTempPath(); //
DeploymentState GetDeploymentState();
......@@ -117,7 +120,6 @@ private:
QString databasePath;
QString ftpRemoteBasePath;
QString deploymentTempPath;
QString downloadTempPath;
bool template_dr, weights_dr, script_dr, videosource_dr;
......@@ -193,18 +195,20 @@ bool task_script_download_required;
//
// ( )
QString task_src_path;
QString task_src_fullpath;
//
bool task_src_download_required;
// ( )
QString task_src_zip_url;
QString deployment_temp_path;
QString download_temp_path;
UProjectDeployProcessingThread *deployProcessingThread;
std::string lastError;
DeploymentState deploymentState;
/*
//?
// (- 1)
......@@ -228,6 +232,15 @@ public: //
/// , ( )
virtual int StartProjectDeployment(int task_id);
/// :
/// 1.
/// 2. ?
/// 3.
virtual int PrepareProject(std::string &response);
///
virtual int OpenPreparedProject(std::string &response);
///
//virtual void SetDatabaseAccess(const std::string &db_address, const std::string &db_name, const std::string &db_login, const std::string &db_password);
//virtual void SetProjectIndices(int gt_id, int sln_id, int weights_id, int script_id);
......@@ -251,9 +264,22 @@ UProjectDeployerQt(void);
virtual ~UProjectDeployerQt(void);
// --------------------------
protected:
// --------------------------
//
// --------------------------
/// ,
int CopyProjectToTempFolder();
///
int OpenProjectMockMode();
///
int SetupProjectMockParameters();
///
int CloseMockProject();
///
/// ( )
//int OpenPreparedProject();
/// ,
///
......
......@@ -152,6 +152,7 @@ int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManager
logDebugMode=atoi(projectIniFile("Log","DebugMode","1"));
disableAdminForm=atoi(projectIniFile("General","DisableAdminForm","0"));
std::string temp_proj_path = projectIniFile("General", "TemporaryProjectPath", "");
serverPort = atoi(projectIniFile("Server","BindPort","45545"));
serverAddress = projectIniFile("Server","BindAddress","127.0.0.2");
......@@ -201,6 +202,12 @@ int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManager
{
application.SetDatabaseMainPath(databaseMainPath);
}
if(temp_proj_path!="")
{
application.GetProjectDeployer()->SetTempProjectDeploymentPath(temp_proj_path);
}
application.GetServerControl()->GetServerTransport()->SetServerBinding(serverAddress, serverPort);
cout<<"ServerAutoStartFlag: "<<serverAutostartFlag<<"\n";
std::cout<<"Test cout "<<serverAddress.c_str()<<" "<<serverPort<<std::endl;
......
......@@ -74,6 +74,33 @@ void UProjectDeployer::SetFtpRemotePath(const std::string &path)
ftp_remote_path = path;
}
void UProjectDeployer::SetTempProjectDeploymentPath(const std::string &path)
{
temp_project_deployment_path = path;
}
std::string UProjectDeployer::GetTempProjectDeploymentPath()
{
return temp_project_deployment_path;
}
/// :
/// 1.
/// 2. ?
/// 3.
int UProjectDeployer::PrepareProject(std::string &response)
{
response="base class called";