Exemplo n.º 1
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());
        }
        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());
        }
Exemplo n.º 3
0
        private static Tuple <XmlJob, string, int, bool> ValidateFileName(string message, string xmlJobFile)
        {
            var tuple = new Tuple <XmlJob, string, int, bool>(null, "", 0, false);

            string[] splitMessage = message.Split(';');
            string   stepName     = splitMessage[0];
            string   xmlFileName  = splitMessage[1];
            int      workerNumber = (Int32.TryParse(splitMessage[2], out int value)) ? value : 0;

            if (Path.GetFileName(xmlJobFile).Equals(xmlFileName))
            {
                XmlJob job  = XmlJobParser.LoadJob(xmlJobFile);
                var    step = job.JobElements.Find(x => x.Id == stepName);

                if (step != null && workerNumber > 0)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    workerNumber--;
                    stringBuilder.Append(stepName + ";" + xmlFileName + ";" + (workerNumber).ToString());
                    return(new Tuple <XmlJob, string, int, bool>(job, stringBuilder.ToString(), workerNumber, true));
                }
                return(tuple);
            }


            return(tuple);
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
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());
        }
        private IJob LoadJob(XmlJob xmlJob, JobBuilder jobBuilder)
        {
            FlowBuilder <FlowJobBuilder> jobFlowBuilder;
            XmlJobElement xmlElement = xmlJob.JobElements.First();

            if (xmlElement is XmlStep)
            {
                jobFlowBuilder = jobBuilder.Flow(_stepsMap[xmlElement.Id]);
            }
            else
            {
                XmlFlow  xmlFlow  = xmlElement as XmlFlow;
                XmlSplit xmlSplit = xmlElement as XmlSplit;

                jobFlowBuilder = jobBuilder.Start(xmlFlow != null ? LoadFlow(xmlFlow) : LoadSplit(xmlSplit));
            }

            HandleSubElements(jobFlowBuilder, xmlJob);
            return(jobFlowBuilder.End().Build());
        }
Exemplo n.º 11
0
        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");
        }
        /// <summary>
        /// Main job Loader method, it loads the job corresponding to the xml file and
        /// stores it in the unity container.
        /// </summary>
        /// <param name="unityContainer"></param>
        /// <param name="xmlJob"></param>
        public void LoadJob(IUnityContainer unityContainer, XmlJob xmlJob)
        {
            JobBuilder jobBuilder = new JobBuilder(xmlJob.Id);

            jobBuilder.Repository(unityContainer.Resolve <IJobRepository>());
            jobBuilder.Incrementer(unityContainer.Resolve <IJobParametersIncrementer>());
            if ("false".Equals(xmlJob.Restartable))
            {
                jobBuilder.PreventRestart();
            }
            if (xmlJob.Listeners != null)
            {
                foreach (var listener in xmlJob.Listeners.Listeners)
                {
                    jobBuilder.Listener(unityContainer.Resolve <IJobExecutionListener>(listener.Ref));
                }
            }
            MapXmlElements(unityContainer, xmlJob);

            IJob job = LoadJob(xmlJob, jobBuilder);

            unityContainer.RegisterInstance(xmlJob.Id, job);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Creates an <see cref="IJobOperator"/> with the specified <see cref="UnityLoader"/> and the given job specification.
 /// </summary>
 /// <param name="loader"></param>
 /// <param name="job">The job specification used to build the <see cref="UnityLoader"/>.</param>
 /// <returns>An instance of <see cref="IJobOperator"/>.</returns>
 public static IJobOperator GetJobOperator(UnityLoader loader, XmlJob job)
 {
     loader.Job = job;
     return(GetJobOperator(loader));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates an <see cref="IJobOperator"/> with a <see cref="UnityLoader"/> build with the given job specification.
 /// </summary>
 /// <param name="job">The job specification used to build the <see cref="UnityLoader"/>.</param>
 /// <returns>An instance of <see cref="IJobOperator"/>.</returns>
 public static IJobOperator GetJobOperator(XmlJob job)
 {
     return(GetJobOperator(new UnityLoader {
         Job = job
     }));
 }
Exemplo n.º 15
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));
        }