Exemple #1
0
        protected override void Cleanup()
        {
            if (_deployment == null)
            {
                return;
            }
            if (_deployment.Status != Deployment.Types.Status.Running &&
                _deployment.Status != Deployment.Types.Status.Starting)
            {
                return;
            }

            Console.WriteLine("Stopping deployment");
            _deploymentServiceClient.DeleteDeployment(new DeleteDeploymentRequest
            {
                Id = _deployment.Id,
            }).PollUntilCompleted();
        }
Exemple #2
0
        private void StopDeployment(Deployment deployment)
        {
            Log.Logger.Information("Stopping {dplName}", deployment.Name);
            // Update any tag changes
            UpdateDeployment(deployment);

            // Stop the deployment
            var deleteDeploymentRequest = new DeleteDeploymentRequest
            {
                Id = deployment.Id
            };

            try
            {
                var startTime = DateTime.Now;
                Reporter.ReportDeploymentStopRequest(matchType);
                var deleteOp = deploymentServiceClient.DeleteDeployment(deleteDeploymentRequest);
                Task.Run(() =>
                {
                    var completed = deleteOp.PollUntilCompleted();
                    Reporter.ReportDeploymentStopDuration(matchType, (DateTime.Now - startTime).TotalSeconds);
                    if (completed.IsCompleted)
                    {
                        Log.Logger.Information("Deployment {dplName} stopped succesfully", completed.Result.Name);
                    }
                    else if (completed.IsFaulted)
                    {
                        Log.Logger.Error("Failed to stop deployment {DplName}. Operation {opName}. Error {err}", deployment.Name, completed.Name, completed.Exception.Message);
                    }
                    else
                    {
                        Log.Logger.Error("Internal error stopping deployment {dplName}. Operation {opName}. Error {err}", completed.Result.Name, completed.Name, completed.Exception.Message);
                    }
                });
            }
            catch (RpcException e)
            {
                Reporter.ReportDeploymentStopFailure(matchType);
                Log.Logger.Warning("Failed to start deployment deletion. Error: {err}", e.Message);
            }
        }
Exemple #3
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);
        }