AppProfile을 업데이트합니다.
코드 샘플
C++
Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.
Bigtable에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id, std::string const& description) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
google::bigtable::admin::v2::AppProfile profile;
profile.set_name(profile_name);
profile.set_description(description);
google::protobuf::FieldMask mask;
mask.add_paths("description");
future<StatusOr<google::bigtable::admin::v2::AppProfile>> profile_future =
instance_admin.UpdateAppProfile(std::move(profile), std::move(mask));
auto modified_profile = profile_future.get();
if (!modified_profile) throw std::move(modified_profile).status();
std::cout << "Updated AppProfile: " << modified_profile->DebugString()
<< "\n";
}
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
google::bigtable::admin::v2::UpdateAppProfileRequest req;
req.mutable_app_profile()->set_name(profile_name);
req.mutable_app_profile()->mutable_multi_cluster_routing_use_any()->Clear();
req.mutable_update_mask()->add_paths("multi_cluster_routing_use_any");
req.set_ignore_warnings(true);
future<StatusOr<google::bigtable::admin::v2::AppProfile>> profile_future =
instance_admin.UpdateAppProfile(std::move(req));
auto modified_profile = profile_future.get();
if (!modified_profile) throw std::move(modified_profile).status();
std::cout << "Updated AppProfile: " << modified_profile->DebugString()
<< "\n";
}
PHP
Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.
Bigtable에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
use Google\ApiCore\ApiException;
use Google\Cloud\Bigtable\Admin\V2\AppProfile;
use Google\Cloud\Bigtable\Admin\V2\AppProfile\SingleClusterRouting;
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\UpdateAppProfileRequest;
use Google\Protobuf\FieldMask;
/**
* Update an App Profile
*
* @param string $projectId The Google Cloud project ID
* @param string $instanceId The ID of the Bigtable instance
* @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)
* @param string $appProfileId The ID of the App Profile to update
*/
function update_app_profile(
string $projectId,
string $instanceId,
string $clusterId,
string $appProfileId
): void {
$instanceAdminClient = new BigtableInstanceAdminClient();
$appProfileName = $instanceAdminClient->appProfileName($projectId, $instanceId, $appProfileId);
$appProfile = new AppProfile([
'name' => $appProfileName,
'description' => 'The updated description',
]);
// create a new routing policy
// allow_transactional_writes refers to Single-Row-Transactions(https://cloud.google.com/bigtable/docs/app-profiles#single-row-transactions)
$routingPolicy = new SingleClusterRouting([
'cluster_id' => $clusterId,
'allow_transactional_writes' => true
]);
// set the newly created routing policy to our app profile
$appProfile->setSingleClusterRouting($routingPolicy);
// or we could also create a multi cluster routing policy like so:
// $routingPolicy = new \Google\Cloud\Bigtable\Admin\V2\AppProfile\MultiClusterRoutingUseAny();
// $appProfile->setMultiClusterRoutingUseAny($routingPolicy);
// returns a string identifier depending on SingleClusterRouting or MultiClusterRoutingUseAny
$routingPolicyStr = $appProfile->getRoutingPolicy();
$updateMask = new FieldMask([
'paths' => ['description', $routingPolicyStr]
]);
printf('Updating the AppProfile %s' . PHP_EOL, $appProfileId);
try {
// Bigtable warns you while updating the routing policy, or when toggling the allow_transactional_writes
// to force it to update, we set ignoreWarnings to true.
// If you just want to update something simple like description, you can remove it.
$updateAppProfileRequest = (new UpdateAppProfileRequest())
->setAppProfile($appProfile)
->setUpdateMask($updateMask)
->setIgnoreWarnings(true);
$operationResponse = $instanceAdminClient->updateAppProfile($updateAppProfileRequest);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$updatedAppProfile = $operationResponse->getResult();
printf('App profile updated: %s' . PHP_EOL, $updatedAppProfile->getName());
// doSomethingWith($updatedAppProfile)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
} catch (ApiException $e) {
if ($e->getStatus() === 'NOT_FOUND') {
printf('App Profile %s does not exist.' . PHP_EOL, $appProfileId);
return;
}
throw $e;
}
}
다음 단계
다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.