Beispiel #1
0
        public Loader(BigtableCredentials credentials, BigtableConfig config)
        {
            GrpcEnvironment.SetThreadPoolSize(BatchAndPoolSize);

            _adminClient = new BigAdminClient(credentials, config);
            _dataClient  = new BigDataClient(credentials, config);
        }
Beispiel #2
0
        public void Setup()
        {
            var test   = "test";
            var config = new BigtableConfig(test, test, test);
            var creds  = new BigtableCredentials();

            _admin = new BigAdminClient(creds, config);
            _data  = new BigDataClient(creds, config);
        }
Beispiel #3
0
        public async Task ConnectAsync(string configFile)
        {
            // Setup
            var config = await BigtableConfig.LoadAsync(configFile);

            var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

            // Get mapper
            _bigtable = new Bigtable(credentials, config);
        }
Beispiel #4
0
        public async Task Readme(string configFile)
        {
            // Load configuration
            var config = BigtableConfig.Load(configFile);

            // Create credentials
            var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

            // Data client
            using (var dataClient = new BigDataClient(credentials, config))
            {
                // Scan myTable
                var rows = await dataClient.GetRowsAsync(
                    tableName : "myTable",
                    startKey : "abc",
                    endKey : "def",
                    rowLimit : 20
                    );

                // Show the user
                foreach (var row in rows)
                {
                    // Write key to console
                    Console.WriteLine("Key: " + row.KeyString);

                    // Iterate the families which were returned
                    foreach (var family in row.FieldsByFamily)
                    {
                        // Results are organized by family
                        var familyName = family.Key;

                        // Iterate the fields in this family
                        foreach (var field in family.Value)
                        {
                            var fieldName = field.Key;

                            // Iterate the versions of the field
                            foreach (var cell in field.Value)
                            {
                                // Write to console
                                Console.WriteLine("{0}:{1} = {2}", familyName, cell.ColumnName, cell.StringValue);
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public static async Task Run()
        {
            // Disable Grpc logging
            GrpcEnvironment.DisableLogging();

            try
            {
                // Create config
                var config = Utilities.GetConfig();

                // Create credentials
                var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

                // Admin client
                using (var adminClient = new BigAdminClient(credentials, config))
                {
                    // Get tables
                    var tables = (await adminClient.ListTablesAsync()).ToArray();

                    // Ensure pricing table exists
                    if (tables.All(t => t.Name != Constants.PricingTable))
                    {
                        // Inform user
                        CommandLine.InformUser("Setup", "Missing example table.  Please run the Examples.Bootstrap project.");

                        // Hard stop
                        return;
                    }

                    // Show user
                    CommandLine.DisplayTables(tables);
                }

                // Wait for keypress
                CommandLine.WaitForUserAndThen("scan for rows");

                // Data client
                using (var dataClient = new BigDataClient(credentials, config))
                {
                    // Target
                    var pricingTable = new BigTable(Constants.PricingTable);

                    // Scan pricing table
                    var pricing = await dataClient.GetRowsAsync(pricingTable, Constants.ScanKeyStart, Constants.ScanKeyEnd, Constants.ScanLimit);

                    // Show the user
                    CommandLine.DisplayRows(pricing);

                    // Wait for keypress
                    CommandLine.WaitForUserAndThen("observe rows");

                    // Test observables
                    var waitSource = new CancellationTokenSource();
                    // ReSharper disable once MethodSupportsCancellation
                    var waitForObservation = Task.Run(() => Task.Delay(-1, waitSource.Token));
                    // Create a subscriber
                    var subscriber = new TestSubscriber(() => waitSource.Cancel());
                    // ReSharper disable once MethodSupportsCancellation
                    var observable = dataClient.ObserveRows(pricingTable, Constants.ScanKeyStart, Constants.ScanKeyEnd, Constants.ScanLimit);
                    using (observable.Subscribe(subscriber))
                    {
                        //await Task.Delay(1000);
                        Task.WaitAny(waitForObservation);
                    }

                    // Wait for keypress
                    CommandLine.WaitForUserAndThen("seek for row");

                    // Seek for data
                    var row = await dataClient.GetRowAsync(pricingTable, Constants.SeekKey);

                    // Show the user
                    CommandLine.DisplayRows(new[] { row });
                }
            }
            catch (Exception exception)
            {
                CommandLine.InformUser("Oops", "Example didn't work out as planned");
                CommandLine.RenderException(exception);
            }
            finally
            {
                // All done
                CommandLine.WaitForUserAndThen("exit");
            }
        }
Beispiel #6
0
 public BigAdminClient(BigtableCredentials credentials, BigtableConfig config, bool isReadOnly = false) : base(config, credentials.CreateAdminChannel)
 {
     // Create
     _client = new BigtableTableService.BigtableTableServiceClient(Channel);
 }
Beispiel #7
0
 public BigAdminClient(BigtableCredentials credentials, string project, string zone, string cluster, bool isReadOnly) : this(credentials, new BigtableConfig(project, zone, cluster), isReadOnly)
 {
 }
 public ClientFactory()
 {
     _config      = Utilities.GetConfig();
     _credentials = BigtableCredentials.UseApplicationDefaultCredentialsAsync().Result;
 }
Beispiel #9
0
        public static async Task Run()
        {
            // Disable Grpc logging
            GrpcEnvironment.DisableLogging();

            try
            {
                // Create config
                var config = Utilities.GetConfig();

                // Create credentials
                var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

                // Mapper client
                using (var bigtable = new Bigtable(credentials, config))
                {
                    var tableExists = await bigtable.TableExists <Pricing>();

                    // Ensure pricing table exists
                    if (!tableExists)
                    {
                        // Inform user
                        CommandLine.InformUser("Setup", "Missing example table.  Please run the Examples.Bootstrap project.");

                        // Hard stop
                        return;
                    }

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.InformUser("Start", "Getting first pricing poco record");

                    // Seek one record
                    var firstPricing = await bigtable.GetFirstRowAsync <Pricing>();

                    // Show user
                    DisplayPricing(firstPricing);

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("get keyed pricing poco");

                    // Seek one record
                    var pricing = await bigtable.GetAsync(new Pricing { Id = Constants.SeekId, Date = Constants.SeekDate });

                    // Show user
                    DisplayPricing(pricing);

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("get alternate-schema pricing poco");

                    // Seek one record using alternate schema
                    var simplePricing = await bigtable.GetAsync(new SimplePricing { Id = Constants.SeekId, Date = Constants.SeekDate });

                    // Show user
                    DisplayPricing(FromSimplePricing(simplePricing));

                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("scan partially-keyed pricing poco");

                    // Seek one record
                    var pricings = await bigtable.ScanAsync(new Pricing { Id = Constants.SeekId }, new Pricing { Id = Constants.SeekId + 1 });

                    // Show user
                    DisplayPricing(pricings.ToArray());


                    // -----------------------------------------------------------------------------------------------------------------///

                    // Inform User
                    CommandLine.WaitForUserAndThen("read write read");

                    // Seek one record
                    var rewrite = await bigtable.GetAsync(new Pricing { Id = Constants.SeekId, Date = Constants.SeekDate + 1 });

                    DisplayPricing(rewrite);

                    var tempHigh = rewrite.High;
                    var tempLow  = rewrite.Low;

                    rewrite.High = 142;
                    rewrite.Low  = null;

                    await bigtable.UpdateAsync(rewrite);

                    var rewriteRead = await bigtable.GetAsync(new Pricing { Id = Constants.SeekId, Date = Constants.SeekDate + 1 });

                    DisplayPricing(rewrite, rewriteRead);
                    rewrite.High = tempHigh;
                    rewrite.Low  = tempLow;
                    await bigtable.UpdateAsync(rewrite);
                }
            }
            catch (Exception exception)
            {
                CommandLine.InformUser("Oops", "Example didn't work out as planned");
                CommandLine.RenderException(exception);
            }
            finally
            {
                // All done
                CommandLine.WaitForUserAndThen("exit");
            }
        }
Beispiel #10
0
        public static async Task Run(BigtableConfig config)
        {
            GrpcEnvironment.DisableLogging();
            try
            {
                var credentials = await BigtableCredentials.UseApplicationDefaultCredentialsAsync();

                // Admin client
                using (var loader = new Loader(credentials, config))
                {
                    // Examine cluster
                    await loader.Initialize();

                    // Ensure pricing table exists
                    if (loader.NoExampleTables)
                    {
                        var state    = "Missing example tables.";
                        var question = "Would you like to create and populate the example tables?";
                        if (!AskUserPermission(state, question))
                        {
                            return;
                        }
                    }
                    else if (loader.SomeExampleTables)
                    {
                        var state    = "Missing some of the example tables.";
                        var question = "Would you like to create and populate the missing tables?";
                        if (!AskUserPermission(state, question))
                        {
                            return;
                        }
                    }
                    else
                    {
                        var state    = "Example tables are present.";
                        var question = "Would you like to DROP, recreate, and populate the example tables?";
                        if (!AskUserPermission(state, question))
                        {
                            return;
                        }
                    }
                    await loader.LoadTables();
                }
            }
            catch (Exception exception)
            {
                // Notify user
                CommandLine.InformUser("Oops", "Bootstrapping did not work out as planned.");
                CommandLine.RenderException(exception);

                // Giveup
                return;
            }
            finally
            {
                // Give user a chance to read screen
                if (Debugger.IsAttached)
                {
                    CommandLine.WaitForUserAndThen("exit");
                }
            }
        }
 public BigDataClient(BigtableCredentials credentials, BigtableConfig config, bool isReadOnly = false) : base(config, () => credentials.CreateDataChannel(isReadOnly))
 {
     // Create
     _client = new BigtableService.BigtableServiceClient(Channel);
 }
Beispiel #12
0
 public BigtableReader(BigtableCredentials credentials, BigtableConfig config)
 {
     AdminClient = new Lazy <BigAdminClient>(() => new BigAdminClient(credentials, config));
     DataClient  = new Lazy <BigDataClient>(() => new BigDataClient(credentials, config));
 }
Beispiel #13
0
 public BigtableReader(BigtableCredentials credentials, string project, string zone, string cluster) : this(credentials, new BigtableConfig(project, zone, cluster))
 {
 }