Ejemplo n.º 1
0
        public virtual Task <T2> ExecuteAsync(T1 obj, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("print list");
            T2 objToPrint = ListObj.CreateObj(obj) as T2;

            return(Task.FromResult(objToPrint));
        }
Ejemplo n.º 2
0
        public async Task <List <QarnotSDK.QJob> > RetrieveAsync(IConfiguration configuration, QarnotSDK.Connection connection, CancellationToken ct)
        {
            DefaultRunConfiguration config = configuration as DefaultRunConfiguration;

            QarnotSDK.QJob job     = null;
            List <QJob>    listJob = null;

            if (!string.IsNullOrEmpty(config.Name))
            {
                CLILogs.Debug("Retrieve QJobs by name : " + config.Name);
                QDataDetail <QJob> level = new QDataDetail <QJob>()
                {
                    Filter = QFilter <QJob> .Eq(t => t.Name, config.Name),
                };
                listJob = await connection.RetrieveJobsAsync(level, cancellationToken : ct);
            }
            else if (!string.IsNullOrEmpty(config.Id))
            {
                CLILogs.Debug("Retrieve QJob by Uuid : " + config.Id);
                job = await connection.RetrieveJobByUuidAsync(config.Id, cancellationToken : ct);
            }
            else
            {
                CLILogs.Debug("Retrieve all the QJobs");
                listJob = await connection.RetrieveJobsAsync(cancellationToken : ct);
            }

            return(listJob ?? new List <QJob>()
            {
                job
            });
        }
Ejemplo n.º 3
0
        public virtual Task <CommandValues.UserInformationCommandValue> ExecuteAsync(UserInformation apiSettings, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("print Account info");

            CommandValues.UserInformationCommandValue objToPrint = InfoObj.CreateObj(apiSettings) as CommandValues.UserInformationCommandValue;
            objToPrint.AccountInformation["Email"]               = apiSettings.Email;
            objToPrint.AccountInformation["MaxInstances"]        = apiSettings.MaxInstances.ToString();
            objToPrint.AccountInformation["Quota Bucket Number"] = apiSettings.BucketCount.ToString() + "/" + apiSettings.MaxBucket.ToString();
            if (iconfig.HumanReadable)
            {
                objToPrint.AccountInformation["Quota Bytes Bucket"] = BytesFormat.ConvertToHumanReadable(apiSettings.UsedQuotaBytesBucket) + "/" + BytesFormat.ConvertToHumanReadable(apiSettings.QuotaBytesBucket);
            }
            else
            {
                objToPrint.AccountInformation["Quota Bytes Bucket"] = apiSettings.UsedQuotaBytesBucket.ToString() + "/" + apiSettings.QuotaBytesBucket.ToString();
            }
            objToPrint.AccountInformation["Quota Task Count"]        = apiSettings.TaskCount.ToString() + "/" + apiSettings.MaxTask.ToString();
            objToPrint.AccountInformation["Quota Running Task"]      = apiSettings.RunningTaskCount.ToString() + "/" + apiSettings.MaxRunningTask.ToString();
            objToPrint.AccountInformation["Quota Total Pool"]        = apiSettings.PoolCount.ToString() + "/" + apiSettings.MaxPool.ToString();
            objToPrint.AccountInformation["Quota Running Pool"]      = apiSettings.RunningPoolCount.ToString() + "/" + apiSettings.MaxRunningPool.ToString();
            objToPrint.AccountInformation["Quota Running Instances"] = apiSettings.RunningInstanceCount.ToString() + "/" + apiSettings.MaxInstances.ToString();
            objToPrint.AccountInformation["Quota Running Cores"]     = apiSettings.RunningCoreCount.ToString();

            return(Task.FromResult(objToPrint));
        }
Ejemplo n.º 4
0
        public async Task <QarnotSDK.QBucket> RetrieveAsync(IConfiguration configuration, QarnotSDK.Connection connection, CancellationToken ct)
        {
            BucketConfiguration config = configuration as BucketConfiguration;

            CLILogs.Debug("Retrieve QBucket by Name : " + config.Name);
            return(await connection.RetrieveBucketAsync(config.Name, ct));
        }
Ejemplo n.º 5
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Bucket : Upload");

            BucketConfiguration config     = iconfig as BucketConfiguration;
            List <Task>         listOfTask = new List <Task>();

            if (!config.ApiConnection.DisableBucketPathsSanitization &&
                (PathSanitization.IsThePathInvalid(config.RemoteRelativePath)))
            {
                return(new CommandValues.GenericInfoCommandValue()
                {
                    Uuid = bucket.Shortname,
                    Message = "Upload failed. Invalid remote path",
                });
            }

            if (!string.IsNullOrEmpty(config.String))
            {
                CLILogs.Debug("Command Bucket : Upload String ");
                CLILogs.Debug(config.StringPath);
                await bucket.UploadStringAsync(config.String, config.StringPath, cancellationToken : ct);
            }

            listOfTask.AddRange(config.LocalPathFiles.Select(localFile => bucket.UploadFileAsync(localFile, config.RemoteRelativePath, cancellationToken: ct)));
            listOfTask.AddRange(config.LocalPathFolders.Select(localFolder => bucket.UploadFolderAsync(localFolder, config.RemoteRelativePath, cancellationToken: ct)));

            await Task.WhenAll(listOfTask);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = bucket.Shortname,
                Message = "Bucket Upload",
            });
        }
Ejemplo n.º 6
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QPool pool, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            PoolSetElasticSettingsConfiguration config = iconfig as PoolSetElasticSettingsConfiguration;

            CLILogs.Debug("Command pool : Pool name " + pool?.Name ?? config?.Name);
            CLILogs.Debug("Command pool : Set Pool Elastic info");

            if (pool == default)
            {
                var message = "Elastic settings update failed. Pool not found";
                throw new System.Exception(message);
            }

            pool.ElasticMinimumTotalSlots  = config.ElasticMinimumTotalSlots == default(int) ? pool.ElasticMinimumTotalSlots : config.ElasticMinimumTotalSlots;
            pool.ElasticMaximumTotalSlots  = config.ElasticMaximumTotalSlots == default(int) ? pool.ElasticMaximumTotalSlots : config.ElasticMaximumTotalSlots;
            pool.ElasticMinimumIdlingSlots = config.ElasticMinimumIdlingSlots == default(int) ? pool.ElasticMinimumIdlingSlots : config.ElasticMinimumIdlingSlots;
            pool.ElasticResizePeriod       = config.ElasticResizePeriod == default(int) ? pool.ElasticResizePeriod : config.ElasticResizePeriod;
            pool.ElasticResizeFactor       = config.ElasticResizeFactor == default(int) ? pool.ElasticResizeFactor : config.ElasticResizeFactor;
            pool.ElasticMinimumIdlingTime  = config.ElasticMinimumIdlingTime == default(int) ? pool.ElasticMinimumIdlingTime : config.ElasticMinimumIdlingTime;
            await pool.CommitAsync(ct);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = pool.Uuid.ToString(),
                Message = "Pool set ",
            });
        }
Ejemplo n.º 7
0
        public virtual async Task <CommandValues.BucketInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Bucket : Info");
            await bucket.UpdateAsync(ct);

            BucketConfiguration config     = iconfig as BucketConfiguration;
            List <string>       folderList = new List <string>();
            string folder = config.RemoteRelativePath ?? "";

            if (!config.ApiConnection.DisableBucketPathsSanitization &&
                (PathSanitization.IsThePathInvalid(folder)))
            {
                return(null);
            }

            folderList = await ExtractBucketFilesInfoFromBucket(bucket, folder, ct, iconfig.HumanReadable);

            return(new CommandValues.BucketInfoCommandValue()
            {
                Shortname = bucket.Shortname,
                TotalFileCount = bucket.FileCount.ToString(),
                TotalUsedSpaceBytes = iconfig.HumanReadable ? this.ConvertBytes.ConvertToHumanReadable(bucket.UsedSpaceBytes, 2) : bucket.UsedSpaceBytes.ToString(),
                BucketFilesDetail = folderList,
            });
        }
Ejemplo n.º 8
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Bucket : SyncFrom");
            BucketConfiguration config = iconfig as BucketConfiguration;

            if (bucket == default)
            {
                var message = "Synchronization failed. Bucket not found";
                throw new System.Exception(message);
            }

            string localFolderPath          = config.LocalPathGet;
            bool   donTDelete               = config.DeleteFiles;
            string remoteFolderRelativePath = config.RemoteRelativePath;

            if (!config.ApiConnection.DisableBucketPathsSanitization &&
                (PathSanitization.IsThePathInvalid(remoteFolderRelativePath)))
            {
                var message = "Synchronization failed. Invalid remote path";
                throw new System.Exception(message);
            }

            CLILogs.Debug("Local path : " + localFolderPath);

            await bucket.SyncRemoteToLocalAsync(localFolderPath, ct, donTDelete, remoteFolderRelativePath);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = bucket.Shortname,
                Message = "Bucket sync to " + localFolderPath,
            });
        }
Ejemplo n.º 9
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            BucketConfiguration config = iconfig as BucketConfiguration;

            if (bucket == default)
            {
                var message = "Removal failed. Bucket not found";
                throw new System.Exception(message);
            }

            if (!config.ApiConnection.DisableBucketPathsSanitization &&
                (config.RemoteRelativePaths.Any(remoteFile => PathSanitization.IsThePathInvalid(remoteFile))))
            {
                var message = "Removal failed. Invalid remote path(s)";
                throw new System.Exception(message);
            }
            CLILogs.Debug("Command Bucket : Remove entities " + string.Join(", ", config.RemoteRelativePaths));
            string returnString = "Bucket delete paths : " + string.Join(", ", config.RemoteRelativePaths);

            await config.RemoteRelativePaths.ParallelForEachAsync(bucket.DeleteEntryAsync, 10, ct : ct);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = bucket.Shortname,
                Message = returnString,
            });
        }
Ejemplo n.º 10
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QTask task, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Task : Snapshot Task");
            var config = iconfig as SnapshotConfiguration;

            if (task == default)
            {
                var message = "Snapshot  failed. Task not found";
                throw new System.Exception(message);
            }

            task.SnapshotWhitelist = config.Whitelist;
            task.SnapshotBlacklist = config.Blacklist;

            if (config.SnapshotPeriodicSec > 0)
            {
                await task.TriggerPeriodicSnapshotAsync(config.SnapshotPeriodicSec, config.Whitelist, config.Blacklist, cancellationToken : ct);
            }
            else
            {
                await task.TriggerSnapshotAsync(config.Whitelist, config.Blacklist, cancellationToken : ct);
            }

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = task.Uuid.ToString(),
                Message = "Task Snapshot",
            });
        }
Ejemplo n.º 11
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QTask task, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Task : Wait");
            var  config = iconfig as StdConfiguration;
            bool end    = false;

            while (end == false)
            {
                if (config.Stdout)
                {
                    var stdmessage = await task.FreshStdoutAsync(ct);

                    if (!string.IsNullOrEmpty(stdmessage))
                    {
                        CLILogs.Info("Stdout:" + Environment.NewLine + stdmessage.Replace("\\n", Environment.NewLine));
                    }
                }
                if (config.Stderr)
                {
                    var stdmessage = await task.FreshStderrAsync(ct);

                    if (!string.IsNullOrEmpty(stdmessage))
                    {
                        CLILogs.Info("Stderr:" + Environment.NewLine + stdmessage.Replace("\\n", Environment.NewLine));
                    }
                }
                end = await task.WaitAsync(taskTimeoutSeconds : 2, ct : ct);
            }

            var info = new CommandValues.GenericInfoCommandValue();

            info.Uuid    = task.Uuid.ToString();
            info.Message = "Task Wait end status : " + task.State;
            return(info);
        }
Ejemplo n.º 12
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Bucket : SyncTo");
            BucketConfiguration config      = iconfig as BucketConfiguration;
            string localFolderPath          = config.LocalPathGet;
            bool   donTDelete               = config.DeleteFiles;
            string remoteFolderRelativePath = config.RemoteRelativePath;

            if (!config.ApiConnection.DisableBucketPathsSanitization &&
                (PathSanitization.IsThePathInvalid(remoteFolderRelativePath)))
            {
                return(new CommandValues.GenericInfoCommandValue()
                {
                    Uuid = bucket.Shortname,
                    Message = "Synchronization failed. Invalid remote path",
                });
            }

            CLILogs.Debug("Local path : " + localFolderPath);

            await bucket.SyncLocalToRemoteAsync(localFolderPath, ct, donTDelete, remoteFolderRelativePath);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = bucket.Shortname,
                Message = localFolderPath + "send to Bucket",
            });
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Set The connection Information to the computer.
        /// </summary>
        /// <param name="iconfig">Configuration Object.</param>
        public void SaveSettings(IConfiguration iconfig)
        {
            CLILogs.Debug("Set the config value");

            string path = this.GetPath((LocalSetUpConfiguration)iconfig);

            this.SetConfigInformation(path, iconfig);
        }
Ejemplo n.º 14
0
 public static void CreateOneLogger(CLILogs.LogsLevel level)
 {
     if (Verbose <= level && level < LogsLevel.NoVerbose)
     {
         Logs[level] = Printer.PrinterFactory.Factory(level, !NoColor);
         CLILogs.Debug("Verbose set " + Enum.GetName(typeof(LogsLevel), level));
     }
 }
Ejemplo n.º 15
0
 public static void DebugException(Exception ex)
 {
     CLILogs.Debug("InnerException : " + ex?.InnerException?.ToString());
     CLILogs.Debug("StackTrace : " + ex?.StackTrace);
     CLILogs.Debug("Source : " + ex?.Source);
     CLILogs.Debug("Data : " + ex?.Data.ToString());
     CLILogs.Debug("TargetSite : " + ex?.TargetSite?.ToString());
     CLILogs.Error(ex?.Message);
 }
Ejemplo n.º 16
0
        public static void IConfiguration(IConfiguration config)
        {
            var jd = new FormatterFactory.JsonFormatter();

            CLILogs.Debug("Config format");
            CLILogs.Debug("Type " + Enum.GetName(typeof(ConfigType), config.Type));
            CLILogs.Debug("Command " + Enum.GetName(typeof(CommandApi), config.Command));
            CLILogs.Debug(jd.Format(config));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Print the CommandLine help.
        /// </summary>
        /// <param name="parser">Parser used (CommandLine).</param>
        /// <param name="errs">Error list.</param>
        /// <param name="argv">argv list.</param>
        /// <typeparam name="T">The generic type parameter: Object to parser to get the usage.</typeparam>
        /// <returns>String usage.</returns>
        public string PrintHelp <T>(CommandLine.ParserResult <T> parser, System.Collections.Generic.IEnumerable <CommandLine.Error> errs, string[] argv)
        {
            // create logs if not already created
            CLILogs.CreateLoggers();

            string         helpText = PrintHelpErrorUsage(parser);
            ParseException ex       = new ParseException();

            // check if a "help" flag is used
            if (argv.Length > 1 && argv[1] == "help")
            {
                CLILogs.Usage(PrintHelpUsage(parser));
                throw new ParseHelpException();
            }

            if (errs == null)
            {
                CLILogs.Usage(helpText);
                throw ex;
            }

            if (errs.Any(x => x.Tag == CommandLine.ErrorType.VersionRequestedError))
            {
                helpText = PrintHelpVersion(parser);
                ex       = new ParseVersionException();
            }
            else if (errs.Any(x => x.Tag == CommandLine.ErrorType.HelpRequestedError))
            {
                helpText = PrintHelpUsage(parser);
                ex       = new ParseHelpException();
            }
            else if (errs.Any(x => x.Tag == CommandLine.ErrorType.HelpVerbRequestedError))
            {
                helpText = PrintHelpVerbUsage(parser);
                ex       = new ParseHelpException();
            }
            else if (errs.Any(x => x.Tag == CommandLine.ErrorType.NoVerbSelectedError ||
                              x.Tag == CommandLine.ErrorType.BadVerbSelectedError))
            {
                helpText = PrintHelpErrorVerbUsage(parser);
                string errorList = string.Empty;
                errs.ToList().ForEach(e => errorList += e.ToString());
                ex = new ParseException(errorList);
                CLILogs.Debug("Parsing error : " + errorList);
            }
            else
            {
                string errorList = string.Empty;
                errs.ToList().ForEach(e => errorList += e.ToString());
                ex = new ParseException(errorList);
                CLILogs.Debug("Parsing error : " + errorList);
            }

            CLILogs.Usage(helpText);
            throw ex;
        }
Ejemplo n.º 18
0
        public virtual Task <T2> ExecuteAsync(T1 obj, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("print info");
            if (objectTransformer != null)
            {
                objectTransformer.Transform(obj);
            }

            return(Task.FromResult <T2>(obj));
        }
Ejemplo n.º 19
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QTask task, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Task : Delete");
            await task.DeleteAsync(cancellationToken : ct);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = task.Uuid.ToString(),
                Message = "Task delete ",
            });
        }
Ejemplo n.º 20
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QPool pool, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command pool : delete");
            await pool.DeleteAsync(ct);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = pool.Uuid.ToString(),
                Message = "Pool delete ",
            });
        }
Ejemplo n.º 21
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QJob job, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("command job : delete");
            await job.DeleteAsync(cancellationToken : ct);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = job.Uuid.ToString(),
                Message = "Job delete  ",
            });
        }
Ejemplo n.º 22
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QBucket bucket, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Bucket : Delete");
            await bucket.DeleteAsync(ct);

            return(new CommandValues.GenericInfoCommandValue()
            {
                Uuid = bucket.Shortname,
                Message = "Bucket deleted",
            });
        }
Ejemplo n.º 23
0
        public virtual APIConnectionInformation ReadFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new FileNotFoundException();
            }

            CLILogs.Debug("File info get " + filePath);

            string[] lines = File.ReadAllLines(filePath);
            return(this.ParseLines(lines));
        }
Ejemplo n.º 24
0
        private void ParseKeyValuePair(Dictionary <string, string> pairs, string line)
        {
            int position = line.IndexOf("=");

            if (position > 0)
            {
                var key   = line.Substring(0, position);
                var value = line.Substring(position + 1);
                pairs[key] = value;
                CLILogs.Debug("  [" + key + "] = [" + value + "]");
            }
        }
Ejemplo n.º 25
0
        public static void CreateLoggers()
        {
            if (!LogSet)
            {
                LogSet = true;
                foreach (LogsLevel level in Enum.GetValues(typeof(LogsLevel)))
                {
                    CreateOneLogger(level);
                }

                CLILogs.Debug("Set Console Color " + (!NoColor).ToString());
            }
        }
Ejemplo n.º 26
0
            private string CreateXML(object obj)
            {
                string jsonSerialize = JsonConvert.SerializeObject(obj);

                CLILogs.Debug(jsonSerialize);
                try
                {
                    return(JsonConvert.DeserializeXNode(jsonSerialize, "Information", false).ToString());
                }
                catch (Newtonsoft.Json.JsonSerializationException ex)
                {
                    CLILogs.Error(ex.Message);
                    return("Value not found");
                }
            }
Ejemplo n.º 27
0
        private Dictionary <string, string> ParseKeyValuePairs(List <string> lines, string name)
        {
            Dictionary <string, string> pairs = new Dictionary <string, string>();

            if (lines == null)
            {
                return(pairs);
            }

            CLILogs.Debug(name + " find :");

            lines.ForEach(line => ParseKeyValuePair(pairs, line));

            return(pairs);
        }
Ejemplo n.º 28
0
        public virtual async Task <CommandValues.GenericInfoCommandValue> ExecuteAsync(QJob job, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("command job : terminate");
            if (job.State == QJobStates.Active)
            {
                await job.TerminateAsync(ct);

                return(new CommandValues.GenericInfoCommandValue()
                {
                    Uuid = job.Uuid.ToString(),
                    Message = "Job terminate  ",
                });
            }

            return(null);
        }
Ejemplo n.º 29
0
        public virtual async Task <string> ExecuteAsync(QTask task, IConfiguration iconfig = null, CancellationToken ct = default(CancellationToken))
        {
            CLILogs.Debug("Command Task : Print Stdout");
            var config = iconfig as StdConfiguration;

            string message = "";

            if (config.Fresh)
            {
                message = await task.FreshStdoutAsync(ct);
            }
            else
            {
                message = await task.StdoutAsync(ct);
            }

            return(string.Join(Environment.NewLine, message.Split("\\n", StringSplitOptions.RemoveEmptyEntries)));
        }
Ejemplo n.º 30
0
        public async Task <List <QarnotSDK.QBucket> > RetrieveAsync(IConfiguration configuration, QarnotSDK.Connection connection, CancellationToken ct)
        {
            BucketConfiguration config = configuration as BucketConfiguration;

            if (config != null && !string.IsNullOrEmpty(config.Name))
            {
                CLILogs.Debug("Retrieve QBucket by Name : " + config.Name);
                return(new List <QBucket>()
                {
                    await connection.RetrieveBucketAsync(config.Name, cancellationToken : ct),
                });
            }
            else
            {
                CLILogs.Debug("Retrieve all the QBuckets");
                return(await connection.RetrieveBucketsAsync(cancellationToken : ct));
            }
        }