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()); }
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); }
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)); }
/// <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)); }
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()); }
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()); }
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()); }
/// <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)); }
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()); }
/// <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"); }
/// <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); return(Start(job, loader)); }