Example #1
0
    public async Task <GameServerDeployment> UpdateRolloutRemoveOverrideConfigAsync(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeploymentRollout rollout = new GameServerDeploymentRollout
        {
            Name = GameServerDeploymentName.FormatProjectLocationDeployment(projectId, "global", deploymentId)
        };

        UpdateGameServerDeploymentRolloutRequest request = new UpdateGameServerDeploymentRolloutRequest
        {
            Rollout    = rollout,
            UpdateMask = new FieldMask {
                Paths = { "game_server_config_overrides" }
            }
        };

        // Make the request.
        Operation <GameServerDeployment, OperationMetadata> response = await client.UpdateGameServerDeploymentRolloutAsync(request);

        Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
        /// <summary>
        /// Updates game deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        /// <returns>Game server deployment name</returns>
        public string UpdateDeployment(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            string parent         = $"projects/{projectId}/locations/global";
            string deploymentName = $"{parent}/gameServerDeployments/{deploymentId}";

            // Construct the request
            var deployment = new GameServerDeployment
            {
                Name   = deploymentName,
                Labels = { { "key", "value" } }
            };
            var fieldMask = new FieldMask {
                Paths = { "labels" }
            };

            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Call the API
            try
            {
                var updated = client.UpdateGameServerDeployment(deployment, fieldMask);

                // Inspect the result
                return($"Game server deployment updated for deployment {deploymentId}. Operation Id: {updated.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"UpdateGameServerDeployment error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Commit a rollback for deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="regionId">Region in which the cluster will be created</param>
        /// <param name="deploymentId">Deployment Id</param>
        public string RevertRollout(
            string projectId    = "YOUR-PROJECT-ID",
            string regionId     = "us-central1-f",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string deploymentName = $"projects/{projectId}/locations/{regionId}/gameServerDeployments/{deploymentId}";

            // Call the API
            try
            {
                var result = client.RevertRollout(deploymentName);

                // Inspect the result
                return($"Rollout reverted for {deploymentId}. Operation ID: {result.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"RevertRollout error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
        /// <summary>
        /// Gets game deployment target
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        public string GetDeploymentTarget(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string parent         = $"projects/{projectId}/locations/global";
            string deploymentName = $"{parent}/gameServerDeployments/{deploymentId}";

            // Call the API
            try
            {
                var result = client.GetDeploymentTarget(deploymentName);

                // Inspect the result
                return($"Found target for {deploymentName} with {result.Clusters.Count} clusters.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetDeploymentTarget error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
    public async Task <GameServerDeployment> UpdateDeploymentAsync(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeployment deployment = new GameServerDeployment
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };

        deployment.Labels.Add("label-key-1", "label-value-1");
        deployment.Labels.Add("label-key-2", "label-value-2");

        UpdateGameServerDeploymentRequest request = new UpdateGameServerDeploymentRequest
        {
            GameServerDeployment = deployment,
            UpdateMask           = new FieldMask {
                Paths = { "labels" }
            }
        };

        // Make the request.
        Operation <GameServerDeployment, OperationMetadata> response = await client.UpdateGameServerDeploymentAsync(request);

        Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result. This result will NOT contain the updated labels.
        // If you want to get the updated resource, use a GET request on the resource.
        return(completedResponse.Result);
    }
Example #6
0
        /// <summary>
        /// Gets game deployment target
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        public string SetRolloutTargetTarget(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string parent             = $"projects/{projectId}/locations/global";
            string deploymentName     = $"{parent}/gameServerDeployments/{deploymentId}";
            var    percentageSelector = new ClusterPercentageSelector
            {
                Percent = 50
            };
            var request = new SetRolloutTargetRequest
            {
                Name = deploymentName,
                ClusterPercentageSelector = { percentageSelector }
            };

            // Call the API
            try
            {
                var result = client.SetRolloutTarget(request);

                // Inspect the result
                return($"Rollout target set for {deploymentId}. Operation Id: {result.Name}.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"SetRolloutTarget error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
Example #7
0
        /// <summary>
        /// Deletes game deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        public string DeleteDeployment(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string parent         = $"projects/{projectId}/locations/global";
            string deploymentName = $"{parent}/gameServerDeployments/{deploymentId}";

            // Call the API
            try
            {
                var result = client.DeleteGameServerDeployment(deploymentName);

                // Inspect the result
                return($"Game server deployment {deploymentId} deleted.");
            }
            catch (Exception e)
            {
                Console.WriteLine($"DeleteGameServerDeployment error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
Example #8
0
    public async Task <GameServerDeployment> CreateDeploymentAsync(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeployment deployment = new GameServerDeployment()
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };
        CreateGameServerDeploymentRequest request = new CreateGameServerDeploymentRequest
        {
            DeploymentId         = deploymentId,
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, "global"),
            GameServerDeployment = deployment
        };

        // Make the request.
        Operation <GameServerDeployment, OperationMetadata> response = await client.CreateGameServerDeploymentAsync(request);

        // Poll until the returned long-running operation is complete.
        Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
Example #9
0
    public GameServerDeploymentRollout GetRollout(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.Create();

        GetGameServerDeploymentRolloutRequest request = new GetGameServerDeploymentRolloutRequest
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };

        // Make the request.
        GameServerDeploymentRollout response = client.GetGameServerDeploymentRollout(request);

        return(response);
    }
    public IList <GameServerDeployment> ListDeployments(
        string projectId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.Create();

        ListGameServerDeploymentsRequest request = new ListGameServerDeploymentsRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation(projectId, "global")
        };

        // Make the request.
        PagedEnumerable <ListGameServerDeploymentsResponse, GameServerDeployment> response = client.ListGameServerDeployments(request);

        // The returned sequence will lazily perform RPCs as it's being iterated over.
        return(response.ToList());
    }
Example #11
0
    public void DeleteDeployment(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.Create();

        DeleteGameServerDeploymentRequest request = new DeleteGameServerDeploymentRequest
        {
            GameServerDeploymentName = GameServerDeploymentName.FromProjectLocationDeployment(projectId, "global", deploymentId)
        };

        // Make the request.
        Operation <Empty, OperationMetadata> response = client.DeleteGameServerDeployment(request);

        // Poll until the returned long-running operation is complete.
        response.PollUntilCompleted();
    }
Example #12
0
        /// <summary>
        /// Gets game deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        /// <returns>Deployment name</returns>
        public List <string> ListGameDeployments(
            string projectId = "YOUR-PROJECT-ID")
        {
            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string parent = $"projects/{projectId}/locations/global";

            // Call the API
            try
            {
                var gameDeployments = client.ListGameServerDeployments(parent);

                // Inspect the result
                List <string> result  = new List <string>();
                bool          hasMore = true;
                Page <GameServerDeployment> currentPage;
                while (hasMore)
                {
                    currentPage = gameDeployments.ReadPage(pageSize: 10);

                    // Read the result in a given page
                    foreach (var gameDeployment in currentPage)
                    {
                        Console.WriteLine($"Game server deployment found: {gameDeployment.Name}");
                        result.Add(gameDeployment.Name);
                    }
                    hasMore = currentPage != null;
                }
                ;

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine($"ListGameServerDeployments error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
    public async Task <GameServerDeployment> UpdateRolloutOverrideConfigAsync(
        string projectId, string deploymentId, string configId, string realmRegionId, string realmId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerConfigOverride configOverride = new GameServerConfigOverride
        {
            ConfigVersion  = configId,
            RealmsSelector = new RealmSelector()
        };

        configOverride.RealmsSelector.Realms.Add(RealmName.FormatProjectLocationRealm(projectId, realmRegionId, realmId));

        GameServerDeploymentRollout rollout = new GameServerDeploymentRollout
        {
            Name = GameServerDeploymentName.FormatProjectLocationDeployment(projectId, "global", deploymentId)
        };

        rollout.GameServerConfigOverrides.Add(configOverride);

        UpdateGameServerDeploymentRolloutRequest request = new UpdateGameServerDeploymentRolloutRequest
        {
            Rollout    = rollout,
            UpdateMask = new FieldMask {
                Paths = { "game_server_config_overrides" }
            }
        };

        // Make the request.
        Operation <GameServerDeployment, OperationMetadata> response = await client.UpdateGameServerDeploymentRolloutAsync(request);

        Operation <GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
        /// <summary>
        /// Starts a rollout
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="regionId">Region in which the cluster will be created</param>
        /// <param name="deploymentId">Deployment Id</param>
        /// <returns>Rollout name</returns>
        public string StartRollout(
            string projectId    = "YOUR-PROJECT-ID",
            string regionId     = "us-central1-f",
            string deploymentId = "YOUR-DEPLOYMENT-ID",
            string templateId   = "YOUR-GAME-SERVER-TEMPLATE-ID")
        {
            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string deploymentName = $"projects/{projectId}/locations/{regionId}/gameServerDeployments/{deploymentId}";

            // Build a spec as shown at https://agones.dev/site/docs/reference/gameserver/
            var container = new JObject();

            container.Add("name", "default");
            container.Add("image", "gcr.io/agones-images/default:1.0");

            var containers = new JArray();

            containers.Add(container);

            var spec = new JObject();

            spec.Add("containers", containers);

            var template = new JObject();

            template.Add("spec", spec);

            var port = new JObject();

            port.Add("name", "default");

            var ports = new JArray();

            ports.Add(port);

            var specObject = new JObject();

            specObject.Add("ports", ports);
            specObject.Add("template", template);

            var gameServerTemplate = new GameServerTemplate
            {
                TemplateId = templateId,
                Spec       = specObject.ToString(),
            };

            var startRolloutRequest = new StartRolloutRequest
            {
                Name = deploymentName,
                NewGameServerTemplate = gameServerTemplate
            };

            // Call the API
            try
            {
                var result = client.StartRollout(startRolloutRequest);

                // Inspect the result
                return($"Deployment rollout started for {deploymentId}. Operation Id: {result.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"StartRollout error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
Example #15
0
        /// <summary>
        /// Creates a new game deployment
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="deploymentId">Deployment Id</param>
        public string CreateDeployment(
            string projectId    = "YOUR-PROJECT-ID",
            string deploymentId = "YOUR-DEPLOYMENT-ID")
        {
            // Build a spec as shown at https://agones.dev/site/docs/reference/gameserver/
            var container = new JObject();

            container.Add("name", "default");
            container.Add("image", "gcr.io/agones-images/default:1.0");
            var containers = new JArray();

            containers.Add(container);

            var spec = new JObject();

            spec.Add("containers", containers);

            var template = new JObject();

            template.Add("spec", spec);

            var port = new JObject();

            port.Add("name", "default");

            var ports = new JArray();

            ports.Add(port);

            var specObject = new JObject();

            specObject.Add("ports", ports);
            specObject.Add("template", template);

            // Initialize the client
            var client = GameServerDeploymentsServiceClient.Create();

            // Construct the request
            string parent             = $"projects/{projectId}/locations/global";
            string deploymentName     = $"{parent}/gameServerDeployments/{deploymentId}";
            var    gameServerTemplate = new GameServerTemplate
            {
                Spec       = specObject.ToString(),
                TemplateId = "default"
            };
            var gameServerDeployment = new GameServerDeployment
            {
                Name = deploymentName,
                NewGameServerTemplate = gameServerTemplate,
            };
            var request = new CreateGameServerDeploymentRequest
            {
                Parent               = parent,
                DeploymentId         = deploymentId,
                GameServerDeployment = gameServerDeployment,
            };

            // Call the API
            try
            {
                var created = client.CreateGameServerDeployment(request);

                // Inspect the result
                return($"Game server deployment created for {deploymentId}. OperationId: {created.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"CreateGameServerDeployment error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }