Exemple #1
0
        private static JobSpecificationExt CreateJobSpecification()
        {
            TaskSpecificationExt testTask = new TaskSpecificationExt();

            testTask.Name          = "ASBTestJob";
            testTask.MinCores      = 1;
            testTask.MaxCores      = 36;
            testTask.WalltimeLimit = 900;
            //testTask.RequiredNodes = null;
            //testTask.IsExclusive = false;
            //testTask.IsRerunnable = false;
            //testTask.StandardInputFile = null;
            testTask.StandardOutputFile = "stdout";
            testTask.StandardErrorFile  = "stderr";
            testTask.ProgressFile       = "stdprog";
            testTask.LogFile            = "stdlog";
            //testTask.ClusterTaskSubdirectory = null;
            testTask.ClusterNodeTypeId = 2;
            testTask.CommandTemplateId = 2;
            //testTask.EnvironmentVariables = new EnvironmentVariableExt[0];
            //testTask.RequiredNodes = new string[] { "r2i4n2" };
            //testTask.PlacementPolicy= "vscatter";
            //testTask.TaskParalizationParameters = new TaskParalizationParameterExt[]
            //{
            //   new TaskParalizationParameterExt
            //   {
            //       MaxCores = 24,
            //       MPIProcesses = 2,
            //       OpenMPThreads = 1
            //   }
            //};
            //testTask.DependsOn = null;
            testTask.Priority                = TaskPriorityExt.Average;
            testTask.EnvironmentVariables    = null;
            testTask.TemplateParameterValues = new CommandTemplateParameterValueExt[0];
            //testTask.JobArrays = "1-2";
            //testTask.TemplateParameterValues = new CommandTemplateParameterValueExt[] {
            //        new CommandTemplateParameterValueExt() { CommandParameterIdentifier = "inputParam", ParameterValue = "someStringParam" }
            //    };


            JobSpecificationExt testJob = new JobSpecificationExt();

            testJob.Name         = "ASBTestJob";
            testJob.Project      = "ExpTests";
            testJob.WaitingLimit = 0;
            //testJob.NotificationEmail = "*****@*****.**";
            //testJob.PhoneNumber = "999111000";
            //testJob.NotifyOnAbort = false;
            //testJob.NotifyOnFinish = false;
            //testJob.NotifyOnStart = false;
            testJob.FileTransferMethodId = 1;
            testJob.ClusterId            = 1;

            testJob.EnvironmentVariables = new EnvironmentVariableExt[0];
            testJob.Tasks = new TaskSpecificationExt[] { testTask };

            return(testJob);
        }
Exemple #2
0
        public static JobSpecification ConvertExtToInt(this JobSpecificationExt jobSpecification)
        {
            var result = new JobSpecification
            {
                Name                 = jobSpecification.Name,
                Project              = jobSpecification.Project,
                WaitingLimit         = jobSpecification.WaitingLimit ?? 0,
                WalltimeLimit        = jobSpecification.WalltimeLimit,
                NotificationEmail    = jobSpecification.NotificationEmail,
                PhoneNumber          = jobSpecification.PhoneNumber,
                NotifyOnAbort        = jobSpecification.NotifyOnAbort,
                NotifyOnFinish       = jobSpecification.NotifyOnFinish,
                NotifyOnStart        = jobSpecification.NotifyOnStart,
                EnvironmentVariables = jobSpecification.EnvironmentVariables?
                                       .Select(s => s.ConvertExtToInt())
                                       .ToList(),
                FileTransferMethodId = jobSpecification.FileTransferMethodId,
                ClusterId            = jobSpecification.ClusterId ?? 0
            };

            //Same Reference for DependOn tasks
            Dictionary <TaskSpecificationExt, TaskSpecification> tasksSpecs = new();

            foreach (var taskExt in jobSpecification.Tasks)
            {
                var convertedTaskSpec = taskExt.ConvertExtToInt(result);
                if (taskExt.DependsOn != null)
                {
                    var taskDependency = new List <TaskDependency>();
                    foreach (var dependentTask in taskExt.DependsOn)
                    {
                        if (tasksSpecs.ContainsKey(dependentTask))
                        {
                            taskDependency.Add(new TaskDependency
                            {
                                TaskSpecification       = convertedTaskSpec,
                                ParentTaskSpecification = tasksSpecs[dependentTask]
                            });
                        }
                        else
                        {
                            //throw new InputValidationException($"Depending task \"{dependentTask.Name}\" for task \"{taskExt.Name}\" contains wrong task dependency.");
                        }
                    }
                    convertedTaskSpec.DependsOn = taskDependency;
                }
                tasksSpecs.Add(taskExt, convertedTaskSpec);
            }
            result.Tasks = tasksSpecs.Values.ToList();

            //Agregation walltimelimit for tasks
            result.WalltimeLimit = result.Tasks.Sum(s => s.WalltimeLimit);
            return(result);
        }
Exemple #3
0
        public async Task <IActionResult> OnPostCreateAndSubmitASBJobAsync()
        {
            try
            {
                string username = "******";
                string password = "******";

                //AuthenticateUserPassword
                sb.AppendLine(String.Format("username: {0}, password: {1}", username, password));
                string sessionCode = await AuthenticateUserPasswordAsync(username, password);

                //string sessionCode = AuthenticateUserKeycloakOpenId(openIdToken);
                sb.AppendLine(String.Format("sessionCode: {0}", sessionCode));

                //CancelJob(2, sessionCode);

                //CreateJobSpecification
                JobSpecificationExt jobSpec = CreateJobSpecification();
                sb.AppendLine(String.Format("JobSpecification created"));
                sb.AppendLine(jobSpec.ToString());

                //CreateJob
                SubmittedJobInfoExt submittedJob = await CreateJobAsync(jobSpec, sessionCode);

                sb.AppendLine(String.Format("Job {0} created", submittedJob.Id));
                sb.AppendLine(submittedJob.ToString());

                //FileUpload
                //UploadInputFiles((long)submittedJob.Id, submittedJob.Tasks?.Select(s => s.Id).ToList(), sessionCode);
                //sb.AppendLine(String.Format("All files uploaded"));

                //SubmitJob
                SubmitJobAsync((long)submittedJob.Id, sessionCode);
                sb.AppendLine(String.Format("Job submitted"));

                AsbSubmittedJob = (long)submittedJob.Id;

                while (submittedJob.State != JobStateExt.Running)
                {
                    Thread.Sleep(30000);
                    submittedJob = await GetCurrentInfoForJobAsync((long)submittedJob.Id, sessionCode);
                }

                sb.AppendLine(String.Format("Job is running"));

                ResponseContent = sb.ToString();
            }
            catch (Exception e)
            {
                ResponseContent = e.Message;
            }
            return(Page());
        }
Exemple #4
0
        public async Task <IActionResult> OnPostCreateAndSubmitTestJobAsync()
        {
            string response = "";

            try
            {
                string username    = "******";
                string password    = "******";
                string openIdToken = ""; // Fill the OpenId token for testing.

                //AuthenticateUserPassword
                sb.AppendLine(String.Format("username: {0}, password: {1}", username, password));
                string sessionCode = await AuthenticateUserPasswordAsync(username, password);

                //string sessionCode = AuthenticateUserKeycloakOpenId(openIdToken);
                sb.AppendLine(String.Format("sessionCode: {0}", sessionCode));

                //CreateJobSpecification
                JobSpecificationExt jobSpec = CreateJobSpecification();
                sb.AppendLine(String.Format("JobSpecification created"));
                sb.AppendLine(jobSpec.ToString());

                //CreateJob
                SubmittedJobInfoExt submittedJob = await CreateJobAsync(jobSpec, sessionCode);

                sb.AppendLine(String.Format("Job {0} created", submittedJob.Id));
                sb.AppendLine(submittedJob.ToString());

                //FileUpload
                UploadInputFilesAsync((long)submittedJob.Id, submittedJob.Tasks?.Select(s => s.Id).ToList(), sessionCode);
                sb.AppendLine(String.Format("All files uploaded"));

                //SubmitJob
                SubmitJobAsync((long)submittedJob.Id, sessionCode);
                sb.AppendLine(String.Format("Job submitted"));

                //MonitorJob
                lastSubmittedJobId = (long)submittedJob.Id; //TODO remove later - only for getCurrentJobInfo
                MonitorJob(submittedJob, sessionCode);

                ResponseContent = sb.ToString();
            }
            catch (Exception e)
            {
                ResponseContent = e.Message;
            }
            return(Page());
        }
Exemple #5
0
 public SubmittedJobInfoExt CreateJob(JobSpecificationExt specification, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser         loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IJobManagementLogic jobLogic   = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork);
             JobSpecification    js         = specification.ConvertExtToInt();
             SubmittedJobInfo    jobInfo    = jobLogic.CreateJob(js, loggedUser, specification.IsExtraLong.Value);
             return(jobInfo.ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Exemple #6
0
        private static async Task <SubmittedJobInfoExt> CreateJobAsync(JobSpecificationExt jobSpec, string sessionCode)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("JobManagement/CreateJob", Method.Post)
            {
                RequestFormat = DataFormat.Json
            }.AddJsonBody(
                new CreateJobModel
            {
                JobSpecification = jobSpec,
                SessionCode      = sessionCode
            });
            var response = await client.ExecuteAsync(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(response.Content.ToString());
            }

            SubmittedJobInfoExt jobInfo = JsonConvert.DeserializeObject <SubmittedJobInfoExt>(response.Content.ToString());

            return(jobInfo);
        }
Exemple #7
0
        public async Task <IActionResult> OnPostTestSubmitAndCancelJobAsync()
        {
            try
            {
                string username = "******";
                string password = "******";

                //AuthenticateUserPassword
                sb.AppendLine(String.Format("username: {0}, password: {1}", username, password));
                string sessionCode = await AuthenticateUserPasswordAsync(username, password);

                sb.AppendLine(String.Format("sessionCode: {0}", sessionCode));

                //CreateJobSpecification
                JobSpecificationExt jobSpec = CreateJobSpecification();
                sb.AppendLine(String.Format("JobSpecification created"));
                sb.AppendLine(jobSpec.ToString());

                //CreateJob
                SubmittedJobInfoExt submittedJob = await CreateJobAsync(jobSpec, sessionCode);

                sb.AppendLine(String.Format("Job {0} created", submittedJob.Id));
                sb.AppendLine(submittedJob.ToString());

                //FileUpload
                UploadInputFilesAsync((long)submittedJob.Id, submittedJob.Tasks?.Select(s => s.Id).ToList(), sessionCode);
                sb.AppendLine(String.Format("All files uploaded"));

                //SubmitJob
                SubmitJobAsync((long)submittedJob.Id, sessionCode);
                sb.AppendLine(String.Format("Job submitted"));

                //TODO DELETE LATER - only for getCurrentInfoForJob
                lastSubmittedJobId = (long)submittedJob.Id;

                //wait for job to be in running state and then cancel this job and delete job content on cluster
                while (true)
                {
                    submittedJob = await GetCurrentInfoForJobAsync((long)submittedJob.Id, sessionCode);

                    if (submittedJob.State == JobStateExt.Running)
                    {
                        sb.AppendLine(String.Format("Job {0} state: {1}", submittedJob.Id, submittedJob.State));

                        //CancelJob
                        sb.AppendLine(String.Format("Canceling job {0} ...", submittedJob.Id));
                        submittedJob = await CancelJobAsync((long)submittedJob.Id, sessionCode);

                        sb.AppendLine(String.Format("Job {0} was canceled.", submittedJob.Id));

                        //DeleteJob
                        sb.AppendLine(String.Format("Deleting job {0} ...", submittedJob.Id));
                        string deleteJobResponse = await DeleteJobAsync((long)submittedJob.Id, sessionCode);

                        sb.AppendLine(deleteJobResponse);

                        break;
                    }
                    Thread.Sleep(30000);
                }

                ResponseContent = sb.ToString();
            }
            catch (Exception e)
            {
                ResponseContent = e.Message;
            }

            return(Page());
        }
Exemple #8
0
        private string ValidateJobSpecificationExt(JobSpecificationExt job)
        {
            if (string.IsNullOrEmpty(job.Name))
            {
                _messageBuilder.AppendLine("Name cannot be empty.");
            }
            else
            {
                if (ContainsIllegalCharacters(job.Name))
                {
                    _messageBuilder.AppendLine("Name contains illegal characters.");
                }
                if (job.Name.Length > ProjectNameLength)
                {
                    _messageBuilder.AppendLine($"Name is too long, maximal length is {ProjectNameLength}");
                }
            }

            if (string.IsNullOrEmpty(job.Project))
            {
                _messageBuilder.AppendLine("Project cannot be empty.");
            }
            else
            {
                if (ContainsIllegalCharacters(job.Project))
                {
                    _messageBuilder.AppendLine("Project contains illegal characters.");
                }
                if (job.Project.Length > ProjectNameLength)
                {
                    _messageBuilder.AppendLine($"Project is too long, maximal length is {ProjectNameLength}");
                }
            }

            if (job.WaitingLimit.HasValue && job.WaitingLimit.Value < 0)
            {
                _messageBuilder.AppendLine("WaitingLimit must be unsigned number");
            }
            if (job.WalltimeLimit.HasValue && job.WalltimeLimit.Value < 0)
            {
                _messageBuilder.AppendLine("WalltimeLimit must be unsigned number");
            }

            if (!string.IsNullOrEmpty(job.NotificationEmail))
            {
                if (job.NotificationEmail.Length > 50)
                {
                    _messageBuilder.AppendLine("Notification email cannot be longer than 50 characters.");
                }

                if (!IsEmailAddress(job.NotificationEmail))
                {
                    _messageBuilder.AppendLine("Notification email address is in a wrong format.");
                }
            }

            if (!string.IsNullOrEmpty(job.PhoneNumber))
            {
                if (job.PhoneNumber.Length > 20)
                {
                    _messageBuilder.AppendLine("Phone number cannot be longer than 20 characters.");
                }

                if (!IsPhoneNumber(job.PhoneNumber))
                {
                    _messageBuilder.AppendLine("Phone number is in a wrong format.");
                }
            }

            if (job.EnvironmentVariables != null)
            {
                foreach (EnvironmentVariableExt variable in job.EnvironmentVariables)
                {
                    if (string.IsNullOrEmpty(variable.Name))
                    {
                        _messageBuilder.AppendLine($"Environment variable's name for the job cannot be empty. ({variable.Name}={variable.Value})");
                    }
                }
            }

            if (job.Tasks == null || job.Tasks.Length == 0)
            {
                {
                    _messageBuilder.AppendLine("Each job has to contain at least one task.");
                }
            }
            else
            {
                foreach (var task in job.Tasks)
                {
                    ValidateTaskSpecificationInput(task);
                }
            }
            return(_messageBuilder.ToString());
        }