Update an AppProfile
Stay organized with collections
Save and categorize content based on your preferences.
Update an AppProfile.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","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)."]]