use of com.qlangtech.tis.runtime.module.action.CreateIndexConfirmModel in project tis by qlangtech.
the class DataxAction method doGotoEsAppCreateConfirm.
@Func(value = PermissionConstant.APP_ADD)
public void doGotoEsAppCreateConfirm(Context context) throws Exception {
this.errorsPageShow(context);
// 这里只做schema的校验
CreateIndexConfirmModel confiemModel = parseJsonPost(CreateIndexConfirmModel.class);
String schemaContent = null;
if (confiemModel.isExpertModel()) {
schemaContent = confiemModel.getExpert().getXml();
} else {
ISearchEngineTypeTransfer typeTransfer = ISearchEngineTypeTransfer.load(this, confiemModel.getDataxName());
schemaContent = typeTransfer.mergeFromStupidModel(confiemModel.getStupid().getModel(), ISearchEngineTypeTransfer.getOriginExpertSchema(null)).toJSONString();
}
ESTableAlias esTableAlias = new ESTableAlias();
esTableAlias.setSchemaContent(schemaContent);
this.saveTableMapper(this, confiemModel.getDataxName(), Collections.singletonList(esTableAlias));
}
use of com.qlangtech.tis.runtime.module.action.CreateIndexConfirmModel in project tis by qlangtech.
the class CollectionAction method createCollection.
/**
* 创建索引实例
*
* @param context
* @param df
* @param indexName
* @param targetColMetas
* @throws Exception
*/
private Optional<Application> createCollection(Context context, WorkFlow df, String indexName, TargetColumnMeta targetColMetas) throws Exception {
Objects.requireNonNull(df, "param df can not be null");
CreateIndexConfirmModel confirmModel = new CreateIndexConfirmModel();
SelectableServer.ServerNodeTopology coreNode = new SelectableServer.ServerNodeTopology();
SelectableServer.CoreNode[] coreNodeInfo = SelectableServer.getCoreNodeInfo(this.getRequest(), this, false, true);
// FIXME 这一步应该是去掉的最终提交的host内容应该是一个ip格式的,应该是取getNodeName的内容,UI中的内容应该要改一下
for (SelectableServer.CoreNode n : coreNodeInfo) {
n.setHostName(n.getNodeName());
}
coreNode.setReplicaCount(1);
coreNode.setShardCount(SHARED_COUNT);
coreNode.setHosts(coreNodeInfo);
confirmModel.setCoreNode(coreNode);
confirmModel.setTplAppId(getTemplateApp(this).getAppId());
ExtendApp extendApp = new ExtendApp();
extendApp.setDptId(SysInitializeAction.DEPARTMENT_DEFAULT_ID);
extendApp.setName(indexName);
extendApp.setRecept(this.getUser().getName());
Objects.requireNonNull(df.getId(), "id of dataflow can not be null");
extendApp.setWorkflow(df.getId() + ":" + df.getName());
confirmModel.setAppform(extendApp);
SchemaResult schemaResult = SchemaAction.mergeWfColsWithTplCollection(this, context, null, ISchemaPluginContext.NULL, (cols, schemaParseResult) -> {
ColumnMetaData pkMeta = targetColMetas.getPKMeta();
PSchemaField field = null;
ColMetaTuple rft = null;
TargetCol tcol = null;
final Map<String, ColMetaTuple> targetCols = targetColMetas.getTargetCols();
for (ISchemaField f : schemaParseResult.getSchemaFields()) {
field = (PSchemaField) f;
rft = targetCols.get(f.getName());
if (rft == null) {
throw new IllegalStateException("field:" + f.getName() + " relevant reflect 'SchemaFieldType' can not be null");
}
boolean isPk = false;
if (StringUtils.equals(pkMeta.getKey(), field.getName())) {
// 设置主键
isPk = true;
field.setIndexed(true);
field.setType(schemaParseResult.getTisType(ReflectSchemaFieldType.STRING.literia));
} else {
field.setType(schemaParseResult.getTisType(rft.getSchemaFieldType()));
}
tcol = targetColMetas.targetColMap.get(field.getName());
if (tcol != null) {
if (tcol.isIndexable()) {
field.setIndexed(true);
}
if (rft.colMeta.getSchemaFieldType().tokenizer) {
if (StringUtils.isNotEmpty(tcol.getToken())) {
field.setTokenizerType(tcol.getToken());
} else {
// 主键不需要分词
if (!isPk && rft.isTypeOf(ReflectSchemaFieldType.STRING)) {
// String类型默认使用like分词
field.setTokenizerType(ReflectSchemaFieldType.LIKE.literia);
}
}
}
}
}
schemaParseResult.setUniqueKey(pkMeta.getKey());
schemaParseResult.setSharedKey(pkMeta.getKey());
});
// 创建索引实例
return this.createCollection(context, confirmModel, schemaResult, (ctx, app, publishSnapshotId, schemaContent) -> {
return this.createNewApp(ctx, app, publishSnapshotId, schemaContent);
});
}
Aggregations