Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #123 from GoogleCloudPlatform/develop
Browse files Browse the repository at this point in the history
merge Develop in with spanner functionality
  • Loading branch information
ccemeraldeyes authored Mar 22, 2017
2 parents a8c276d + 64ff8ef commit 127fa8a
Show file tree
Hide file tree
Showing 2,279 changed files with 2,523,699 additions and 80,068 deletions.
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ will be disabled. e.g.,
}
}
```
* `BIGTABLE_CUSTOM_PLANS` (A map of plan names to string maps with fields `guid`, `name`, `description`,
`storage_type`, `num_nodes`, `display_name`, and `service` (Bigtable's service id)) - if unset, the service
will be disabled. e.g.,

```json
{
"bt_plan": {
"name": "bt_plan",
"description": "Bigtable basic plan",
"storage_type": "HDD",
"num_nodes": "5",
"display_name": "Bigtable Plan",
"service": "b8e19880-ac58-42ef-b033-f7cd9c94d1fe"
}
}
```
* `SPANNER_CUSTOM_PLANS` (A map of plan names to string maps with fields `guid`, `name`, `description`,
`num_nodes` `display_name`, and `service` (Spanner's service id)) - if unset, the service
will be disabled. e.g.,

```json
{
"spannerplan": {
"name": "spannerplan",
"description": "Basic Spanner plan",
"num_nodes": "15",
"display_name": "Spanner Plan",
"service": "51b3e27e-d323-49ce-8c5f-1211e6409e82"
}
}
```


## Usage
Expand All @@ -103,7 +134,7 @@ will be disabled. e.g.,
1. Click on the tile and fill in any required fields (tabs will be orange if updates are needed)
1. Once the tile is green and updates are applied, review the service/plan access and
update if necessary using cf disable-service-access. By default, all services and plans
are enabled except CloudSQL (unless plans have been saved for it). If you wish to change this,
are enabled except CloudSQL, Bigtable, and Spanner (unless plans have been saved for them). If you wish to change this,
you'll need to use the cf cli's service-access commands.

### (Optional) Increase the default provision/bind timeout
Expand Down Expand Up @@ -262,6 +293,26 @@ Notes:
}
```

* [Spanner](https://cloud.google.com/spanner/docs/) (BETA Google Service)
* Provison
* `name` (defaults to a generated value)
* `display_name` (defaults to a generated value)
* `location` (defaults to regional-us-central1)
* Bind
* `role` without "roles/" prefix (see https://cloud.google.com/iam/docs/understanding-roles for available roles), e.g. spanner.admin

**Example Binding credentials**

```json
"credentials": {
"Email": "redacted",
"Name": "redacted",
"PrivateKeyData": "redacted",
"UniqueId": "redacted",
"instance_id": "foobar",
}
```

## Change Notes

see https://github.com/GoogleCloudPlatform/gcp-service-broker/blob/master/CHANGELOG.md
Expand Down
14 changes: 9 additions & 5 deletions brokerapi/brokers/account_managers/service_account_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (sam *ServiceAccountManager) CreateAccountInGoogle(instanceID string, bindi
Email: newSA.Email,
UniqueId: newSA.UniqueId,
PrivateKeyData: newSAKey.PrivateKeyData,
ProjectId: sam.ProjectId,
ProjectId: sam.ProjectId,
}

saBytes, err := json.Marshal(&newSAInfo)
Expand Down Expand Up @@ -167,14 +167,18 @@ func (b *ServiceAccountManager) BuildInstanceCredentials(bindDetails map[string]
// XXX names are truncated to 20 characters because of a bug in the IAM service
func ServiceAccountName(bindingId string) string {
name := saPrefix + bindingId
return name[:20]
if len(name) > 20 {
return name[:20]
} else {
return name
}
}

type ServiceAccountInfo struct {
// the bits to save
Name string
Email string
UniqueId string
Name string
Email string
UniqueId string
ProjectId string

// the bit to return
Expand Down
170 changes: 11 additions & 159 deletions brokerapi/brokers/brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net/http"
"os"

"gcp-service-broker/fakes"
"github.com/jinzhu/gorm"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -61,161 +62,12 @@ var _ = Describe("Brokers", func() {
}`)
os.Setenv("SECURITY_USER_NAME", "username")
os.Setenv("SECURITY_USER_PASSWORD", "password")
os.Setenv("SERVICES", `[
{
"id": "b9e4332e-b42b-4680-bda5-ea1506797474",
"description": "A Powerful, Simple and Cost Effective Object Storage Service",
"name": "google-storage",
"bindable": true,
"plan_updateable": false,
"metadata": {
"displayName": "Google Cloud Storage",
"longDescription": "A Powerful, Simple and Cost Effective Object Storage Service",
"documentationUrl": "https://cloud.google.com/storage/docs/overview",
"supportUrl": "https://cloud.google.com/support/"
},
"tags": ["gcp", "storage"]
},
{
"id": "628629e3-79f5-4255-b981-d14c6c7856be",
"description": "A global service for real-time and reliable messaging and streaming data",
"name": "google-pubsub",
"bindable": true,
"plan_updateable": false,
"metadata": {
"displayName": "Google PubSub",
"longDescription": "A global service for real-time and reliable messaging and streaming data",
"documentationUrl": "https://cloud.google.com/pubsub/docs/",
"supportUrl": "https://cloud.google.com/support/"
},
"tags": ["gcp", "pubsub"]
},
{
"id": "f80c0a3e-bd4d-4809-a900-b4e33a6450f1",
"description": "A fast, economical and fully managed data warehouse for large-scale data analytics",
"name": "google-bigquery",
"bindable": true,
"plan_updateable": false,
"metadata": {
"displayName": "Google BigQuery",
"longDescription": "A fast, economical and fully managed data warehouse for large-scale data analytics",
"documentationUrl": "https://cloud.google.com/bigquery/docs/",
"supportUrl": "https://cloud.google.com/support/"
},
"tags": ["gcp", "bigquery"]
},
{
"id": "4bc59b9a-8520-409f-85da-1c7552315863",
"description": "Google Cloud SQL is a fully-managed MySQL database service",
"name": "google-cloudsql",
"bindable": true,
"plan_updateable": false,
"metadata": {
"displayName": "Google CloudSQL",
"longDescription": "Google Cloud SQL is a fully-managed MySQL database service",
"documentationUrl": "https://cloud.google.com/sql/docs/",
"supportUrl": "https://cloud.google.com/support/"
},
"tags": ["gcp", "cloudsql"]
},
{
"id": "5ad2dce0-51f7-4ede-8b46-293d6df1e8d4",
"description": "Machine Learning Apis including Vision, Translate, Speech, and Natural Language",
"name": "google-ml-apis",
"bindable": true,
"plan_updateable": false,
"metadata": {
"displayName": "Google Machine Learning APIs",
"longDescription": "Machine Learning Apis including Vision, Translate, Speech, and Natural Language",
"documentationUrl": "https://cloud.google.com/ml/",
"supportUrl": "https://cloud.google.com/support/"
},
"tags": ["gcp", "ml"]
},
{
"id": "b8e19880-ac58-42ef-b033-f7cd9c94d1fe",
"description": "A high performance NoSQL database service for large analytical and operational workloads",
"name": "google-bigtable",
"bindable": true,
"plan_updateable": false,
"metadata": {
"displayName": "Google Bigtable",
"longDescription": "A high performance NoSQL database service for large analytical and operational workloads",
"documentationUrl": "https://cloud.google.com/bigtable/",
"supportUrl": "https://cloud.google.com/support/",
"imageUrl": "https://cloud.google.com/_static/images/cloud/products/logos/svg/bigtable.svg"
},
"tags": ["gcp", "bigtable"]
}
]`)
os.Setenv("PRECONFIGURED_PLANS", `[
{
"service_id": "b9e4332e-b42b-4680-bda5-ea1506797474",
"name": "standard",
"display_name": "Standard",
"description": "Standard storage class",
"features": {"storage_class": "STANDARD"}
},
{
"service_id": "b9e4332e-b42b-4680-bda5-ea1506797474",
"name": "nearline",
"display_name": "Nearline",
"description": "Nearline storage class",
"features": {"storage_class": "NEARLINE"}
},
{
"service_id": "b9e4332e-b42b-4680-bda5-ea1506797474",
"name": "reduced_availability",
"display_name": "Durable Reduced Availability",
"description": "Durable Reduced Availability storage class",
"features": {"storage_class": "DURABLE_REDUCED_AVAILABILITY"}
},
{
"service_id": "628629e3-79f5-4255-b981-d14c6c7856be",
"name": "default",
"display_name": "Default",
"description": "PubSub Default plan",
"features": ""
},
{ "service_id": "f80c0a3e-bd4d-4809-a900-b4e33a6450f1",
"name": "default",
"display_name": "Default",
"description": "BigQuery default plan",
"features": ""
},
{
"service_id": "5ad2dce0-51f7-4ede-8b46-293d6df1e8d4",
"name": "default",
"display_name": "Default",
"description": "Machine Learning api default plan",
"features": ""
}
]`)

os.Setenv("CLOUDSQL_CUSTOM_PLANS", `{
"test_plan": {
"guid": "test_plan",
"name": "bar",
"description": "testplan",
"tier": "4",
"pricing_plan": "athing",
"max_disk_size": "20",
"display_name": "FOOBAR",
"service": "4bc59b9a-8520-409f-85da-1c7552315863"
}
}`)

os.Setenv("BIGTABLE_CUSTOM_PLANS", `{
"test_bigtable_plan": {
"guid": "foo2",
"name": "bar2",
"description": "test-bigtable-plan",
"storage_type": "SSD",
"num_nodes": "3",
"display_name": "FOOBAR2",
"service": "b8e19880-ac58-42ef-b033-f7cd9c94d1fe"
}
}`)
os.Setenv("SERVICES", fakes.Services)
os.Setenv("PRECONFIGURED_PLANS", fakes.PreconfiguredPlans)

os.Setenv("CLOUDSQL_CUSTOM_PLANS", fakes.TestCloudSQLPlan)
os.Setenv("BIGTABLE_CUSTOM_PLANS", fakes.TestBigtablePlan)
os.Setenv("SPANNER_CUSTOM_PLANS", fakes.TestSpannerPlan)

instanceId = "newid"
bindingId = "newbinding"
Expand Down Expand Up @@ -281,8 +133,8 @@ var _ = Describe("Brokers", func() {
})

Describe("Broker init", func() {
It("should have 6 services in sevices map", func() {
Expect(len(gcpBroker.ServiceBrokerMap)).To(Equal(6))
It("should have 7 services in sevices map", func() {
Expect(len(gcpBroker.ServiceBrokerMap)).To(Equal(7))
})

It("should have a default client", func() {
Expand All @@ -295,8 +147,8 @@ var _ = Describe("Brokers", func() {
})

Describe("getting broker catalog", func() {
It("should have 6 services available", func() {
Expect(len(gcpBroker.Services())).To(Equal(6))
It("should have 7 services available", func() {
Expect(len(gcpBroker.Services())).To(Equal(7))
})

It("should have 3 storage plans available", func() {
Expand Down
16 changes: 16 additions & 0 deletions brokerapi/brokers/gcp_service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"gcp-service-broker/brokerapi/brokers/cloudsql"
"gcp-service-broker/brokerapi/brokers/models"
"gcp-service-broker/brokerapi/brokers/pubsub"
"gcp-service-broker/brokerapi/brokers/spanner"
"gcp-service-broker/brokerapi/brokers/storage"
"gcp-service-broker/db_service"
"gcp-service-broker/utils"
Expand Down Expand Up @@ -153,6 +154,14 @@ func New(Logger lager.Logger) (*GCPAsyncServiceBroker, error) {
AccountManager: saManager,
},
},
models.SpannerName: &spanner.SpannerBroker{
Client: self.GCPClient,
ProjectId: self.RootGCPCredentials.ProjectId,
Logger: self.Logger,
BrokerBase: broker_base.BrokerBase{
AccountManager: saManager,
},
},
}
// replace the mapping from name to a mapping from id
for _, service := range *self.Catalog {
Expand Down Expand Up @@ -589,6 +598,13 @@ func InitCatalogFromEnv() ([]models.Service, error) {
}
servicePlans[bigtableServiceId] = append(servicePlans[bigtableServiceId], bigtablePlans...)

// set up spanner custom plans
spannerPlans, spannerServiceId, err := getDynamicPlans("SPANNER_CUSTOM_PLANS", spanner.MapPlan)
if err != nil {
return []models.Service{}, err
}
servicePlans[spannerServiceId] = append(servicePlans[spannerServiceId], spannerPlans...)

// get the ids of all plans in the current catalog
var currentPlanIds []string
for _, plans := range servicePlans {
Expand Down
1 change: 1 addition & 0 deletions brokerapi/brokers/models/service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const BigtableName = "google-bigtable"
const CloudsqlName = "google-cloudsql"
const PubsubName = "google-pubsub"
const MlName = "google-ml-apis"
const SpannerName = "google-spanner"
const AppCredsEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
const AppCredsFileName = "application-default-credentials.json"
const RootSaEnvVar = "ROOT_SERVICE_ACCOUNT_JSON"
Loading

0 comments on commit 127fa8a

Please sign in to comment.