| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a773840 commit 88c8638
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ | |||
| 17 | 17 | // [START batch_job_logs] | |
| 18 | 18 | #include "google/cloud/batch/v1/batch_client.h" | |
| 19 | 19 | #include "google/cloud/logging/v2/logging_service_v2_client.h" | |
| 20 | + #include "google/cloud/location.h" | ||
| 20 | 21 | #include "google/cloud/project.h" | |
| 21 | 22 | ||
| 22 | 23 | // [END batch_job_logs] | |
@@ -45,17 +46,17 @@ void JobLogs(std::vector<std::string> const& argv) { | |||
| 45 | 46 | // [START batch_job_logs] | |
| 46 | 47 | [](std::string const& project_id, std::string const& location_id, | |
| 47 | 48 | std::string const& job_id) { | |
| 48 | - auto const name = "projects/" + project_id + "/locations/" + location_id + | ||
| 49 | - "/jobs/" + job_id; | ||
| 49 | + auto const project = google::cloud::Project(project_id); | ||
| 50 | + auto const location = google::cloud::Location(project, location_id); | ||
| 51 | + auto const name = location.FullName() + "/jobs/" + job_id; | ||
| 50 | 52 | auto batch = google::cloud::batch_v1::BatchServiceClient( | |
| 51 | 53 | google::cloud::batch_v1::MakeBatchServiceConnection()); | |
| 52 | 54 | auto job = batch.GetJob(name); | |
| 53 | 55 | if (!job) throw std::move(job).status(); | |
| 54 | 56 | ||
| 55 | 57 | auto logging = google::cloud::logging_v2::LoggingServiceV2Client( | |
| 56 | 58 | google::cloud::logging_v2::MakeLoggingServiceV2Connection()); | |
| 57 | - auto const project = google::cloud::Project(project_id); | ||
| 58 | - auto const log_name = "projects/" + project_id + "/logs/batch_task_logs"; | ||
| 59 | + auto const log_name = project.FullName() + "/logs/batch_task_logs"; | ||
| 59 | 60 | google::logging::v2::ListLogEntriesRequest request; | |
| 60 | 61 | request.mutable_resource_names()->Add(project.FullName()); | |
| 61 | 62 | request.set_filter("logName=\"" + log_name + | |
@@ -78,7 +79,9 @@ google::cloud::batch::v1::Job CreateTestJob( | |||
| 78 | 79 | std::string const& project_id, std::string const& location_id, | |
| 79 | 80 | std::string const& job_id) { | |
| 80 | 81 | google::cloud::batch::v1::CreateJobRequest request; | |
| 81 | - request.set_parent("projects/" + project_id + "/locations/" + location_id); | ||
| 82 | + request.set_parent( | ||
| 83 | + google::cloud::Location(google::cloud::Project(project_id), location_id) | ||
| 84 | + .FullName()); | ||
| 82 | 85 | request.set_job_id(job_id); | |
| 83 | 86 | // Most of the job description is fixed in this example; use a string to | |
| 84 | 87 | // initialize it. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,7 @@ | |||
| 24 | 24 | #include "google/cloud/internal/background_threads_impl.h" | |
| 25 | 25 | #include "google/cloud/internal/getenv.h" | |
| 26 | 26 | #include "google/cloud/internal/random.h" | |
| 27 | + #include "google/cloud/location.h" | ||
| 27 | 28 | #include "google/cloud/project.h" | |
| 28 | 29 | #include "google/cloud/status_or.h" | |
| 29 | 30 | #include "google/cloud/testing_util/integration_test.h" | |
@@ -73,16 +74,16 @@ class InstanceAdminIntegrationTest | |||
| 73 | 74 | ||
| 74 | 75 | StatusOr<std::vector<std::string>> ListInstances( | |
| 75 | 76 | BigtableInstanceAdminClient& client) { | |
| 76 | - auto const project_name = Project(project_id_).FullName(); | ||
| 77 | - auto sor = client.ListInstances(project_name); | ||
| 77 | + auto const project = Project(project_id_); | ||
| 78 | + auto sor = client.ListInstances(project.FullName()); | ||
| 78 | 79 | if (!sor) return std::move(sor).status(); | |
| 79 | 80 | auto resp = *std::move(sor); | |
| 80 | 81 | ||
| 81 | 82 | // If either zone_a_ or zone_b_ are in the list of failed locations then we | |
| 82 | 83 | // cannot proceed. | |
| 83 | 84 | EXPECT_THAT(resp.failed_locations(), | |
| 84 | - Not(AnyOf(Contains(project_name + "/locations/" + zone_a_), | ||
| 85 | - Contains(project_name + "/locations/" + zone_b_)))); | ||
| 85 | + Not(AnyOf(Contains(Location(project, zone_a_).FullName()), | ||
| 86 | + Contains(Location(project, zone_b_).FullName())))); | ||
| 86 | 87 | std::vector<std::string> names; | |
| 87 | 88 | names.reserve(resp.instances_size()); | |
| 88 | 89 | auto& instances = *resp.mutable_instances(); | |
@@ -118,21 +119,22 @@ class InstanceAdminIntegrationTest | |||
| 118 | 119 | }; | |
| 119 | 120 | ||
| 120 | 121 | btadmin::CreateInstanceRequest IntegrationTestConfig( | |
| 121 | - std::string const& project, std::string const& instance_id, | ||
| 122 | - std::string const& location, | ||
| 122 | + std::string const& project_id, std::string const& instance_id, | ||
| 123 | + std::string const& location_id, | ||
| 123 | 124 | btadmin::Instance::Type type = btadmin::Instance::DEVELOPMENT, | |
| 124 | 125 | int32_t serve_nodes = 0) { | |
| 126 | + auto const project = Project(project_id); | ||
| 127 | + auto const location = Location(project, location_id); | ||
| 125 | 128 | // The description cannot exceed 30 characters | |
| 126 | 129 | auto const display_name = ("IT " + instance_id).substr(0, 30); | |
| 127 | - auto const project_name = Project(project).FullName(); | ||
| 128 | 130 | ||
| 129 | 131 | btadmin::Cluster c; | |
| 130 | - c.set_location(project_name + "/locations/" + location); | ||
| 132 | + c.set_location(location.FullName()); | ||
| 131 | 133 | c.set_serve_nodes(serve_nodes); | |
| 132 | 134 | c.set_default_storage_type(btadmin::StorageType::HDD); | |
| 133 | 135 | ||
| 134 | 136 | btadmin::CreateInstanceRequest r; | |
| 135 | - r.set_parent(std::move(project_name)); | ||
| 137 | + r.set_parent(project.FullName()); | ||
| 136 | 138 | r.set_instance_id(instance_id); | |
| 137 | 139 | r.mutable_instance()->set_type(type); | |
| 138 | 140 | r.mutable_instance()->set_display_name(std::move(display_name)); | |
@@ -326,7 +328,7 @@ TEST_F(InstanceAdminIntegrationTest, CreateListGetDeleteInstanceTest) { | |||
| 326 | 328 | TEST_F(InstanceAdminIntegrationTest, CreateListGetDeleteClusterTest) { | |
| 327 | 329 | auto const instance_id = RandomInstanceId(generator_); | |
| 328 | 330 | auto const cluster_id = instance_id + "-cl2"; | |
| 329 | - auto const project_name = Project(project_id_).FullName(); | ||
| 331 | + auto const project = Project(project_id_); | ||
| 330 | 332 | auto const instance_name = bigtable::InstanceName(project_id_, instance_id); | |
| 331 | 333 | auto const cluster_name = | |
| 332 | 334 | bigtable::ClusterName(project_id_, instance_id, cluster_id); | |
@@ -339,7 +341,7 @@ TEST_F(InstanceAdminIntegrationTest, CreateListGetDeleteClusterTest) { | |||
| 339 | 341 | ||
| 340 | 342 | // Create cluster | |
| 341 | 343 | btadmin::Cluster c; | |
| 342 | - c.set_location(project_name + "/locations/" + zone_b_); | ||
| 344 | + c.set_location(Location(project, zone_b_).FullName()); | ||
| 343 | 345 | c.set_serve_nodes(3); | |
| 344 | 346 | c.set_default_storage_type(btadmin::StorageType::HDD); | |
| 345 | 347 | auto cluster = client_.CreateCluster(instance_name, cluster_id, c).get(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ | |||
| 22 | 22 | #include "google/cloud/internal/getenv.h" | |
| 23 | 23 | #include "google/cloud/internal/random.h" | |
| 24 | 24 | #include "google/cloud/internal/retry_loop.h" | |
| 25 | + #include "google/cloud/location.h" | ||
| 25 | 26 | #include "google/cloud/project.h" | |
| 26 | 27 | #include "google/cloud/testing_util/chrono_literals.h" | |
| 27 | 28 | #include "google/cloud/testing_util/scoped_environment.h" | |
@@ -251,7 +252,7 @@ TEST_F(TableAdminIntegrationTest, WaitForConsistencyCheck) { | |||
| 251 | 252 | // to create an instance with at least 2 clusters to test it. | |
| 252 | 253 | auto const id = TableTestEnvironment::RandomInstanceId(); | |
| 253 | 254 | auto const random_table_id = RandomTableId(); | |
| 254 | - auto const project_name = Project(project_id()).FullName(); | ||
| 255 | + auto const project = Project(project_id()); | ||
| 255 | 256 | auto const instance_name = bigtable::InstanceName(project_id(), id); | |
| 256 | 257 | auto const table_name = | |
| 257 | 258 | bigtable::TableName(project_id(), id, random_table_id); | |
@@ -270,20 +271,18 @@ TEST_F(TableAdminIntegrationTest, WaitForConsistencyCheck) { | |||
| 270 | 271 | in.set_display_name(std::move(display_name)); | |
| 271 | 272 | ||
| 272 | 273 | btadmin::Cluster c1; | |
| 273 | - c1.set_location(project_name + "/locations/" + | ||
| 274 | - TableTestEnvironment::zone_a()); | ||
| 274 | + c1.set_location(Location(project, TableTestEnvironment::zone_a()).FullName()); | ||
| 275 | 275 | c1.set_serve_nodes(3); | |
| 276 | 276 | c1.set_default_storage_type(btadmin::StorageType::HDD); | |
| 277 | 277 | ||
| 278 | 278 | btadmin::Cluster c2; | |
| 279 | - c2.set_location(project_name + "/locations/" + | ||
| 280 | - TableTestEnvironment::zone_b()); | ||
| 279 | + c2.set_location(Location(project, TableTestEnvironment::zone_b()).FullName()); | ||
| 281 | 280 | c2.set_serve_nodes(3); | |
| 282 | 281 | c2.set_default_storage_type(btadmin::StorageType::HDD); | |
| 283 | 282 | ||
| 284 | 283 | // Create the new instance. | |
| 285 | 284 | auto instance = instance_admin_client | |
| 286 | - .CreateInstance(project_name, id, std::move(in), | ||
| 285 | + .CreateInstance(project.FullName(), id, std::move(in), | ||
| 287 | 286 | {{id + "-c1", std::move(c1)}, | |
| 288 | 287 | {id + "-c2", std::move(c2)}}) | |
| 289 | 288 | .get(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | #include "google/cloud/bigtable/testing/random_names.h" | |
| 24 | 24 | #include "google/cloud/internal/getenv.h" | |
| 25 | 25 | #include "google/cloud/internal/random.h" | |
| 26 | + #include "google/cloud/location.h" | ||
| 26 | 27 | #include "google/cloud/log.h" | |
| 27 | 28 | #include "google/cloud/project.h" | |
| 28 | 29 | #include <algorithm> | |
@@ -48,6 +49,7 @@ void BigtableHelloInstance(std::vector<std::string> const& argv) { | |||
| 48 | 49 | namespace cbt = ::google::cloud::bigtable; | |
| 49 | 50 | namespace cbta = ::google::cloud::bigtable_admin; | |
| 50 | 51 | using ::google::cloud::future; | |
| 52 | + using ::google::cloud::Location; | ||
| 51 | 53 | using ::google::cloud::Project; | |
| 52 | 54 | using ::google::cloud::Status; | |
| 53 | 55 | using ::google::cloud::StatusOr; | |
@@ -61,7 +63,8 @@ void BigtableHelloInstance(std::vector<std::string> const& argv) { | |||
| 61 | 63 | ||
| 62 | 64 | //! [check instance exists] | |
| 63 | 65 | std::cout << "\nCheck Instance exists:\n"; | |
| 64 | - std::string const project_name = Project(project_id).FullName(); | ||
| 66 | + auto const project = Project(project_id); | ||
| 67 | + std::string const project_name = project.FullName(); | ||
| 65 | 68 | StatusOr<google::bigtable::admin::v2::ListInstancesResponse> instances = | |
| 66 | 69 | instance_admin.ListInstances(project_name); | |
| 67 | 70 | if (!instances) throw std::move(instances).status(); | |
@@ -93,7 +96,7 @@ void BigtableHelloInstance(std::vector<std::string> const& argv) { | |||
| 93 | 96 | ||
| 94 | 97 | // production instance needs at least 3 nodes | |
| 95 | 98 | google::bigtable::admin::v2::Cluster c; | |
| 96 | - c.set_location(project_name + "/locations/" + zone); | ||
| 99 | + c.set_location(Location(project, zone).FullName()); | ||
| 97 | 100 | c.set_serve_nodes(3); | |
| 98 | 101 | c.set_default_storage_type(google::bigtable::admin::v2::HDD); | |
| 99 | 102 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | #include "google/cloud/bigtable/testing/random_names.h" | |
| 21 | 21 | #include "google/cloud/internal/absl_str_join_quiet.h" | |
| 22 | 22 | #include "google/cloud/internal/getenv.h" | |
| 23 | + #include "google/cloud/location.h" | ||
| 23 | 24 | #include "google/cloud/log.h" | |
| 24 | 25 | #include "google/cloud/project.h" | |
| 25 | 26 | #include <iterator> | |
@@ -34,20 +35,22 @@ void CreateInstance( | |||
| 34 | 35 | //! [create instance] [START bigtable_create_prod_instance] | |
| 35 | 36 | namespace cbta = ::google::cloud::bigtable_admin; | |
| 36 | 37 | using ::google::cloud::future; | |
| 38 | + using ::google::cloud::Location; | ||
| 37 | 39 | using ::google::cloud::Project; | |
| 38 | 40 | using ::google::cloud::StatusOr; | |
| 39 | 41 | [](cbta::BigtableInstanceAdminClient instance_admin, | |
| 40 | 42 | std::string const& project_id, std::string const& instance_id, | |
| 41 | 43 | std::string const& zone) { | |
| 42 | - std::string project_name = Project(project_id).FullName(); | ||
| 44 | + auto const project = Project(project_id); | ||
| 45 | + std::string project_name = project.FullName(); | ||
| 43 | 46 | std::string cluster_id = instance_id + "-c1"; | |
| 44 | 47 | ||
| 45 | 48 | google::bigtable::admin::v2::Instance in; | |
| 46 | 49 | in.set_type(google::bigtable::admin::v2::Instance::PRODUCTION); | |
| 47 | 50 | in.set_display_name("Put description here"); | |
| 48 | 51 | ||
| 49 | 52 | google::bigtable::admin::v2::Cluster cluster; | |
| 50 | - cluster.set_location(project_name + "/locations/" + zone); | ||
| 53 | + cluster.set_location(Location(project, zone).FullName()); | ||
| 51 | 54 | cluster.set_serve_nodes(3); | |
| 52 | 55 | cluster.set_default_storage_type(google::bigtable::admin::v2::HDD); | |
| 53 | 56 | ||
@@ -76,21 +79,23 @@ void CreateDevInstance( | |||
| 76 | 79 | //! [create dev instance] [START bigtable_create_dev_instance] | |
| 77 | 80 | namespace cbta = ::google::cloud::bigtable_admin; | |
| 78 | 81 | using ::google::cloud::future; | |
| 82 | + using ::google::cloud::Location; | ||
| 79 | 83 | using ::google::cloud::Project; | |
| 80 | 84 | using ::google::cloud::StatusOr; | |
| 81 | 85 | ||
| 82 | 86 | [](cbta::BigtableInstanceAdminClient instance_admin, | |
| 83 | 87 | std::string const& project_id, std::string const& instance_id, | |
| 84 | 88 | std::string const& zone) { | |
| 85 | - std::string project_name = Project(project_id).FullName(); | ||
| 89 | + auto const project = Project(project_id); | ||
| 90 | + std::string project_name = project.FullName(); | ||
| 86 | 91 | std::string cluster_id = instance_id + "-c1"; | |
| 87 | 92 | ||
| 88 | 93 | google::bigtable::admin::v2::Instance in; | |
| 89 | 94 | in.set_type(google::bigtable::admin::v2::Instance::DEVELOPMENT); | |
| 90 | 95 | in.set_display_name("Put description here"); | |
| 91 | 96 | ||
| 92 | 97 | google::bigtable::admin::v2::Cluster cluster; | |
| 93 | - cluster.set_location(project_name + "/locations/" + zone); | ||
| 98 | + cluster.set_location(Location(project, zone).FullName()); | ||
| 94 | 99 | cluster.set_serve_nodes(0); | |
| 95 | 100 | cluster.set_default_storage_type(google::bigtable::admin::v2::HDD); | |
| 96 | 101 | ||
@@ -119,13 +124,15 @@ void CreateReplicatedInstance( | |||
| 119 | 124 | // [START bigtable_create_replicated_cluster] | |
| 120 | 125 | namespace cbta = ::google::cloud::bigtable_admin; | |
| 121 | 126 | using ::google::cloud::future; | |
| 127 | + using ::google::cloud::Location; | ||
| 122 | 128 | using ::google::cloud::Project; | |
| 123 | 129 | using ::google::cloud::StatusOr; | |
| 124 | 130 | ||
| 125 | 131 | [](cbta::BigtableInstanceAdminClient instance_admin, | |
| 126 | 132 | std::string const& project_id, std::string const& instance_id, | |
| 127 | 133 | std::string const& zone_a, std::string const& zone_b) { | |
| 128 | - std::string project_name = Project(project_id).FullName(); | ||
| 134 | + auto const project = Project(project_id); | ||
| 135 | + std::string project_name = project.FullName(); | ||
| 129 | 136 | std::string c1 = instance_id + "-c1"; | |
| 130 | 137 | std::string c2 = instance_id + "-c2"; | |
| 131 | 138 | ||
@@ -134,12 +141,12 @@ void CreateReplicatedInstance( | |||
| 134 | 141 | in.set_display_name("Put description here"); | |
| 135 | 142 | ||
| 136 | 143 | google::bigtable::admin::v2::Cluster cluster1; | |
| 137 | - cluster1.set_location(project_name + "/locations/" + zone_a); | ||
| 144 | + cluster1.set_location(Location(project, zone_a).FullName()); | ||
| 138 | 145 | cluster1.set_serve_nodes(3); | |
| 139 | 146 | cluster1.set_default_storage_type(google::bigtable::admin::v2::HDD); | |
| 140 | 147 | ||
| 141 | 148 | google::bigtable::admin::v2::Cluster cluster2; | |
| 142 | - cluster2.set_location(project_name + "/locations/" + zone_b); | ||
| 149 | + cluster2.set_location(Location(project, zone_b).FullName()); | ||
| 143 | 150 | cluster2.set_serve_nodes(3); | |
| 144 | 151 | cluster2.set_default_storage_type(google::bigtable::admin::v2::HDD); | |
| 145 | 152 | ||
@@ -296,16 +303,17 @@ void CreateCluster( | |||
| 296 | 303 | namespace cbt = ::google::cloud::bigtable; | |
| 297 | 304 | namespace cbta = ::google::cloud::bigtable_admin; | |
| 298 | 305 | using ::google::cloud::future; | |
| 306 | + using ::google::cloud::Location; | ||
| 299 | 307 | using ::google::cloud::Project; | |
| 300 | 308 | using ::google::cloud::StatusOr; | |
| 301 | 309 | [](cbta::BigtableInstanceAdminClient instance_admin, | |
| 302 | 310 | std::string const& project_id, std::string const& instance_id, | |
| 303 | 311 | std::string const& cluster_id, std::string const& zone) { | |
| 304 | - std::string project_name = Project(project_id).FullName(); | ||
| 312 | + auto const project = Project(project_id); | ||
| 305 | 313 | std::string instance_name = cbt::InstanceName(project_id, instance_id); | |
| 306 | 314 | ||
| 307 | 315 | google::bigtable::admin::v2::Cluster c; | |
| 308 | - c.set_location(project_name + "/locations/" + zone); | ||
| 316 | + c.set_location(Location(project, zone).FullName()); | ||
| 309 | 317 | c.set_serve_nodes(3); | |
| 310 | 318 | c.set_default_storage_type(google::bigtable::admin::v2::HDD); | |
| 311 | 319 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ | |||
| 13 | 13 | // limitations under the License. | |
| 14 | 14 | ||
| 15 | 15 | #include "google/cloud/bigtable/instance_admin.h" | |
| 16 | + #include "google/cloud/location.h" | ||
| 16 | 17 | #include <sstream> | |
| 17 | 18 | #include <string> | |
| 18 | 19 | #include <type_traits> | |
@@ -52,8 +53,8 @@ future<StatusOr<btadmin::Instance>> InstanceAdmin::CreateInstance( | |||
| 52 | 53 | auto request = std::move(instance_config).as_proto(); | |
| 53 | 54 | request.set_parent(project_name()); | |
| 54 | 55 | for (auto& kv : *request.mutable_clusters()) { | |
| 55 | - kv.second.set_location(project_name() + "/locations/" + | ||
| 56 | - kv.second.location()); | ||
| 56 | + kv.second.set_location( | ||
| 57 | + Location(project_name(), kv.second.location()).FullName()); | ||
| 57 | 58 | } | |
| 58 | 59 | return connection_->CreateInstance(request); | |
| 59 | 60 | } | |
@@ -63,7 +64,7 @@ future<StatusOr<btadmin::Cluster>> InstanceAdmin::CreateCluster( | |||
| 63 | 64 | std::string const& cluster_id) { | |
| 64 | 65 | google::cloud::internal::OptionsSpan span(options_); | |
| 65 | 66 | auto cluster = std::move(cluster_config).as_proto(); | |
| 66 | - cluster.set_location(project_name() + "/locations/" + cluster.location()); | ||
| 67 | + cluster.set_location(Location(project_name(), cluster.location()).FullName()); | ||
| 67 | 68 | btadmin::CreateClusterRequest request; | |
| 68 | 69 | request.mutable_cluster()->Swap(&cluster); | |
| 69 | 70 | request.set_parent(InstanceName(instance_id)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,8 @@ | |||
| 15 | 15 | #include "google/cloud/bigtable/instance_admin.h" | |
| 16 | 16 | #include "google/cloud/bigtable/admin/mocks/mock_bigtable_instance_admin_connection.h" | |
| 17 | 17 | #include "google/cloud/bigtable/testing/mock_policies.h" | |
| 18 | + #include "google/cloud/location.h" | ||
| 19 | + #include "google/cloud/project.h" | ||
| 18 | 20 | #include "google/cloud/testing_util/status_matchers.h" | |
| 19 | 21 | #include <gmock/gmock.h> | |
| 20 | 22 | ||
@@ -73,7 +75,7 @@ auto const kProfileName = | |||
| 73 | 75 | "projects/the-project/instances/the-instance/appProfiles/the-profile"; | |
| 74 | 76 | ||
| 75 | 77 | std::string LocationName(std::string const& location) { | |
| 76 | - return kProjectName + ("/locations/" + location); | ||
| 78 | + return Location(Project(kProjectName), location).FullName(); | ||
| 77 | 79 | } | |
| 78 | 80 | ||
| 79 | 81 | Status FailingStatus() { return Status(StatusCode::kPermissionDenied, "fail"); } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments