Просмотр исходного кода

AMBARI-10294. Usability: bootstrapping hosts shows "Preparing" without any information and seems stuck (dlysnichenko)

Lisnichenko Dmitro 10 лет назад
Родитель
Сommit
75f9c51f63

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSHostStatusCollector.java

@@ -36,8 +36,8 @@ import org.apache.commons.logging.LogFactory;
 class BSHostStatusCollector {
   private File requestIdDir;
   private List<BSHostStatus> hostStatus;
-  private static final String logFileFilter = ".log";
-  private static final String doneFileFilter = ".done";
+  public static final String logFileFilter = ".log";
+  public static final String doneFileFilter = ".done";
   private static Log LOG = LogFactory.getLog(BSHostStatusCollector.class);
 
   private List<String> hosts;

+ 29 - 4
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java

@@ -26,6 +26,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
+import static org.apache.ambari.server.bootstrap.BSHostStatusCollector.doneFileFilter;
 
 import org.apache.ambari.server.bootstrap.BootStrapStatus.BSStat;
 import org.apache.commons.io.FileUtils;
@@ -238,18 +239,42 @@ class BSRunner extends Thread {
       LOG.info("Kicking off the scheduler for polling on logs in " +
           this.requestIdDir);
       try {
-
-        LOG.info("Bootstrap output, log="
-              + bootStrapErrorFilePath + " " + bootStrapOutputFilePath);
+        String logInfoMessage = "Bootstrap output, log="
+              + bootStrapErrorFilePath + " " + bootStrapOutputFilePath + " at " + this.ambariHostname;
+        LOG.info(logInfoMessage);
         int exitCode = process.waitFor();
         String outMesg = "";
-        String errMesg = "";
+        String errMesg = "";       
         try {
           outMesg = FileUtils.readFileToString(new File(bootStrapOutputFilePath));
           errMesg = FileUtils.readFileToString(new File(bootStrapErrorFilePath));
         } catch(IOException io) {
           LOG.info("Error in reading files ", io);
         }
+        PrintWriter setupAgentDoneWriter = null;
+        PrintWriter setupAgentLogWriter  = null; 
+        try {
+          if (exitCode != 0) {      
+            for (String host : hostString.split(",")) {
+              setupAgentDoneWriter = new PrintWriter(new File(requestIdDir, host + BSHostStatusCollector.doneFileFilter));
+              setupAgentLogWriter = new PrintWriter(new File(requestIdDir, host + BSHostStatusCollector.logFileFilter));
+              setupAgentLogWriter.print(logInfoMessage + "\n Error while bootstrapping:\n" + errMesg);
+              setupAgentDoneWriter.print(exitCode);
+              setupAgentDoneWriter.close();
+              setupAgentLogWriter.close();
+            }
+                     
+          }
+        } finally {
+          if (setupAgentDoneWriter != null) {
+            setupAgentDoneWriter.close();
+          }
+
+          if (setupAgentLogWriter != null) {
+            setupAgentLogWriter.close();
+          }
+        }
+
         scriptlog = outMesg + "\n\n" + errMesg;
         LOG.info("Script log Mesg " + scriptlog);
         if (exitCode != 0) {