Beispiel #1
0
        public static void StoreJobTaskOutputFile(GridJobTask task, string file, byte[] data)
        {
            CreateTaskDirectoriesIfNotExists(task);

            var fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{file}";

            File.WriteAllBytes(fp, data);
        }
Beispiel #2
0
        public static string ResolveFilePath(GridJob job, GridJobTask task, GridJobFile file)
        {
            if (file.ShareMode == EGridJobFileShare.SharedBetweenTasks)
            {
                return($"{JobsDirectory}\\{job.Name}\\{file.FileName}");
            }

            return($"{JobsDirectory}\\{job.Name}\\task-{task.TaskId}\\{file.FileName}");
        }
Beispiel #3
0
        public static bool CreateTaskDirectoriesIfNotExists(GridJobTask task)
        {
            if (!CheckIfTaskDirectoriesExists(task))
            {
                Directory.CreateDirectory($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}");
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        public static void CreateDirectoriesForTask(GridJobTask task)
        {
            if (CreateTaskDirectoriesIfNotExists(task))
            {
                return;
            }

            CleanupDirectory($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}");
            CreateDirectoriesForTask(task);
        }
Beispiel #5
0
        public static void StoreJobTaskFile(GridJobTask task, GridJobFile file)
        {
            CreateTaskDirectoriesIfNotExists(task);

            var fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{file.FileName}";

            if (file.ShareMode == EGridJobFileShare.SharedBetweenTasks)
            {
                fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\{file.FileName}";
            }

            File.WriteAllBytes(fp, file.Bytes);
        }
Beispiel #6
0
        public static bool IsJobTaskFileExistsAndValid(GridJobTask task, GridJobFile jobFile)
        {
            var fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\{jobFile.FileName}";

            if (jobFile.ShareMode == EGridJobFileShare.SharedBetweenTasks)
            {
                if (!File.Exists(fp))
                {
                    return(false);
                }

                return(CryptoUtils.CrcOfFile(fp) == jobFile.CheckSum);
            }

            fp = $"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{jobFile.FileName}";
            if (!File.Exists(fp))
            {
                return(false);
            }

            return(CryptoUtils.CrcOfFile(fp) == jobFile.CheckSum);
        }
Beispiel #7
0
        private static GridJobModule LoadModule(GridJobTask task, GridJobFileLink link)
        {
            var moduleFile = task.ParentJob.JobFiles.FirstOrDefault(x => x.FileName == link.FileName);

            if (moduleFile == null)
            {
                throw new GridJobTaskCommandException(task, $"Unable to locate referenced module file {link} in task instance");
            }

            moduleFile.Bytes = File.ReadAllBytes(GridIo.ResolveFilePath(task, moduleFile));
            moduleFile.UpdateCheckSum();

            Assembly assembly;

            try {
                assembly = Assembly.Load(moduleFile.Bytes);
            } catch (Exception e) {
                throw new GridJobTaskCommandException(task, $"Unable to load module assembly file {link} when try to execute task", e);
            }

            var entryPoint = assembly.GetExportedTypes().FirstOrDefault(t => t.BaseType == typeof(GridJobModule));

            if (entryPoint == null)
            {
                throw new GridJobTaskCommandException(task, $"Unable to load module {link}: target module do not release {typeof(GridJobModule).FullName} class");
            }

            dynamic obj;

            try {
                obj = Activator.CreateInstance(entryPoint, null);
            } catch (Exception err) {
                throw new GridJobTaskCommandException(task, $"Unable to load module {link}: unable to create instance of {entryPoint.FullName} module entrypoint class", err);
            }

            return((GridJobModule)obj);
        }
Beispiel #8
0
 public static bool CheckIfTaskDirectoriesExists(GridJobTask task)
 {
     return(Directory.Exists($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}"));
 }
Beispiel #9
0
 public static string ResolveFilePath(GridJobTask task, string fileName)
 {
     return($"{JobsDirectory}\\{task.ParentJob.Name}\\task-{task.TaskId}\\{fileName}");
 }
Beispiel #10
0
 public GridJobTaskCommandException(GridJobTask task, string msg, Exception err)
     : base(msg, err)
 {
     Task = task;
 }
Beispiel #11
0
 public abstract void ExecuteTask(GridTaskExecutor executor, GridJobTask task, ILog logger);
Beispiel #12
0
 public void WriteFileOutput(GridJobTask task, string outputFile, string text)
 {
     GridIo.StoreJobTaskOutputFile(task, outputFile, Encoding.UTF8.GetBytes(text));
 }
Beispiel #13
0
 public void PrepareJobTaskDirectories(GridJobTask task)
 {
     GridIo.CreateDirectoriesForTask(task);
 }
Beispiel #14
0
 public string ResolveFilePath(GridJobTask task, string fileName)
 {
     return(GridIo.ResolveFilePath(task, fileName));
 }
Beispiel #15
0
 public string ResolveFilePath(GridJobTask task, GridJobFile file)
 {
     return(GridIo.ResolveFilePath(task.ParentJob, task, file));
 }