public ClusterNodeUsage GetCurrentClusterNodeUsage(long clusterNodeId, AdaptorUser loggedUser)
        {
            ClusterNodeType nodeType = GetClusterNodeTypeById(clusterNodeId);

            return(SchedulerFactory.GetInstance(nodeType.Cluster.SchedulerType).CreateScheduler(nodeType.Cluster)
                   .GetCurrentClusterNodeUsage(nodeType));
        }
Ejemplo n.º 2
0
        public FileTransferMethod GetFileTransferMethod(long submittedJobInfoId, AdaptorUser loggedUser)
        {
            log.Info("Getting file transfer method for submitted job info ID " + submittedJobInfoId + " with user " + loggedUser.GetLogIdentification());
            SubmittedJobInfo jobInfo = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork).GetSubmittedJobInfoById(submittedJobInfoId, loggedUser);
            var certificateGenerator = new CertificateGenerator.CertificateGenerator();

            certificateGenerator.GenerateKey(2048);
            string publicKey      = certificateGenerator.DhiPublicKey();
            string jobDir         = FileSystemUtils.GetJobClusterDirectoryPath(jobInfo.Specification.FileTransferMethod.Cluster.LocalBasepath, jobInfo.Specification);
            var    transferMethod = new FileTransferMethod
            {
                Protocol       = jobInfo.Specification.FileTransferMethod.Protocol,
                ServerHostname = jobInfo.Specification.FileTransferMethod.ServerHostname,
                SharedBasePath = jobDir,
                Credentials    = new AsymmetricKeyCredentials
                {
                    Username   = jobInfo.Specification.ClusterUser.Username,
                    PrivateKey = certificateGenerator.DhiPrivateKey(),
                    PublicKey  = publicKey
                }
            };

            SchedulerFactory.GetInstance(jobInfo.Specification.Cluster.SchedulerType).CreateScheduler(jobInfo.Specification.Cluster).AllowDirectFileTransferAccessForUserToJob(publicKey, jobInfo);
            return(transferMethod);
        }
Ejemplo n.º 3
0
        public CommandTemplate ModifyCommandTemplate(long commandTemplateId, string name, string description, string code, string executableFile, string preparationScript)
        {
            CommandTemplate commandTemplate = _unitOfWork.CommandTemplateRepository.GetById(commandTemplateId);

            if (commandTemplate is null)
            {
                throw new RequestedObjectDoesNotExistException("The specified command template is not defined in HEAppE!");
            }

            if (!commandTemplate.IsEnabled)
            {
                throw new InputValidationException("The specified command template is deleted.");
            }

            if (commandTemplate.IsGeneric)
            {
                throw new InputValidationException("The specified command template is generic.");
            }

            if (executableFile is null)
            {
                throw new InputValidationException("The specified command template must have specified executable file!");
            }

            Cluster cluster = commandTemplate.ClusterNodeType.Cluster;
            var     commandTemplateParameters = SchedulerFactory.GetInstance(cluster.SchedulerType)
                                                .CreateScheduler(cluster)
                                                .GetParametersFromGenericUserScript(cluster, executableFile)
                                                .ToList();

            var templateParameters = new List <CommandTemplateParameter>();

            foreach (string parameter in commandTemplateParameters)
            {
                templateParameters.Add(new CommandTemplateParameter()
                {
                    Identifier  = parameter,
                    Description = parameter,
                    Query       = string.Empty
                });
            }

            commandTemplate.Name              = name;
            commandTemplate.Description       = description;
            commandTemplate.Code              = code;
            commandTemplate.PreparationScript = preparationScript;
            commandTemplate.TemplateParameters.ForEach(cmdParameters => _unitOfWork.CommandTemplateParameterRepository.Delete(cmdParameters));
            commandTemplate.TemplateParameters.AddRange(templateParameters);
            commandTemplate.ExecutableFile    = executableFile;
            commandTemplate.CommandParameters = string.Join(' ', commandTemplateParameters.Select(x => $"%%{"{"}{x}{"}"}"));

            _unitOfWork.Save();
            return(commandTemplate);
        }
 private IEnumerable <string> GetUserDefinedScriptParametres(Cluster cluster, string userScriptPath)
 {
     try
     {
         return(SchedulerFactory.GetInstance(cluster.SchedulerType).CreateScheduler(cluster).GetParametersFromGenericUserScript(cluster, userScriptPath).ToList());
     }
     catch (Exception)
     {
         _messageBuilder.AppendLine($"Unable to read or locate script at '{userScriptPath}'.");
         return(Enumerable.Empty <string>());
     }
 }
Ejemplo n.º 5
0
        public void EndFileTransfer(long submittedJobInfoId, FileTransferMethod transferMethod, AdaptorUser loggedUser)
        {
            log.Info("Removing file transfer method for submitted job info ID " + submittedJobInfoId + " with user " + loggedUser.GetLogIdentification());
            SubmittedJobInfo         jobInfo = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork).GetSubmittedJobInfoById(submittedJobInfoId, loggedUser);
            AsymmetricKeyCredentials asymmetricKeyCredentials = transferMethod.Credentials as AsymmetricKeyCredentials;

            if (asymmetricKeyCredentials != null)
            {
                SchedulerFactory.GetInstance(jobInfo.Specification.Cluster.SchedulerType).CreateScheduler(jobInfo.Specification.Cluster).
                RemoveDirectFileTransferAccessForUserToJob(asymmetricKeyCredentials.PublicKey, jobInfo);
            }
            else
            {
                log.Error("Credentials of class " + transferMethod.Credentials.GetType().Name +
                          " are not supported. Change the HaaSMiddleware.BusinessLogicTier.FileTransfer.FileTransferLogic.EndFileTransfer() method to add support for additional credential types.");
                throw new ArgumentException("Credentials of class " + transferMethod.Credentials.GetType().Name +
                                            " are not supported. Change the HaaSMiddleware.BusinessLogicTier.FileTransfer.FileTransferLogic.EndFileTransfer() method to add support for additional credential types.");
            }
        }
        public IEnumerable <string> GetCommandTemplateParametersName(long commandTemplateId, string userScriptPath, AdaptorUser loggedUser)
        {
            CommandTemplate commandTemplate = unitOfWork.CommandTemplateRepository.GetById(commandTemplateId);

            if (commandTemplate is null)
            {
                throw new RequestedObjectDoesNotExistException("The specified command template is not defined in HEAppE!");
            }

            if (commandTemplate.IsGeneric)
            {
                string scriptPath = commandTemplate.TemplateParameters.Where(w => w.IsVisible)
                                    .FirstOrDefault()?.Identifier;
                if (string.IsNullOrEmpty(scriptPath))
                {
                    throw new RequestedObjectDoesNotExistException("The user-script command parameter for the generic command template is not defined in HEAppE!");
                }

                if (string.IsNullOrEmpty(userScriptPath))
                {
                    throw new RequestedObjectDoesNotExistException("The generic command template should contain script path!");
                }

                Cluster cluster = commandTemplate.ClusterNodeType.Cluster;
                var     commandTemplateParameters = new List <string>()
                {
                    scriptPath
                };
                commandTemplateParameters.AddRange(SchedulerFactory.GetInstance(cluster.SchedulerType).CreateScheduler(cluster).GetParametersFromGenericUserScript(cluster, userScriptPath).ToList());
                return(commandTemplateParameters);
            }
            else
            {
                return(commandTemplate.TemplateParameters.Select(s => s.Identifier)
                       .ToList());
            }
        }
Ejemplo n.º 7
0
        public void SchedulerService()
        {
            try
            {
                _schedular = new Timer(new TimerCallback(SchedularCallback));

                //Set the Default Time.
                var scheduler     = SchedulerFactory.GetInstance();
                var scheduledTime = scheduler.GetScheduledTime();
                var timeSpan      = scheduledTime.Subtract(DateTime.Now);

                string schedule = string.Format("{0} day(s) {1} hour(s) {2} minute(s) {3} seconds(s)",
                                                timeSpan.Days,
                                                timeSpan.Hours,
                                                timeSpan.Minutes,
                                                timeSpan.Seconds);

                _logger.Info("ServicioScheduler", string.Format("Service mode: {0}.", SchedulerCommonSettings.SchedulerMode));
                _logger.Info("ServicioScheduler", string.Format("Service to run after: {0}.", schedule));

                //Ejecutamos servicio que descarga la información de vialidad nacional
                var fixture = new ScraperFixture();
                fixture.ExecuteFixture();

                //Get the difference in Minutes between the Scheduled and Current Time.
                var dueTime = Convert.ToInt32(timeSpan.TotalMilliseconds);

                //Change the Timer's Due Time.
                _schedular.Change(dueTime, Timeout.Infinite);
            }
            catch (Exception ex)
            {
                _logger.Error("ServicioScheduler", ex.Message, ex);
                StopWindowsService();
            }
        }
Ejemplo n.º 8
0
        public CommandTemplate CreateCommandTemplate(long genericCommandTemplateId, string name, string description, string code, string executableFile, string preparationScript)
        {
            CommandTemplate commandTemplate = _unitOfWork.CommandTemplateRepository.GetById(genericCommandTemplateId);

            if (commandTemplate is null)
            {
                throw new RequestedObjectDoesNotExistException("The specified command template is not defined in HEAppE!");
            }

            if (!commandTemplate.IsGeneric)
            {
                throw new InputValidationException("The specified command template is not generic.");
            }

            if (!commandTemplate.IsEnabled)
            {
                throw new InputValidationException("The specified command template is deleted.");
            }

            var commandTemplateParameter = commandTemplate.TemplateParameters.Where(w => w.IsVisible)
                                           .FirstOrDefault();

            if (string.IsNullOrEmpty(commandTemplateParameter?.Identifier))
            {
                throw new RequestedObjectDoesNotExistException("The user-script command parameter for the generic command template is not defined in HEAppE!");
            }

            if (string.IsNullOrEmpty(executableFile))
            {
                throw new InputValidationException("The generic command template should contain script path!");
            }

            Cluster cluster = commandTemplate.ClusterNodeType.Cluster;
            var     commandTemplateParameters = SchedulerFactory.GetInstance(cluster.SchedulerType)
                                                .CreateScheduler(cluster)
                                                .GetParametersFromGenericUserScript(cluster, executableFile)
                                                .ToList();

            List <CommandTemplateParameter> templateParameters = new();

            foreach (string parameter in commandTemplateParameters)
            {
                templateParameters.Add(new CommandTemplateParameter()
                {
                    Identifier  = parameter,
                    Description = parameter,
                    Query       = string.Empty
                });
            }

            CommandTemplate newCommandTemplate = new CommandTemplate()
            {
                Name               = name,
                Description        = description,
                IsGeneric          = false,
                IsEnabled          = true,
                ClusterNodeType    = commandTemplate.ClusterNodeType,
                ClusterNodeTypeId  = commandTemplate.ClusterNodeTypeId,
                Code               = code,
                ExecutableFile     = executableFile,
                PreparationScript  = preparationScript,
                TemplateParameters = templateParameters,
                CommandParameters  = string.Join(' ', commandTemplateParameters.Select(x => $"%%{"{"}{x}{"}"}"))
            };

            _unitOfWork.CommandTemplateRepository.Insert(newCommandTemplate);
            _unitOfWork.Save();

            return(newCommandTemplate);
        }