Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit 1b8ef07a authored by aivan_2008's avatar aivan_2008
Browse files

Implemented first working prototype of project deployer

--HG--
branch : DeploymentQt
parent 27e9ffa5757d
......@@ -5,6 +5,9 @@
#-------------------------------------------------
QT -= gui
QT += network
TARGET = rdk.static.qt
TEMPLATE = lib
......@@ -12,6 +15,11 @@ CONFIG += staticlib
include(RdkDefines.pri)
contains(DEFINES, RDK_USE_SQL)
{
QT += sql
}
#DEFINES += LIBRDK_LIBRARY_EXPORT
#DEFINES += RDK_UNICODE_RUN
#DEFINES += RDK_QT
......@@ -140,13 +148,12 @@ SOURCES += \
../../../Core/Application/UServerControl.cpp \
../../../Core/Application/UServerTransport.cpp \
../../../Core/Application/UServerTransportTcp.cpp \
../../../Core/Application/Qt/UServerTransportTcpQt.cpp \
../../../Core/Application/UTestManager.cpp \
../../../Core/System/Gcc/pevents.cpp \
../../../Core/Engine/UComponentFactory.cpp \
../../../Deploy/Include/rdk_version.cpp \
../../../Core/Application/UProjectDeployer.cpp \
../../../Core/Application/Qt/UProjectDeployerQt.cpp \
../../../Core/Application/UServerTransportHttp.cpp \
../../../Core/Application/UServerTransportHttp.cpp
HEADERS +=\
......@@ -267,15 +274,23 @@ HEADERS +=\
../../../Core/Application/UServerControl.h \
../../../Core/Application/UServerTransport.h \
../../../Core/Application/UServerTransportTcp.h \
../../../Core/Application/Qt/UServerTransportTcpQt.h \
../../../Core/Application/UTestManager.h \
../../../Core/System/Gcc/pevents.h \
../../../Core/Engine/UComponentFactory.h \
../../../Deploy/Include/rdk_version.h \
../../../Core/Application/UProjectDeployer.h \
../../../Core/Application/Qt/UProjectDeployerQt.h \
../../../Core/Application/UServerTransportHttp.h \
../../../Core/Application/UServerTransportHttp.h
contains(DEFINES, RDK_USE_SQL)
{
SOURCES += \
../../../Core/Application/Qt/UProjectDeployerQt.cpp # \
HEADERS +=\
../../../Core/Application/Qt/UProjectDeployerQt.h # \
}
unix {
DESTDIR = $$PWD/../../../../Bin/Platform/Linux/Lib.Qt
}
......
......@@ -258,6 +258,11 @@ int Rpc_UnInit(void)
return 0;
}
bool Rpc_IsInit()
{
return (ClientsArray.size()>0);
}
///
int Rpc_Ping(int server_index, int timeout)
......@@ -408,6 +413,11 @@ int Rpc_AddServer(void)
return 0;
}
int Rpc_LastServerId()
{
return (int)ClientsArray.size()-1;
}
int Rpc_DelServer(int server_index)
{
if((int)ClientsArray.size()-1 < server_index)
......@@ -491,6 +501,25 @@ int Rpc_GetChannelName(int server_index, int channel_index, const char* &result,
return 0;
}
int Rpc_GetDeploymentState(int server_index, const char* &dp_state, int& dp_progress, int& dp_cap, int timeout)
{
RDK::USerStorageXML request,response;
int res=ProcessSimpleCommand("GetChannelName", server_index, -1, timeout, request, response);
if(res)
return res;
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
std::string s;
std::stringstream ss;
ss<<res_string.c_str();
ss>>dp_cap>>dp_progress>>s;
dp_state=s.c_str();
return 0;
}
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, int timeout)
{
RDK::USerStorageXML request,response;
......@@ -516,3 +545,24 @@ int Rpc_LoadProject(int server_index, const char* project_path, int timeout)
request.WriteString("FileName", project_path);
return ProcessSimpleCommand("LoadProject", server_index, -1, timeout, request, response);
}
int Rpc_DeployProject(int server_index, int task_index, int &resp, int timeout)
{
RDK::USerStorageXML request,response;
request.Create("Request");
request.WriteInteger("TaskId", task_index);
int res=ProcessSimpleCommand("DeployProject", server_index, 0, timeout, request, response);
static std::string res_string;
res_string=response.ReadString("Data", "").c_str();
resp = atoi(res_string.c_str());
//result=res_string.c_str();
if(res)
return res;
}
......@@ -64,6 +64,8 @@ int Rpc_Init(int num_serverPtz_MoveZoom);
int Rpc_UnInit(void);
bool Rpc_IsInit();
///
int Rpc_Ping(int server_index, int timeout);
......@@ -75,6 +77,8 @@ int Rpc_AddServer(void);
int Rpc_DelServer(int server_index);
int Rpc_LastServerId();
///////////////
int Rpc_StartChannel(int server_index, int channel_index, int timeout);
......@@ -89,10 +93,14 @@ int Rpc_SetNumChannels(int server_index, int num_channels, int timeout);
int Rpc_GetChannelName(int server_index, int channel_index, const char* &result, int timeout);
int Rpc_GetDeploymentState(int server_index, const char* &dp_state, int& dp_progress, int& dp_cap, int timeout);
int Rpc_SetChannelName(int server_index, int channel_index, const char* channel_name, 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);
#endif // RDKQTCPCLIENTLIB_H
This diff is collapsed.
......@@ -2,43 +2,238 @@
#define UProjectDeployerQtH
#include "../../../Deploy/Include/rdk.h"
#include "../UProjectDeployer.h"
#include "../UIVisualController.h"
#include <QtSql>
#include <QThread>
#include <QMutex>
#include <thread>
#include <mutex>
#include <curl/curl.h>
struct FtpFile {
const char *filename;
FILE *stream;
};
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out = (struct FtpFile *)stream;
if(!out->stream) {
/* open file for writing */
out->stream = fopen(out->filename, "wb");
if(!out->stream)
{
std::cerr<<"Stream out failure";
return -1; /* failure, can't open file to write */
}
}
size_t res = fwrite(buffer, size, nmemb, out->stream);
std::cerr<<"Res = "<<res<<std::endl;
return res;
}
namespace RDK{
class UApplication;
class RDK_LIB_TYPE UProjectDeployerQt: public UAppController
enum DeploymentState
{
DS_NULL,
DS_Unknown,
DS_DownloadTemplate,
DS_UnpackTemplate,
DS_DownloadWeights,
DS_UnpackWeights,
DS_DownloadScripts,
DS_UnpackScripts,
DS_DownloadData,
DS_UnpackData,
DS_Error
};
class RDK_LIB_TYPE UProjectDeployProcessingThread: public QThread
{
Q_OBJECT
public:
UProjectDeployProcessingThread();
~UProjectDeployProcessingThread();
void run() override;
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);
void SetDeploymentProgressCap(const int &value);
void PrepareProjectDeployment(bool task_template_dr, const QString& task_template_path,
bool task_weights_dr, const QString& task_weights_path,
bool task_script_dr, const QString& task_script_path,
bool task_vsrc_dr, int task_vrc_type, const QString& task_vsrc_path);
void RunProjectDeployment();
///Get
QString GetDatabasePath();
QString GetFtpRemoteBasePath();
QString GetDeploymentTempPath();
QString GetDownloadTempPath(); //
DeploymentState GetDeploymentState();
std::string GetDeploymentStateString();
int GetDeploymentProgress();
int GetDeploymentProgressCap();
private slots:
void processReadyReadStandardError();
void processReadyReadStandardOutput();
private:
bool DownloadZip(const QString &remote_url, const QString& dst_zip_file);
bool UnpackZipFolder(const QString &local_zip_folder, const QString& local_dst_folder);
bool UnpackZipFile(const QString &local_zip_folder, const QString& local_dst_folder);
void DeployTemplate();
bool VerifyTemplate();
void DeployScript();
bool VerifyScript();
void DeployWeights();
bool VerifyWeights();
void DeployData();
bool VerifyData();
private:
QMutex deploymentStateMutex;
QMutex deploymentProgressMutex;
QMutex deploymentProgressCapMutex;
QString databasePath;
QString ftpRemoteBasePath;
QString deploymentTempPath;
QString downloadTempPath;
bool template_dr, weights_dr, script_dr, videosource_dr;
int videosource_type;
QString template_path, weights_path, script_path, videosource_path;
DeploymentState deploymentState;
int deploymentProgressCap;
int deploymentProgress;
QProcess zip_process;
CURL *curl;
CURLcode res;
};
class RDK_LIB_TYPE UProjectDeployerQt: public UProjectDeployer
{
friend class UApplication;
protected: //
protected: //
///
UEPtr<UApplication> Application;
QSqlDatabase *db;
protected: //
protected: //
//
QString task_name; //
int task_template_id; //
int task_weights_id; //
int task_src_type; // (0-, 1- )
int task_src_id; //
// -
bool task_template_download_required;
// ( ?)
QString task_template_name;
// ()
QString task_template_path;
// ZIP ,
//std::string task_template_zip_url;
//
//
QString task_weights_path;
//
bool task_weights_download_required;
// ( ,
bool task_weights_conf_download_required;
// -
QString task_weights_config_path;
//
//std::string task_weights_zip_url;
//std::string task_weights_conf_zip_url;
//
//
int task_script_id;
// ()
QString task_script_path;
//
bool task_script_download_required;
//
//std::string task_script_zip_url;
//
// ( )
QString task_src_path;
//
bool task_src_download_required;
// ( )
QString task_src_zip_url;
QString deployment_temp_path;
QString download_temp_path;
UProjectDeployProcessingThread *deployProcessingThread;
/*
//?
// (- 1)
std::string project_path;
std::string project_url;
// :
std::string database_address;
std::string database_port;
std::string database_login;
std::string database_password;
//
int project_gt_id;
int project_sln_id;
int project_weigts_id;
int project_script_id;
*/
protected://
//
bool DestroyProcessingThread();
public: //
virtual int StartProjectDeployment(const std::string &project_path, const std::string &project_url);
virtual void SetDatabaseCredentials(const std::string &db_address, const std::string &db_port, 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);
/// , ( )
virtual int StartProjectDeployment(int task_id);
///
//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);
virtual void AConnectToDatabase();
virtual std::string GetDeploymentState();
virtual int GetStageCap();
virtual int GetStageProgress();
public: //
QSqlDatabase *GetDatabase() {return db;};
// --------------------------
//
......
......@@ -5,11 +5,10 @@
#include "../Utilities/UIniFile.h"
#include "../../Deploy/Include/rdk_application.h"
namespace RDK {
///
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT>
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT, class ServerTransportT, class UProjectDeployerT>
class RDK_LIB_TYPE UAppCore
{
public:
......@@ -21,6 +20,10 @@ public:
///
ServerControlT serverControl;
///
ServerTransportT serverTransport;
DecoderCommonT rpcDecoderCommon;
///
......@@ -35,6 +38,9 @@ public:
///
TestManagerT rdkTestManager;
///
UProjectDeployerT projectDeployer;
public:
std::string startProjectName;
int autoStartProjectFlag;
......@@ -45,6 +51,8 @@ public:
int minimizeToTray;
std::string programName;
std::string configsMainPath;
std::string databaseMainPath;
std::string remoteFtpDatabasePath;
int neverSleepOnMMThreadContention;
std::string logDir;
int startupDelay;
......@@ -56,32 +64,50 @@ public:
int disableAdminForm;
int serverPort;
std::string serverAddress;
int serverAutostartFlag;
public:
UAppCore(void);
~UAppCore(void);
///
int Init(const std::string &application_file_name, const std::string &log_dir, int argc, char *argv[]);
int Init(const std::string &application_file_name, const std::string &ini_file_name, const std::string &log_dir, int argc, char *argv[]);
};
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT>
UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, DispatcherT, DecoderT, DecoderCommonT>::UAppCore(void)
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT, class ServerTransportT, class ProjectDeployerT>
UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, DispatcherT, DecoderT, DecoderCommonT, ServerTransportT, ProjectDeployerT>::UAppCore(void)
{
rdkTestManager.SetApplication(&application);
rpcDispatcher.SetApplication(&application);
rpcDecoder.SetDispatcher(&rpcDispatcher);
rpcDecoderCommon.SetDispatcher(&rpcDispatcher);
application.SetTestManager(&rdkTestManager);
rpcDispatcher.SetDecoderPrototype(&rpcDecoder);
rpcDispatcher.SetCommonDecoder(&rpcDecoderCommon);
serverControl.SetApplication(&application);
serverControl.SetRpcDispatcher(&rpcDispatcher);
serverTransport.SetApplication(&application);
serverControl.SetServerTransport(&serverTransport);
//
application.SetProjectDeployer(&projectDeployer);
//application.SetRpcDispatcher(&rpcDispatcher);
application.SetServerControl(&serverControl);
application.SetEngineControl(&engineControl);
application.SetProject(&project);
}
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT>
UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, DispatcherT, DecoderT, DecoderCommonT>::~UAppCore(void)
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT, class ServerTransportT, class ProjectDeployerT>
UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, DispatcherT, DecoderT, DecoderCommonT, ServerTransportT, ProjectDeployerT>::~UAppCore(void)
{
application.PauseChannel(-1);
application.CloseProject();
......@@ -89,12 +115,16 @@ UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, D
}
///
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT>
int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, DispatcherT, DecoderT, DecoderCommonT>::Init(const std::string &application_file_name, const std::string &log_dir, int argc, char *argv[])
template<class ApplicationT, class EngineControlT, class ProjectT, class ServerControlT, class TestManagerT, class DispatcherT, class DecoderT, class DecoderCommonT, class ServerTransportT, class ProjectDeployerT>
int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManagerT, DispatcherT, DecoderT, DecoderCommonT, ServerTransportT, ProjectDeployerT>::Init(const std::string &application_file_name, const std::string& ini_file_name, const std::string &log_dir, int argc, char *argv[])
{
//std::cout<<"Test sout init"<<std::endl;
// ini
RDK::UIniFile<char> projectIniFile;
projectIniFile.LoadFromFile("VideoAnalytics.ini");
projectIniFile.LoadFromFile(ini_file_name);
startProjectName = projectIniFile("General", "AutoexecProjectFileName", "");
autoStartProjectFlag = RDK::atoi(projectIniFile("General", "autoStartProjectFlag", "0"));
hideAdminForm = RDK::atoi(projectIniFile("General", "HideAdminForm", "0"));
......@@ -111,6 +141,9 @@ int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManager
useNewXmlFormatProjectFile=atoi(projectIniFile("General","UseNewXmlFormatProjectFile","0"));
useNewProjectFilesStructure=atoi(projectIniFile("General","UseNewProjectFilesStructure","0"));
databaseMainPath=projectIniFile("General","DatabaseMainPath","");
remoteFtpDatabasePath=projectIniFile("General","RemoteFtpDatabasePath","");
if(startupDelay>0)
{
RDK::Sleep(startupDelay);
......@@ -120,6 +153,16 @@ int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManager
disableAdminForm=atoi(projectIniFile("General","DisableAdminForm","0"));
serverPort = atoi(projectIniFile("Server","BindPort","45545"));
serverAddress = projectIniFile("Server","BindAddress","127.0.0.2");
serverAutostartFlag = atoi(projectIniFile("Server","AutostartServer","0"));
std::string database_address = projectIniFile("PostgreSQL","DatabaseAddress","127.0.0.1");
std::string database_name = projectIniFile("PostgreSQL","DatabaseName","videoanalytics");
std::string database_login = projectIniFile("PostgreSQL","DatabaseLogin","");
std::string database_password = projectIniFile("PostgreSQL","DatabasePassword","");
application.SetApplicationFileName(application_file_name);
if(logDir.empty())
application.SetLogDir(log_dir);
......@@ -133,8 +176,16 @@ int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManager
application.ChangeUseNewProjectFilesStructure(useNewProjectFilesStructure);
if(argc > 1)
application.ProcessCommandLineArgs(argc, argv);
try
{
if(argc > 1)
application.ProcessCommandLineArgs(argc, argv);
}
catch(exception &ex)
{
MLog_LogMessage(RDK_GLOB_MESSAGE,RDK_EX_WARNING,ex.what());
return 11711;
}
application.Init();
......@@ -146,6 +197,29 @@ int UAppCore<ApplicationT, EngineControlT, ProjectT, ServerControlT, TestManager
return returnCode;
}
if(databaseMainPath!="")
{
application.SetDatabaseMainPath(databaseMainPath);
}
application.GetServerControl()->GetServerTransport()->SetServerBinding(serverAddress, serverPort);
cout<<"ServerAutoStartFlag: "<<serverAutostartFlag<<"\n";
std::cout<<"Test cout "<<serverAddress.c_str()<<" "<<serverPort<<std::endl;
if(serverAutostartFlag)
{
std::cout<<"Start TCP server on "<<serverAddress.c_str()<<" "<<serverPort<<std::endl;
application.GetServerControl()->GetServerTransport()->ServerStart();
}
if(remoteFtpDatabasePath!="")
{
application.GetProjectDeployer()->SetFtpRemotePath(remoteFtpDatabasePath);
}
if(database_login!="" && database_password!="")
{
application.GetProjectDeployer()->SetDatabaseAccess(database_address, database_name, database_login, database_password);
}
if(!startProjectName.empty())