Ejemplo n.º 1
0
        /// <summary>
        /// Deal with any arguments and possible output filename.
        /// If a output filename is specified, create a string 'format' based
        /// on that and string out the arg.
        /// </summary>
        private void ParseExecutableArgs(SearchSpecification searchSpec, SearchEntity searchEntity)
        {
            var outputFormat   = "output-{0}.xml";
            var executableArgs = searchSpec.ExecutableArgs;

            if (!string.IsNullOrEmpty(executableArgs))
            {
                var tokens = executableArgs.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                if (tokens.Any(token => token == "-out"))
                {
                    var indexOfOutArg      = tokens.IndexOf("-out");
                    var indexOfOutFilename = indexOfOutArg + 1;
                    if (indexOfOutFilename > tokens.Count - 1)
                    {
                        throw new Exception("No filename specified for -out argument");
                    }
                    var outputFilename = tokens[indexOfOutArg + 1];
                    var name           = Path.GetFileNameWithoutExtension(outputFilename);
                    var extension      = Path.GetExtension(outputFilename);
                    outputFormat = name + "-{0}" + extension;

                    // Strip out the -out filename args as we already set it later
                    executableArgs = executableArgs.Replace(" -out " + outputFilename, " ");
                }
            }

            searchEntity.ExecutableArgsSanitised = executableArgs;
            searchEntity.OutputfileFormat        = outputFormat;
        }
Ejemplo n.º 2
0
        private SearchEntity CreateSearchEntity(SearchSpecification search, DatabaseEntity database)
        {
            var queryId      = Guid.NewGuid();
            var searchEntity = new SearchEntity(queryId);

            searchEntity.Name                    = search.Name;
            searchEntity.JobId                   = queryId.ToString();
            searchEntity.InputContainer          = "job-" + queryId.ToString();
            searchEntity.OutputContainer         = "job-" + queryId.ToString();
            searchEntity.DatabaseId              = search.DatabaseName;
            searchEntity.DatabaseType            = database.Type;
            searchEntity.DatabaseContainer       = database.ContainerName;
            searchEntity.Executable              = search.Executable;
            searchEntity.ExecutableArgs          = search.ExecutableArgs;
            searchEntity.ExecutableArgsSanitised = search.ExecutableArgs;
            searchEntity.State                   = SearchState.StagingData;
            searchEntity.StartTime               = DateTime.UtcNow;
            searchEntity.PoolId                  = search.PoolId;
            searchEntity.PoolDisplayName         = search.PoolDisplayName;
            searchEntity.TargetDedicated         = search.TargetDedicated;
            searchEntity.VirtualMachineSize      = search.VirtualMachineSize;
            searchEntity.CompletedTasks          = 0;
            searchEntity.TotalTasks              = search.SearchInputFiles.Count();
            ParseExecutableArgs(search, searchEntity);
            _tableStorageProvider.InsertEntity(searchEntity);
            return(searchEntity);
        }
Ejemplo n.º 3
0
        public Guid SubmitSearch(SearchSpecification search)
        {
            if (search == null)
            {
                throw new ArgumentNullException("search");
            }

            ValidateExecutableArgs(search.ExecutableArgs);

            var db = _databaseProvider.GetDatabase(search.DatabaseName);

            if (db == null)
            {
                throw new ArgumentException(string.Format("Cannot find database {0}", search.DatabaseName));
            }
            var fragments = _databaseProvider.GetDatabaseFragments(search.DatabaseName);

            if (fragments == null || fragments.Count == 0)
            {
                throw new ArgumentException(string.Format("Database has no fragments {0}", search.DatabaseName));
            }

            var searchEntity = CreateSearchEntity(search, db);

            try
            {
                // Upload all the inputs to storage
                Parallel.ForEach(search.SearchInputFiles, queryFile =>
                {
                    var filename = Path.GetFileName(queryFile.Filename);
                    _blobStorageProvider.UploadBlobFromStream(searchEntity.InputContainer, filename, queryFile.Content);
                });

                var queryIndex    = 0;
                var searchQueries = new List <SearchQueryEntity>();
                foreach (var queryFile in search.SearchInputFiles)
                {
                    var query = new SearchQueryEntity(searchEntity.Id, queryIndex.ToString());
                    query.OutputContainer     = searchEntity.OutputContainer;
                    query.QueryFilename       = Path.GetFileName(queryFile.Filename);
                    query.State               = QueryState.Waiting;
                    query.QueryOutputFilename = GetQueryOutputFilename(searchEntity.OutputfileFormat, queryIndex.ToString());
                    query.LogOutputFilename   = GetLogFilename(searchEntity.OutputfileFormat, queryIndex.ToString());
                    searchQueries.Add(query);
                    queryIndex++;
                }

                _tableStorageProvider.InsertEntities(searchQueries);

                // Stage the generic batch scripts to storage
                var resourceFiles = InputFileStager.StageImportScripts(_blobStorageProvider);
                SubmitBatchJob(searchEntity, searchQueries, resourceFiles);

                searchEntity.State = SearchState.WaitingForResources;
                _tableStorageProvider.UpdateEntity(searchEntity);
            }
            catch (Exception e)
            {
                if (e is AggregateException)
                {
                    e = e.InnerException;
                }

                searchEntity.State  = SearchState.Error;
                searchEntity.Errors = e.ToString();
                _tableStorageProvider.UpdateEntity(searchEntity);

                throw e;
            }

            return(searchEntity.Id);
        }