Connecting to ScaleOut in Google Cloud
The GcpBootstrapGatewayProvider class allows the Scaleout.Client library to connect to a ScaleOut cluster running on Google Cloud Compute instances using only GCP credentials to discover ScaleOut hosts.
Background
When a GcpBootstrapGatewayProvider instance is
supplied to a GridConnection
Connect
or
ConnectAsync
call, your connection string can omit the
bootstrapGateway
parameter.
The GcpBootstrapGatewayProvider uses tag metadata that is present on your GPC compute instances to find ScaleOut hosts. This metadata is present whenever ScaleOut hosts are launched using the standard ScaleOut configuration template or the ScaleOut Management Console.
Prerequisites
The GcpBootstrapGatewayProvider is available in the Scaleout.Client.GoogleCloud NuGet package.
Procedure
Add a reference to the Scaleout.Client.GoogleCloud NuGet package.
Supply an GcpBootstrapGatewayProvider instance to the
GridConnection
when connecting.
using System;
using Scaleout.Client;
using Scaleout.Client.GoogleCloud;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Compute.V1;
class Program
{
static void Main(string[] args)
{
// Build GCP InstancesClient:
InstancesClientBuilder clientBuilder = new InstancesClientBuilder();
clientBuilder.Credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("[email protected]")
{
Scopes = InstancesClient.DefaultScopes
}.FromPrivateKey("-----BEGIN PRIVATE KEY..."));
InstancesClient instancesClient = clientBuilder.Build();
// Set up the provider:
var gcpProv = new GcpBootstrapGatewayProvider(
instancesClient,
zone: "us-central1-a",
projectId: "example-deployments-123654",
gatewayType: GatewayType.Public,
scaleoutStoreName: "MyProdClusterCentral");
// Connect to the ScaleOut service and build a cache:
string connectionString = "useSecure=false;maxPoolsize=16";
var conn = GridConnection.Connect(connectionString, gcpProv);
var cacheBuilder = new CacheBuilder<string, string>("My Cache", conn);
var cache = cacheBuilder.Build();
//...
}
}
- The
GcpBootstrapGatewayProvider
constructor requires ascaleoutStoreName
argument. All ScaleOut clusters in GCP are assigned names upon deployment--use the name you gave your cluster for this parameter. - The
gatewayType
parameter indicates whether the Scaleout.Client library should connect using your compute instance's public or private IP address. UseGatewayType.Private
whenever possible to avoid data egress charges.