Search in sources :

Example 1 with FCoreRequest

use of com.qlangtech.tis.coredefine.biz.FCoreRequest in project tis by qlangtech.

the class CoreAction method doCreateCore.

/**
 * 创建一个应用
 */
@SuppressWarnings("all")
@Func(PermissionConstant.APP_INITIALIZATION)
public void doCreateCore(final Context context) throws Exception {
    final Integer groupNum = this.getInt("group");
    // 最大组内副本数目 改过了
    final Integer repliation = this.getInt("replica");
    if (groupNum == null || groupNum < 1) {
        this.addErrorMessage(context, "组数不能小于1");
        return;
    }
    if (repliation == null || repliation < 1) {
        this.addErrorMessage(context, "组内副本数不能小于1");
        return;
    }
    FCoreRequest request = createCoreRequest(context, groupNum, repliation, "创建", true);
    this.createCollection(this, context, groupNum, repliation, request, this.getServerGroup0().getPublishSnapshotId());
}
Also used : FCoreRequest(com.qlangtech.tis.coredefine.biz.FCoreRequest) Func(com.qlangtech.tis.manage.spring.aop.Func)

Example 2 with FCoreRequest

use of com.qlangtech.tis.coredefine.biz.FCoreRequest in project tis by qlangtech.

the class CoreAction method createCoreRequest.

/**
 * @param context
 * @param assignGroupCount 已经分配到的group数量
 * @param group            添加的组数
 * @param replica
 * @param setVerbs
 * @return
 */
private FCoreRequest createCoreRequest(Context context, int assignGroupCount, int group, int replica, String setVerbs, boolean isAppNameAware, boolean mustSelectMoreOneReplicAtLeast) {
    // boolean valid = false;
    // CoreRequest request = ;
    CoreRequest coreRequest = createIps(context, this.getCollectionName(), null);
    FCoreRequest result = new FCoreRequest(coreRequest, assignGroupCount + group, assignGroupCount);
    // StringBuffer addserverSummary = new StringBuffer();
    // 不用为单独的一个组设置服务ip地址
    final int GROUP_SIZE = 1;
    for (int i = 0; i < GROUP_SIZE; i++) {
        ParseIpResult parseResult = parseIps(context, String.valueOf(assignGroupCount + i), isAppNameAware, mustSelectMoreOneReplicAtLeast);
        if (parseResult.valid && parseResult.ips.length > 0) {
            if ((parseResult.ips.length * MAX_SHARDS_PER_NODE) < (group * replica)) {
                this.addErrorMessage(context, "您选择的机器节点不足,至少要" + ((group * replica) / MAX_SHARDS_PER_NODE) + "台机器");
            // if (replica < parseResult.ips.length) {
            // this.addErrorMessage(context, "第" + (assignGroupCount +
            // i)
            // + "组," + setVerbs + "副本数目最大为" + replica + "台");
            } else {
                // for (int j = 0; j < replica; j++) {
                for (int j = 0; j < parseResult.ips.length; j++) {
                    result.addNodeIps((assignGroupCount + i), parseResult.ips[j]);
                }
                // addserverSummary.append()
                // this.addActionMessage(context, "第" + (assignGroupCount +
                // i)
                // + "组," + setVerbs + "副本机为" + parseResult.ipLiteria);
                this.addActionMessage(context, "选择的机器为:" + parseResult.ipLiteria);
                result.setValid(true);
            }
        }
    }
    if (!result.isValid()) {
        this.addErrorMessage(context, "请至少为任何一组添加一个以上副本节点");
    }
    return result;
}
Also used : FCoreRequest(com.qlangtech.tis.coredefine.biz.FCoreRequest) FCoreRequest(com.qlangtech.tis.coredefine.biz.FCoreRequest)

Example 3 with FCoreRequest

use of com.qlangtech.tis.coredefine.biz.FCoreRequest in project tis by qlangtech.

the class AddAppAction method createCollection.

protected Optional<Application> createCollection(Context context, CreateIndexConfirmModel confiemModel, SchemaResult schemaResult, ICreateNewApp appCreator) throws Exception {
    ExtendApp extApp = confiemModel.getAppform();
    appendPrefix(extApp);
    String workflow = confiemModel.getAppform().getWorkflow();
    if (StringUtils.isBlank(workflow)) {
        this.addErrorMessage(context, "缺少全量数据流信息");
        return Optional.empty();
    }
    final String[] candidateNodeIps = confiemModel.getCoreNodeCandidate();
    if (candidateNodeIps == null || candidateNodeIps.length < 1) {
        this.addErrorMessage(context, "请选择引擎节点");
        return Optional.empty();
    }
    if (!schemaResult.isSuccess()) {
        return Optional.empty();
    }
    Application app = new Application();
    app.setAppId(confiemModel.getTplAppId());
    Integer publishSnapshotId = getPublishSnapshotId(this.getServerGroupDAO(), app);
    byte[] content = schemaResult.content;
    SelectableServer.ServerNodeTopology coreNode = confiemModel.getCoreNode();
    final int gourpCount = coreNode.getShardCount();
    int repliation = coreNode.getReplicaCount();
    // 由于是在日常环境中,默认就是设置为 1*1
    FCoreRequest request = new FCoreRequest(CoreAction.createIps(context, extApp.getProjectName(), candidateNodeIps), gourpCount);
    for (String ip : candidateNodeIps) {
        request.addNodeIps(gourpCount - 1, ip);
    }
    request.setValid(true);
    CreateAppResult createResult = appCreator.createNewApp(context, extApp, publishSnapshotId, content);
    if (!createResult.isSuccess()) {
        return Optional.of(app);
    }
    IAppSource.save(this, extApp.getProjectName(), extApp.createAppSource(this));
    /**
     * *************************************************************************************
     * 因为这里数据库的事务还没有提交,需要先将schema配置信息保存到缓存中去以便solrcore节点能获取到
     * 设置缓存
     * **************************************************************************************
     */
    final AppKey appKey = AppKey.create(extApp.getProjectName());
    if (!(createResult instanceof CreateSnapshotResult)) {
        throw new IllegalStateException("instance of createResult must be CreateSnapshotResult");
    }
    CreateSnapshotResult snapshotResult = (CreateSnapshotResult) createResult;
    appKey.setTargetSnapshotId((long) snapshotResult.getNewId());
    appKey.setFromCache(false);
    appKeyProcess.process(appKey);
    LoadSolrCoreConfigByAppNameServlet.getSnapshotDomain(ConfigFileReader.getConfigList(), appKey, this);
    CoreAction.createCollection(this, context, gourpCount, repliation, request, snapshotResult.getNewId());
    return Optional.of(app);
}
Also used : SelectableServer(com.qlangtech.tis.coredefine.module.control.SelectableServer) FCoreRequest(com.qlangtech.tis.coredefine.biz.FCoreRequest) AppKey(com.qlangtech.tis.openapi.impl.AppKey)

Aggregations

FCoreRequest (com.qlangtech.tis.coredefine.biz.FCoreRequest)3 SelectableServer (com.qlangtech.tis.coredefine.module.control.SelectableServer)1 Func (com.qlangtech.tis.manage.spring.aop.Func)1 AppKey (com.qlangtech.tis.openapi.impl.AppKey)1