Mettre à jour le déploiement

Mettez à jour un déploiement de Game Servers.

Exemple de code

Java

Pour savoir comment installer et utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes Game Servers.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.gaming.v1.GameServerDeployment;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import com.google.cloud.gaming.v1.OperationMetadata;
import com.google.protobuf.FieldMask;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class UpdateDeployment {
  public static void updateGameServerDeployment(String projectId, String deploymentId)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // String projectId = "your-project-id";
    // String deploymentId = "your-game-server-deployment-id";
    // 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.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {
      String deploymentName =
          String.format(
              "projects/%s/locations/global/gameServerDeployments/%s", projectId, deploymentId);

      GameServerDeployment deployment =
          GameServerDeployment.newBuilder()
              .setName(deploymentName)
              .putLabels("key", "value")
              .build();

      FieldMask fieldMask = FieldMask.newBuilder().addPaths("labels").build();

      OperationFuture<GameServerDeployment, OperationMetadata> call =
          client.updateGameServerDeploymentAsync(deployment, fieldMask);

      GameServerDeployment updated = call.get(1, TimeUnit.MINUTES);
      System.out.println("Game Server Deployment updated: " + updated.getName());
    }
  }
}

Python

Pour savoir comment installer et utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes Game Servers.

def update_deployment(project_id, deployment_id):
    """Updates a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.UpdateGameServerDeploymentRequest(
        game_server_deployment=game_server_deployments.GameServerDeployment(
            name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}",
            labels={"label-key-1": "label-value-1", "label-key-2": "label-value-2"},
        ),
        update_mask=field_mask.FieldMask(paths=["labels"]),
    )

    operation = client.update_game_server_deployment(request)
    print(f"Update deployment operation: {operation.operation.name}")
    operation.result(timeout=120)

Étape suivante

Pour rechercher et filtrer des exemples de code pour d'autres produits Google Cloud, consultez l'exemple de navigateur Google Cloud.