Пример #1
0
        private void NameVauleForm_Load(object sender, EventArgs e)
        {
            m_table.Columns.Add("Name", typeof(string));
            m_table.Columns.Add("Value", typeof(string));
            m_dataGrid.DataSource = m_table;
            foreach (string key in m_pairs.Keys)
            {
                m_table.Rows.Add(key, m_pairs[key]);
            }
            m_table.AcceptChanges();

            if (Blocks != null)
            {
                m_blockList.Items.Clear();
                foreach (var block in Blocks)
                {
                    ListViewItem item = m_blockList.Items.Add(block.Name);
                    item.SubItems.Add(block.Length.ToString());
                    item.SubItems.Add(block.Committed.ToString());
                }
            }

            m_txtLeaseID.Text     = LeaseID;
            m_txtLeaseState.Text  = LeaseState.ToString();
            m_txtLeaseStatus.Text = LeaseStatus.ToString();
        }
Пример #2
0
 internal void ActivateLease()
 {
     // Set leaseTime
     leaseTime = DateTime.UtcNow.Add(initialLeaseTime);
     state     = LeaseState.Active;
     leaseManager.ActivateLease(this);
 }
Пример #3
0
        public EntityInfo(
            string name,
            DateTime?lastModified,
            long size,
            string absoluteUri,
            string contentType,
            string contentEncoding,
            string contentHash,
            LeaseState leaseState,
            bool leaseLocked)
        {
            Name = name;

            LastModified = lastModified;

            Size = size;

            AbsoluteUri = absoluteUri;

            ContentType = contentType;

            ContentEncoding = contentEncoding;

            ContentHash = contentHash;

            LeaseState = leaseState;

            LeaseLocked = leaseLocked;
        }
Пример #4
0
        internal void UpdateState()
        {
            // Called by the lease manager to update the state of this lease,
            // basically for knowing if it has expired

            if (_currentState != LeaseState.Active)
            {
                return;
            }
            if (CurrentLeaseTime > TimeSpan.Zero)
            {
                return;
            }

            // Expired. Try to renew using sponsors.

            if (_sponsors != null)
            {
                _currentState = LeaseState.Renewing;
                lock (this) {
                    _renewingSponsors = new Queue(_sponsors);
                }
                CheckNextSponsor();
            }
            else
            {
                _currentState = LeaseState.Expired;
            }
        }
Пример #5
0
 internal void ActivateLease()
 {
     // Set leaseTime
     leaseTime = DateTime.UtcNow.Add(initialLeaseTime);
     state = LeaseState.Active;
     leaseManager.ActivateLease(this);
 }
Пример #6
0
        public static string GetName(LeaseState LeaseStateEnum)
        {
            switch (LeaseStateEnum)
            {
            case LeaseState.Unassigned:
                return("Unassigned");

            case LeaseState.Released:
                return("Released");

            case LeaseState.Offered:
                return("Offered");

            case LeaseState.Assigned:
                return("Assigned");

            case LeaseState.Declined:
                return("Declined");

            case LeaseState.Static:
                return("Static");

            default:
                return("Unknown");
            }
        }
 /// <summary>
 /// Creates a new BlobDownloadDetails instance for mocking.
 /// </summary>
 public static BlobDownloadDetails BlobDownloadDetails(
     DateTimeOffset lastModified,
     IDictionary <string, string> metadata,
     string contentRange,
     string contentEncoding,
     string cacheControl,
     string contentDisposition,
     string contentLanguage,
     long blobSequenceNumber,
     DateTimeOffset copyCompletedOn,
     string copyStatusDescription,
     string copyId,
     string copyProgress,
     Uri copySource,
     CopyStatus copyStatus,
     LeaseDurationType leaseDuration,
     LeaseState leaseState,
     LeaseStatus leaseStatus,
     string acceptRanges,
     int blobCommittedBlockCount,
     bool isServerEncrypted,
     string encryptionKeySha256,
     string encryptionScope,
     byte[] blobContentHash,
     long tagCount,
     string versionId,
     bool isSealed,
     IList <ObjectReplicationPolicy> objectReplicationSourceProperties,
     string objectReplicationDestinationPolicy)
 => new BlobDownloadDetails
 {
     LastModified          = lastModified,
     Metadata              = metadata,
     ContentRange          = contentRange,
     ContentEncoding       = contentEncoding,
     CacheControl          = cacheControl,
     ContentDisposition    = contentDisposition,
     ContentLanguage       = contentLanguage,
     BlobSequenceNumber    = blobSequenceNumber,
     CopyCompletedOn       = copyCompletedOn,
     CopyStatusDescription = copyStatusDescription,
     CopyId                               = copyId,
     CopyProgress                         = copyProgress,
     CopySource                           = copySource,
     CopyStatus                           = copyStatus,
     LeaseDuration                        = leaseDuration,
     LeaseState                           = leaseState,
     LeaseStatus                          = leaseStatus,
     AcceptRanges                         = acceptRanges,
     BlobCommittedBlockCount              = blobCommittedBlockCount,
     IsServerEncrypted                    = isServerEncrypted,
     EncryptionKeySha256                  = encryptionKeySha256,
     EncryptionScope                      = encryptionScope,
     BlobContentHash                      = blobContentHash,
     TagCount                             = tagCount,
     VersionId                            = versionId,
     IsSealed                             = isSealed,
     ObjectReplicationSourceProperties    = objectReplicationSourceProperties,
     ObjectReplicationDestinationPolicyId = objectReplicationDestinationPolicy
 };
Пример #8
0
 internal void Remove()
 {
     if (this.state != LeaseState.Expired)
     {
         this.state = LeaseState.Expired;
         this.leaseManager.DeleteLease(this);
     }
 }
Пример #9
0
 public Lease()
 {
     _currentState       = LeaseState.Initial;
     _initialLeaseTime   = LifetimeServices.LeaseTime;
     _renewOnCallTime    = LifetimeServices.RenewOnCallTime;
     _sponsorshipTimeout = LifetimeServices.SponsorshipTimeout;
     _leaseExpireTime    = DateTime.UtcNow + _initialLeaseTime;
 }
Пример #10
0
		public Lease()
		{
			_currentState = LeaseState.Initial;
			_initialLeaseTime = LifetimeServices.LeaseTime;
			_renewOnCallTime = LifetimeServices.RenewOnCallTime;
			_sponsorshipTimeout = LifetimeServices.SponsorshipTimeout;
			_leaseExpireTime = DateTime.Now + _initialLeaseTime;
		}
Пример #11
0
 public JobLease()
 {
     initialleasetime   = TimeSpan.FromSeconds(3);
     sponsorshiptimeout = TimeSpan.FromSeconds(10);
     renewoncalltime    = TimeSpan.FromSeconds(2);
     currentleasetime   = TimeSpan.FromSeconds(10);
     currentstate       = LeaseState.Null;
 }
Пример #12
0
 public Lease()
 {
     this._currentState       = LeaseState.Initial;
     this._initialLeaseTime   = LifetimeServices.LeaseTime;
     this._renewOnCallTime    = LifetimeServices.RenewOnCallTime;
     this._sponsorshipTimeout = LifetimeServices.SponsorshipTimeout;
     this._leaseExpireTime    = DateTime.Now + this._initialLeaseTime;
 }
 /// <summary>
 /// Creates a new PathProperties instance for mocking.
 /// </summary>
 public static PathProperties PathProperties(
     DateTimeOffset lastModified,
     DateTimeOffset creationTime,
     IDictionary <string, string> metadata,
     DateTimeOffset copyCompletionTime,
     string copyStatusDescription,
     string copyId,
     string copyProgress,
     Uri copySource,
     CopyStatus copyStatus,
     bool isIncrementalCopy,
     LeaseDurationType leaseDuration,
     LeaseState leaseState,
     LeaseStatus leaseStatus,
     long contentLength,
     string contentType,
     ETag eTag,
     byte[] contentHash,
     IEnumerable <string> contentEncoding,
     string contentDisposition,
     IEnumerable <string> contentLanguage,
     string cacheControl,
     string acceptRanges,
     bool isServerEncrypted,
     string encryptionKeySha256,
     string accessTier,
     string archiveStatus,
     DateTimeOffset accessTierChangeTime)
 => new PathProperties()
 {
     LastModified          = lastModified,
     CreatedOn             = creationTime,
     Metadata              = metadata,
     CopyCompletedOn       = copyCompletionTime,
     CopyStatusDescription = copyStatusDescription,
     CopyId            = copyId,
     CopyProgress      = copyProgress,
     CopySource        = copySource,
     CopyStatus        = copyStatus,
     IsIncrementalCopy = isIncrementalCopy,
     LeaseDuration     = leaseDuration,
     LeaseState        = leaseState,
     LeaseStatus       = leaseStatus,
     ContentLength     = contentLength,
     ContentType       = contentType,
     ETag                = eTag,
     ContentHash         = contentHash,
     ContentEncoding     = contentEncoding,
     ContentDisposition  = contentDisposition,
     ContentLanguage     = contentLanguage,
     CacheControl        = cacheControl,
     AcceptRanges        = acceptRanges,
     IsServerEncrypted   = isServerEncrypted,
     EncryptionKeySha256 = encryptionKeySha256,
     AccessTier          = accessTier,
     ArchiveStatus       = archiveStatus,
     AccessTierChangedOn = accessTierChangeTime
 };
Пример #14
0
 // Constructor.
 public Lease(MarshalByRefObject obj, TimeSpan leaseTime,
              TimeSpan renewOnCallTime, TimeSpan sponsorshipTimeout)
 {
     this.obj = obj;
     this.initialLeaseTime   = leaseTime;
     this.renewOnCallTime    = renewOnCallTime;
     this.sponsorshipTimeout = sponsorshipTimeout;
     this.state = LeaseState.Initial;
 }
Пример #15
0
 public BlobArtifactDetailEntity(string name, string fileName, Uri uri, long size, string md5, LeaseState leaseState) : this()
 {
     Name       = name;
     FileName   = fileName;
     Uri        = uri;
     Size       = size;
     MD5        = md5;
     LeaseState = leaseState;
 }
Пример #16
0
 // Used for a lease which has been created, but will not be used
 internal void Remove()
 {
     BCLDebug.Trace("REMOTE", "Lease ", id, " Remove state ", ((Enum)state).ToString());
     if (state == LeaseState.Expired)
     {
         return;
     }
     state = LeaseState.Expired;
     leaseManager.DeleteLease(this);
 }
Пример #17
0
 public BindingLease(string clientId, PhysicalAddress owner, InternetAddress address, byte[] hostName, DateTime expiration, UInt32 sessionId, LeaseState state)
 {
     this._clientId = clientId;
     this._owner = owner;
     this._address = address;
     this._hostName = hostName;
     this._expiration = expiration;
     this._sessionId = sessionId;
     this._state = state;
 }
Пример #18
0
 public BindingLease(string clientId, PhysicalAddress owner, InternetAddress address, byte[] hostName, DateTime expiration, UInt32 sessionId, LeaseState state)
 {
     this._clientId   = clientId;
     this._owner      = owner;
     this._address    = address;
     this._hostName   = hostName;
     this._expiration = expiration;
     this._sessionId  = sessionId;
     this._state      = state;
 }
Пример #19
0
 internal Lease(TimeSpan initialLeaseTime, TimeSpan renewOnCallTime, TimeSpan sponsorshipTimeout, MarshalByRefObject managedObject)
 {
     this.renewOnCallTime    = renewOnCallTime;
     this.sponsorshipTimeout = sponsorshipTimeout;
     this.initialLeaseTime   = initialLeaseTime;
     this.managedObject      = managedObject;
     this.leaseManager       = LeaseManager.GetLeaseManager();
     this.sponsorTable       = new Hashtable(10);
     this.state = LeaseState.Initial;
 }
 internal Lease(TimeSpan initialLeaseTime, TimeSpan renewOnCallTime, TimeSpan sponsorshipTimeout, MarshalByRefObject managedObject)
 {
     this.renewOnCallTime = renewOnCallTime;
     this.sponsorshipTimeout = sponsorshipTimeout;
     this.initialLeaseTime = initialLeaseTime;
     this.managedObject = managedObject;
     this.leaseManager = LeaseManager.GetLeaseManager();
     this.sponsorTable = new Hashtable(10);
     this.state = LeaseState.Initial;
 }
Пример #21
0
        internal static void VerifyLeaseState(MethodInfo method, string scope, LeaseState leaseState, LeaseStatus leaseStatus, CloudBlobDirectory directory = null)
        {
            string lockId = FormatLockId(method, scope);

            CloudBlobDirectory lockDirectory = directory ?? _lockDirectory;
            CloudBlockBlob     lockBlob      = lockDirectory.GetBlockBlobReference(lockId);

            lockBlob.FetchAttributes();
            Assert.Equal(leaseState, lockBlob.Properties.LeaseState);
            Assert.Equal(leaseStatus, lockBlob.Properties.LeaseStatus);
        }
            public async Task VerifyLockState(string lockId, LeaseState state, LeaseStatus status)
            {
                var    container = BlobServiceClient.GetBlobContainerClient("azure-webjobs-hosts");
                string blobName  = string.Format("locks/{0}/{1}", HostId, lockId);
                var    lockBlob  = container.GetBlockBlobClient(blobName);

                Assert.True(await lockBlob.ExistsAsync());
                BlobProperties blobProperties = await lockBlob.GetPropertiesAsync();

                Assert.AreEqual(state, blobProperties.LeaseState);
                Assert.AreEqual(status, blobProperties.LeaseStatus);
            }
            public void VerifyLockState(string lockId, LeaseState state, LeaseStatus status)
            {
                CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();
                var             container  = blobClient.GetContainerReference("azure-webjobs-hosts");
                string          blobName   = string.Format("locks/{0}/{1}", Config.HostId, lockId);
                var             lockBlob   = container.GetBlockBlobReference(blobName);

                Assert.True(lockBlob.Exists());
                lockBlob.FetchAttributes();

                Assert.Equal(state, lockBlob.Properties.LeaseState);
                Assert.Equal(status, lockBlob.Properties.LeaseStatus);
            }
Пример #24
0
 private void AddTime(TimeSpan renewalSpan)
 {
     if (this.state != LeaseState.Expired)
     {
         DateTime time2 = DateTime.UtcNow.Add(renewalSpan);
         if (this.leaseTime.CompareTo(time2) < 0)
         {
             this.leaseManager.ChangedLeaseTime(this, time2);
             this.leaseTime = time2;
             this.state     = LeaseState.Active;
         }
     }
 }
 private void AddTime(TimeSpan renewalSpan)
 {
     if (this.state != LeaseState.Expired)
     {
         DateTime time2 = DateTime.UtcNow.Add(renewalSpan);
         if (this.leaseTime.CompareTo(time2) < 0)
         {
             this.leaseManager.ChangedLeaseTime(this, time2);
             this.leaseTime = time2;
             this.state = LeaseState.Active;
         }
     }
 }
        internal static void VerifyLeaseState(MethodInfo method, string scope, LeaseState leaseState, LeaseStatus leaseStatus)
        {
            string lockId = string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name);

            if (!string.IsNullOrEmpty(scope))
            {
                lockId += "." + scope;
            }

            CloudBlockBlob lockBlob = _lockDirectory.GetBlockBlobReference(lockId);

            lockBlob.FetchAttributes();
            Assert.Equal(leaseState, lockBlob.Properties.LeaseState);
            Assert.Equal(leaseStatus, lockBlob.Properties.LeaseStatus);
        }
Пример #27
0
        private void CheckNextSponsor()
        {
            if (this._renewingSponsors.Count == 0)
            {
                this._currentState     = LeaseState.Expired;
                this._renewingSponsors = null;
                return;
            }
            ISponsor @object = (ISponsor)this._renewingSponsors.Peek();

            this._renewalDelegate = new Lease.RenewalDelegate(@object.Renewal);
            IAsyncResult asyncResult = this._renewalDelegate.BeginInvoke(this, null, null);

            ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.ProcessSponsorResponse), asyncResult, this._sponsorshipTimeout, true);
        }
Пример #28
0
        void CheckNextSponsor()
        {
            if (_renewingSponsors.Count == 0)
            {
                _currentState     = LeaseState.Expired;
                _renewingSponsors = null;
                return;
            }

            ISponsor nextSponsor = (ISponsor)_renewingSponsors.Peek();

            _renewalDelegate = new RenewalDelegate(nextSponsor.Renewal);
            IAsyncResult ar = _renewalDelegate.BeginInvoke(this, null, null);

            ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, new WaitOrTimerCallback(ProcessSponsorResponse), ar, _sponsorshipTimeout, true);
        }
 /// <summary>
 /// Creates a new FileDownloadDetails instance for mocking.
 /// </summary>
 public static FileDownloadDetails FileDownloadDetails(
     DateTimeOffset lastModified,
     IDictionary <string, string> metadata,
     string contentRange,
     ETag eTag,
     string contentEncoding,
     string cacheControl,
     string contentDisposition,
     string contentLanguage,
     DateTimeOffset copyCompletionTime,
     string copyStatusDescription,
     string copyId,
     string copyProgress,
     Uri copySource,
     CopyStatus copyStatus,
     LeaseDurationType leaseDuration,
     LeaseState leaseState,
     LeaseStatus leaseStatus,
     string acceptRanges,
     bool isServerEncrypted,
     string encryptionKeySha256,
     byte[] contentHash)
 => new FileDownloadDetails()
 {
     LastModified          = lastModified,
     Metadata              = metadata,
     ContentRange          = contentRange,
     ETag                  = eTag,
     ContentEncoding       = contentEncoding,
     CacheControl          = cacheControl,
     ContentDisposition    = contentDisposition,
     ContentLanguage       = contentLanguage,
     CopyCompletedOn       = copyCompletionTime,
     CopyStatusDescription = copyStatusDescription,
     CopyId                = copyId,
     CopyProgress          = copyProgress,
     CopySource            = copySource,
     CopyStatus            = copyStatus,
     LeaseDuration         = leaseDuration,
     LeaseState            = leaseState,
     LeaseStatus           = leaseStatus,
     AcceptRanges          = acceptRanges,
     IsServerEncrypted     = isServerEncrypted,
     EncryptionKeySha256   = encryptionKeySha256,
     ContentHash           = contentHash
 };
Пример #30
0
        private void AddTime(TimeSpan renewalSpan)
        {
            if (this.state == LeaseState.Expired)
            {
                return;
            }
            DateTime utcNow   = DateTime.UtcNow;
            DateTime dateTime = this.leaseTime;
            DateTime newTime  = utcNow.Add(renewalSpan);

            if (this.leaseTime.CompareTo(newTime) >= 0)
            {
                return;
            }
            this.leaseManager.ChangedLeaseTime(this, newTime);
            this.leaseTime = newTime;
            this.state     = LeaseState.Active;
        }
Пример #31
0
        private void AddTime(TimeSpan renewalSpan)
        {
            if (state == LeaseState.Expired)
            {
                return;
            }

            DateTime now          = DateTime.UtcNow;
            DateTime oldLeaseTime = leaseTime;
            DateTime renewTime    = now.Add(renewalSpan);

            if (leaseTime.CompareTo(renewTime) < 0)
            {
                leaseManager.ChangedLeaseTime(this, renewTime);
                leaseTime = renewTime;
                state     = LeaseState.Active;
            }
            //BCLDebug.Trace("REMOTE","Lease ",id," AddTime renewalSpan ",renewalSpan," current Time ",now," old leaseTime ",oldLeaseTime," new leaseTime ",leaseTime," state ",((Enum)state).ToString());
        }
Пример #32
0
 public static string GetName(LeaseState LeaseStateEnum)
 {
     switch (LeaseStateEnum)
     {
         case LeaseState.Unassigned:
             return "Unassigned";
         case LeaseState.Released:
             return "Released";
         case LeaseState.Offered:
             return "Offered";
         case LeaseState.Assigned:
             return "Assigned";
         case LeaseState.Declined:
             return "Declined";
         case LeaseState.Static:
             return "Static";
         default:
             return "Unknown";
     }
 }
Пример #33
0
        internal static void CheckBlobContainerCondition(Microsoft.WindowsAzure.DevelopmentStorage.Store.BlobContainer blobContainer, IContainerCondition condition, bool?isForSource, bool shouldCheckLease, ContainerLeaseInfo leaseInfo)
        {
            if (condition != null && condition.IfModifiedSinceTime.HasValue && condition.IfModifiedSinceTime.Value >= blobContainer.LastModificationTime)
            {
                throw new ConditionNotMetException(null, isForSource, null);
            }
            if (condition != null && condition.IfNotModifiedSinceTime.HasValue && condition.IfNotModifiedSinceTime.Value < blobContainer.LastModificationTime)
            {
                throw new ConditionNotMetException(null, isForSource, null);
            }
            if (shouldCheckLease && condition != null && condition.LeaseId.HasValue && leaseInfo != null)
            {
                LeaseState?state          = leaseInfo.State;
                LeaseState valueOrDefault = state.GetValueOrDefault();
                if (state.HasValue)
                {
                    switch (valueOrDefault)
                    {
                    case LeaseState.Available:
                    case LeaseState.Broken:
                    {
                        if (!leaseInfo.Id.HasValue)
                        {
                            throw new LeaseNotPresentException();
                        }
                        throw new LeaseLostException();
                    }

                    case LeaseState.Expired:
                    {
                        throw new LeaseLostException();
                    }
                    }
                }
                if (leaseInfo.Id.Value != condition.LeaseId.Value)
                {
                    throw new LeaseHeldException();
                }
            }
        }
Пример #34
0
        internal Lease(TimeSpan initialLeaseTime,
                       TimeSpan renewOnCallTime,
                       TimeSpan sponsorshipTimeout,
                       MarshalByRefObject managedObject
                       )
        {
            id = nextId++;
            BCLDebug.Trace("REMOTE", "Lease Constructor ", managedObject, " initialLeaseTime " + initialLeaseTime + " renewOnCall " + renewOnCallTime + " sponsorshipTimeout ", sponsorshipTimeout);

            // Set Policy
            this.renewOnCallTime    = renewOnCallTime;
            this.sponsorshipTimeout = sponsorshipTimeout;
            this.initialLeaseTime   = initialLeaseTime;
            this.managedObject      = managedObject;

            //Add lease to leaseManager
            leaseManager = LeaseManager.GetLeaseManager();

            // Initialize tables
            sponsorTable = new Hashtable(10);
            state        = LeaseState.Initial;
        }
Пример #35
0
        internal Lease(TimeSpan initialLeaseTime,
                       TimeSpan renewOnCallTime,                       
                       TimeSpan sponsorshipTimeout,
                       MarshalByRefObject managedObject
                      )
        {
            id = nextId++;
            BCLDebug.Trace("REMOTE", "Lease Constructor ",managedObject," initialLeaseTime "+initialLeaseTime+" renewOnCall "+renewOnCallTime+" sponsorshipTimeout ",sponsorshipTimeout);

            // Set Policy            
            this.renewOnCallTime = renewOnCallTime;
            this.sponsorshipTimeout = sponsorshipTimeout;
            this.initialLeaseTime = initialLeaseTime;
            this.managedObject = managedObject;

            //Add lease to leaseManager
            leaseManager = LeaseManager.GetLeaseManager();

            // Initialize tables
            sponsorTable = new Hashtable(10);
            state = LeaseState.Initial;
        }
Пример #36
0
 private void ProcessSponsorResponse(object state, bool timedOut)
 {
     if (!timedOut)
     {
         try
         {
             IAsyncResult result   = (IAsyncResult)state;
             TimeSpan     timeSpan = this._renewalDelegate.EndInvoke(result);
             if (timeSpan != TimeSpan.Zero)
             {
                 this.Renew(timeSpan);
                 this._currentState     = LeaseState.Active;
                 this._renewingSponsors = null;
                 return;
             }
         }
         catch
         {
         }
     }
     this.Unregister((ISponsor)this._renewingSponsors.Dequeue());
     this.CheckNextSponsor();
 }
Пример #37
0
        void ProcessSponsorResponse(object state, bool timedOut)
        {
            if (!timedOut)
            {
                try
                {
                    IAsyncResult ar      = (IAsyncResult)state;
                    TimeSpan     newSpan = _renewalDelegate.EndInvoke(ar);
                    if (newSpan != TimeSpan.Zero)
                    {
                        Renew(newSpan);
                        _currentState     = LeaseState.Active;
                        _renewingSponsors = null;
                        return;
                    }
                }
                catch { }
            }

            // Sponsor failed, timed out, or returned TimeSpan.Zero

            Unregister((ISponsor)_renewingSponsors.Dequeue());                  // Drop the sponsor
            CheckNextSponsor();
        }
Пример #38
0
		internal void UpdateState ()
		{
			// Called by the lease manager to update the state of this lease,
			// basically for knowing if it has expired

			if (_currentState != LeaseState.Active) return;
			if (CurrentLeaseTime > TimeSpan.Zero) return;

			// Expired. Try to renew using sponsors.

			if (_sponsors != null)
			{
				_currentState = LeaseState.Renewing;
				lock (this) {
					_renewingSponsors = new Queue (_sponsors);
				}
				CheckNextSponsor ();
			}
			else
				_currentState = LeaseState.Expired;
		}
Пример #39
0
		void CheckNextSponsor ()
		{
			if (_renewingSponsors.Count == 0) {
				_currentState = LeaseState.Expired;
				_renewingSponsors = null;
				return;
			}

			ISponsor nextSponsor = (ISponsor) _renewingSponsors.Peek();
			_renewalDelegate = new RenewalDelegate (nextSponsor.Renewal);
			IAsyncResult ar = _renewalDelegate.BeginInvoke (this, null, null);
			ThreadPool.RegisterWaitForSingleObject (ar.AsyncWaitHandle, new WaitOrTimerCallback (ProcessSponsorResponse), ar, _sponsorshipTimeout, true);
		}
Пример #40
0
		void ProcessSponsorResponse (object state, bool timedOut)
		{
			if (!timedOut)
			{
				try
				{
					IAsyncResult ar = (IAsyncResult)state;
					TimeSpan newSpan = _renewalDelegate.EndInvoke (ar);
					if (newSpan != TimeSpan.Zero)
					{
						Renew (newSpan);
						_currentState = LeaseState.Active;
						_renewingSponsors = null;
						return;
					}
				}
				catch { }
			}

			// Sponsor failed, timed out, or returned TimeSpan.Zero

			Unregister ((ISponsor) _renewingSponsors.Dequeue());	// Drop the sponsor
			CheckNextSponsor ();
		}
Пример #41
0
        /// <summary>
        /// Checks the lease status of a container, both from its attributes and from a container listing.
        /// </summary>
        /// <param name="container">The container to test.</param>
        /// <param name="expectedStatus">The expected lease status.</param>
        /// <param name="expectedState">The expected lease state.</param>
        /// <param name="expectedDuration">The expected lease duration.</param>
        /// <param name="description">A description of the circumstances that lead to the expected status.</param>
        private async Task CheckLeaseStatusAsync(
            CloudBlobContainer container,
            LeaseStatus expectedStatus,
            LeaseState expectedState,
            LeaseDuration expectedDuration,
            string description)
        {
            await container.FetchAttributesAsync();
            Assert.AreEqual(expectedStatus, container.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedState, container.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedDuration, container.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");

            ContainerResultSegment containers = await this.blobClient.ListContainersSegmentedAsync(container.Name, ContainerListingDetails.None, null, null, null, null);
            BlobContainerProperties propertiesInListing = (from CloudBlobContainer c in containers.Results
                                                           where c.Name == container.Name
                                                           select c.Properties).Single();

            Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListContainers)");
            Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListContainers)");
            Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListContainers)");
        }
Пример #42
0
        /// <summary>
        /// Checks the lease status of a blob, both from its attributes and from a blob listing.
        /// </summary>
        /// <param name="blob">The blob to test.</param>
        /// <param name="expectedStatus">The expected lease status.</param>
        /// <param name="expectedState">The expected lease state.</param>
        /// <param name="expectedDuration">The expected lease duration.</param>
        /// <param name="description">A description of the circumstances that lead to the expected status.</param>
        private async Task CheckLeaseStatusAsync(
            CloudBlob blob,
            LeaseStatus expectedStatus,
            LeaseState expectedState,
            LeaseDuration expectedDuration,
            string description)
        {
            await blob.FetchAttributesAsync();
            Assert.AreEqual(expectedStatus, blob.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedState, blob.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedDuration, blob.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");

            BlobResultSegment blobs = await blob.Container.ListBlobsSegmentedAsync(blob.Name, true, BlobListingDetails.None, null, null, null, null);
            BlobProperties propertiesInListing = (from CloudBlob b in blobs.Results
                                                  where b.Name == blob.Name
                                                  select b.Properties).Single();

            Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListBlobs)");
            Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListBlobs)");
            Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListBlobs)");
        }
Пример #43
0
        /// <summary>
        /// Checks the lease status of a container, both from its attributes and from a container listing.
        /// </summary>
        /// <param name="container">The container to test.</param>
        /// <param name="expectedStatus">The expected lease status.</param>
        /// <param name="expectedState">The expected lease state.</param>
        /// <param name="expectedDuration">The expected lease duration.</param>
        /// <param name="description">A description of the circumstances that lead to the expected status.</param>
        private void CheckLeaseStatus(
            CloudBlobContainer container,
            LeaseStatus expectedStatus,
            LeaseState expectedState,
            LeaseDuration expectedDuration,
            string description)
        {
            container.FetchAttributes();
            Assert.AreEqual(expectedStatus, container.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedState, container.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedDuration, container.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");

            BlobContainerProperties propertiesInListing = (from CloudBlobContainer c in this.blobClient.ListContainers(
                                                               container.Name,
                                                               ContainerListingDetails.None)
                                                           where c.Name == container.Name
                                                           select c.Properties).Single();

            Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListContainers)");
            Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListContainers)");
            Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListContainers)");
        }
Пример #44
0
 // Used for a lease which has been created, but will not be used
 internal void Remove()
 {
     BCLDebug.Trace("REMOTE","Lease ",id," Remove state ",((Enum)state).ToString());
     if (state == LeaseState.Expired)
         return;
     state = LeaseState.Expired;            
     leaseManager.DeleteLease(this);
 }
 internal void Remove()
 {
     if (this.state != LeaseState.Expired)
     {
         this.state = LeaseState.Expired;
         this.leaseManager.DeleteLease(this);
     }
 }
Пример #46
0
        private void AddTime(TimeSpan renewalSpan)
        {
            if (state == LeaseState.Expired)
                return;

            DateTime now = DateTime.UtcNow;
            DateTime oldLeaseTime = leaseTime;
            DateTime renewTime = now.Add(renewalSpan);
            if (leaseTime.CompareTo(renewTime) < 0)
            {
                leaseManager.ChangedLeaseTime(this, renewTime);
                leaseTime = renewTime;
                state = LeaseState.Active;
            }
            //BCLDebug.Trace("REMOTE","Lease ",id," AddTime renewalSpan ",renewalSpan," current Time ",now," old leaseTime ",oldLeaseTime," new leaseTime ",leaseTime," state ",((Enum)state).ToString());            
        }
		// Constructor.
		public Lease(MarshalByRefObject obj, TimeSpan leaseTime,
					 TimeSpan renewOnCallTime, TimeSpan sponsorshipTimeout)
				{
					this.obj = obj;
					this.initialLeaseTime = leaseTime;
					this.renewOnCallTime = renewOnCallTime;
					this.sponsorshipTimeout = sponsorshipTimeout;
					this.state = LeaseState.Initial;
				}
Пример #48
0
		public void Activate()
		{
			// Called when then Lease is registered in the LeaseManager
			_currentState = LeaseState.Active;
		}
Пример #49
0
        /// <summary>
        /// Checks the lease status of a blob, both from its attributes and from a blob listing.
        /// </summary>
        /// <param name="blob">The blob to test.</param>
        /// <param name="expectedStatus">The expected lease status.</param>
        /// <param name="expectedState">The expected lease state.</param>
        /// <param name="expectedDuration">The expected lease duration.</param>
        /// <param name="description">A description of the circumstances that lead to the expected status.</param>
        private void CheckLeaseStatus(
            CloudBlob blob,
            LeaseStatus expectedStatus,
            LeaseState expectedState,
            LeaseDuration expectedDuration,
            string description)
        {
            blob.FetchAttributes();
            Assert.AreEqual(expectedStatus, blob.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedState, blob.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
            Assert.AreEqual(expectedDuration, blob.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");

            BlobProperties propertiesInListing = (from CloudBlob b in blob.Container.ListBlobs(
                                                      blob.Name,
                                                      true /* use flat blob listing */,
                                                      BlobListingDetails.None,
                                                      null /* options */)
                                                  where b.Name == blob.Name
                                                  select b.Properties).Single();

            Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListBlobs)");
            Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListBlobs)");
            Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListBlobs)");
        }
 internal void ActivateLease()
 {
     this.leaseTime = DateTime.UtcNow.Add(this.initialLeaseTime);
     this.state = LeaseState.Active;
     this.leaseManager.ActivateLease(this);
 }
        public void ParseHeaders(System.Net.HttpWebResponse response)
        {
            //TODO: determine what we want to do about potential missing headers and date parsing errors

            ETag = response.Headers[ProtocolConstants.Headers.ETag].Trim('"');
            Date = Parsers.ParseDateHeader(response.Headers[ProtocolConstants.Headers.OperationDate]);
            LastModified = Parsers.ParseDateHeader(response.Headers[ProtocolConstants.Headers.LastModified]);

            switch (response.Headers[ProtocolConstants.Headers.LeaseStatus])
            {
                case ProtocolConstants.HeaderValues.LeaseStatus.Locked:
                    LeaseStatus = LeaseStatus.Locked;
                    break;
                case ProtocolConstants.HeaderValues.LeaseStatus.Unlocked:
                    LeaseStatus = LeaseStatus.Unlocked;
                    break;
                default:
                    throw new AzureResponseParseException(ProtocolConstants.Headers.LeaseStatus, response.Headers[ProtocolConstants.Headers.LeaseStatus]);
            }

            switch (response.Headers[ProtocolConstants.Headers.LeaseState])
            {
                case ProtocolConstants.HeaderValues.LeaseState.Available:
                    LeaseState = Common.LeaseState.Available;
                    break;
                case ProtocolConstants.HeaderValues.LeaseState.Breaking:
                    LeaseState = Common.LeaseState.Breaking;
                    break;
                case ProtocolConstants.HeaderValues.LeaseState.Broken:
                    LeaseState = Common.LeaseState.Broken;
                    break;
                case ProtocolConstants.HeaderValues.LeaseState.Expired:
                    LeaseState = Common.LeaseState.Expired;
                    break;
                case ProtocolConstants.HeaderValues.LeaseState.Leased:
                    LeaseState = Common.LeaseState.Leased;
                    break;
                default:
                    throw new AzureResponseParseException(ProtocolConstants.Headers.LeaseState, response.Headers[ProtocolConstants.Headers.LeaseState]);
            }

            switch (response.Headers[ProtocolConstants.Headers.LeaseDuration])
            {
                case ProtocolConstants.HeaderValues.LeaseDuration.Fixed:
                    LeaseDuration = LeaseDuration.Fixed;
                    break;
                case ProtocolConstants.HeaderValues.LeaseDuration.Infinite:
                    LeaseDuration = LeaseDuration.Infinite;
                    break;
                default:
                    LeaseDuration = LeaseDuration.NotSpecified;
                    break;
            }

            var metadata = new Dictionary<string, string>();
            foreach (var headerKey in response.Headers.AllKeys)
            {
                if (headerKey.StartsWith(ProtocolConstants.Headers.MetaDataPrefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    metadata[headerKey.Substring(ProtocolConstants.Headers.MetaDataPrefix.Length)] = response.Headers[headerKey];
                }
            }
            Metadata = new ReadOnlyDictionary<string, string>(metadata);
        }