예제 #1
0
        public void TestClone()
        {
            CommandLineArgs args = new CommandLineArgs();

            args.AddFlag("my_test_flag_1");
            args.AddFlag("my_test_flag_2");
            args.AddFlag("aAaAa");

            args.SetValue("test_value", "My Test Value");
            args.SetValue("aAaAa", "aaaaa");

            CommandLineArgs clone = args.Clone();

            args.RemoveFlag("aaaaa");
            args.RemoveValue("aaaaa");
            clone.RemoveFlag("my_test_flag_1");
            clone.RemoveFlag("my_test_flag_2");
            clone.RemoveValue("test_value");

            Assert.AreEqual(3, args.Count);
            Assert.AreEqual(2, clone.Count);

            Assert.AreEqual("my_test_flag_1 my_test_flag_2 test_value \"My Test Value\"", args.ToString());
            Assert.AreEqual("aaaaa aaaaa \"aaaaa\"", clone.ToString());
        }
예제 #2
0
        public static CommandLineArgs GetCurrentClean()
        {
            CommandLineArgs args = Current.Clone();

            args.RemoveFlag(ArgRestart);
            args.RemoveFlag(ArgUpdated);
            return(args);
        }
예제 #3
0
        /// <summary>
        /// Builds commandlines for reach batch server based in the pool node count
        /// </summary>
        /// <param name="args"></param>
        /// <param name="cmdLine"></param>
        /// <param name="poolNodeCount"></param>
        /// <returns></returns>
        private IList <string> CompileCommandLines(CommandLineArgs cmdLine, List <ResourceFile> inputFiles, string containerSasToken, int poolNodeCount, string jobId, OsType os, string applicationPackage, BatchType bType)
        {
            // var z = inputFiles.Where(x => x.FilePath.ToLower().Contains(cmdLine.PackageName.ToLower())).FirstOrDefault();

            List <string> commandLines = new List <string>();

            //Need to replace the paths to
            for (int i = 0; i < poolNodeCount; i++)
            {
                var threadCmdLine = (CommandLineArgs)cmdLine.Clone();

                //Set package name to the path on the node (if set)
                if (!string.IsNullOrWhiteSpace(threadCmdLine.BuildFileName))
                {
                    var pkg = inputFiles.Where(x => x.FilePath.ToLower().Contains(Path.GetFileName(cmdLine.BuildFileName.ToLower()))).FirstOrDefault();
                    threadCmdLine.BuildFileName = pkg.FilePath;
                }

                //Set the DacPac name to the path on the node (if set)
                if (!string.IsNullOrWhiteSpace(threadCmdLine.DacPacArgs.PlatinumDacpac))
                {
                    var dac = inputFiles.Where(x => x.FilePath.ToLower().Contains(Path.GetFileName(cmdLine.DacPacArgs.PlatinumDacpac.ToLower()))).FirstOrDefault();
                    threadCmdLine.DacPacArgs.PlatinumDacpac = dac.FilePath;
                }

                //Set the queryfile name to the path on the node (if set)
                if (threadCmdLine.QueryFile != null && !string.IsNullOrWhiteSpace(threadCmdLine.QueryFile.Name))
                {
                    var qu = inputFiles.Where(x => x.FilePath.ToLower().Contains(Path.GetFileName(threadCmdLine.QueryFile.Name.ToLower()))).FirstOrDefault();
                    threadCmdLine.QueryFile = new FileInfo(qu.FilePath);
                }

                //Update the RootLoggingPath as appropriate
                switch (os)
                {
                case OsType.Windows:
                    threadCmdLine.RootLoggingPath = string.Format("D:\\{0}", jobId);
                    break;

                case OsType.Linux:
                    threadCmdLine.RootLoggingPath = "$AZ_BATCH_TASK_WORKING_DIR";
                    break;
                }



                //Set the name of the output file (if set)
                if (threadCmdLine.OutputFile != null)
                {
                    var tmpName = $"{threadCmdLine.RootLoggingPath}/{threadCmdLine.OutputFile.Name}{i}.csv"; //use forward slash for Linux compat.
                    threadCmdLine.OutputFile = new FileInfo(tmpName);
                }


                //Set the override file for this node.
                var tmp    = string.Format(baseTargetFormat, i);
                var target = inputFiles.Where(x => x.FilePath.ToLower().Contains(tmp.ToLower())).FirstOrDefault();
                if (target != null)
                {
                    threadCmdLine.MultiDbRunConfigFileName = target.FilePath;
                }

                //Set set the Sas URL
                threadCmdLine.BatchArgs.OutputContainerSasUrl = containerSasToken;

                StringBuilder sb = new StringBuilder();
                switch (os)
                {
                case OsType.Windows:
                    sb.Append($"cmd /c set &&  %AZ_BATCH_APP_PACKAGE_{applicationPackage}%\\sbm.exe ");
                    break;

                case OsType.Linux:
                    sb.Append($"/bin/sh -c 'printenv && $AZ_BATCH_APP_PACKAGE_{applicationPackage.ToLower()}/sbm ");
                    break;
                }
                sb.Append($"--loglevel {threadCmdLine.LogLevel} batch ");

                switch (bType)
                {
                case BatchType.Run:
                    sb.Append("runthreaded ");
                    break;

                case BatchType.Query:
                    sb.Append("querythreaded ");
                    break;
                }
                switch (os)
                {
                case OsType.Windows:
                    sb.Append(threadCmdLine.ToBatchString());
                    break;

                case OsType.Linux:
                    sb.Append(threadCmdLine.ToBatchString() + "'");
                    break;
                }



                commandLines.Add(sb.ToString());
            }

            return(commandLines);
        }