public void RunJob(string xmlFile, string jobName, UnityLoader loader, bool shouldFail)
        {
            // Flush output file
            GetFileNamesOut().ForEach(s => { if (File.Exists(s))
                                             {
                                                 File.Delete(s);
                                             }
                                      });

            // Prerequisites
            GetFileNamesIn().ForEach(s => Assert.IsTrue(new FileInfo(s).Exists, "Job input file " + s + " does not exist, job can't be run"));
            GetFileNamesOut().ForEach(s => Assert.IsFalse(new FileInfo(s).Exists, "Job output file " + s + " should have been deleted before test"));

            XmlJob       job         = XmlJobParser.LoadJob(xmlFile);
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(loader, job);

            Assert.IsNotNull(jobOperator);
            long?executionId = jobOperator.StartNextInstance(jobName);

            Assert.IsNotNull(executionId);

            JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId);

            //job SHOULD BE FAILED because of rollback having occured
            if (shouldFail)
            {
                Assert.IsTrue(jobExecution.Status.IsUnsuccessful());
            }
            else
            {
                Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            }
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }
Example #2
0
        public void RunJobWithTaskletMergeCopy()
        {
            //prepare stuff
            if (!Directory.Exists(TestDataDirectoryToMerge))
            {
                Directory.CreateDirectory(TestDataDirectoryToMerge);
            }

            FileInfo ofi = new FileInfo(Path.Combine(TestDataDirectoryToMerge, "report1_merged_copy.txt"));

            if (!ofi.Exists)
            {
                using (FileStream fs = File.OpenRead(Path.Combine(TestDataDirectoryIn, "report0.txt")))
                    using (FileStream ofs = File.OpenWrite(Path.Combine(TestDataDirectoryToMerge, "report1_merged_copy.txt")))
                    {
                        fs.CopyTo(ofs);
                    }
            }

            XmlJob       job         = XmlJobParser.LoadJob("Job1.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1MergeCopy(), job);

            Assert.IsNotNull(jobOperator);
            long?executionId = jobOperator.StartNextInstance(job.Id);

            Assert.IsNotNull(executionId);

            JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId);

            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }
Example #3
0
        public void RunTestWithSuppliedDbConfig()
        {
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyDbUnityLoader());

            Assert.IsInstanceOfType(jobOperator, typeof(SimpleJobOperator));
            Type         t           = jobOperator.GetType();
            PropertyInfo f           = t.GetProperty("JobLauncher", BindingFlags.Instance | BindingFlags.Public);
            IJobLauncher jobLauncher = (IJobLauncher)f.GetValue(jobOperator);

            Assert.IsNotNull(jobLauncher);
            Assert.IsInstanceOfType(jobLauncher, typeof(SimpleJobLauncher));
            PropertyInfo   f2            = t.GetProperty("JobRepository", BindingFlags.Instance | BindingFlags.Public);
            IJobRepository jobRepository = (IJobRepository)f2.GetValue(jobOperator);

            Assert.IsNotNull(jobRepository);
            Assert.IsInstanceOfType(jobRepository, typeof(SimpleJobRepository));
            PropertyInfo        f3          = t.GetProperty("JobRegistry", BindingFlags.Instance | BindingFlags.Public);
            IListableJobLocator jobRegistry = (IListableJobLocator)f3.GetValue(jobOperator);

            Assert.IsNotNull(jobRegistry);
            Assert.IsInstanceOfType(jobRegistry, typeof(MapJobRegistry));
            PropertyInfo f4          = t.GetProperty("JobExplorer", BindingFlags.Instance | BindingFlags.Public);
            IJobExplorer jobExplorer = (IJobExplorer)f4.GetValue(jobOperator);

            Assert.IsNotNull(jobExplorer);
            Assert.IsInstanceOfType(jobExplorer, typeof(SimpleJobExplorer));
            FieldInfo       f5  = jobRepository.GetType().GetField("_jobInstanceDao", BindingFlags.Instance | BindingFlags.NonPublic);
            IJobInstanceDao dao = (IJobInstanceDao)f5.GetValue(jobRepository);

            Assert.IsNotNull(dao);
            Assert.IsInstanceOfType(dao, typeof(DbJobInstanceDao));
        }
Example #4
0
 public void ErrorHandlingTest()
 {
     using (var runtime = new BatchRuntime())
     {
         Assert.Throws <BatchRuntimeException>(() => runtime.Execute("ech test"));
     }
 }
Example #5
0
        public void RunJobWithTasklet()
        {
            XmlJob       job         = XmlJobParser.LoadJob("Job1.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1(), job);

            Assert.IsNotNull(jobOperator);
            Assert.AreEqual(1, jobOperator.StartNextInstance(job.Id));
        }
Example #6
0
        public static JobExecution Start(XmlJob job, UnityLoader loader)
        {
            loader.Job = job;
            var jobOperator = (SimpleJobOperator)BatchRuntime.GetJobOperator(loader);
            var executionId = jobOperator.StartNextInstance(job.Id);

            return(jobOperator.JobExplorer.GetJobExecution((long)executionId));
        }
Example #7
0
        /// <summary>
        /// Starts given job.
        /// </summary>
        /// <param name="xmlJobFile"></param>
        /// <param name="loader"></param>
        /// <returns></returns>
        public static JobExecution Start(string xmlJobFile, UnityLoader loader)
        {
            var job = XmlJobParser.LoadJob(xmlJobFile);

            loader.Job = job;
            var jobOperator = (SimpleJobOperator)BatchRuntime.GetJobOperator(loader);
            var executionId = jobOperator.StartNextInstance(job.Id);

            return(jobOperator.JobExplorer.GetJobExecution((long)executionId));
        }
Example #8
0
        public void RunJobWithTasklet()
        {
            XmlJob       job         = XmlJobParser.LoadJob("JobSqlScript.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1(), job);

            Assert.IsNotNull(jobOperator);
            Assert.AreEqual(1, jobOperator.StartNextInstance(job.Id));
            JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution(1);

            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
        }
Example #9
0
        public void PowerShellExitStatus()
        {
            XmlJob       job         = XmlJobParser.LoadJob("JobPowerShellExitStatus.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderPowerShellExitStatus(), job);

            Assert.IsNotNull(jobOperator);
            long?executionId = jobOperator.StartNextInstance(job.Id);

            Assert.IsNotNull(executionId);
            JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId);

            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }
Example #10
0
        public void RunJobWithTaskletReset()
        {
            FileUtils.CopyDir(TestDataDirectoryIn, TestDataDirectoryToReset);

            XmlJob       job         = XmlJobParser.LoadJob("Job1.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1Reset(), job);

            Assert.IsNotNull(jobOperator);
            long?executionId = jobOperator.StartNextInstance(job.Id);

            Assert.IsNotNull(executionId);

            JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId);

            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }
Example #11
0
        /// <summary>
        /// Restarts given job.
        /// </summary>
        /// <param name="xmlJobFile"></param>
        /// <param name="loader"></param>
        /// <returns></returns>
        public static JobExecution ReStart(string xmlJobFile, UnityLoader loader)
        {
            var job = XmlJobParser.LoadJob(xmlJobFile);

            loader.Job = job;
            var jobOperator  = (SimpleJobOperator)BatchRuntime.GetJobOperator(loader);
            var jobExecution = GetLastFailedJobExecution(job.Id, jobOperator.JobExplorer);

            if (jobExecution == null)
            {
                throw new JobExecutionNotFailedException(
                          String.Format("No failed or stopped execution found for job={0}", job.Id));
            }
            var executionId = jobOperator.Restart(jobExecution.Id.Value);

            return(jobOperator.JobExplorer.GetJobExecution((long)executionId));
        }
Example #12
0
        public void ExecuteWorkDirTest()
        {
            using (var tempDir = TempDirectory.Create())
                using (var runtime = new BatchRuntime())
                {
                    var outPath = "workDirTest.txt";
                    FileSystem.DeleteFile(outPath);
                    FileAssert.DoesNotExist(outPath);
                    runtime.Execute(@"echo test> workDirTest.txt");
                    FileAssert.Exists(outPath);

                    outPath = Path.Combine(tempDir.TempPath, outPath);
                    FileSystem.DeleteFile(outPath);
                    FileAssert.DoesNotExist(outPath);
                    runtime.Execute(@"echo test> workDirTest.txt", tempDir.TempPath);
                    FileAssert.Exists(outPath);
                }
        }
Example #13
0
        public void RunJobWithTaskletMerge()
        {
            if (!Directory.Exists(TestDataDirectoryToMerge))
            {
                Directory.CreateDirectory(TestDataDirectoryToMerge);
            }

            XmlJob       job         = XmlJobParser.LoadJob("Job1.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1Merge(), job);

            Assert.IsNotNull(jobOperator);
            long?executionId = jobOperator.StartNextInstance(job.Id);

            Assert.IsNotNull(executionId);

            JobExecution jobExecution = ((SimpleJobOperator)jobOperator).JobExplorer.GetJobExecution((long)executionId);

            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }
Example #14
0
        /// <summary>
        /// Stops a given running job.
        /// </summary>
        /// <param name="xmlJobFile"></param>
        /// <param name="loader"></param>
        public static void Stop(string xmlJobFile, UnityLoader loader)
        {
            var job = XmlJobParser.LoadJob(xmlJobFile);

            loader.Job = job;
            var jobOperator   = (SimpleJobOperator)BatchRuntime.GetJobOperator(loader);
            var jobExecutions = GetRunningJobExecutions(job.Id, jobOperator.JobExplorer);

            if (jobExecutions == null || !jobExecutions.Any())
            {
                throw new JobExecutionNotFailedException(
                          string.Format("No running execution found for job={0}", job.Id));
            }
            foreach (var jobExecution in jobExecutions)
            {
                jobExecution.Status = BatchStatus.Stopping;
                jobOperator.JobRepository.Update(jobExecution);
            }
            Logger.Info("Job {0} was stopped.", job.Id);
        }
        public void RunJobWithTasklet()
        {
            //Delete any prior existing output file
            FileInfo priorOutputFile = new FileInfo(TestPathOut);

            if (priorOutputFile.Exists)
            {
                priorOutputFile.Delete();
            }

            XmlJob       job         = XmlJobParser.LoadJob("Job1.xml");
            IJobOperator jobOperator = BatchRuntime.GetJobOperator(new MyUnityLoaderJob1(), job);

            Assert.IsNotNull(jobOperator);
            Assert.AreEqual(1, jobOperator.StartNextInstance(job.Id));

            // Post controls
            FileInfo outputFile = new FileInfo(TestPathOut);

            Assert.IsTrue(outputFile.Exists, "Job output file does not exist, job was not successful");
            Assert.IsTrue(outputFile.Length > 0, "Job output file is empty, job was not successful");
        }
Example #16
0
        public static JobExecution WorkerStart(string xmlJobFile, UnityLoader loader, string hostName, string username = "******", string password = "******", int workerUpdateTimeInterval = 15)
        {
            ControlQueue _controlQueue = GetControlQueue(controlQueueName, hostName, username, password);


            int      messageCount             = _controlQueue.GetMessageCount();
            XmlJob   job                      = null;
            TimeSpan WorkerUpdatetimeInterval = TimeSpan.FromSeconds(workerUpdateTimeInterval);

            if (messageCount != 0)
            {
                for (int i = 0; i < messageCount; i++)
                {
                    string fileName = Path.GetFileName(xmlJobFile);
                    string message  = _controlQueue.Receive(fileName);
                    if (ValidateMessage(message)) // for 3 items
                    {
                        Tuple <XmlJob, string, int, bool> tuple = ValidateFileName(message, xmlJobFile);
                        if (tuple.Item4)
                        {
                            // Resend the message to the controlQueue
                            if (tuple.Item3 > 0)
                            {
                                _controlQueue.Send(tuple.Item2);
                            }
                            job = tuple.Item1;
                            Guid guid = Guid.NewGuid();
                            foreach (XmlStep step in job.JobElements)
                            {
                                step.RemoteChunking          = new XmlRemoteChunking();
                                step.RemoteChunking.HostName = hostName;
                                step.RemoteChunking.Master   = false;
                                step.RemoteChunking.WorkerID = guid.ToString();
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                do
                {
                    messageCount = _controlQueue.GetMessageCount();
                    if (messageCount != 0)
                    {
                        for (int i = 0; i < messageCount; i++)
                        {
                            string fileName = Path.GetFileName(xmlJobFile);
                            string message  = _controlQueue.Receive(fileName);
                            if (ValidateMessage(message)) // for 3 items
                            {
                                Tuple <XmlJob, string, int, bool> tuple = ValidateFileName(message, xmlJobFile);
                                if (tuple.Item4)
                                {
                                    // Resend the message to the controlQueue
                                    if (tuple.Item3 > 0)
                                    {
                                        _controlQueue.Send(tuple.Item2);
                                    }
                                    job = tuple.Item1;
                                    Guid guid = Guid.NewGuid();
                                    foreach (XmlStep step in job.JobElements)
                                    {
                                        step.RemoteChunking          = new XmlRemoteChunking();
                                        step.RemoteChunking.HostName = hostName;
                                        step.RemoteChunking.Master   = false;
                                        step.RemoteChunking.WorkerID = guid.ToString();
                                    }
                                    break;
                                }
                            }
                        }
                        break;
                    }
                    else
                    {
                        Logger.Info("No master job provided. Wait for worker {0} seconds.", WorkerUpdatetimeInterval.TotalSeconds);
                        Thread.Sleep(WorkerUpdatetimeInterval);
                        //throw new JobExecutionException("No master job provided");
                    }
                } while (messageCount == 0);
            }


            _controlQueue.Requeue();
            loader.Job = job;
            var jobOperator = (SimpleJobOperator)BatchRuntime.GetJobOperator(loader);
            var executionId = jobOperator.StartNextInstance(job.Id);

            return(jobOperator.JobExplorer.GetJobExecution((long)executionId));
        }