更新 AppProfile
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
更新 AppProfile。
程式碼範例
C++
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to update an AppProfile in Google Cloud Bigtable using C++ and PHP client libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe C++ examples show how to update an AppProfile's description and modify its routing configuration by clearing the \u003ccode\u003emulti_cluster_routing_use_any\u003c/code\u003e settings.\u003c/p\u003e\n"],["\u003cp\u003eThe PHP example showcases how to update an AppProfile with a new description and set a \u003ccode\u003eSingleClusterRouting\u003c/code\u003e policy, including the ability to \u003ccode\u003eallow_transactional_writes\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eBoth code samples highlight the importance of setting up Application Default Credentials for authentication and provide links to related documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe PHP code also illustrates how to handle potential errors, like an \u003ccode\u003eAppProfile\u003c/code\u003e not being found, during the update process.\u003c/p\u003e\n"]]],[],null,["Update an AppProfile.\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::future;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id, std::string const& instance_id,\n std::string const& profile_id, std::string const& description) {\n std::string profile_name =\n cbt::AppProfileName(project_id, instance_id, profile_id);\n\n google::bigtable::admin::v2::AppProfile profile;\n profile.set_name(profile_name);\n profile.set_description(description);\n\n google::protobuf::FieldMask mask;\n mask.add_paths(\"description\");\n\n future\u003cStatusOr\u003cgoogle::bigtable::admin::v2::AppProfile\u003e\u003e profile_future =\n instance_admin.UpdateAppProfile(std::move(profile), std::move(mask));\n auto modified_profile = profile_future.get();\n if (!modified_profile) throw std::move(modified_profile).status();\n std::cout \u003c\u003c \"Updated AppProfile: \" \u003c\u003c modified_profile-\u003eDebugString()\n \u003c\u003c \"\\n\";\n }\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::future;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id, std::string const& instance_id,\n std::string const& profile_id) {\n std::string profile_name =\n cbt::AppProfileName(project_id, instance_id, profile_id);\n\n google::bigtable::admin::v2::UpdateAppProfileRequest req;\n req.mutable_app_profile()-\u003eset_name(profile_name);\n req.mutable_app_profile()-\u003emutable_multi_cluster_routing_use_any()-\u003eClear();\n req.mutable_update_mask()-\u003eadd_paths(\"multi_cluster_routing_use_any\");\n req.set_ignore_warnings(true);\n\n future\u003cStatusOr\u003cgoogle::bigtable::admin::v2::AppProfile\u003e\u003e profile_future =\n instance_admin.UpdateAppProfile(std::move(req));\n auto modified_profile = profile_future.get();\n if (!modified_profile) throw std::move(modified_profile).status();\n std::cout \u003c\u003c \"Updated AppProfile: \" \u003c\u003c modified_profile-\u003eDebugString()\n \u003c\u003c \"\\n\";\n }\n\nPHP\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\ApiCore\\ApiException;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\AppProfile;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\AppProfile\\SingleClusterRouting;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Client\\BigtableInstanceAdminClient;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\UpdateAppProfileRequest;\n use Google\\Protobuf\\FieldMask;\n\n /**\n * Update an App Profile\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n * @param string $clusterId The ID of the new cluster where the new App Profile will route it's requests(in case of single cluster routing)\n * @param string $appProfileId The ID of the App Profile to update\n */\n function update_app_profile(\n string $projectId,\n string $instanceId,\n string $clusterId,\n string $appProfileId\n ): void {\n $instanceAdminClient = new BigtableInstanceAdminClient();\n $appProfileName = $instanceAdminClient-\u003eappProfileName($projectId, $instanceId, $appProfileId);\n\n $appProfile = new AppProfile([\n 'name' =\u003e $appProfileName,\n 'description' =\u003e 'The updated description',\n ]);\n\n // create a new routing policy\n // allow_transactional_writes refers to Single-Row-Transactions(https://cloud.google.com/bigtable/docs/app-profiles#single-row-transactions)\n $routingPolicy = new SingleClusterRouting([\n 'cluster_id' =\u003e $clusterId,\n 'allow_transactional_writes' =\u003e true\n ]);\n\n // set the newly created routing policy to our app profile\n $appProfile-\u003esetSingleClusterRouting($routingPolicy);\n\n // or we could also create a multi cluster routing policy like so:\n // $routingPolicy = new \\Google\\Cloud\\Bigtable\\Admin\\V2\\AppProfile\\MultiClusterRoutingUseAny();\n // $appProfile-\u003esetMultiClusterRoutingUseAny($routingPolicy);\n\n // returns a string identifier depending on SingleClusterRouting or MultiClusterRoutingUseAny\n $routingPolicyStr = $appProfile-\u003egetRoutingPolicy();\n\n $updateMask = new FieldMask([\n 'paths' =\u003e ['description', $routingPolicyStr]\n ]);\n\n printf('Updating the AppProfile %s' . PHP_EOL, $appProfileId);\n\n try {\n // Bigtable warns you while updating the routing policy, or when toggling the allow_transactional_writes\n // to force it to update, we set ignoreWarnings to true.\n // If you just want to update something simple like description, you can remove it.\n $updateAppProfileRequest = (new UpdateAppProfileRequest())\n -\u003esetAppProfile($appProfile)\n -\u003esetUpdateMask($updateMask)\n -\u003esetIgnoreWarnings(true);\n $operationResponse = $instanceAdminClient-\u003eupdateAppProfile($updateAppProfileRequest);\n\n $operationResponse-\u003epollUntilComplete();\n if ($operationResponse-\u003eoperationSucceeded()) {\n $updatedAppProfile = $operationResponse-\u003egetResult();\n printf('App profile updated: %s' . PHP_EOL, $updatedAppProfile-\u003egetName());\n // doSomethingWith($updatedAppProfile)\n } else {\n $error = $operationResponse-\u003egetError();\n // handleError($error)\n }\n } catch (ApiException $e) {\n if ($e-\u003egetStatus() === 'NOT_FOUND') {\n printf('App Profile %s does not exist.' . PHP_EOL, $appProfileId);\n return;\n }\n throw $e;\n }\n }\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]