예제 #1
0
        /// <summary>
        /// Do the lookup!
        /// </summary>
        protected override void ProcessRecord()
        {
            // Setup for verbosity if we need it.
            var listener = new PSListener(this);

            Trace.Listeners.Add(listener);
            try
            {
                PandaTask t            = null;
                bool      needdatasets = OutputContainerNames.IsPresent || InputContainerNames.IsPresent;

                if (ParameterSetName == "TaskID")
                {
                    t = TaskID.FindPandaJobWithTaskName(needdatasets);
                }
                if (ParameterSetName == "TaskObject")
                {
                    t = PandaTaskObject.ID.FindPandaJobWithTaskName(needdatasets);
                }
                if (ParameterSetName == "TaskName")
                {
                    t = TaskName.FindPandaJobWithTaskName(needdatasets);
                }
                if (ParameterSetName == "DatasetGRIDJob")
                {
                    // Get the job and resulting dataset name.
                    var job = JobParser.FindJob(JobName, JobVersion);
                    var ds  = job.ResultingDataSetName(DatasetName.Trim(), JobIteration);

                    // Now, look up the job itself.
                    t = (ds + "/").FindPandaJobWithTaskName();
                }

                // We really can't deal with a bad task below. The returned objects are sufficiently complex.
                if (t == null)
                {
                    throw new ArgumentException("Unable to find the task in panda: was it ever submitted?");
                }

                // Dump the info to the output pipeline as requested.
                if (JobStatus.IsPresent)
                {
                    WriteObject(t.status);
                }
                if (InputContainerNames.IsPresent)
                {
                    WriteObject(t.DataSetNamesIN());
                }
                if (OutputContainerNames.IsPresent)
                {
                    WriteObject(t.DataSetNamesOUT());
                }
            } finally
            {
                Trace.Listeners.Remove(listener);
            }
        }
예제 #2
0
        /// <summary>
        /// Get a job and print it out.
        /// </summary>
        protected override void ProcessRecord()
        {
            int version;

            if (!int.TryParse(JobVersion, out version))
            {
                throw new ArgumentException(string.Format("JobVersion must be a valid integer, not '{0}'", JobVersion));
            }

            var job = JobParser.FindJob(JobName, version);

            if (job == null)
            {
                throw new ArgumentException(string.Format("Job '{0}' v{1} not found on system. Create .jobspec?", JobName, JobVersion));
            }

            var str = job.Print(prettyPrint: !PrintCacheForm.IsPresent);

            WriteObject(str);
        }
예제 #3
0
        private string GetJobDatasetName()
        {
            string dataset;
            // Get the job, see if it is finished, and then get the output dataset.
            var job = JobParser.FindJob(JobName, JobVersion);

            if (job == null)
            {
                throw new ArgumentException($"Job {JobName} v{JobVersion} is not known to the system!");
            }

            // Get the resulting job name for this guy.
            var pandaJobName = job.ResultingDataSetName(JobSourceDatasetName, JobIteration) + "/";

            // Now, to get the output dataset, we need to fetch the job.
            var pandaTask = pandaJobName.FindPandaJobWithTaskName(true);

            if (pandaTask == null)
            {
                throw new ArgumentException($"No panda task found with name '{pandaJobName}' for job '{JobName}' v{JobVersion}.");
            }
            if (pandaTask.status != "finished" && pandaTask.status != "done")
            {
                throw new ArgumentException($"Panda task {pandaTask.jeditaskid} has status {pandaTask.status} - which is not done or finished ({pandaJobName}).");
            }
            var containers = pandaTask.DataSetNamesOUT();

            if (containers.Length > 1)
            {
                throw new ArgumentException($"There are more than one output container for the panda task {pandaTask.jeditaskid} - can't decide. Need code upgrade!! Thanks for the fish!");
            }
            if (containers.Length == 0)
            {
                throw new ArgumentException($"There are no output containers for the panda task {pandaTask.jeditaskid} ({pandaJobName}) - so nothing to fetch!");
            }
            dataset = containers.First();
            return(dataset);
        }
예제 #4
0
        /// <summary>
        /// Fetch a particular dataset.
        /// </summary>
        protected override void ProcessRecord()
        {
            var listener = new PSListener(this);

            Trace.Listeners.Add(listener);
            try
            {
                // Get the actual dataset name.
                var dataset = DatasetName;
                if (ParameterSetName == "job")
                {
                    // Get the job, see if it is finished, and then get the output dataset.
                    var job = JobParser.FindJob(JobName, JobVersion);
                    if (job == null)
                    {
                        throw new ArgumentException($"Job {JobName} v{JobVersion} is not known to the system!");
                    }

                    // Get the resulting job name for this guy.
                    var pandaJobName = job.ResultingDataSetName(JobSourceDatasetName) + "/";

                    // Now, to get the output dataset, we need to fetch the job.
                    var pandaTask = pandaJobName.FindPandaJobWithTaskName(true);
                    if (pandaTask == null)
                    {
                        throw new ArgumentException($"No panda task found with name '{pandaJobName}' for job '{JobName}' v{JobVersion}.");
                    }
                    var containers = pandaTask.DataSetNamesOUT();
                    if (containers.Length > 1)
                    {
                        throw new ArgumentException($"There are more than one output container for the panda task {pandaTask.jeditaskid} - can't decide. Need code upgrade!! Thanks for the fish!");
                    }
                    dataset = containers.First();
                }

                // Find all the members of this dataset.
                var allFilesToCopy = DataSetManager.ListOfFilesInDataSetAsync(dataset, m => DisplayStatus($"Listing Files in {dataset}", m), failNow: () => Stopping)
                                     .Result;
                if (nFiles != 0)
                {
                    allFilesToCopy = allFilesToCopy
                                     .OrderBy(u => u.AbsolutePath)
                                     .Take(nFiles)
                                     .ToArray();
                }

                // Next, see what the test is. It is only exists right now.
                if (!Exists)
                {
                    throw new ArgumentException("Test-GRIDDataset just use the -Exists flag.");
                }

                // Query the location to see if we have a decent copy there.
                var loc = Location.AsIPlace().Result;

                var hasFiles = Task.WhenAll(allFilesToCopy
                                            .Select(f => loc.HasFileAsync(f, m => DisplayStatus($"Checking Files {dataset}", m), failNow: () => Stopping)))
                               .Result
                               .All(f => f);

                // Dump all the returned files out to whatever is next in the pipeline.
                using (var pl = listener.PauseListening())
                {
                    WriteObject(hasFiles);
                }
            }
            finally
            {
                Trace.Listeners.Remove(listener);
            }
        }
예제 #5
0
        /// <summary>
        /// Fetch a particular dataset.
        /// </summary>
        protected override void ProcessRecord()
        {
            var listener = new PSListener(this);

            Trace.Listeners.Add(listener);
            try
            {
                // Get the actual dataset name.
                var dataset = DatasetName.Trim();
                if (ParameterSetName == "job")
                {
                    // Get the job, see if it is finished, and then get the output dataset.
                    var job = JobParser.FindJob(JobName, JobVersion);
                    if (job == null)
                    {
                        throw new ArgumentException($"Job {JobName} v{JobVersion} is not known to the system!");
                    }

                    // Get the resulting job name for this guy.
                    var pandaJobName = job.ResultingDataSetName(JobSourceDatasetName, JobIteration) + "/";

                    // Now, to get the output dataset, we need to fetch the job.
                    var pandaTask = pandaJobName.FindPandaJobWithTaskName(true);
                    if (pandaTask == null)
                    {
                        throw new ArgumentException($"No panda task found with name '{pandaJobName}' for job '{JobName}' v{JobVersion}.");
                    }
                    var containers = pandaTask.DataSetNamesOUT();
                    if (containers.Length > 1)
                    {
                        throw new ArgumentException($"There are more than one output container for the panda task {pandaTask.jeditaskid} - can't decide. Need code upgrade!! Thanks for the fish!");
                    }
                    dataset = containers.First();
                }

                // Find all the members of this dataset.
                var allFilesToCopy = DataSetManager.ListOfFilesInDataSetAsync(dataset, m => DisplayStatus($"Listing Files in {dataset}", m), failNow: () => Stopping)
                                     .Result;
                if (nFiles != 0)
                {
                    allFilesToCopy = allFilesToCopy
                                     .OrderBy(u => u.AbsolutePath)
                                     .Take(nFiles)
                                     .ToArray();
                }

                // Turn the source and destination locations into actual locations.
                var locSource = SourceLocation.AsIPlace().Result;
                var locDest   = DestinationLocation.AsIPlace().Result;

                // Do the actual copy. This will fail if one of the files can't be found at the source.
                var resultUris = DataSetManager
                                 .CopyFilesAsync(locSource, locDest, allFilesToCopy, mbox => DisplayStatus($"Downloading {dataset}", mbox), failNow: () => Stopping, timeout: Timeout)
                                 .Result;

                // Dump all the returned files out to whatever is next in the pipeline.
                if (PassThru.IsPresent)
                {
                    using (var pl = listener.PauseListening())
                    {
                        foreach (var ds in resultUris)
                        {
                            WriteObject(ds);
                        }
                    }
                }
            }
            finally
            {
                Trace.Listeners.Remove(listener);
            }
        }
예제 #6
0
        /// <summary>
        /// Load up the job requested. Fail, obviously, if we can't.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Setup for verbosity if we need it.
            var listener = new PSListener(this);

            Trace.Listeners.Add(listener);
            try
            {
                // Get the job
                var job = JobParser.FindJob(JobName, JobVersion);

                // Get the expected resulting dataset name. Since this will be a personal
                // dataset, we need to get the GRID info.
                var    originalDatasetName = DatasetName.Trim();
                string resultDatasetName   = job.ResultingDataSetName(originalDatasetName, _gridCredentials, JobIteration);

                // See if there is already a job defined that will produce this
                var pandaJob = (resultDatasetName + "/").FindPandaJobWithTaskName(useCacheIfPossible: !DoNotUsePandaTaskCache.IsPresent);

                if (pandaJob == null)
                {
                    // Where are we going to be doing the submission on?
                    var sm = JobParser.GetSubmissionMachine();

                    // Get the remove environment configured if it needs to be
                    var firstJob = false;
                    if (_connection == null)
                    {
                        firstJob    = true;
                        _connection = new SSHConnection(sm.MachineName, sm.UserName);
                        _connection
                        .Apply(() => DisplayStatus("Setting up ATLAS"))
                        .setupATLAS(dumpOnly: WhatIf.IsPresent)
                        .Apply(() => DisplayStatus("Setting up Rucio"))
                        .setupRucio(_gridCredentials.Username, dumpOnly: WhatIf.IsPresent)
                        .Apply(() => DisplayStatus("Acquiring GRID credentials"))
                        .VomsProxyInit("atlas", failNow: () => Stopping, dumpOnly: WhatIf.IsPresent);
                    }

                    // Check to see if the original dataset exists. We will use the location known as Local for doing the
                    // setup, I suppose.
                    var files = _connection
                                .Apply(() => DisplayStatus("Checking dataset exists on the GRID"))
                                .FilelistFromGRID(originalDatasetName, failNow: () => Stopping, dumpOnly: WhatIf.IsPresent);
                    if (files.Length == 0 && !WhatIf.IsPresent)
                    {
                        throw new ArgumentException($"Dataset '{originalDatasetName}' has zero files - won't submit a job against it!");
                    }

                    // Submit the job
                    _connection
                    .SubmitJobAsync(job, originalDatasetName, resultDatasetName, DisplayStatus, failNow: () => Stopping, sameJobAsLastTime: !firstJob, dumpOnly: WhatIf.IsPresent)
                    .WaitAndUnwrapException();

                    // Try to find the job again if requested. The submission can take a very long time to show up in
                    // big panda, so skip unless requested.
                    if (WaitForPandaRegistration)
                    {
                        var pandJobResult = Policy
                                            .Handle <InvalidOperationException>()
                                            .WaitAndRetryForever(nthRetry => TimeSpan.FromMinutes(1),
                                                                 (e, ts) => { WriteWarning($"Failed to find the submitted panda job on bigpanda: {e.Message}. Will wait one minute and try again."); })
                                            .ExecuteAndCapture(() => FindPandaJobForDS(resultDatasetName));
                        if (pandJobResult.Outcome != OutcomeType.Successful)
                        {
                            throw pandJobResult.FinalException;
                        }
                        pandaJob = pandJobResult.Result;
                    }
                }

                // Return a helper obj that contains the info about this job that can be used by other commands.
                if (pandaJob != null)
                {
                    var r = new AtlasPandaTaskID()
                    {
                        ID = pandaJob.jeditaskid, Name = pandaJob.taskname
                    };
                    using (var pp = listener.PauseListening())
                    {
                        WriteObject(r);
                    }
                }
            } finally
            {
                Trace.Listeners.Remove(listener);
            }
        }