Search in sources :

Example 1 with WorkFlowCriteria

use of com.qlangtech.tis.workflow.pojo.WorkFlowCriteria in project tis by qlangtech.

the class OfflineDatasourceAction method getWorkflowId.

private Integer getWorkflowId(String topologyName) {
    // return SqlTaskNodeMeta.getTopologyProfile(topologyName).getDataflowId();
    WorkFlowCriteria wc = new WorkFlowCriteria();
    wc.createCriteria().andNameEqualTo(topologyName);
    List<WorkFlow> workFlows = this.getWorkflowDAOFacade().getWorkFlowDAO().selectByExample(wc);
    for (WorkFlow wf : workFlows) {
        // topologyPojo.setDataflowId(wf.getId());
        return wf.getId();
    }
    throw new IllegalStateException("topology:" + topologyName + " can not find workflow record in db");
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria)

Example 2 with WorkFlowCriteria

use of com.qlangtech.tis.workflow.pojo.WorkFlowCriteria in project tis by qlangtech.

the class TestCollectionAction method clearUpDB.

private void clearUpDB() {
    IWorkflowDAOFacade wfDaoFacade = applicationContext.getBean("wfDaoFacade", IWorkflowDAOFacade.class);
    DatasourceTableCriteria tabCriteria = new DatasourceTableCriteria();
    tabCriteria.createCriteria().andNameEqualTo(TEST_TABLE_EMPLOYEES_NAME);
    wfDaoFacade.getDatasourceTableDAO().deleteByExample(tabCriteria);
    DatasourceDbCriteria dbCriteria = new DatasourceDbCriteria();
    dbCriteria.createCriteria().andNameEqualTo(TEST_DS_NAME);
    wfDaoFacade.getDatasourceDbDAO().deleteByExample(dbCriteria);
    WorkFlowCriteria wfCriteria = new WorkFlowCriteria();
    wfCriteria.createCriteria().andNameEqualTo(TEST_TABLE_EMPLOYEES_NAME);
    wfDaoFacade.getWorkFlowDAO().deleteByExample(wfCriteria);
    // daoContext" class="com.qlangtech.tis.manage.common.RunContextImpl
    RunContext daoContext = applicationContext.getBean("daoContext", RunContext.class);
    ApplicationCriteria appCriteria = new ApplicationCriteria();
    appCriteria.createCriteria().andProjectNameEqualTo(TISCollectionUtils.NAME_PREFIX + TEST_TABLE_EMPLOYEES_NAME);
    for (Application app : daoContext.getApplicationDAO().selectByExample(appCriteria)) {
        ServerGroupCriteria sgCriteria = new ServerGroupCriteria();
        sgCriteria.createCriteria().andAppIdEqualTo(app.getAppId());
        daoContext.getServerGroupDAO().deleteByExample(sgCriteria);
    }
    daoContext.getApplicationDAO().deleteByExample(appCriteria);
    for (Long gid : daoContext.getServerGroupDAO().getServergroupWithoutAppReference()) {
        // assertNotNull(g.getGid());
        daoContext.getServerGroupDAO().deleteByPrimaryKey(gid.intValue());
    }
// select g.gid
// from server_group g left join application a on g.app_id = a.app_id
// where a.app_id is null
}
Also used : ApplicationCriteria(com.qlangtech.tis.manage.biz.dal.pojo.ApplicationCriteria) DatasourceTableCriteria(com.qlangtech.tis.workflow.pojo.DatasourceTableCriteria) ServerGroupCriteria(com.qlangtech.tis.manage.biz.dal.pojo.ServerGroupCriteria) IWorkflowDAOFacade(com.qlangtech.tis.workflow.dao.IWorkflowDAOFacade) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) DatasourceDbCriteria(com.qlangtech.tis.workflow.pojo.DatasourceDbCriteria) Application(com.qlangtech.tis.manage.biz.dal.pojo.Application)

Example 3 with WorkFlowCriteria

use of com.qlangtech.tis.workflow.pojo.WorkFlowCriteria 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);
}
Also used : PrimaryTableMeta(com.qlangtech.tis.sql.parser.er.PrimaryTableMeta) TableRelation(com.qlangtech.tis.sql.parser.er.TableRelation) SqlDataFlowTopology(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology) WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria) ERRules(com.qlangtech.tis.sql.parser.er.ERRules) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 4 with WorkFlowCriteria

use of com.qlangtech.tis.workflow.pojo.WorkFlowCriteria in project tis by qlangtech.

the class OfflineDatasourceAction method doGetWorkflows.

// /**
// * Do get commit version diff. 获取两个版本的变更记录
// *
// * @param context the context
// * @throws Exception the exception
// */
// public void doGetCommitVersionDiff(Context context) throws Exception {
// String fromVersion = this.getString("fromVersion");
// String toVersion = this.getString("toVersion");
// if (StringUtils.isBlank(fromVersion) || fromVersion.length() != 40) {
// this.addErrorMessage(context, "fromVersion版本号错误");
// return;
// }
// if (StringUtils.isBlank(toVersion) || toVersion.length() != 40) {
// this.addErrorMessage(context, "toVersion版本号错误");
// return;
// }
// String directory = this.getString("directory");
// int projectId;
// if (StringUtils.equals("datasource_daily", directory)) {
// projectId = GitUtils.DATASOURCE_PROJECT_ID;
// } else if (StringUtils.equals("datasource_online", directory)) {
// projectId = GitUtils.DATASOURCE_PROJECT_ID;
// } else if (StringUtils.equals("workflow", directory)) {
// projectId = GitUtils.WORKFLOW_GIT_PROJECT_ID;
// } else {
// throw new RuntimeException("directory = " + directory + " is wrong!");
// }
// GitCommitVersionDiff diff = GitUtils.$().getGitCommitVersionDiff(fromVersion, toVersion, projectId);
// this.setBizResult(context, diff);
// }
/**
 * Do get workflows. 获取去数据库查找所有工作流
 *
 * @param context the context
 * @throws Exception the exception
 */
public void doGetWorkflows(Context context) throws Exception {
    Pager pager = createPager();
    IWorkFlowDAO wfDAO = this.getWorkflowDAOFacade().getWorkFlowDAO();
    WorkFlowCriteria query = new WorkFlowCriteria();
    query.createCriteria();
    query.setOrderByClause("id desc");
    pager.setTotalCount(wfDAO.countByExample(query));
    this.setBizResult(context, new PaginationResult(pager, wfDAO.selectByExample(query, pager.getCurPage(), pager.getRowsPerPage())));
}
Also used : Pager(com.koubei.web.tag.pager.Pager) IWorkFlowDAO(com.qlangtech.tis.workflow.dao.IWorkFlowDAO) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria)

Example 5 with WorkFlowCriteria

use of com.qlangtech.tis.workflow.pojo.WorkFlowCriteria in project tis by qlangtech.

the class SchemaAction method getWorkflow.

private WorkFlow getWorkflow(String wfName) {
    WorkFlowCriteria wquery = new WorkFlowCriteria();
    wquery.createCriteria().andNameEqualTo(wfName);
    List<WorkFlow> workFlows = this.getWorkflowDAOFacade().getWorkFlowDAO().selectByExample(wquery, 1, 1);
    Optional<WorkFlow> first = workFlows.stream().findFirst();
    if (!first.isPresent()) {
        throw new IllegalStateException("workflow:" + wfName + " can not find relevant instance in db");
    }
    return first.get();
}
Also used : WorkFlow(com.qlangtech.tis.workflow.pojo.WorkFlow) WorkFlowCriteria(com.qlangtech.tis.workflow.pojo.WorkFlowCriteria)

Aggregations

WorkFlowCriteria (com.qlangtech.tis.workflow.pojo.WorkFlowCriteria)5 WorkFlow (com.qlangtech.tis.workflow.pojo.WorkFlow)3 Pager (com.koubei.web.tag.pager.Pager)1 Application (com.qlangtech.tis.manage.biz.dal.pojo.Application)1 ApplicationCriteria (com.qlangtech.tis.manage.biz.dal.pojo.ApplicationCriteria)1 ServerGroupCriteria (com.qlangtech.tis.manage.biz.dal.pojo.ServerGroupCriteria)1 Func (com.qlangtech.tis.manage.spring.aop.Func)1 SqlDataFlowTopology (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta.SqlDataFlowTopology)1 ERRules (com.qlangtech.tis.sql.parser.er.ERRules)1 PrimaryTableMeta (com.qlangtech.tis.sql.parser.er.PrimaryTableMeta)1 TableRelation (com.qlangtech.tis.sql.parser.er.TableRelation)1 IWorkFlowDAO (com.qlangtech.tis.workflow.dao.IWorkFlowDAO)1 IWorkflowDAOFacade (com.qlangtech.tis.workflow.dao.IWorkflowDAOFacade)1 DatasourceDbCriteria (com.qlangtech.tis.workflow.pojo.DatasourceDbCriteria)1 DatasourceTableCriteria (com.qlangtech.tis.workflow.pojo.DatasourceTableCriteria)1