@Override
public void doWork() throws Exception {
boolean exit = false;
logger.info("start monitor operation progress for target " + targetName);
OperationStatusWithDetail detailedStatus = null;
SoftwareManagementClient monitorClient = new SoftwareManagementClient();
monitorClient.init();
while (!exit) {
try {
Thread.sleep(queryInterval);
} catch (InterruptedException e) {
logger.info("monitor thread is waked up by caller to stop monitoring");
stop = true;
}
if (stop) {
logger.info("received stop signal, will do one more query then exit, so as to retrieve the final progress after Ironfan exits.");
exit = true;
}
logger.info("progress query started");
detailedStatus = monitorClient.getOperationStatusWithDetail(targetName);
if (null == detailedStatus) {
logger.error("Failed to query progress. Something wrong with the Monitor Service?");
break;
}
logger.info("progress finished? " + detailedStatus.getOperationStatus().isFinished());
logger.debug(detailedStatus.toString());
logger.info("progress query completed");
if (detailedStatus.getOperationStatus().getProgress() < 100) {
int progress = detailedStatus.getOperationStatus().getProgress();
if (statusUpdater != null) {
statusUpdater.setProgress(((double) progress) / 100);
}
}
setLastErrorMsg(detailedStatus.getOperationStatus().getErrorMsg());
clusterEntityMgr.handleOperationStatus(targetName.split("-")[0], detailedStatus, exit);
// for large scale cluster (100+ nodes), don't need to query too frequent which will cause too much overhead on Chef Server
if (queryInterval == QUERY_INTERVAL_DEFAULT) {
int size = detailedStatus.getClusterData().getClusterSize();
if (size > BIG_CLUSTER_NODES_COUNT) {
queryInterval = Math.min(QUERY_INTERVAL_MAX, QUERY_INTERVAL_LONG * (size / BIG_CLUSTER_NODES_COUNT));
logger.info("progress query interval set to " + queryInterval / 1000 + "s because this cluster has " + size + " nodes");
}
}