Move the "getRenamedWorkerReport"-code in its own method.
This commit is contained in:
parent
6891c467d4
commit
c98e8df323
|
@ -515,30 +515,7 @@ public class UrlsServiceImpl implements UrlsService {
|
||||||
// Rename the worker-report to indicate success or failure.
|
// Rename the worker-report to indicate success or failure.
|
||||||
String workerReportBaseName = this.workerReportsDirPath + File.separator + workerId + File.separator + workerId + "_assignments_" + assignmentRequestCounter + "_report";
|
String workerReportBaseName = this.workerReportsDirPath + File.separator + workerId + File.separator + workerId + "_assignments_" + assignmentRequestCounter + "_report";
|
||||||
File workerReport = new File(workerReportBaseName + ".json");
|
File workerReport = new File(workerReportBaseName + ".json");
|
||||||
File renamedWorkerReport = null;
|
File renamedWorkerReport = getRenamedWorkerReport(workerReportBaseName, workerReport, errorMsg); // It may return null.
|
||||||
boolean wasWorkerReportRenamed = true;
|
|
||||||
try {
|
|
||||||
// Check if the workerReport does not exist under this name, as it may have been renamed previously to "failed" and now is the 2nd try.
|
|
||||||
if ( !workerReport.isFile() ) {
|
|
||||||
// Then this is the 2nd try and the report has already been renamed to "failed" the 1st time.
|
|
||||||
workerReport = new File(workerReportBaseName + "_failed.json");
|
|
||||||
if ( !workerReport.isFile() ) { // In this case, an error exists, since this file was deleted before its time.
|
|
||||||
logger.error("The workerReport file \"" + workerReport.getAbsolutePath() + "\" does not exist!");
|
|
||||||
wasWorkerReportRenamed = false; // Do not proceed on renaming the non-existing file.
|
|
||||||
// TODO - Do we need additional handling? This report may be either successful or failed but the file was deleted.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( wasWorkerReportRenamed ) { // Only if the file exists.
|
|
||||||
renamedWorkerReport = new File(workerReportBaseName + ((errorMsg == null) ? "_successful.json" : "_failed.json"));
|
|
||||||
if ( !workerReport.renameTo(renamedWorkerReport) ) {
|
|
||||||
logger.warn("There was a problem when renaming the workerReport: " + workerReport.getName());
|
|
||||||
wasWorkerReportRenamed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("There was a problem when renaming the workerReport: " + workerReport.getName(), e);
|
|
||||||
wasWorkerReportRenamed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the IP of this worker.
|
// Get the IP of this worker.
|
||||||
WorkerInfo workerInfo = UrlsController.workersInfoMap.get(workerId);
|
WorkerInfo workerInfo = UrlsController.workersInfoMap.get(workerId);
|
||||||
|
@ -558,7 +535,7 @@ public class UrlsServiceImpl implements UrlsService {
|
||||||
logger.error("HTTP-Connection problem with the submission of the \"postReportResultToWorker\" of worker \"" + workerId + "\" and assignments_" + assignmentRequestCounter + "! Error-code was: " + responseCode);
|
logger.error("HTTP-Connection problem with the submission of the \"postReportResultToWorker\" of worker \"" + workerId + "\" and assignments_" + assignmentRequestCounter + "! Error-code was: " + responseCode);
|
||||||
return false;
|
return false;
|
||||||
} else if ( errorMsg == null ) // If the worker was notified, then go delete the successful workerReport.
|
} else if ( errorMsg == null ) // If the worker was notified, then go delete the successful workerReport.
|
||||||
fileUtils.deleteFile(wasWorkerReportRenamed ? renamedWorkerReport.getAbsolutePath() : workerReport.getAbsolutePath());
|
fileUtils.deleteFile((renamedWorkerReport != null) ? renamedWorkerReport.getAbsolutePath() : workerReport.getAbsolutePath());
|
||||||
return true;
|
return true;
|
||||||
} catch (HttpServerErrorException hsee) {
|
} catch (HttpServerErrorException hsee) {
|
||||||
logger.error("The Worker \"" + workerId + "\" failed to handle the \"postReportResultToWorker\", of assignments_" + assignmentRequestCounter + ": " + hsee.getMessage());
|
logger.error("The Worker \"" + workerId + "\" failed to handle the \"postReportResultToWorker\", of assignments_" + assignmentRequestCounter + ": " + hsee.getMessage());
|
||||||
|
@ -580,6 +557,34 @@ public class UrlsServiceImpl implements UrlsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static File getRenamedWorkerReport(String workerReportBaseName, File workerReport, String errorMsg)
|
||||||
|
{
|
||||||
|
File renamedWorkerReport = null;
|
||||||
|
try {
|
||||||
|
// Check if the workerReport does not exist under this name, as it may have been renamed previously to "failed" and now is the 2nd try.
|
||||||
|
if ( !workerReport.isFile() ) {
|
||||||
|
// Then this is the 2nd try and the report has already been renamed to "failed" the 1st time.
|
||||||
|
workerReport = new File(workerReportBaseName + "_failed.json");
|
||||||
|
if ( !workerReport.isFile() ) { // In this case, an error exists, since this file was deleted before its time.
|
||||||
|
logger.error("The workerReport file \"" + workerReport.getAbsolutePath() + "\" does not exist!");
|
||||||
|
// TODO - Do we need additional handling? This report may be either successful or failed but the file was deleted.
|
||||||
|
return null; // Do not proceed on renaming the non-existing file.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Only if the file exists, proceed to renaming it.
|
||||||
|
renamedWorkerReport = new File(workerReportBaseName + ((errorMsg == null) ? "_successful.json" : "_failed.json"));
|
||||||
|
if ( !workerReport.renameTo(renamedWorkerReport) ) {
|
||||||
|
logger.warn("There was a problem when renaming the workerReport: " + workerReport.getName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("There was a problem when renaming the workerReport: " + workerReport.getName(), e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return renamedWorkerReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// The "batchExecute" does not work in this Impala-Database, so this is a "giant-query" solution.
|
// The "batchExecute" does not work in this Impala-Database, so this is a "giant-query" solution.
|
||||||
// Note: this causes an "Out of memory"-ERROR in the current version of the Impala JDBC driver. If a later version is provided, then this code should be tested.
|
// Note: this causes an "Out of memory"-ERROR in the current version of the Impala JDBC driver. If a later version is provided, then this code should be tested.
|
||||||
private static PreparedStatement constructLargeInsertQuery(Connection con, String baseInsertQuery, int dataSize, int numParamsPerRow) throws RuntimeException {
|
private static PreparedStatement constructLargeInsertQuery(Connection con, String baseInsertQuery, int dataSize, int numParamsPerRow) throws RuntimeException {
|
||||||
|
|
Loading…
Reference in New Issue