Search in sources :

Example 1 with StreamProcess

use of com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess in project tis by qlangtech.

the class IndexBackflowManager method getCallbackResult.

/**
 * 轮询是否回流完成
 *
 * @param replica
 * @param url
 * @return
 */
private BackflowResult getCallbackResult(Replica replica, URL url) {
    int applyCount = 0;
    BackflowResult callbackResult = null;
    while (applyCount++ < MAX_RETRY) {
        callbackResult = HttpUtils.processContent(url, new StreamProcess<BackflowResult>() {

            @Override
            public BackflowResult p(int status, InputStream stream, Map<String, List<String>> headerFields) {
                BackflowResult callbackResult = null;
                try {
                    String body = IOUtils.toString(stream, TisUTF8.get());
                    callbackResult = JSON.parseObject(body, BackflowResult.class);
                    callbackResult.setResponseBody(body);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                return callbackResult;
            }
        }, 10);
        NodeBackflowStatus nodeStatus = getReplicaNodeStatus(replica);
        nodeStatus.setWaiting(false);
        if (callbackResult.isFaild()) {
            log.error(replica.getCoreUrl() + ",index back faild:" + callbackResult.getMsg() + "\n body:" + callbackResult.getResponseBody());
            nodeStatus.setFaild(true);
            return callbackResult;
        }
        String coreName = null;
        if (!callbackResult.isSuccess()) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            coreName = replica.getStr(CORE_NAME_PROP);
            log.info("waitting index flowback " + coreName + "," + callbackResult.getCopyStatus() + "retry count:" + applyCount + ",remain:" + this.replicaCountDown.getCount() + "nodes");
            // ▼▼▼ 取得当前阶段的执行状态
            nodeStatus.setAllSize((int) callbackResult.indexflowback_status.getAll());
            nodeStatus.setReaded((int) callbackResult.indexflowback_status.getReaded());
            // ▲▲▲
            continue;
        } else {
            callbackResult.getCopyStatus();
            // 执行完成
            final int allSize = (int) callbackResult.indexflowback_status.getAll();
            nodeStatus.setAllSize(allSize);
            nodeStatus.setReaded(allSize);
            nodeStatus.setComplete(true);
        }
        return callbackResult;
    }
    if (applyCount >= MAX_RETRY) {
        log.error(replica.getStr(CORE_NAME_PROP) + " index back faild:exceed the max retry count " + MAX_RETRY);
    }
    return callbackResult;
}
Also used : StreamProcess(com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess) InputStream(java.io.InputStream) NodeBackflowStatus(com.qlangtech.tis.fullbuild.phasestatus.impl.IndexBackFlowPhaseStatus.NodeBackflowStatus) IOException(java.io.IOException)

Example 2 with StreamProcess

use of com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess in project tis by qlangtech.

the class CoreAction method pushConfig2Engine.

public static void pushConfig2Engine(BasicModule module, Context context, DocCollection collection, int snapshotId, boolean needReload) throws Exception {
    // module.errorsPageShow(context);
    if (traverseCollectionReplic(collection, false, /* collection */
    new ReplicaCallback() {

        @Override
        public boolean process(boolean isLeader, final Replica replica) throws Exception {
            try {
                URL url = new URL(replica.getStr(BASE_URL_PROP) + "/admin/cores?action=CREATEALIAS&" + ICoreAdminAction.EXEC_ACTION + "=" + ICoreAdminAction.ACTION_UPDATE_CONFIG + "&core=" + replica.getStr(CORE_NAME_PROP) + "&" + ZkStateReader.COLLECTION_PROP + "=" + collection.getName() + "&needReload=" + needReload + "&" + ICoreAdminAction.TARGET_SNAPSHOT_ID + "=" + snapshotId);
                return HttpUtils.processContent(url, new StreamProcess<Boolean>() {

                    @Override
                    public Boolean p(int status, InputStream stream, Map<String, List<String>> headerFields) {
                        ProcessResponse result = null;
                        if ((result = ProcessResponse.processResponse(stream, (err) -> module.addErrorMessage(context, replica.getName() + "," + err))).success) {
                        // addActionMessage(context, "成功触发了创建索引集群" + groupNum + "组,组内" + repliationCount + "个副本");
                        // return true;
                        }
                        return true;
                    }
                });
            } catch (MalformedURLException e) {
                // e.printStackTrace();
                log.error(collection.getName(), e);
                module.addErrorMessage(context, e.getMessage());
            }
            return true;
        }
    })) {
    // module.addActionMessage(context, "已经更新全部服务器配置文件");
    }
}
Also used : ServerGroupAdapter(com.qlangtech.tis.runtime.pojo.ServerGroupAdapter) StringUtils(org.apache.commons.lang.StringUtils) IExecChainContext(com.qlangtech.tis.exec.IExecChainContext) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) URL(java.net.URL) TIS(com.qlangtech.tis.TIS) IndexStreamCodeGenerator(com.qlangtech.tis.compiler.streamcode.IndexStreamCodeGenerator) LoggerFactory(org.slf4j.LoggerFactory) com.qlangtech.tis.manage(com.qlangtech.tis.manage) ExecResult(com.qlangtech.tis.assemble.ExecResult) CORE_NAME_PROP(org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP) Stat(org.apache.zookeeper.data.Stat) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) DBNode(com.qlangtech.tis.sql.parser.DBNode) SolrServerException(org.apache.solr.client.solrj.SolrServerException) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) BASE_URL_PROP(org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP) GenerateDAOAndIncrScript(com.qlangtech.tis.compiler.streamcode.GenerateDAOAndIncrScript) SelectableServer(com.qlangtech.tis.coredefine.module.control.SelectableServer) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) PostParam(com.qlangtech.tis.manage.common.HttpUtils.PostParam) com.qlangtech.tis.manage.biz.dal.pojo(com.qlangtech.tis.manage.biz.dal.pojo) IStreamIncrGenerateStrategy(com.qlangtech.tis.sql.parser.tuple.creator.IStreamIncrGenerateStrategy) IncrStreamFactory(com.qlangtech.tis.plugin.incr.IncrStreamFactory) org.apache.solr.common.cloud(org.apache.solr.common.cloud) com.qlangtech.tis.manage.common(com.qlangtech.tis.manage.common) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) Descriptor(com.qlangtech.tis.extension.Descriptor) Collectors(java.util.stream.Collectors) IFullBuildContext(com.qlangtech.tis.fullbuild.IFullBuildContext) ViewPojo(com.qlangtech.tis.runtime.module.screen.ViewPojo) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) FCoreRequest(com.qlangtech.tis.coredefine.biz.FCoreRequest) FlinkJobDeploymentDetails(com.qlangtech.tis.coredefine.module.action.impl.FlinkJobDeploymentDetails) SolrQuery(org.apache.solr.client.solrj.SolrQuery) QueryCloudSolrClient(com.qlangtech.tis.manage.servlet.QueryCloudSolrClient) RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) com.qlangtech.tis.workflow.pojo(com.qlangtech.tis.workflow.pojo) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Pager(com.koubei.web.tag.pager.Pager) java.util(java.util) BasicScreen(com.qlangtech.tis.runtime.module.screen.BasicScreen) RcDeployment(com.qlangtech.tis.coredefine.module.action.impl.RcDeployment) Func(com.qlangtech.tis.manage.spring.aop.Func) QueryIndexServlet(com.qlangtech.tis.manage.servlet.QueryIndexServlet) Context(com.alibaba.citrus.turbine.Context) IAppSourcePipelineController(com.qlangtech.tis.order.center.IAppSourcePipelineController) Lists(com.google.common.collect.Lists) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) QueryResutStrategy(com.qlangtech.tis.manage.servlet.QueryResutStrategy) ClusterStateCollectAction(com.qlangtech.tis.runtime.module.action.ClusterStateCollectAction) StreamProcess(com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess) InstanceDirDesc(com.qlangtech.tis.coredefine.module.screen.Corenodemanage.InstanceDirDesc) ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) StringWriter(java.io.StringWriter) JSONTokener(org.json.JSONTokener) IOException(java.io.IOException) ICoreAdminAction(com.qlangtech.tis.cloud.ICoreAdminAction) Maps(com.google.common.collect.Maps) StreamCodeContext(com.qlangtech.tis.sql.parser.stream.generate.StreamCodeContext) ReplicState(com.qlangtech.tis.coredefine.module.screen.Corenodemanage.ReplicState) IParamContext(com.qlangtech.tis.order.center.IParamContext) JSON(com.alibaba.fastjson.JSON) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) TisException(com.qlangtech.tis.lang.TisException) IWorkFlowBuildHistoryDAO(com.qlangtech.tis.workflow.dao.IWorkFlowBuildHistoryDAO) ZkUtils(com.qlangtech.tis.solrj.util.ZkUtils) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) TisAppLaunchPort(com.qlangtech.tis.web.start.TisAppLaunchPort) Feature(com.alibaba.fastjson.parser.Feature) InputStream(java.io.InputStream) MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TisException(com.qlangtech.tis.lang.TisException) URL(java.net.URL) StreamProcess(com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 3 with StreamProcess

use of com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess in project tis by qlangtech.

the class SolrFieldsParser method parseSchema.

public ParseResult parseSchema(InputStream is, ISchemaFieldTypeContext schemaPlugin, boolean shallValidate) throws Exception {
    DocumentBuilderFactory schemaDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
    // 只是读取schema不作校验
    schemaDocumentBuilderFactory.setValidating(shallValidate);
    final ParseResult result = new ParseResult(shallValidate);
    DocumentBuilder builder = schemaDocumentBuilderFactory.newDocumentBuilder();
    InputSource input = new InputSource(is);
    if (!shallValidate) {
        builder.setEntityResolver(new EntityResolver() {

            public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
                InputSource source = new InputSource();
                source.setCharacterStream(new StringReader(""));
                return source;
            }
        });
    } else {
        final DefaultHandler mh = new DefaultHandler() {

            public void error(SAXParseException e) throws SAXException {
                result.errlist.add("行号:" + e.getLineNumber() + " " + e.getMessage() + "<br/>");
            }

            public void fatalError(SAXParseException e) throws SAXException {
                this.error(e);
            }
        };
        builder.setErrorHandler(mh);
        builder.setEntityResolver(new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
                // final String tisrepository = TSearcherConfigFetcher.get().getTisConsoleHostAddress();
                final String tisrepository = Config.getConfigRepositoryHost();
                final URL url = new URL(tisrepository + "/dtd/solrschema.dtd");
                return new InputSource(new ByteArrayInputStream(ConfigFileContext.processContent(url, new StreamProcess<byte[]>() {

                    @Override
                    public byte[] p(int status, InputStream stream, Map<String, List<String>> headerFields) {
                        try {
                            return IOUtils.toByteArray(stream);
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                })));
            }
        });
    }
    Document document = null;
    try {
        document = builder.parse(input);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
    if (!result.isValid()) {
        return result;
    }
    return parse(document, schemaPlugin, shallValidate);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.w3c.dom.Document) URL(java.net.URL) SAXException(org.xml.sax.SAXException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) StreamProcess(com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParseException(org.xml.sax.SAXParseException) StringReader(java.io.StringReader) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Aggregations

StreamProcess (com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Context (com.alibaba.citrus.turbine.Context)1 JSON (com.alibaba.fastjson.JSON)1 Feature (com.alibaba.fastjson.parser.Feature)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Pager (com.koubei.web.tag.pager.Pager)1 TIS (com.qlangtech.tis.TIS)1 ExecResult (com.qlangtech.tis.assemble.ExecResult)1 ICoreAdminAction (com.qlangtech.tis.cloud.ICoreAdminAction)1 ITISCoordinator (com.qlangtech.tis.cloud.ITISCoordinator)1 GenerateDAOAndIncrScript (com.qlangtech.tis.compiler.streamcode.GenerateDAOAndIncrScript)1 IndexStreamCodeGenerator (com.qlangtech.tis.compiler.streamcode.IndexStreamCodeGenerator)1 FCoreRequest (com.qlangtech.tis.coredefine.biz.FCoreRequest)1 FlinkJobDeploymentDetails (com.qlangtech.tis.coredefine.module.action.impl.FlinkJobDeploymentDetails)1 RcDeployment (com.qlangtech.tis.coredefine.module.action.impl.RcDeployment)1 SelectableServer (com.qlangtech.tis.coredefine.module.control.SelectableServer)1 CoreNode (com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)1