private string GetDeploymentId(PublishContext context) { Deployment deployment = new Deployment(); do { // If a deployment has many roles to initialize, this // thread must throttle requests so the Azure portal // doesn't reply with a "too many requests" error Thread.Sleep(SleepDuration); try { deployment = new Deployment( ComputeClient.Deployments.GetBySlot(context.ServiceName, GetSlot(context.ServiceSettings.Slot))); } catch (CloudException ex) { if (ex.Response.StatusCode != HttpStatusCode.InternalServerError) { throw; } } } while (deployment.Status != DeploymentStatus.Starting && deployment.Status != DeploymentStatus.Running); return deployment.PrivateID; }
private void VerifyDeployment(PublishContext context) { try { WriteVerboseWithTimestamp(Resources.PublishInitializingMessage); var roleInstanceSnapshot = new Dictionary<string, RoleInstance>(); // Continue polling for deployment until all of the roles // indicate they're ready Deployment deployment; do { deployment = new Deployment( ComputeClient.Deployments.GetBySlot(context.ServiceName, GetSlot(context.ServiceSettings.Slot))); // The goal of this loop is to output a message whenever the status of a role // instance CHANGES. To do that, we have to remember the last status of all role instances // and that's what the roleInstanceSnapshot array is for foreach (RoleInstance currentInstance in deployment.RoleInstanceList) { // We only care about these three statuses, ignore other intermediate statuses if (string.Equals(currentInstance.InstanceStatus, RoleInstanceStatus.BusyRole) || string.Equals(currentInstance.InstanceStatus, RoleInstanceStatus.ReadyRole) || string.Equals(currentInstance.InstanceStatus, RoleInstanceStatus.CreatingRole)) { bool createdOrChanged = false; // InstanceName is unique and concatenates the role name and instance name if (roleInstanceSnapshot.ContainsKey(currentInstance.InstanceName)) { // If we already have a snapshot of that role instance, update it RoleInstance previousInstance = roleInstanceSnapshot[currentInstance.InstanceName]; if (!string.Equals(previousInstance.InstanceStatus, currentInstance.InstanceStatus)) { // If the instance status changed, we need to output a message previousInstance.InstanceStatus = currentInstance.InstanceStatus; createdOrChanged = true; } } else { // If this is the first time we run through, we also need to output a message roleInstanceSnapshot[currentInstance.InstanceName] = currentInstance; createdOrChanged = true; } if (createdOrChanged) { string statusResource; switch (currentInstance.InstanceStatus) { case RoleInstanceStatus.BusyRole: statusResource = Resources.PublishInstanceStatusBusy; break; case RoleInstanceStatus.ReadyRole: statusResource = Resources.PublishInstanceStatusReady; break; default: statusResource = Resources.PublishInstanceStatusCreating; break; } WriteVerboseWithTimestamp( Resources.PublishInstanceStatusMessage, currentInstance.InstanceName, currentInstance.RoleName, statusResource); } } } // If a deployment has many roles to initialize, this // thread must throttle requests so the Azure portal // doesn't reply with a "too many requests" error Thread.Sleep(SleepDuration); } while (deployment.RoleInstanceList.Any(r => r.InstanceStatus != RoleInstanceStatus.ReadyRole)); WriteVerboseWithTimestamp(Resources.PublishCreatedWebsiteMessage, deployment.Url); } catch (CloudException) { throw new InvalidOperationException( string.Format(Resources.CannotFindDeployment, context.ServiceName, context.ServiceSettings.Slot)); } }