示例#1
0
        /// <summary>
        /// We need to verify that a user has sufficient permissions in order to run the assemblers.
        /// </summary>
        /// <param name="SSHUser">The SSH username of the user.</param>
        /// <param name="SSHPass">The SSH password of the user.</param>
        /// <returns>Returns a boolean value representing whether or not they have sufficient permissions.</returns>
        public static bool VerifyPermissions(string SSHUser, string SSHPass)
        {
            using (var client = new SshClient(Accessors.BD_IP, SSHUser, SSHPass))
            {
                try
                {
                    client.Connect();

                    LinuxCommands.CreateDirectory(client, Accessors.VERIFY_PERMISSIONS_TEST_DIR);

                    if (!string.IsNullOrEmpty(ErrorHandling.error))
                    {
                        ErrorHandling.error = "You do not have sufficient permissions to write to the proper directories. Please contact the BigDog Linux team about addressing this problem.";

                        return(false);
                    }

                    else
                    {
                        // We want to remove the directory we just created as a test. We recursively force the deletion.
                        LinuxCommands.RemoveFile(client, Accessors.VERIFY_PERMISSIONS_TEST_DIR, "-rf");

                        return(true);
                    }
                }

                // SSH Connection couldn't be established.
                catch (SocketException e)
                {
                    ErrorHandling.error = "The SSH connection couldn't be established. " + e.Message;

                    return(false);
                }

                // Authentication failure.
                catch (SshAuthenticationException e)
                {
                    ErrorHandling.error = "The credentials were entered incorrectly. " + e.Message;

                    return(false);
                }

                // The SSH connection was dropped.
                catch (SshConnectionException e)
                {
                    ErrorHandling.error = "The connection was terminated unexpectedly. " + e.Message;

                    return(false);
                }

                catch (Exception e)
                {
                    ErrorHandling.error = "There was an uncaught exception. " + e.Message;

                    return(false);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Creates all the necessary folders, downloads the config scripts, and adds the job to the scheduler on BigDog.
        /// </summary>
        /// <returns>Returns true only if a job gets successfully added to SGE.</returns>
        public bool CreateJob()
        {
            // The init.sh script will contain all the basic logic to download the data and initiate the job on the assembler(s).
            using (var client = new SshClient(Accessors.BD_IP, genomeModel.SSHUser, genomeModel.SSHPass))
            {
                // Set defaults
                //Accessors.masterPath = "/share/scratch/bioinfo/" + HelperMethods.GetUsername();
                string node             = Accessors.BD_COMPUTE_NODE1; // default
                string wgetLogParameter = "--output-file=" + Accessors.GetJobLogPath(seed) + "wget.error";
                string initPath         = Accessors.GetJobConfigPath(seed) + "init.sh";
                string masurcaPath      = Accessors.GetJobConfigPath(seed) + "masurca_config.txt";
                string jobName          = HelperMethods.GetUsername() + "-" + seed;

                try
                {
                    client.Connect();

                    if (NoError())
                    {
                        LinuxCommands.CreateDirectory(client, Accessors.USER_ROOT_JOB_DIRECTORY, "-p");
                    }
                    if (NoError())
                    {
                        LinuxCommands.CreateDirectory(client, Accessors.GetJobPath(seed), "-p");
                    }
                    if (NoError())
                    {
                        LinuxCommands.CreateDirectory(client, Accessors.GetJobDataPath(seed), "-p");
                    }
                    if (NoError())
                    {
                        LinuxCommands.CreateDirectory(client, Accessors.GetJobConfigPath(seed), "-p");
                    }
                    if (NoError())
                    {
                        LinuxCommands.CreateDirectory(client, Accessors.GetJobOutputPath(seed), "-p");
                    }
                    if (NoError())
                    {
                        // Create subdirectories in the output directory to separate the outputs.
                        if (genomeModel.UseMasurca)
                        {
                            LinuxCommands.CreateDirectory(client, Accessors.GetMasurcaOutputPath(seed), "-p");
                        }

                        if (genomeModel.UseSGA)
                        {
                            LinuxCommands.CreateDirectory(client, Accessors.GetSgaOutputPath(seed), "-p");
                        }

                        if (genomeModel.UseWGS)
                        {
                            LinuxCommands.CreateDirectory(client, Accessors.GetWgsOutputPath(seed), "-p");
                        }
                    }
                    if (NoError())
                    {
                        LinuxCommands.CreateDirectory(client, Accessors.GetJobLogPath(seed), "-p");
                    }

                    if (NoError())
                    {
                        LinuxCommands.DownloadFile(client, initPath, InitConfigURL, wgetLogParameter);
                    }
                    if (NoError())
                    {
                        LinuxCommands.RunDos2Unix(client, initPath);
                    }

                    if (NoError())
                    {
                        LinuxCommands.DownloadFile(client, masurcaPath, MasurcaConfigURL, wgetLogParameter);
                    }
                    if (NoError())
                    {
                        LinuxCommands.RunDos2Unix(client, masurcaPath);
                    }

                    if (NoError())
                    {
                        LinuxCommands.ChangePermissions(client, Accessors.GetJobPath(seed), "777", "-R");
                    }

                    if (NoError())
                    {
                        // So COMPUTENODE2 has a smaller load, we want to use that instead.
                        if (LinuxCommands.GetNodeLoad(client, Accessors.BD_COMPUTE_NODE1) > LinuxCommands.GetNodeLoad(client, Accessors.BD_COMPUTE_NODE2))
                        {
                            node = Accessors.BD_COMPUTE_NODE2;
                        }

                        else
                        {
                            node = Accessors.BD_COMPUTE_NODE1;
                        }
                    }

                    if (NoError())
                    {
                        LinuxCommands.AddJobToScheduler(client, Accessors.GetJobDataPath(seed), Accessors.GetJobLogPath(seed), node, jobName, initPath);
                    }

                    if (NoError())
                    {
                        genomeModel.SGEJobId = LinuxCommands.SetJobNumber(client, genomeModel.SSHUser, jobName);
                    }

                    // There were no errors.
                    if (NoError())
                    {
                        return(true);
                    }

                    else
                    {
                        return(false);
                    }
                }

                // SSH Connection couldn't be established.
                catch (SocketException e)
                {
                    ErrorHandling.error = "The SSH connection couldn't be established. " + e.Message;

                    return(false);
                }

                // Authentication failure.
                catch (SshAuthenticationException e)
                {
                    ErrorHandling.error = "The credentials were entered incorrectly. " + e.Message;

                    return(false);
                }

                // The SSH connection was dropped.
                catch (SshConnectionException e)
                {
                    ErrorHandling.error = "The connection was terminated unexpectedly. " + e.Message;

                    return(false);
                }

                catch (Exception e)
                {
                    ErrorHandling.error = "There was an uncaught exception. " + e.Message;

                    return(false);
                }
            }
        }