Inheritance: IRegionEndpoint
Exemplo n.º 1
0
        public IRegionEndpoint GetRegionEndpoint(string regionName)
        {
            try
            {
                try
                {
                    _readerWriterLock.EnterReadLock();

                    IRegionEndpoint endpoint;
                    if (_regionEndpointMap.TryGetValue(regionName, out endpoint))
                    {
                        return(endpoint);
                    }
                }
                finally
                {
                    if (_readerWriterLock.IsReadLockHeld)
                    {
                        _readerWriterLock.ExitReadLock();
                    }
                }

                try
                {
                    _readerWriterLock.EnterWriteLock();

                    IRegionEndpoint endpoint;
                    // Check again to see if region is in cache in case another thread got the write lock before and filled the cache.
                    if (_regionEndpointMap.TryGetValue(regionName, out endpoint))
                    {
                        return(endpoint);
                    }

                    JsonData partitions = _root["partitions"];
                    foreach (JsonData partition in partitions)
                    {
                        string description;
                        if (IsRegionInPartition(regionName, partition, out description))
                        {
                            endpoint = new RegionEndpointV3(regionName, description, partition, partition["services"]);
                            _regionEndpointMap.Add(regionName, endpoint);
                            return(endpoint);
                        }
                    }
                }
                finally
                {
                    if (_readerWriterLock.IsWriteLockHeld)
                    {
                        _readerWriterLock.ExitWriteLock();
                    }
                }
            }
            catch (Exception)
            {
                throw new AmazonClientException("Invalid endpoint.json format.");
            }

            return(GetNonstandardRegionEndpoint(regionName));
        }
        public IRegionEndpoint GetRegionEndpoint(string regionName)
        {
            try
            {
                lock (_regionEndpointMapLock)
                {
                    IRegionEndpoint endpoint;
                    if (_regionEndpointMap.TryGetValue(regionName, out endpoint))
                    {
                        return(endpoint);
                    }
                    else
                    {
                        JsonData partitions = _root["partitions"];
                        foreach (JsonData partition in partitions)
                        {
                            string description;
                            if (IsRegionInPartition(regionName, partition, out description))
                            {
                                endpoint = new RegionEndpointV3(regionName, description, partition, partition["services"]);
                                _regionEndpointMap.Add(regionName, endpoint);
                                return(endpoint);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw new AmazonClientException("Invalid endpoint.json format.");
            }

            return(GetNonstandardRegionEndpoint(regionName));
        }
Exemplo n.º 3
0
        public IRegionEndpoint GetRegionEndpoint(string regionName)
        {
            try
            {
                lock (_regionEndpointMapLock)
                {
                    IRegionEndpoint endpoint;
                    if (_regionEndpointMap.TryGetValue(regionName, out endpoint))
                    {
                        return(endpoint);
                    }
                    else
                    {
                        JsonData partitions = _root["partitions"];
                        foreach (JsonData partition in partitions)
                        {
                            JsonData region = partition["regions"][regionName];
                            if (region != null)
                            {
                                endpoint = new RegionEndpointV3(regionName, (string)region["description"], partition, partition["services"]);
                                _regionEndpointMap.Add(regionName, endpoint);
                                return(endpoint);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw new AmazonClientException("Invalid endpoint.json format.");
            }

            return(GetUnknownRegionEndpoint(regionName));
        }
 public IRegionEndpoint GetRegionEndpoint(string regionName)
 {
     try
     {
         lock (_regionEndpointMapLock)
         {
             if (_regionEndpointMap.TryGetValue(regionName, out IRegionEndpoint value))
             {
                 return(value);
             }
             foreach (JsonData item in (IEnumerable)_root["partitions"])
             {
                 if (IsRegionInPartition(regionName, item, out string description))
                 {
                     value = new RegionEndpointV3(regionName, description, item, item["services"]);
                     _regionEndpointMap.Add(regionName, value);
                     return(value);
                 }
             }
         }
     }
     catch (Exception)
     {
         throw new AmazonClientException("Invalid endpoint.json format.");
     }
     return(GetNonstandardRegionEndpoint(regionName));
 }
Exemplo n.º 5
0
        public IRegionEndpoint GetRegionEndpoint(string regionName)
        {
            try
            {
                lock (_regionEndpointMapLock)
                {
                    IRegionEndpoint endpoint;
                    if (_regionEndpointMap.TryGetValue(regionName, out endpoint))
                    {
                        return endpoint;
                    }
                    else
                    {
                        JsonData partitions = _root["partitions"];
                        foreach (JsonData partition in partitions)
                        {
                            string description;
                            if (IsRegionInPartition(regionName, partition, out description))
                            {
                                endpoint = new RegionEndpointV3(regionName, description, partition, partition["services"]);
                                _regionEndpointMap.Add(regionName, endpoint);
                                return endpoint;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw new AmazonClientException("Invalid endpoint.json format.");
            }

            return GetNonstandardRegionEndpoint(regionName);
        }
Exemplo n.º 6
0
        /// <summary>
        /// This region name is non-standard.  Search the whole endpoints.json file to
        /// determine the partition this region is in.
        /// </summary>
        private IRegionEndpoint GetNonstandardRegionEndpoint(string regionName)
        {
            try
            {
                _readerWriterLock.EnterReadLock();

                IRegionEndpoint regionEndpoint;
                if (_nonStandardRegionNameToObjectMap.TryGetValue(regionName, out regionEndpoint))
                {
                    return(regionEndpoint);
                }
            }
            finally
            {
                if (_readerWriterLock.IsReadLockHeld)
                {
                    _readerWriterLock.ExitReadLock();
                }
            }

            try
            {
                _readerWriterLock.EnterWriteLock();

                IRegionEndpoint regionEndpoint;
                // Check again to see if region is in cache in case another thread got the write lock before and filled the cache.
                if (_nonStandardRegionNameToObjectMap.TryGetValue(regionName, out regionEndpoint))
                {
                    return(regionEndpoint);
                }

                // default to "aws" partition
                JsonData partitionData            = _root["partitions"][0];
                string   regionDescription        = GetUnknownRegionDescription(regionName);
                JsonData servicesData             = partitionData["services"];
                bool     foundContainingPartition = false;

                const string validRegionRegexStr = @"^[a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?$";
                var          match = Regex.Match(regionName, validRegionRegexStr, RegexOptions.Compiled);

                foreach (JsonData partition in _root["partitions"])
                {
                    JsonData partitionServices = partition["services"];
                    foreach (string service in partitionServices.PropertyNames)
                    {
                        if (partitionServices[service] != null && partitionServices[service].Count > 0)
                        {
                            JsonData serviceData = partitionServices[service];
                            if (serviceData != null && serviceData["endpoints"][regionName] != null)
                            {
                                partitionData            = partition;
                                servicesData             = partitionServices;
                                foundContainingPartition = true;
                                break;
                            }
                        }
                    }
                }
                if (!foundContainingPartition && !match.Success)
                {
                    throw new ArgumentException("Invalid region endpoint provided");
                }
                regionEndpoint = new RegionEndpointV3(regionName, regionDescription, partitionData, servicesData);
                _nonStandardRegionNameToObjectMap.Add(regionName, regionEndpoint);
                return(regionEndpoint);
            }
            finally
            {
                if (_readerWriterLock.IsWriteLockHeld)
                {
                    _readerWriterLock.ExitWriteLock();
                }
            }
        }