public async Task <GameServerCluster> UpdateClusterAsync(
        string projectId, string regionId, string realmId, string clusterId)
    {
        // Create the client.
        GameServerClustersServiceClient client = await GameServerClustersServiceClient.CreateAsync();

        GameServerCluster cluster = new GameServerCluster()
        {
            GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId)
        };

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

        UpdateGameServerClusterRequest request = new UpdateGameServerClusterRequest
        {
            GameServerCluster = cluster,
            UpdateMask        = new FieldMask {
                Paths = { "labels" }
            }
        };

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

        Operation <GameServerCluster, 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);
    }
示例#2
0
        public void GetGameServerClusterRequestObject()
        {
            moq::Mock <GameServerClustersService.GameServerClustersServiceClient> mockGrpcClient = new moq::Mock <GameServerClustersService.GameServerClustersServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetGameServerClusterRequest request = new GetGameServerClusterRequest
            {
                GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"),
            };
            GameServerCluster expectedResponse = new GameServerCluster
            {
                GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"),
                CreateTime            = new wkt::Timestamp(),
                UpdateTime            = new wkt::Timestamp(),
                Labels =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                ConnectionInfo = new GameServerClusterConnectionInfo(),
                Etag           = "etage8ad7218",
                Description    = "description2cf9da67",
            };

            mockGrpcClient.Setup(x => x.GetGameServerCluster(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            GameServerClustersServiceClient client = new GameServerClustersServiceClientImpl(mockGrpcClient.Object, null);
            GameServerCluster response             = client.GetGameServerCluster(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
    public async Task <GameServerCluster> CreateClusterAsync(
        string projectId, string regionId, string realmId, string clusterId, string gkeName)
    {
        // Create the client.
        GameServerClustersServiceClient client = await GameServerClustersServiceClient.CreateAsync();

        GameServerCluster cluster = new GameServerCluster()
        {
            GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId),
            ConnectionInfo        = new GameServerClusterConnectionInfo
            {
                GkeClusterReference = new GkeClusterReference
                {
                    Cluster = gkeName
                },
                Namespace = "default"
            }
        };
        CreateGameServerClusterRequest request = new CreateGameServerClusterRequest
        {
            ParentAsRealmName   = RealmName.FromProjectLocationRealm(projectId, regionId, realmId),
            GameServerClusterId = clusterId,
            GameServerCluster   = cluster
        };

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

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

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
示例#4
0
        /// <summary>
        /// Initialize client that will be used to send requests.This client only needs to be created
        /// once, and can be reused for multiple requests. After completing all of your requests, call
        /// the "close" method on the client to safely clean up any remaining background resources.
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="regionId">Region in which the cluster will be created</param>
        /// <param name="realmId"></param>
        /// <param name="clusterId">The id of the game server cluster</param>
        /// <param name="gkeName">The name of Google Kubernetes Engine cluster</param>
        public string CreateGameServerCluster(
            string projectId = "YOUR-PROJECT-ID",
            string regionId  = "us-central1",
            string realmId   = "YOUR-REALM-ID",
            string clusterId = "YOUR-GAME-SERVER-CLUSTER-ID",
            string gkeName   = "projects/YOUR-PROJECT-ID/locations/us-central1/clusters/test")
        {
            // Initialize the client
            var client = GameServerClustersServiceClient.Create();

            // Construct the request
            string parent            = $"projects/{projectId}/locations/{regionId}/realms/{realmId}";
            string clusterName       = $"{parent}/gameServerClusters/{clusterId}";
            var    gameServerCluster = new GameServerCluster
            {
                Name           = clusterName,
                ConnectionInfo = new GameServerClusterConnectionInfo
                {
                    GkeName   = gkeName,
                    Namespace = "default"
                }
            };
            var request = new CreateGameServerClusterRequest
            {
                Parent = parent,
                GameServerClusterId = clusterId,
                GameServerCluster   = gameServerCluster
            };

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

                // Inspect the result
                return($"Game server cluster created: {created.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"CreateGameServerCluster error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
示例#5
0
    public GameServerCluster GetCluster(
        string projectId, string regionId, string realmId, string clusterId)
    {
        // Create the client.
        GameServerClustersServiceClient client = GameServerClustersServiceClient.Create();

        GetGameServerClusterRequest request = new GetGameServerClusterRequest
        {
            GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId),
            View = GameServerClusterView.Full
        };

        // Make the request.
        GameServerCluster response = client.GetGameServerCluster(request);

        // You could write response.Name and response.ClusterState to the console
        // to see the installed versions of Agones and Kubernetes on the cluster.

        return(response);
    }
示例#6
0
        public async stt::Task GetGameServerClusterRequestObjectAsync()
        {
            moq::Mock <GameServerClustersService.GameServerClustersServiceClient> mockGrpcClient = new moq::Mock <GameServerClustersService.GameServerClustersServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetGameServerClusterRequest request = new GetGameServerClusterRequest
            {
                GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"),
                View = GameServerClusterView.Basic,
            };
            GameServerCluster expectedResponse = new GameServerCluster
            {
                GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster("[PROJECT]", "[LOCATION]", "[REALM]", "[CLUSTER]"),
                CreateTime            = new wkt::Timestamp(),
                UpdateTime            = new wkt::Timestamp(),
                Labels =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                ConnectionInfo = new GameServerClusterConnectionInfo(),
                Etag           = "etage8ad7218",
                Description    = "description2cf9da67",
                ClusterState   = new KubernetesClusterState(),
            };

            mockGrpcClient.Setup(x => x.GetGameServerClusterAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <GameServerCluster>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            GameServerClustersServiceClient client = new GameServerClustersServiceClientImpl(mockGrpcClient.Object, null);
            GameServerCluster responseCallSettings = await client.GetGameServerClusterAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            GameServerCluster responseCancellationToken = await client.GetGameServerClusterAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>
        /// Deletes a game server cluster
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="regionId">Region in which the cluster will be created</param>
        /// <param name="realmId"></param>
        /// <param name="clusterId">The id of the game server cluster</param>
        public string UpdateGameServerCluster(
            string projectId = "YOUR-PROJECT-ID",
            string regionId  = "us-central1-f",
            string realmId   = "YOUR-REALM-ID",
            string clusterId = "YOUR-GAME-SERVER-CLUSTER-ID")
        {
            // Initialize the client
            var client = GameServerClustersServiceClient.Create();

            // Construct the request
            string parent      = $"projects/{projectId}/locations/{regionId}/realms/{realmId}";
            string clusterName = $"{parent}/gameServerClusters/{clusterId}";
            var    cluster     = new GameServerCluster
            {
                Name   = clusterName,
                Labels = { { "key", "value" } }
            };
            var fieldMask = new FieldMask();

            fieldMask.Paths.Add("labels");

            // Call the API
            try
            {
                var updatedOperationId = client.UpdateGameServerCluster(cluster, fieldMask);

                // Inspect the result
                return($"Game server cluster updated: {cluster.Name}. OperationId: {updatedOperationId}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"UpdateGameServerCluster error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }