Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = ["googleapis", "googleapis-raw"]
resolver = "2"

[workspace.package]
version = "0.16.1" # don't forget to update `./googleapis/Cargo.toml`
version = "0.17.1-beta.3" # don't forget to update `./googleapis/Cargo.toml`
authors = [
"Ferrous Systems",
"Mozilla Services Engineering <services-engineering+code@mozilla.com>",
Expand All @@ -29,11 +29,15 @@ repository = "https://github.com/mozilla-services/mozilla-rust-sdk/"
edition = "2021"

[workspace.dependencies]
futures = "0.3.5"
futures = "0.3"
# Absolutely lock to these versions of grpcio and protobuf with a `=` prefix
# Not providing that lock means that cargo will "helpfully" update beyond those
# versions because versions are a suggestion, not a rule.
# NOTE: update the versions in `README.md` as well.
grpcio = { version = "=0.13.0" }
grpcio = { version = "0.13.0", default-features = false, features = [
"boringssl",
"protobufv3-codec",
] }
# grpcio currently does NOT support protobuf 3+
protobuf = { version = "=2.28.0" }
# protobuf = { version = "=2.28.0" }
protobuf = { version = "=3.4.0" } # locked by grpcio-compiler 0.13
1 change: 1 addition & 0 deletions googleapis-raw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ slog-term = "2.6"
slog-stdlog = "4.0"
slog-async = "2.5"
log = "0.4"
protobuf-codegen = "3.4.0" # limited by grpcio-compiler

[features]
default = ["spanner"]
Expand Down
116 changes: 70 additions & 46 deletions googleapis-raw/examples/bigtable-helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};

use futures::executor::block_on;
// use futures::StreamExt;
use google_cloud_rust_raw::bigtable::admin::v2::{
bigtable_instance_admin::GetClusterRequest,
bigtable_instance_admin_grpc::BigtableInstanceAdminClient,
Expand All @@ -25,13 +26,17 @@ use google_cloud_rust_raw::bigtable::admin::v2::{
instance::Cluster, table::ColumnFamily, table::GcRule, table::Table,
};
use google_cloud_rust_raw::bigtable::v2::{
bigtable::MutateRowsRequest, bigtable::MutateRowsRequest_Entry, bigtable_grpc::BigtableClient,
data::Mutation, data::Mutation_SetCell,
bigtable::mutate_rows_request::Entry, data::mutation::SetCell, data::Mutation,
};
/*
use google_cloud_rust_raw::bigtable::v2::{
bigtable::MutateRowResponse, bigtable::MutateRowsRequest, bigtable_grpc::BigtableClient,
};
*/
use google_cloud_rust_raw::empty::Empty;
use grpcio::{Channel, ChannelBuilder, ChannelCredentials, ClientUnaryReceiver, EnvBuilder};
use protobuf::well_known_types::Duration;
use protobuf::RepeatedField;
use protobuf::well_known_types::duration::Duration;
use protobuf::MessageField;

#[allow(dead_code)]
fn timestamp() -> u128 {
Expand Down Expand Up @@ -65,21 +70,25 @@ fn get_cluster(
cluster_id: &str,
) -> ::grpcio::Result<Cluster> {
println!("Get cluster information");
let mut request = GetClusterRequest::new();
request.set_name(cluster_id.to_string());
let request = GetClusterRequest {
name: cluster_id.to_string(),
..Default::default()
};
client.get_cluster(&request)
}

/// Lists all tables for a given cluster
///
fn list_tables(client: &BigtableTableAdminClient, instance_id: &str) {
println!("List all existing tables");
let mut request = ListTablesRequest::new();
request.set_parent(instance_id.to_string());
let request = ListTablesRequest {
parent: instance_id.to_string(),
..Default::default()
};
match client.list_tables(&request) {
Ok(response) => {
response
.get_tables()
.tables
.iter()
.for_each(|table| println!(" table: {:?}", table));
}
Expand All @@ -96,10 +105,12 @@ fn create_table(
table: Table,
) -> ::grpcio::Result<Table> {
println!("Creating table {}", table_name);
let mut request = CreateTableRequest::new();
request.set_parent(instance_id.to_string());
request.set_table(table);
request.set_table_id("hello-world".to_string());
let request = CreateTableRequest {
parent: instance_id.to_string(),
table: MessageField::some(table),
table_id: "hello-world".to_string(),
..Default::default()
};
client.create_table(&request)
}

Expand All @@ -109,8 +120,10 @@ fn delete_table_async(
table_name: &str,
) -> grpcio::Result<ClientUnaryReceiver<Empty>> {
println!("Deleting the {} table", table_name);
let mut request = DeleteTableRequest::new();
request.set_name(table_name.to_string());
let request = DeleteTableRequest {
name: table_name.to_string(),
..Default::default()
};
client.delete_table_async(&request)
}

Expand All @@ -123,8 +136,6 @@ async fn async_main() {
let cluster_id = String::from(
"projects/mozilla-rust-sdk-dev/instances/mozilla-rust-sdk/clusters/mozilla-rust-sdk-c1",
);
// common table endpoint
let endpoint = "bigtable.googleapis.com";
// Google Cloud configuration.
let admin_endpoint = "bigtableadmin.googleapis.com";
// The table name
Expand All @@ -135,10 +146,10 @@ async fn async_main() {

// Create a Bigtable client.
let channel = connect(admin_endpoint);
let client = BigtableInstanceAdminClient::new(channel.clone());
let admin_client = BigtableInstanceAdminClient::new(channel.clone());

// display cluster information
let cluster = get_cluster(&client, &cluster_id).unwrap();
let cluster = get_cluster(&admin_client, &cluster_id).unwrap();
dbg!(cluster);

// create admin client for tables
Expand All @@ -148,17 +159,23 @@ async fn async_main() {
list_tables(&admin_client, &instance_id);

// create a new table with a custom column family / gc rule
let mut duration = Duration::new();
duration.set_seconds(60 * 60 * 24 * 5);
let duration = Duration {
seconds: 60 * 60 * 24 * 5,
..Default::default()
};
let mut gc_rule = GcRule::new();
gc_rule.set_max_num_versions(2);
gc_rule.set_max_age(duration);
let mut column_family = ColumnFamily::new();
column_family.set_gc_rule(gc_rule);
let column_family = ColumnFamily {
gc_rule: MessageField::some(gc_rule),
..Default::default()
};
let mut hash_map = HashMap::new();
hash_map.insert(column_family_id.to_string(), column_family);
let mut table = Table::new();
table.set_column_families(hash_map);
let table = Table {
column_families: hash_map,
..Default::default()
};
match create_table(&admin_client, &instance_id, &table_name, table) {
Ok(table) => println!(" table {:?} created", table),
Err(error) => println!(" failed to created table: {}", error),
Expand All @@ -173,38 +190,45 @@ async fn async_main() {
for (i, greeting) in greetings.iter().enumerate() {
let row_key = format!("greeting{}", i);

let mut set_cell = Mutation_SetCell::new();
set_cell.set_column_qualifier(column.to_string().into_bytes());
set_cell.set_timestamp_micros(-1);
set_cell.set_value(greeting.to_string().into_bytes());
set_cell.set_family_name(column_family_id.to_string());
let set_cell = SetCell {
column_qualifier: column.to_string().into_bytes(),
timestamp_micros: -1,
value: greeting.to_string().into_bytes(),
family_name: column_family_id.to_string(),
..Default::default()
};

let mut mutation = Mutation::new();
mutation.set_set_cell(set_cell);

let mut request = MutateRowsRequest_Entry::new();
request.set_row_key(row_key.into_bytes());
request.set_mutations(RepeatedField::from_vec(vec![mutation]));
let entry = Entry {
row_key: row_key.into_bytes(),
mutations: vec![mutation],
..Default::default()
};

mutation_requests.push(request);
mutation_requests.push(entry);
}

// TODO:: fix this.admin_client
// `.collect()` needs a type.
// apply changes and check responses
/*
let channel = connect(endpoint);
let _client = BigtableClient::new(channel.clone());
let mut request = MutateRowsRequest::new();
request.set_table_name(table_name.to_string());
request.set_entries(RepeatedField::from_vec(mutation_requests));
let request = MutateRowsRequest {
table_name: table_name.to_string(),
entries: mutation_requests,
..Default::default()
};

/*

TODO:: fix this.admin_client
`.collect()` needs a type.
// apply changes and check responses
let client = BigtableClient::new(channel.clone());
let response = client
.mutate_rows(&request).unwrap()
.collect()
.into_future()
.wait().unwrap();
.mutate_rows(&request)
.unwrap()
.collect::<Vec<Result<MutateRowResponse, protobuf::Error>>>()
.await
.unwrap();
for response in response.iter() {
for entry in response.get_entries().iter() {
let status = entry.get_status();
Expand Down
12 changes: 6 additions & 6 deletions googleapis-raw/examples/cloudasset-list.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::sync::Arc;

use google_cloud_rust_raw::cloud::asset::v1::{
asset_service_grpc::AssetServiceClient,
asset_service::ExportAssetsRequest,
asset_service::ExportAssetsRequest, asset_service_grpc::AssetServiceClient,
};
use grpcio::{Channel, ChannelBuilder, ChannelCredentials, EnvBuilder};
use std::error::Error;


fn connect(endpoint: &str) -> Channel {
// Set up the gRPC environment.
let env = Arc::new(EnvBuilder::new().build());
Expand All @@ -28,15 +26,17 @@ fn main() -> Result<(), Box<dyn Error>> {
let channel = connect(endpoint);
let client = AssetServiceClient::new(channel);

let mut req = ExportAssetsRequest::new();
req.set_parent(format!("projects/{}", "mozilla-rust-sdk-dev"));
let req = ExportAssetsRequest {
parent: format!("projects/{}", "mozilla-rust-sdk-dev"),
..Default::default()
};

match client.export_assets(&req) {
Ok(response) => {
// NOTE: the API for this recently changd. Please refer to
// GCP documentation for details about these changes.
print!("{:?}", response);
},
}
Err(error) => println!("Failed to list assets: {}", error),
}

Expand Down
Loading