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());
        }
Beispiel #2
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);
 }
Beispiel #3
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);
 }
Beispiel #4
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 RunJob(string xmlFile, string jobName, UnityLoader loader)
 {
     RunJob(xmlFile,jobName,loader, false);
 }
Beispiel #6
0
        /// <summary>
        /// Creates an <see cref="IJobOperator"/> with the specified <see cref="UnityLoader"/>.
        /// </summary>
        /// <param name="loader">The <see cref="UnityLoader"/> to use.</param>
        /// <returns>An instance of <see cref="IJobOperator"/>.</returns>
        public static IJobOperator GetJobOperator(UnityLoader loader)
        {
            IUnityContainer unityContainer = new UnityContainer();
            unityContainer.AddNewExtension<PostprocessingUnityExtension>();
            unityContainer.AddNewExtension<StepScopeExtension>();
            unityContainer.AddNewExtension<SingletonExtension>();
            loader.Load(unityContainer);

            IJobOperator jobOperator = unityContainer.Resolve<IJobOperator>();
            if (jobOperator != null)
            {
                Logger.Debug("Loaded BatchContainerServiceProvider with className = {0}", jobOperator.GetType());
            }
            return jobOperator;
        }
Beispiel #7
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);
 }