Ejemplo n.º 1
0
 public async Task <object> StopDeployment(dynamic data)
 {
     return(await Task.Run(() => {
         PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken);
         DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken);
         _deploymentServiceClient.StopDeployment(new StopDeploymentRequest
         {
             Id = data._DeploymentID,
             ProjectName = data._ProjectName
         });
         return data._DeploymentID;
     }));
 }
        public static void StopDeployment(Deployment deployment)
        {
            ExceptionHandler.HandleGrpcCall(() =>
            {
                var request = new StopDeploymentRequest
                {
                    Id          = deployment.Id,
                    ProjectName = deployment.ProjectName,
                };

                deploymentServiceClient.StopDeployment(request);
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     This stops the local and cloud deployments as a cleanup.
        /// </summary>
        private static void Cleanup()
        {
            Console.WriteLine("Cleaning up");
            LocalDeploymentServiceClient.StopDeployment(new StopDeploymentRequest
            {
                Id          = _localDeployment.Id,
                ProjectName = _localDeployment.ProjectName
            });

            CloudDeploymentServiceClient.StopDeployment(new StopDeploymentRequest
            {
                Id          = _cloudDeployment.Id,
                ProjectName = _cloudDeployment.ProjectName
            });
        }
Ejemplo n.º 4
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.StopDeployment(new StopDeploymentRequest
            {
                Id          = _deployment.Id,
                ProjectName = _deployment.ProjectName
            });
        }
Ejemplo n.º 5
0
        private static void StopDeploymentByName(DeploymentServiceClient deploymentServiceClient, string projectName,
                                                 string deploymentName)
        {
            var activeDeployments = ListLaunchedActiveDeployments(deploymentServiceClient, projectName);

            var deployment = activeDeployments.FirstOrDefault(d => d.Name == deploymentName);

            if (deployment == null)
            {
                Console.WriteLine($"Unable to stop the deployment {deployment.Name} because it can't be found or isn't running.");
                return;
            }

            Console.WriteLine($"Stopping active deployment by name: {deployment.Name}");

            deploymentServiceClient.StopDeployment(new StopDeploymentRequest
            {
                Id          = deployment.Id,
                ProjectName = projectName
            });
        }
Ejemplo n.º 6
0
 private static void StopDeploymentById(DeploymentServiceClient client, string projectName, string deploymentId)
 {
     try
     {
         Console.WriteLine($"Stopping deployment with id {deploymentId}");
         client.StopDeployment(new StopDeploymentRequest
         {
             Id          = deploymentId,
             ProjectName = projectName
         });
     }
     catch (Grpc.Core.RpcException e)
     {
         if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound)
         {
             Console.WriteLine("<error:unknown-deployment>");
         }
         else
         {
             throw;
         }
     }
 }
Ejemplo n.º 7
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 a current running deployment with live tag");
            var currentLiveDeployment = DeploymentServiceClient
                                        .ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            })
                                        .First(d => d.Status == Deployment.Types.Status.Running && d.Tag.Contains("my_live_tag"));

            Console.WriteLine("Putting the deployment to maintenance mode");
            currentLiveDeployment.Tag.Remove("my_live_tag");
            currentLiveDeployment.WorkerFlags.Add(new WorkerFlag
            {
                Key        = "maintenance",
                Value      = "true",
                WorkerType = "unity"
            });
            DeploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = currentLiveDeployment
            });

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

            Console.WriteLine("Stopping the deployment");
            DeploymentServiceClient.StopDeployment(new StopDeploymentRequest
            {
                Id          = currentLiveDeployment.Id,
                ProjectName = currentLiveDeployment.ProjectName
            });

            Console.WriteLine("Starting a new deployment with empty tags");
            var newDeployment = currentLiveDeployment.Clone();

            newDeployment.StartingSnapshotId = latestSnapshot.Id;
            newDeployment.Tag.Clear();
            newDeployment = DeploymentServiceClient
                            .CreateDeployment(new CreateDeploymentRequest {
                Deployment = newDeployment
            })
                            .PollUntilCompleted()
                            .GetResultOrNull();

            Console.WriteLine("Putting the new deployment to live");
            newDeployment.Tag.Add("my_live_tag");
            DeploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = newDeployment
            });

            Cleanup(newDeployment);
        }