public CSharpMSUnitTestExecutionHandler(AutomationJob job2Run, string rootResultPath, Project project)
        {
            this.RootResultPath = rootResultPath;

            this.Job2Run = job2Run;

            this.vcsRootFolder = project.VCSRootPath;
        }
Ejemplo n.º 2
0
 public static Project AddProject(Project instance)
 {
     using (ES1AutomationEntities context = new ES1AutomationEntities())
     {
         context.Projects.Add(instance);
         context.SaveChanges();
         return instance;
     }
 }
Ejemplo n.º 3
0
        public async Task <string> Create(string companyId, CreateProjectVm vm)
        {
            var company = await _companyRepository.GetFirstOrDefault(companyId) ?? throw new Exception($"No Company found against id:'{companyId}'");

            var project = new Core.Model.Project(company, vm.Title, vm.Description);

            company.AddProject(project);

            await _companyRepository.SaveChanges();

            return(project.Id);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// take the job to run
        /// 1. If the build is not installed, install the build
        /// 2. After the build is installed, set the environment status to BuildInstalled
        /// 3. Wait the Environment Manager Windows Service to restart all the machines
        /// 4. After restart, set the category of "Restarted" for each machine in DB
        /// 5. Check whether all the machines in SUT are restarted, if yes, start to run the test cases, else, continue to wait.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void HandleSaberAgentActions(object source, ElapsedEventArgs e)
        {
            // Get the latest config
            if (!InitializeConfiguration())
            {
                timer.Start();
                Log.logger.Info("There is no environment config in this agent, do nothing.");
                return;
            }
            //flush DNS first. Sometimes there're some DNS issue after the vAPP is created
            try
            {
                Common.Windows.WindowsServices.RestartService("Dnscache", 60 * 1000);//restart the DNS Client
                Log.logger.Info("Restart the DNS client service.");
                System.Threading.Thread.Sleep(1000);
                Log.logger.Info("Flush DNS.");
                DNSHelper.FlushDNS();
            }
            catch (Exception ex)
            {
                Log.logger.Error("Failed to flush the DNS on the test agent before the product setup.", ex);
            }

            if (!IsCurrentServiceHostTestAgent())
            {
                timer.Stop();
                Log.logger.Error("The saber agent doesn't run on the agent machine, do nothing.");
                return;
            }

            SaberAgent.Log.logger.Info(string.Format("The service is currently running on the test agent machine."));
            Log.logger.Info(string.Format("Start to monitor the jobs to handle by Saber Agent"));
            Log.logger.Info(string.Format("Stop the timer"));
            timer.Stop();

            //for debug purpose, wait the process attachment of VSTS
            while (debug)
            {
                System.Threading.Thread.Sleep(1000 * 10);
                Log.logger.Info(string.Format("The process is waiting to be attached for debuging..."));
            }

            //Take one job to run
            Log.logger.Info(string.Format("Start to take one job to run"));
            try
            {
                job2Run = GetAssignedJob();
                if (null == job2Run)
                {
                    Log.logger.Info(string.Format("Could not find a job whose status is Ready, start another loop."));
                    timer.Start();
                    return;
                }

            }
            catch (Exception ex)
            {
                Log.logger.Error(string.Format("Met exception when try to take one job in the saber agent to run"));
                Log.logger.Error(string.Format("Error detail: {0}", ex.Message + ex.StackTrace));
                timer.Start();
                return;
            }

            Log.logger.Info(string.Format("The id of the job taken by this agent is {0}", job2Run.JobId));

            //Initialize all parameters that may used below

            //Handle the job
            try
            {
                TestEnvironment sut = TestEnvironment.GetEnvironmentById(job2Run.SUTEnvironmentId.Value);
                TestEnvironment testAgent = TestEnvironment.GetEnvironmentById(job2Run.TestAgentEnvironmentId.Value);
                this.product = AutomationJob.GetProductOfJobByJobId(job2Run.JobId);
                this.project = AutomationJob.GetProjectOfJobByJobId(job2Run.JobId);

                //determine which deployment helper used to deploy the product
                switch (product.Name.ToLower())
                {
                    case "sourceone":
                    case "supervisor web"://The supervisor installer in integrated into the S1 installation.
                        productDeploymentHelper = new SourceOneDeploymentHelper();
                        break;
                    case "data protection search":
                        productDeploymentHelper = new DPSearch.DPSearchDeploymentHelper();
                        break;
                    case "common index search":
                        productDeploymentHelper = new CISDeploymentHelper();
                        break;
                    case "reveal 1.0":
                        productDeploymentHelper = new DPSearch.DPSearchDeploymentHelper();
                        break;
                }

                SaberAgent.Log.logger.Debug(string.Format("The status of the SUT [{0}] is {1}", sut.Name, sut.EnvironmentStatus));
                SaberAgent.Log.logger.Debug(string.Format("The status of the TestAgent [{0}] is {1}", testAgent.Name, testAgent.EnvironmentStatus));
                SaberAgent.Log.logger.Debug(string.Format("The status of the job [{0}] is {1}", job2Run.Name, job2Run.JobStatus));

                if (sut.EnvironmentStatus == EnvironmentStatus.AgentServiceInstalledAndReady)
                {
                    try
                    {
                        MakesureTestAgentCanAccessSUTMachines();
                        job2Run.AddJobProgressInformation(string.Format("Start to install Build for Job [{0}:{1}]", job2Run.JobId, job2Run.Name));
                        productDeploymentHelper.InstallProduct(sut);
                        job2Run.AddJobProgressInformation(string.Format("Build is installed successfully for Job [{0}:{1}]", job2Run.JobId, job2Run.Name));
                        sut.SetEnvironmentStatus(EnvironmentStatus.BuildInstalled);
                    }
                    catch (Exception ex)
                    {
                        Log.logger.Error(string.Format("Error occured during install build on the environment {0}", sut.EnvironmentId));
                        Log.logger.Error(string.Format("Exception detail: {0} {1}", ex.Message, ex.StackTrace));
                        job2Run.AddJobProgressInformation(string.Format("Error occurred during the installation of build for Job [{0}:{1}]", job2Run.JobId, job2Run.Name));
                        sut.SetEnvironmentStatus(EnvironmentStatus.Error);
                        job2Run.SetJobsStatus(JobStatus.Failed);
                        timer.Start();
                        return;
                    }
                }
                else if (sut.EnvironmentStatus == EnvironmentStatus.BuildInstalled)
                {
                    //The status will be handled by the environment management service
                    //The environment management service will restart all the servers, and udate the environment status to Ready
                    job2Run.AddJobProgressInformation(string.Format("Going to reboot the machines with build installed for Job [{0}:{1}]", job2Run.JobId, job2Run.Name));
                    SaberAgent.Log.logger.Info(string.Format("Change Environment Status of {0} from BuildInstalled-->Ready", sut.Name));
                    sut.SetEnvironmentStatus(EnvironmentStatus.Ready);
                    productDeploymentHelper.RebootMachinesAfterProductInstalled(sut);
                    job2Run.AddJobProgressInformation(string.Format("All machines with build installed are rebooted for Job [{0}:{1}]", job2Run.JobId, job2Run.Name));
                }
                else if (sut.EnvironmentStatus == EnvironmentStatus.Ready)
                {
                    //Run test case
                    if (job2Run.JobStatus == JobStatus.Ready)
                    {
                        string message = string.Format("Wait until all the machines are rebooted before run the test case for Job [{0}:{1}]", job2Run.JobId, job2Run.Name);
                        Log.logger.Info(message);
                        job2Run.AddJobProgressInformation(message);
                        if (productDeploymentHelper.WaitAllMachinesStartedAfterReboot(sut))
                        {
                            string info = string.Format("All machines have been restarted.");
                            Log.logger.Info(info);
                            job2Run.AddJobProgressInformation(info);

                            productDeploymentHelper.CheckPreconditionForEachTestExecution(sut);
                            info = string.Format("All services are running. Ready to run the test cases for Job [{0}:{1}]", job2Run.JobId, job2Run.Name);
                            Log.logger.Info(info);
                            job2Run.AddJobProgressInformation(info);

                            info = string.Format("Start to run the test cases for Job [{0}:{1}]", job2Run.JobId, job2Run.Name);
                            Log.logger.Info(info);
                            job2Run.AddJobProgressInformation(info);

                            //get the saber module
                            string temp_message = "Start to install the Saber.";
                            /*
                            Log.logger.Info(temp_message);
                            job2Run.AddJobProgressInformation(temp_message);
                            if (GetAndBuildSaber())
                            {
                                temp_message = "Succeed to install the Saber.";
                                Log.logger.Info(temp_message);
                                job2Run.AddJobProgressInformation(temp_message);
                            }
                            else
                            {
                                temp_message = "Failed to install the Saber.";
                                Log.logger.Info(temp_message);
                                job2Run.AddJobProgressInformation(temp_message);
                                job2Run.SetJobsStatus(JobStatus.Failed);
                                timer.Start();
                                return;
                            }
                            */

                            //sync the test code
                            if (!GetTestScriptsOfJob(project))
                            {
                                temp_message = string.Format("Failed to sync the automation scripts of project [{0}].", project.Name);
                                Log.logger.Error(temp_message);
                                job2Run.AddJobProgressInformation(temp_message);
                                job2Run.SetJobsStatus(JobStatus.Failed);
                                timer.Start();
                                return;
                            }

                            //Copy the scripts to the remote saberAgent if has any such agent
                            DeployAutomationScriptsOfJob(testAgent);

                            //run the setup script of task
                            AutomationTask task = AutomationJob.GetTaskOfJobByJobId(job2Run.JobId);
                            string setupScript = task.SetupScript;

                            string scriptRootFolder = @"C:\SaberAgent\AutomationScripts";
                            string currentDirectoryFolder = string.Format(@"{0}\{1}\", scriptRootFolder, project.VCSRootPath);
                            message = @"Wait 1 minutes before run the test cases";
                            job2Run.AddJobProgressInformation(message);
                            System.Threading.Thread.Sleep(1000 * 60 * 1);//wait one minutes before run the test cases.

                            if (!string.IsNullOrEmpty(setupScript))
                            {
                                job2Run.AddJobProgressInformation(string.Format("Start to run the setup script of this task[ {0}:{1}]", task.Name, setupScript));
                                string temp = System.IO.Path.GetTempFileName() + ".bat";
                                TXTHelper.ClearTXTContent(temp);

                                TXTHelper.WriteNewLine(temp, "C:", Encoding.Default);
                                TXTHelper.WriteNewLine(temp, string.Format("cd {0}", currentDirectoryFolder), Encoding.Default);
                                TXTHelper.WriteNewLine(temp, setupScript, Encoding.Default);

                                string result = CMDScript.RumCmdWithWindowsVisible(temp, string.Empty);
                                job2Run.AddJobProgressInformation(result);

                                FileHelper.DeleteFile(temp);

                                job2Run.AddJobProgressInformation(string.Format("Setup script is executed for task {0}.", task.Name));
                            }

                            //Set job status to running
                            job2Run.SetJobsStatus(JobStatus.Running);
                            try
                            {
                                message = string.Format("Start to run the test cases of job [{0}:{1}].", job2Run.JobId, job2Run.Name);
                                job2Run.AddJobProgressInformation(message);
                                Log.logger.Info(message);

                                //System.Threading.Thread.Sleep(1000 * 60 * 5);//Neil, sleep 5 minute before run the test cases, maybe the SQL service is not started yet.

                                RunAllTestCases();

                                info = string.Format("All the test cases are finished for Job [{0}:{1}]", job2Run.JobId, job2Run.Name);
                                Log.logger.Info(info);
                                job2Run.AddJobProgressInformation(info);
                            }
                            catch (Exception ex)
                            {
                                info = string.Format("Error occured during running test cases on the environment {0}", sut.Name);
                                Log.logger.Error(info);
                                Log.logger.Error(string.Format("Exception detail: {0} {1}", ex.Message, ex.StackTrace));
                                job2Run.AddJobProgressInformation(info);
                                job2Run.SetJobsStatus(JobStatus.Failed);
                                timer.Start();
                                return;
                            }

                            //run the teardown scripts of task
                            string teardownScript = task.TeardownScript;
                            if (!string.IsNullOrEmpty(teardownScript))
                            {
                                string temp = System.IO.Path.GetTempFileName() + ".bat";
                                TXTHelper.ClearTXTContent(temp);

                                TXTHelper.WriteNewLine(temp, "C:", Encoding.Default);
                                TXTHelper.WriteNewLine(temp, string.Format("cd {0}", currentDirectoryFolder), Encoding.Default);
                                TXTHelper.WriteNewLine(temp, teardownScript, Encoding.Default);

                                string result = CMDScript.RumCmd(temp, string.Empty);
                                job2Run.AddJobProgressInformation(result);

                                FileHelper.DeleteFile(temp);
                            }

                            //collect the product logs from SUT
                            string localResultFolderForJob = GetLocalResultFolderForJob();
                            if (!string.IsNullOrEmpty(localResultFolderForJob))
                            {
                                string localProductionLogsFolder = System.IO.Path.Combine(localResultFolderForJob, "production_logs");
                                FileHelper.CreateFolder(localProductionLogsFolder);
                                productDeploymentHelper.CollectProductionLogsAfterExecutionToLocal(sut, localProductionLogsFolder);
                                CopyProductionLogsToCentralResultFileServer(localProductionLogsFolder);
                            }
                            //set job status to complelte
                            job2Run.SetJobsStatus(JobStatus.Complete);
                        }
                        else
                        {
                            string info = string.Format("Timeout to wait all the machines to be restarted and ready for Job [{0}:{1}].", job2Run.JobId, job2Run.Name);
                            Log.logger.Info(info);
                            job2Run.AddJobProgressInformation(info);
                            job2Run.SetJobsStatus(JobStatus.Timeout);
                            timer.Start();
                            return;
                        }
                    }
                    else
                    {
                        //deleting the scripts folder
                        string scriptRootFolder = SaberAgentInstallPath + @"\AutomationScripts";
                        string message = string.Format("Start to delete the scrpt folder {0}", scriptRootFolder);
                        if (FileHelper.IsExistsFolder(scriptRootFolder))
                        {
                            FileHelper.EmptyFolder(scriptRootFolder);
                            message = string.Format("Delete the scrpt folder {0}", scriptRootFolder);
                            SaberAgent.Log.logger.Info(message);
                        }

                        Log.logger.Info(string.Format("The Job {0} is running or completed, we'll not to rerun it anymore.", job2Run.JobId));
                        timer.Start();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                SaberAgent.Log.logger.Error(ex.Message, ex);
                job2Run.SetJobsStatus(JobStatus.Failed);
                timer.Start();
                return;
            }
            finally
            {
                timer.Start();
            }
        }
Ejemplo n.º 5
0
        private bool GetTestScriptsOfJob(Project project)
        {
            if (!FileHelper.IsExistsFolder(LocalScriptRootPath))
            {
                FileHelper.CreateFolder(LocalScriptRootPath);
            }
            String batName = null;
            switch (project.VCSType)
            {
                case (int)VCSType.TFS:
                    batName = "SyncTFSCode.bat";
                    break;
                case (int)VCSType.ClearCase:
                    batName = "SyncClearCaseCode.bat";
                    break;
                case (int)VCSType.Git:
                    batName = "SyncGITCode.bat";
                    break;
                case (int)VCSType.NotSync:
                    return true;
            }

            int i = 0;
            string output = string.Empty;
            do
            {
                string bat = @"C:\SaberAgent\" + batName;
                string cspFileName = @"C:\SaberAgent\CSPs\" + project.Name + ".csp";//currently, we get the csp by the project name
                if (project.VCSType == (int)VCSType.Git)
                {
                    string log = string.Format(@">{0}\synclog.log", SaberAgentInstallPath);
                    SaberAgent.Log.logger.Info(string.Format(@"Start to run command [{0} /C {1}] to syn the code.", bat, project.VCSServer + " " + LocalScriptRootPath + " " + log));
                    output = CMDScript.RumCmd(bat, project.VCSServer + " " + LocalScriptRootPath + " " + log);
                }
                else
                {
                    output = CMDScript.RumCmd(bat, project.VCSRootPath + " " + project.VCSServer + " " + project.VCSUser + " \"" + project.VCSPassword + "\" " + cspFileName);
                }
                SaberAgent.Log.logger.Info(string.Format("The output of the code syncing is [{0}].", output));

                i++;
            } while (System.IO.Directory.EnumerateDirectories(LocalScriptRootPath).Count() == 0 && i < 5);

            if (System.IO.Directory.EnumerateDirectories(LocalScriptRootPath).Count() == 0)
            {
                SaberAgent.Log.logger.Error(output);
                return false;
            }
            else
            {
                SaberAgent.Log.logger.Info(output);
                return true;
            }
        }
Ejemplo n.º 6
0
 public RubyMiniTestExecutionHandler(AutomationJob job2Run, string rootResultPath, Project project)
 {
     this.RootResultPath = rootResultPath;
     this.Job2Run = job2Run;
     this.vcsRootPath = project.VCSRootPath;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Invoked when <see cref="ToEntity"/> operation is about to return.
        /// </summary>
        /// <param name="entity"><see cref="Product"/> converted from <see cref="ProductDTO"/>.</param>
partial         static void OnEntity(this ProjectDTO dto, Project entity);
Ejemplo n.º 8
0
        /// <summary>
        /// Converts this instance of <see cref="ProductDTO"/> to an instance of <see cref="Product"/>.
        /// </summary>
        /// <param name="dto"><see cref="ProductDTO"/> to convert.</param>
        public static Project ToEntity(this ProjectDTO dto)
        {
            if (dto == null) return null;

            var entity = new Project();

            entity.ProjectId = dto.ProjectId;
            entity.Name = dto.Name;
            entity.Description = dto.Description;
            entity.VCSType = dto.VCSType;
            entity.VCSServer = dto.VCSServer;
            entity.VCSUser = dto.VCSUser;
            entity.VCSPassword = dto.VCSPassword;
            entity.VCSRootPath = dto.VCSRootPath;
            entity.RunTime = dto.RunTime;

            dto.OnEntity(entity);

            return entity;
        }