Search in sources :

Example 1 with DBConfigSuit

use of com.qlangtech.tis.db.parser.DBConfigSuit in project tis by qlangtech.

the class OfflineDatasourceAction method doGetDatasourceDbById.

/**
 * Do get datasource db. 获取一个db的git配置信息
 *
 * @param context the context
 */
public void doGetDatasourceDbById(Context context) {
    Integer dbId = this.getInt("id");
    DBConfigSuit configSuit = offlineManager.getDbConfig(this, dbId);
    this.setBizResult(context, configSuit);
}
Also used : DBConfigSuit(com.qlangtech.tis.db.parser.DBConfigSuit)

Example 2 with DBConfigSuit

use of com.qlangtech.tis.db.parser.DBConfigSuit in project tis by qlangtech.

the class OfflineManager method getDbConfig.

public DBConfigSuit getDbConfig(IPluginContext pluginContext, DatasourceDb db) {
    Objects.requireNonNull(db, "instance of DatasourceDb can not be null");
    DBDataXReaderDescName dbDataXReaderDesc = this.getDBDataXReaderDescName(db.getName());
    DataxReader dbDataxReader = null;
    if (dbDataXReaderDesc.isSupportDataXReader()) {
        dbDataxReader = getDBDataxReader(pluginContext, db.getName());
    }
    DBConfigSuit dbSuit = new DBConfigSuit(db, dbDataXReaderDesc.isSupportDataXReader(), dbDataxReader != null);
    if (dbDataxReader != null) {
        List<ISelectedTab> selectedTabs = dbDataxReader.getSelectedTabs();
        dbSuit.addTabs(selectedTabs.stream().map((t) -> t.getName()).collect(Collectors.toList()));
    }
    PostedDSProp dbProp = new PostedDSProp(db.getName(), DbScope.DETAILED);
    IPluginStore<DataSourceFactory> dbStore = TIS.getDataBasePluginStore(dbProp);
    DataSourceFactory dsPlugin = dbStore.getPlugin();
    dbSuit.setDetailed(dsPlugin);
    DataSourceFactoryPluginStore facadeStore = TIS.getDataBasePluginStore(new PostedDSProp(db.getName(), DbScope.FACADE));
    if (facadeStore.getPlugin() != null) {
        dbSuit.setFacade(facadeStore.getPlugin());
    }
    return dbSuit;
}
Also used : DBConfigSuit(com.qlangtech.tis.db.parser.DBConfigSuit) DataxReader(com.qlangtech.tis.datax.impl.DataxReader)

Example 3 with DBConfigSuit

use of com.qlangtech.tis.db.parser.DBConfigSuit in project tis by qlangtech.

the class CollectionAction method doCreate.

// /**
// * 回调获取索引创建的状态
// *
// * @param context
// * @throws Exception
// */
// public void doGetTaskStatus(Context context) throws Exception {
// JSONObject post = this.parseJsonPost();
// Integer taskId = post.getInteger(IParamContext.KEY_TASK_ID);
// boolean showLog = post.getBooleanValue(KEY_SHOW_LOG);
// 
// WorkFlowBuildHistory buildHistory = this.getWorkflowDAOFacade().getWorkFlowBuildHistoryDAO().selectByPrimaryKey(taskId);
// if (buildHistory == null) {
// throw new IllegalStateException("taskid:" + taskId + "relevant buildHistory can not be null");
// }
// if (StringUtils.isEmpty(buildHistory.getAppName())) {
// throw new IllegalStateException("the prop appname of buildHistory can not be empty");
// }
// LogReader logReader = new LogReader();
// if (showLog) {
// RpcServiceReference service = StatusRpcClient.getService(getSolrZkClient());
// PMonotorTarget.Builder t = PMonotorTarget.newBuilder();
// t.setLogtype(LogCollectorClient.convert(LogType.FULL.typeKind));
// t.setCollection(buildHistory.getAppName());
// if (taskId > 0) {
// t.setTaskid(taskId);
// }
// StatusRpcClient.AssembleSvcCompsite feedbackRpc = service.get();
// StreamObserver<PMonotorTarget> observer = feedbackRpc.registerMonitorEvent(logReader);
// observer.onNext(t.build());
// Thread.sleep(3000);
// observer.onCompleted();
// }
// Map<String, Object> bizResult = Maps.newHashMap();
// bizResult.put("status", new ExtendWorkFlowBuildHistory(buildHistory));
// if (showLog) {
// bizResult.put("log", logReader.logContent.toString());
// }
// this.setBizResult(context, bizResult);
// 
// }
/**
 * 创建索实例
 *
 * @param context
 * @throws Exception
 */
public void doCreate(Context context) throws Exception {
    JSONObject post = getIndexWithPost();
    Objects.requireNonNull(this.indexName, "indexName can not be null");
    JSONObject datasource = post.getJSONObject("datasource");
    JSONObject incrCfg = post.getJSONObject("incr");
    if (datasource == null) {
        throw new IllegalStateException("prop 'datasource' can not be null");
    }
    final String targetTable = post.getString("table");
    if (StringUtils.isEmpty(targetTable)) {
        throw new IllegalStateException("param 'table' can not be null");
    }
    // this.indexName = StringUtils.defaultIfEmpty(post.getString(KEY_INDEX_NAME), targetTable);
    List<String> existCollection = CoreAction.listCollection(this, context);
    if (existCollection.contains(this.getCollectionName())) {
        // throw new IllegalStateException();
        this.addErrorMessage(context, "index:" + this.getCollectionName() + " already exist in cloud");
        return;
    }
    PluginItems dataSourceItems = getDataSourceItems(datasource);
    if (dataSourceItems.items.size() < 1) {
        throw new IllegalStateException("datasource item can not small than 1,now:" + dataSourceItems.items.size());
    }
    TargetColumnMeta targetColMetas = getTargetColumnMeta(this, context, post, targetTable, dataSourceItems);
    if (!targetColMetas.valid) {
        return;
    }
    dataSourceItems.save(context);
    if (context.hasErrors()) {
        return;
    }
    DBConfigSuit dsDb = (DBConfigSuit) context.get(IMessageHandler.ACTION_BIZ_RESULT);
    Objects.requireNonNull(dsDb, "can not find dsDb which has insert into DB just now");
    TISTable table = new TISTable();
    table.setTableName(targetTable);
    table.setDbId(dsDb.getDbId());
    OfflineManager.ProcessedTable dsTable = offlineManager.addDatasourceTable(table, this, this, context, false, true);
    if (context.hasErrors()) {
        return;
    }
    this.setBizResult(context, new Object());
    Objects.requireNonNull(dsTable, "dsTable can not be null");
    // 开始创建DF
    final String topologyName = indexName.param;
    File parent = new File(SqlTaskNode.parent, topologyName);
    FileUtils.forceMkdir(parent);
    final SqlTaskNodeMeta.SqlDataFlowTopology topology = this.createTopology(topologyName, dsTable, targetColMetas);
    OfflineDatasourceAction.CreateTopologyUpdateCallback dbSaver = new OfflineDatasourceAction.CreateTopologyUpdateCallback(this.getUser(), this.getWorkflowDAOFacade(), true);
    WorkFlow df = dbSaver.execute(topologyName, topology);
    // 保存一个时间戳
    SqlTaskNodeMeta.persistence(topology, parent);
    boolean hasCreateCollection = false;
    Optional<Application> createdApp = Optional.empty();
    try {
        // 在在引擎节点上创建实例节点
        createdApp = this.createCollection(context, df, indexName.param, targetColMetas);
        hasCreateCollection = true;
        if (incrCfg != null) {
            logger.info("start incr channel create");
            if (!createIncrSyncChannel(context, incrCfg)) {
                return;
            }
        }
    } catch (Throwable e) {
        if (hasCreateCollection) {
            // 需要将已经 创建的索引删除
            this.deleteCollectionInCloud(context, indexName.getCollectionName());
        }
        throw e;
    }
    // 需要提交一下事务
    TransactionStatus tranStatus = (TransactionStatus) ActionContext.getContext().get(TransactionStatus.class.getSimpleName());
    Objects.requireNonNull(tranStatus, "transtatus can not be null");
    transactionManager.commit(tranStatus);
    if (!createdApp.isPresent()) {
        throw new IllegalStateException("createdApp can not be null");
    }
    // 现在需要开始触发全量索引了
    CoreAction.TriggerBuildResult triggerBuildResult = CoreAction.triggerFullIndexSwape(this, context, createdApp.get(), SHARED_COUNT);
    this.setBizResult(context, triggerBuildResult);
}
Also used : TransactionStatus(org.springframework.transaction.TransactionStatus) DBConfigSuit(com.qlangtech.tis.db.parser.DBConfigSuit) OfflineDatasourceAction(com.qlangtech.tis.offline.module.action.OfflineDatasourceAction) OfflineManager(com.qlangtech.tis.offline.module.manager.impl.OfflineManager) JSONObject(com.alibaba.fastjson.JSONObject) SqlTaskNodeMeta(com.qlangtech.tis.sql.parser.SqlTaskNodeMeta) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) Application(com.qlangtech.tis.manage.biz.dal.pojo.Application)

Aggregations

DBConfigSuit (com.qlangtech.tis.db.parser.DBConfigSuit)3 JSONObject (com.alibaba.fastjson.JSONObject)1 DataxReader (com.qlangtech.tis.datax.impl.DataxReader)1 Application (com.qlangtech.tis.manage.biz.dal.pojo.Application)1 OfflineDatasourceAction (com.qlangtech.tis.offline.module.action.OfflineDatasourceAction)1 OfflineManager (com.qlangtech.tis.offline.module.manager.impl.OfflineManager)1 SqlTaskNodeMeta (com.qlangtech.tis.sql.parser.SqlTaskNodeMeta)1 File (java.io.File)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1