Esempio n. 1
0
        private static void DoRucioDownload(ISSHConnection connection, string localDirectory, Action<string> fileStatus, Func<bool> failNow, int timeout, string fileListName)
        {
            string filesThatFailedToDownload = "";
            bool foundClockSkewMessage = false;
            connection.ExecuteCommand(string.Format("rucio download --dir {1} `cat {0}`", fileListName, localDirectory), l =>
            {
                // Look for something that indicates which file we are currently getting from the GRID.
                if (fileStatus != null)
                {
                    const string fileNameMarker = "Starting the download of ";
                    var idx = l.IndexOf(fileNameMarker);
                    if (idx >= 0)
                    {
                        var closeBracket = l.IndexOf(']', idx);
                        var startOfFileName = idx + fileNameMarker.Length;
                        fileStatus(l.Substring(startOfFileName, closeBracket - startOfFileName));
                    }
                }

                // Watch for the end to see the overall status
                if (l.Contains("Files that cannot be downloaded :"))
                {
                    filesThatFailedToDownload = l.Split(' ').Where(i => !string.IsNullOrWhiteSpace(i)).Last();
                }
                foundClockSkewMessage |= l.Contains("check clock skew between hosts.");
            },
            refreshTimeout: true, failNow: failNow, secondsTimeout: timeout);

            // Check for errors that happened while running the command.
            if (filesThatFailedToDownload != "0")
            {
                // Special case - there was a clock skew error.
                if (foundClockSkewMessage)
                {
                    throw new ClockSkewException($"Failed to download {filesThatFailedToDownload} files due to clock skew. Please double check!");
                }

                // Something else - will likely require a human to get involved.
                throw new FileFailedToDownloadException($"Failed to download all the files from the GRID - {filesThatFailedToDownload} files failed to download!");
            }
        }