Exemple #1
0
        /// <summary>
        ///     This contains the implementation of the "Game maintenance" scenario.
        ///     1. Get the currently running cloud deployment that needs taking down for maintenance.
        ///     2. Lock down the deployment by removing the `live` tag and setting the worker flag.
        ///     3. Take a snapshot of the deployment.
        ///     4. Stop the deployment.
        ///     5. Start a new cloud deployment based on the old deployment, but with clean tags.
        ///     6. Mark the new cloud deployment live by adding the `live` tag.
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            Setup();

            Console.WriteLine("Finding the current running deployment");
            var currentLiveDeployment = DeploymentServiceClient.GetRunningDeploymentByName(new GetRunningDeploymentByNameRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName,
            });

            Console.WriteLine("Putting the deployment to maintenance mode");
            currentLiveDeployment.Deployment.Tags.Remove("my_live_tag");
            var setTagsRequest = new SetDeploymentTagsRequest
            {
                DeploymentId = currentLiveDeployment.Deployment.Id,
                Tags         = { currentLiveDeployment.Deployment.Tags },
            };

            DeploymentServiceClient.SetDeploymentTags(setTagsRequest);


            Console.WriteLine("Taking a cloud snapshot");
            var latestSnapshot = SnapshotServiceClient.TakeSnapshot(new TakeSnapshotRequest
            {
                Snapshot = new Snapshot
                {
                    ProjectName    = currentLiveDeployment.Deployment.ProjectName,
                    DeploymentName = currentLiveDeployment.Deployment.DeploymentName
                }
            }).PollUntilCompleted()
                                 .GetResultOrNull();

            Console.WriteLine("Stopping the deployment");
            DeploymentServiceClient.DeleteDeployment(new DeleteDeploymentRequest
            {
                Id = currentLiveDeployment.Deployment.Id,
            }).PollUntilCompleted();

            Console.WriteLine("Starting a new deployment with empty tags");
            var newDeployment = DeploymentServiceClient.CreateDeployment(new CreateDeploymentRequest
            {
                DeploymentName     = currentLiveDeployment.Deployment.DeploymentName,
                ProjectName        = currentLiveDeployment.Deployment.ProjectName,
                StartingSnapshotId = latestSnapshot.Id,
                LaunchConfig       = currentLiveDeployment.Deployment.LaunchConfig,
                AssemblyName       = currentLiveDeployment.Deployment.AssemblyName,
            })
                                .PollUntilCompleted()
                                .GetResultOrNull();

            Console.WriteLine("Putting the new deployment to live");
            var setLiveTagsRequest = new SetDeploymentTagsRequest
            {
                DeploymentId = newDeployment.Id,
            };

            setTagsRequest.Tags.Add("my_live_tag");
            DeploymentServiceClient.SetDeploymentTags(setLiveTagsRequest);

            Cleanup(newDeployment);
        }