デプロイメントを更新

Game Servers のデプロイを更新します。

コードサンプル

Java

Game Servers のクライアント ライブラリをインストールして使用する方法については、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

Game Servers のクライアント ライブラリをインストールして使用する方法については、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)

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。