use of com.qlangtech.tis.fullbuild.phasestatus.impl.IndexBackFlowPhaseStatus.NodeBackflowStatus 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.fullbuild.phasestatus.impl.IndexBackFlowPhaseStatus.NodeBackflowStatus in project tis by qlangtech.
the class IndexBackFlowPhaseStatus method getProcessStatus.
@Override
public IProcessDetailStatus<NodeBackflowStatus> getProcessStatus() {
return new IProcessDetailStatus<NodeBackflowStatus>() {
@Override
public Collection<NodeBackflowStatus> getDetails() {
if (nodesStatus.isEmpty()) {
NodeBackflowStatus mock = new NodeBackflowStatus(StringUtils.EMPTY);
mock.setWaiting(true);
return Collections.singleton(mock);
}
return nodesStatus.values();
}
@Override
public int getProcessPercent() {
int allrow = 0;
for (NodeBackflowStatus s : nodesStatus.values()) {
allrow += s.getAllSize();
}
if (allrow < 1) {
return 0;
}
double weight = 0;
double percent = 0;
for (Map.Entry<String, NodeBackflowStatus> entry : nodesStatus.entrySet()) {
weight = (entry.getValue().getReaded() * 100) / allrow;
percent += entry.getValue().getPercent() * weight;
}
return (int) (percent / 100);
}
@Override
public void detailVisit(IChildProcessStatusVisitor visitor) {
for (NodeBackflowStatus s : nodesStatus.values()) {
visitor.visit(s);
}
}
};
}
use of com.qlangtech.tis.fullbuild.phasestatus.impl.IndexBackFlowPhaseStatus.NodeBackflowStatus in project tis by qlangtech.
the class IndexBackFlowPhaseStatus method getNode.
/**
* 取得某個节点的索引回流状态對象
*/
public NodeBackflowStatus getNode(String nodeName) {
NodeBackflowStatus nodeBackflowStatus = this.nodesStatus.get(nodeName);
if (nodeBackflowStatus == null) {
nodeBackflowStatus = new NodeBackflowStatus(nodeName);
this.nodesStatus.put(nodeName, nodeBackflowStatus);
}
return nodeBackflowStatus;
}
Aggregations