示例#1
0
 public void NormalCall()
 {
     // Make sure it doesn't break.
     var location = new Locator();
     var ls = location.FindBestLocations();
     Assert.IsNotNull(ls);
 }
示例#2
0
 public void ScreenLocations()
 {
     AtlasWorkFlows.Utils.IPLocationTests.SetIpName("pc.cern.ch");
     Locator.SetLocationFilter(loc => false);
     var locator = new Locator();
     var lst = locator.FindBestLocations();
     Assert.IsNotNull(lst);
     Assert.AreEqual(0, lst.Length);
 }
示例#3
0
 public void CERNNotAtCERN()
 {
     AtlasWorkFlows.Utils.IPLocationTests.SetIpName("bogus.nytimes.com");
     var locator = new Locator();
     var lst = locator.FindBestLocations();
     Assert.IsNotNull(lst);
     var cern = lst.Where(l => l.Name == "MyTestLocation").FirstOrDefault();
     Assert.IsNull(cern);
 }
示例#4
0
        /// <summary>
        /// Find the DSInfo with the best possible location provider (local, remote, etc.).
        /// </summary>
        /// <param name="datasetname">The GRID dataset name to find pointers to.</param>
        /// <param name="fileFilter">Filter the potential list of files to be returned or downloaded (can really speed up things if you want one file in a large dataset).</param>
        /// <param name="locationFilter">Filter out the locations that we are allowed to fetch the file from.</param>
        /// <returns></returns>
        public static DSInfo FetchDSInfo(string datasetname, Func<string[], string[]> fileFilter, Func<string, bool> locationFilter)
        {
            // Basic parameter checks
            if (string.IsNullOrWhiteSpace(datasetname))
            {
                throw new ArgumentException("Dataset name is empty");
            }

            // Get a location so we can see if we can fetch the dataset
            var locator = new Locator();
            var locationList = locator.FindBestLocations();
            if (locationFilter != null)
            {
                locationList = locationList.Where(loc => locationFilter(loc.Name)).ToArray();
            }
            if (locationList.Length == 0)
            {
                throw new InvalidOperationException(string.Format("There are no valid ways to download dataset '{0}' from your current location.", datasetname));
            }

            // Get the info for each dataset.
            var allDSInfo = (from loc in locationList
                             let dsi = loc.GetDSInfo(datasetname)
                             select new
                             {
                                 dsinfo = dsi,
                                 islocal = dsi.IsLocal(fileFilter)
                             }).ToArray();

            // First, if anyone has something local, then we should grab that.
            var localDS = allDSInfo.Where(d => d.islocal).OrderByDescending(d => d.dsinfo.LocationProvider.Priority).ToArray();

            // Ok, now we need the ones that can generate it.
            if (localDS.Length == 0)
            {
                localDS = allDSInfo.Where(d => d.dsinfo.CanBeGeneratedAutomatically).OrderByDescending(d => d.dsinfo.LocationProvider.Priority).ToArray();
            }

            // Did we strike out?
            var locationInfo = localDS.FirstOrDefault();
            if (locationInfo == null)
            {
                var locationListText = "";
                foreach (var l in locationList)
                {
                    locationListText += l.Name + " ";
                }
                throw new ArgumentException(string.Format("Do not know how to generate the dataset '{0}' at any of the locations {1} (which are the only ones working where the computer is located)", datasetname, locationListText));
            }
            var dsinfo = locationInfo.dsinfo;
            return dsinfo;
        }