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;
}
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, "已经更新全部服务器配置文件");
}
}
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);
}
Aggregations