/// <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; } }
/// <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; } }
/// <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; } }
/// <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> /// 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; } }
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()); }
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(); }
/// <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; } }
/// <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; } }
/// <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; } }