180 lines
6.0 KiB
C++
180 lines
6.0 KiB
C++
/**
|
||
* @file WorkflowCompiler.h
|
||
* @brief 工作流编译器
|
||
*
|
||
* @author 黄军
|
||
* @date 2011-8-23
|
||
*/
|
||
|
||
#ifndef PAI_FRAME_WORKFLOWENGINE_WORKFLOWCOMPILER_H
|
||
#define PAI_FRAME_WORKFLOWENGINE_WORKFLOWCOMPILER_H
|
||
|
||
#include <time.h>
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <map>
|
||
|
||
#include "ModuleManager.h"
|
||
#include "ModuleMetaData.h"
|
||
#include "WorkflowConstants.h"
|
||
#include "WorkFlowFile.h"
|
||
#include "ConfigureManager.h"
|
||
#include "StringUtils.h"
|
||
#include "DataSetRepository.h"
|
||
#include "DataSetInfo.h"
|
||
#include "Turtle.h"
|
||
using namespace pai::ios::seis;
|
||
|
||
namespace pai {
|
||
namespace workflow {
|
||
|
||
/*编译参数*/
|
||
typedef struct SCompileParam {
|
||
//编译主目录
|
||
std::string strCompileRootPath;
|
||
//代码文件名称
|
||
std::string strSoureCodeFileName;
|
||
//动态库名称
|
||
std::string strShareLibName;
|
||
//类库输出路径
|
||
std::string strOutputLibDir;
|
||
|
||
SCompileParam():strCompileRootPath(), strSoureCodeFileName(),
|
||
strShareLibName(), strOutputLibDir()
|
||
{
|
||
|
||
}
|
||
|
||
} SCompileParam;
|
||
|
||
/*编译内部参数*/
|
||
typedef struct SCompileInnerParam {
|
||
//部署路径
|
||
std::string strProjectDeployPath;
|
||
//Shell模板文件夹路径
|
||
std::string strCompileShellPath;
|
||
//Makefile模板文件夹路径
|
||
std::string strCompileMakePath;
|
||
//日志文件名称
|
||
std::string strLogFileName;
|
||
//工作流编译器固定的头文件全路径(临时)
|
||
std::string strFixedIncludePaths;
|
||
//工作流编译器固定的类库全路径(临时)
|
||
std::string strFixedLibPaths;
|
||
//工作流编译器固定的类库名称(临时)
|
||
std::string strFixedLibNames;
|
||
//工作流编译环境检查脚本路径
|
||
std::string strCompilerCheckShellPath;
|
||
|
||
SCompileInnerParam():strProjectDeployPath(), strCompileShellPath(), strCompileMakePath(), \
|
||
strLogFileName(), strFixedIncludePaths(), strFixedLibPaths(), strFixedLibNames(),\
|
||
strCompilerCheckShellPath(){}
|
||
} SCompileInnerParam;
|
||
|
||
struct SWorkflowResource;
|
||
/**
|
||
* @brief 工作流编译器
|
||
*
|
||
* 提供了工作流编译器的基本接口方法:
|
||
* (1)执行工作流代码的编译
|
||
*
|
||
*/
|
||
class PAI_WORKFLOWENGINE_EXPORT CWorkflowCompiler {
|
||
public:
|
||
CWorkflowCompiler(const std::string& strConfigPath);
|
||
CWorkflowCompiler();
|
||
virtual ~CWorkflowCompiler();
|
||
|
||
public:
|
||
/*
|
||
* @brief 编译工作流代码文件
|
||
*
|
||
* 在传递编译参数是,保证工作流代码在编译主目录(strCompileRootPath)下;
|
||
* 编译成功后,编译组件会把类库存放到,类库输出路径(strOutputLibDir);
|
||
* 如果编译有错误,错误信息先保存在errorMsg里
|
||
*
|
||
* @param[in] workFlowFile 编译的工作流文件对象
|
||
* @param[in] SCompileParam 编译参数
|
||
* @param[in/out] errorMsg 编译错误信息
|
||
* @pre 要先初始化errorMsg
|
||
* @return 编译是否成功
|
||
*/
|
||
bool CompileWorkflowFile(CWorkFlowFile* worflowFile,const SCompileParam& condition,std::string &strErrorMsg);
|
||
/*
|
||
* @brief 获取当前工作流对象,需要传递给MapReduce配置信息
|
||
* @param[in] workFlowFile 编译的工作流文件对象
|
||
* @param[in/out] properties 配置信息
|
||
*/
|
||
void GetWorkFlowProperties(CWorkFlowFile* worflowFile,Properties& properties);
|
||
/*
|
||
* @brief 生成作业jar文件
|
||
* 在Jar模板文件,添加工作流动态库、配置文件.
|
||
* @param[in] strTemplateJarPath Jar模板文件路径
|
||
* @param[in] resource 工作流资源信息
|
||
* @param[in] strJobFilePath 作业文件路径
|
||
* @return 生成作业文件是否成功
|
||
*/
|
||
bool GeneratorJobFile(const std::string& strTemplateJarPath,const SWorkflowResource& resource,std::string& strJobFilePath);
|
||
/*
|
||
* @brief 临时生成PSTM作业jar文件
|
||
* 在Jar模板文件,添加工作流动态库、配置文件,pstm.ini文件
|
||
* @param[in] strTemplateJarPath Jar模板文件路径
|
||
* @param[in] resource 工作流资源信息
|
||
* @param[in] strJobFilePath 作业文件路径
|
||
* @return 生成作业文件是否成功
|
||
*/
|
||
std::string GetConfigPath() const { return this->m_strConfigPath;}
|
||
void SetConfigPath(const std::string& strConfigPath ) { this->m_strConfigPath = strConfigPath; }
|
||
private:
|
||
//解析配置获取,编译内部需要的参数
|
||
void GetComipleInnerParam(SCompileInnerParam& param);
|
||
/*
|
||
* @brief 分析工作流模块引用的类库信息
|
||
*
|
||
* 分析工作流模块引用的类库信息,然后调用@ref ModuleManager的GetLibInfo()方法获取类库信息
|
||
*
|
||
* @param[in] workFlowFile 编译的工作流文件对象
|
||
* @param[in/out] reflibs 引用类库集合
|
||
* @return 编译是否成功
|
||
*/
|
||
bool AnalyzeRefLib(CWorkFlowFile* worflowFile,std::vector<CModuleMetaData*>* reflibs);
|
||
/*
|
||
* @brief 工作流内部编译操作
|
||
*
|
||
* 通过外部设置的参数、内部设置的参数;以及引用的类库信息;
|
||
* 生成编译器需要编译信息(主要包含:编译代码位置,引用的类库信息),并把这些信息设置到Shell环境变量;
|
||
* 最后执行comipler.sh(会去调用makfile模板-workflow.mk),编译代码。
|
||
*
|
||
* @param[in] externalParam 编译外部参数
|
||
* @param[in] innerParam 编译内部参数
|
||
* @param[in] reflibs 引用模块类库信息
|
||
* @param[in/out] errorMsg 错误信息
|
||
* @pre 要先初始化errorMsg
|
||
* @return 编译是否成功
|
||
*/
|
||
bool InnerCompiler(const SCompileParam& externalParam,const SCompileInnerParam& innerParam,std::vector<CModuleMetaData*>* reflibs,std::string& strErrorMsg);
|
||
//获取编译参数
|
||
std::string GetCompileParameters(const SCompileParam& externalParam, const SCompileInnerParam& innerParam, std::vector<
|
||
CModuleMetaData*>* reflibs);
|
||
//读取编译日志
|
||
bool ReadCompileLog(const std::string& strLogPath,std::string& strContents);
|
||
//检查编译参数
|
||
virtual bool CheckExternalParam(const SCompileParam& /*externalParam*/){ return true;}
|
||
//工作流编译环境检查
|
||
bool PreCompileCheck(const SCompileInnerParam& innerParam);
|
||
|
||
public:
|
||
//执行Shell系统调用
|
||
bool static CallSystemShell(const std::string& strCommand);
|
||
|
||
private:
|
||
std::string m_strConfigPath;
|
||
|
||
};
|
||
|
||
}
|
||
}
|
||
|
||
#endif
|