use of com.qlangtech.tis.manage.spring.aop.Func in project tis by qlangtech.
the class FullbuildWorkflowAction method doCreateNewTask.
/**
* assemble 节点接收到来自console节点的触发任务,开始执行需要创建一个new的workflowbuildhistory记录
*
* @param context
*/
@Func(value = PermissionConstant.DATAFLOW_MANAGE, sideEffect = false)
public void doCreateNewTask(Context context) {
final TriggerType triggerType = TriggerType.parse(this.getInt(IFullBuildContext.KEY_TRIGGER_TYPE));
Application app = null;
// appname 可以为空
String appname = this.getString(IFullBuildContext.KEY_APP_NAME);
if (StringUtils.isNotBlank(appname)) {
app = this.getApplicationDAO().selectByName(appname);
if (app == null) {
throw new IllegalStateException("appname:" + appname + " relevant app pojo is not exist");
}
}
WorkFlowBuildHistory task = new WorkFlowBuildHistory();
task.setCreateTime(new Date());
task.setStartTime(new Date());
// task.setWorkFlowId(worflowid);
task.setTriggerType(triggerType.getValue());
task.setState((byte) ExecResult.DOING.getValue());
// Integer buildHistoryId = null;
// 从什么阶段开始执行
FullbuildPhase fromPhase = FullbuildPhase.parse(getInt(IParamContext.COMPONENT_START, FullbuildPhase.FullDump.getValue()));
FullbuildPhase endPhase = FullbuildPhase.parse(getInt(IParamContext.COMPONENT_END, FullbuildPhase.IndexBackFlow.getValue()));
if (app == null) {
if (endPhase.bigThan(FullbuildPhase.JOIN)) {
endPhase = FullbuildPhase.JOIN;
}
}
if (fromPhase.getValue() > FullbuildPhase.FullDump.getValue()) {
// 如果是从非第一步开始执行的话,需要客户端提供依赖的history记录id
task.setHistoryId(this.getInt(IFullBuildContext.KEY_BUILD_HISTORY_TASK_ID));
}
// 说明只有workflow的流程和索引没有关系,所以不可能执行到索引build阶段去
// task.setEndPhase((app == null) ? FullbuildPhase.JOIN.getValue() : FullbuildPhase.IndexBackFlow.getValue());
task.setEndPhase(endPhase.getValue());
task.setStartPhase(fromPhase.getValue());
if (app != null) {
task.setAppId(app.getAppId());
task.setAppName(app.getProjectName());
}
// 生成一个新的taskid
this.setBizResult(context, new CreateNewTaskResult(getHistoryDAO().insertSelective(task), app));
}
use of com.qlangtech.tis.manage.spring.aop.Func in project tis by qlangtech.
the class OfflineDatasourceAction method doGetDsRelevantReaderDesc.
@Func(value = PermissionConstant.PERMISSION_DATASOURCE_EDIT, sideEffect = false)
public void doGetDsRelevantReaderDesc(Context context) {
com.alibaba.fastjson.JSONObject form = this.parseJsonPost();
Integer dbId = form.getInteger("dbId");
if (dbId == null) {
throw new IllegalStateException("dbId can not be null");
}
com.qlangtech.tis.workflow.pojo.DatasourceDb db = this.offlineDAOFacade.getDatasourceDbDAO().selectByPrimaryKey(dbId);
// IPluginStore<DataSourceFactory> dbPlugin = TIS.getDataBasePluginStore(new PostedDSProp(db.getName(), DbScope.DETAILED));
// DataSourceFactory.BaseDataSourceFactoryDescriptor descriptor = (DataSourceFactory.BaseDataSourceFactoryDescriptor) dbPlugin.getPlugin().getDescriptor();
OfflineManager.DBDataXReaderDescName defaultDataXReaderDescName = offlineManager.getDBDataXReaderDescName(db.getName());
Map<String, Object> result = Maps.newHashMap();
if (!defaultDataXReaderDescName.readerDescName.isPresent()) {
// throw new IllegalStateException("datasource:" + db.getName() + " desc:" + descriptor.getDisplayName() + " has not relevant DataXReader defined");
// result.put(KEY_DATA_READER_SETTED + "NotSupport", descriptor.getId());
this.addErrorMessage(context, "插件:" + defaultDataXReaderDescName.dsDescriptor.getId() + " 不支持表导入");
return;
}
DataxReader dataxReader = OfflineManager.getDBDataxReader(this, db.getName());
if (dataxReader != null) {
result.put(KEY_DATA_READER_SETTED, true);
// this.setBizResult(context, result);
// return;
}
DescriptorExtensionList<DataxReader, Descriptor<DataxReader>> descriptorList = TIS.get().getDescriptorList(DataxReader.class);
Optional<DataxReader.BaseDataxReaderDescriptor> dataXReaderDesc = descriptorList.stream().filter((de) -> {
return defaultDataXReaderDescName.getReaderDescName().equals(de.getDisplayName());
}).map((d) -> (DataxReader.BaseDataxReaderDescriptor) d).findFirst();
if (!dataXReaderDesc.isPresent()) {
throw new IllegalStateException("DataXReaderDescName:" + defaultDataXReaderDescName.getReaderDescName() + " can not find relevant DataXReader Descriptor");
}
result.put("readerDesc", new DescriptorsJSON(dataXReaderDesc.get()).getDescriptorsJSON());
result.put("processMeta", DataxAction.getDataXBasicProcessMetaByReader(dataXReaderDesc.get()));
this.setBizResult(context, result);
}
use of com.qlangtech.tis.manage.spring.aop.Func in project tis by qlangtech.
the class OfflineDatasourceAction method doSaveErRule.
/**
* 保存ER关系
*
* @param context
* @throws Exception
*/
@Func(value = PermissionConstant.DATAFLOW_UPDATE)
public void doSaveErRule(Context context) throws Exception {
com.alibaba.fastjson.JSONObject j = this.parseJsonPost();
ERRules erRules = new ERRules();
final String topology = j.getString("topologyName");
if (StringUtils.isEmpty(topology)) {
throw new IllegalArgumentException("param 'topology' can not be empty");
}
SqlDataFlowTopology df = SqlTaskNodeMeta.getSqlDataFlowTopology(topology);
com.alibaba.fastjson.JSONArray edges = j.getJSONArray("edges");
com.alibaba.fastjson.JSONArray nodes = j.getJSONArray("nodes");
com.alibaba.fastjson.JSONObject edge = null;
com.alibaba.fastjson.JSONObject sourceNode = null;
com.alibaba.fastjson.JSONObject targetNode = null;
com.alibaba.fastjson.JSONObject linkrule = null;
com.alibaba.fastjson.JSONArray linkKeyList = null;
com.alibaba.fastjson.JSONObject link = null;
com.alibaba.fastjson.JSONObject nodeTuple = null;
com.alibaba.fastjson.JSONObject node = null;
com.alibaba.fastjson.JSONObject ermeta = null;
TableRelation erRelation = null;
for (int i = 0; i < edges.size(); i++) {
edge = edges.getJSONObject(i);
sourceNode = edge.getJSONObject("sourceNode");
// getTableName(sourceNode);
targetNode = edge.getJSONObject("targetNode");
// getTableName(targetNode);
linkrule = edge.getJSONObject("linkrule");
if (linkrule == null) {
throw new IllegalStateException("linkrule can not be null");
}
erRelation = $(edge.getString("id"), df, getTableName(targetNode), getTableName(sourceNode), TabCardinality.parse(linkrule.getString("cardinality")));
linkKeyList = linkrule.getJSONArray("linkKeyList");
for (int jj = 0; jj < linkKeyList.size(); jj++) {
link = linkKeyList.getJSONObject(jj);
erRelation.addJoinerKey(link.getString("parentKey"), link.getString("childKey"));
}
erRules.addRelation(erRelation);
}
com.alibaba.fastjson.JSONObject nodeMeta = null;
com.alibaba.fastjson.JSONObject colTransfer = null;
DependencyNode dumpNode = null;
com.alibaba.fastjson.JSONArray columnTransferList = null;
TabExtraMeta tabMeta = null;
String sharedKey = null;
for (int index = 0; index < nodes.size(); index++) {
nodeTuple = nodes.getJSONObject(index);
node = nodeTuple.getJSONObject("node");
ermeta = node.getJSONObject("extraMeta");
dumpNode = new DependencyNode();
if (ermeta != null) {
tabMeta = new TabExtraMeta();
tabMeta.setPrimaryIndexTab(ermeta.getBoolean("primaryIndexTab"));
if (tabMeta.isPrimaryIndexTab()) {
sharedKey = ermeta.getString("sharedKey");
tabMeta.setSharedKey(sharedKey);
com.alibaba.fastjson.JSONArray primaryIndexColumnNames = ermeta.getJSONArray("primaryIndexColumnNames");
com.alibaba.fastjson.JSONObject primaryIndex = null;
List<PrimaryLinkKey> names = Lists.newArrayList();
PrimaryLinkKey plinkKey = null;
for (int i = 0; i < primaryIndexColumnNames.size(); i++) {
primaryIndex = primaryIndexColumnNames.getJSONObject(i);
plinkKey = new PrimaryLinkKey();
plinkKey.setName(primaryIndex.getString("name"));
plinkKey.setPk(primaryIndex.getBoolean("pk"));
names.add(plinkKey);
}
tabMeta.setPrimaryIndexColumnNames(names);
}
tabMeta.setMonitorTrigger(ermeta.getBoolean("monitorTrigger"));
tabMeta.setTimeVerColName(null);
if (tabMeta.isMonitorTrigger()) {
tabMeta.setTimeVerColName(ermeta.getString("timeVerColName"));
}
columnTransferList = ermeta.getJSONArray("columnTransferList");
for (int i = 0; i < columnTransferList.size(); i++) {
colTransfer = columnTransferList.getJSONObject(i);
tabMeta.addColumnTransfer(new ColumnTransfer(colTransfer.getString("colKey"), colTransfer.getString("transfer"), colTransfer.getString("param")));
}
dumpNode.setExtraMeta(tabMeta);
}
dumpNode.setId(node.getString("id"));
nodeMeta = node.getJSONObject("nodeMeta");
dumpNode.setTabid(nodeMeta.getString("tabid"));
dumpNode.setDbid(nodeMeta.getString("dbid"));
Position pos = new Position();
pos.setX(node.getIntValue("x"));
pos.setY(node.getIntValue("y"));
dumpNode.setPosition(pos);
dumpNode.setName(nodeMeta.getString("tabname"));
// dumpNode.setExtraSql(nodeMeta.getString("sqlcontent"));
erRules.addDumpNode(dumpNode);
}
List<PrimaryTableMeta> primaryTabs = erRules.getPrimaryTabs();
if (primaryTabs.size() < 1) {
this.addErrorMessage(context, "还没有定义ER主索引表");
return;
}
List<PrimaryLinkKey> pkNames = null;
for (PrimaryTableMeta meta : primaryTabs) {
if (StringUtils.isEmpty(meta.getSharedKey())) {
this.addErrorMessage(context, "主索引表:" + meta.getTabName() + " 还未定义分区键");
}
pkNames = meta.getPrimaryKeyNames();
if (pkNames.size() < 1) {
this.addErrorMessage(context, "主索引表:" + meta.getTabName() + " 还未定义主键");
}
}
if (this.hasErrors(context)) {
return;
}
// File parent = new File(SqlTaskNode.parent, topology);
// FileUtils.forceMkdir(parent);
// FileUtils.write(new File(parent, ERRules.ER_RULES_FILE_NAME), ERRules.serialize(erRules), getEncode(), false);
ERRules.write(topology, erRules);
// System.out.println(j.toJSONString());
long wfId = df.getProfile().getDataflowId();
if (wfId < 1) {
throw new IllegalStateException("topology '" + topology + "' relevant wfid can not be null");
}
WorkFlow wf = new WorkFlow();
wf.setOpTime(new Date());
WorkFlowCriteria wfCriteria = new WorkFlowCriteria();
wfCriteria.createCriteria().andIdEqualTo((int) wfId);
this.getWorkflowDAOFacade().getWorkFlowDAO().updateByExampleSelective(wf, wfCriteria);
}
use of com.qlangtech.tis.manage.spring.aop.Func in project tis by qlangtech.
the class OfflineDatasourceAction method doDeleteDatasourceDbById.
/**
* 删除db
*
* @param context
*/
@Func(value = PermissionConstant.PERMISSION_DATASOURCE_EDIT)
public void doDeleteDatasourceDbById(Context context) throws Exception {
Integer id = this.getInt("id");
Objects.requireNonNull(id, "param id can not be null");
DbScope dbModel = DbScope.parse(this.getString("dbModel"));
this.offlineManager.deleteDbById(id, dbModel, this, context);
}
use of com.qlangtech.tis.manage.spring.aop.Func in project tis by qlangtech.
the class OperationLogInterceptor method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
BasicModule action = (BasicModule) invocation.getAction();
final Method method = action.getExecuteMethod();
final String result = invocation.invoke();
Func func = method.getAnnotation(Func.class);
if (func != null && !func.sideEffect()) {
return result;
}
AppDomainInfo appDomain = CheckAppDomainExistValve.getAppDomain(daoContext);
OperationLog log = new OperationLog();
log.setOpType(BasicModule.parseMehtodName());
if (StringUtils.startsWith(log.getOpType(), "doGet")) {
return result;
}
log.setCreateTime(new Date());
if (!(appDomain instanceof Nullable)) {
log.setAppName(appDomain.getAppName());
}
ActionProxy proxy = invocation.getProxy();
// log.setOpType(proxy.getMethod());
HttpServletRequest request = ServletActionContext.getRequest();
if (StringUtils.indexOf(request.getClass().getSimpleName(), "Mock") > -1) {
// 当前是测试流程的话就不需要记录日志了
return result;
}
IUser user = UserUtils.getUser(request, daoContext);
if (user == null) {
throw new IllegalStateException("user can not be null");
}
StringBuffer jsonObject = new StringBuffer();
JSONObject params = null;
Map<String, String[]> paramsMap = null;
String url = request.getRequestURL().toString();
jsonObject.append("request:");
jsonObject.append(url).append("\n");
String requestBody = null;
if (!ConfigFileContext.HTTPMethod.GET.name().equals(request.getMethod())) {
paramsMap = request.getParameterMap();
if (paramsMap.size() > 0) {
params = new JSONObject();
for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
if (entry.getValue().length == 1) {
params.put(entry.getKey(), entry.getValue()[0]);
} else {
params.put(entry.getKey(), entry.getValue());
}
}
jsonObject.append("params:").append("\n");
jsonObject.append(params.toString(1)).append("\n");
}
try (ServletInputStream input = request.getInputStream()) {
if (!input.isFinished()) {
requestBody = IOUtils.toString(input, TisUTF8.get());
jsonObject.append("body:").append("\n");
jsonObject.append(requestBody).append("\n");
}
}
}
Context context = new MockContext();
jsonObject.append("\n=================================");
jsonObject.append("response:").append("\n");
jsonObject.append(AjaxValve.buildResultStruct(context));
log.setTabName(proxy.getActionName());
log.setUsrId(user.getId());
log.setUsrName(user.getName());
log.setOpDesc(jsonObject.toString());
operationLogDAO.insertSelective(log);
return result;
}
Aggregations