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

Commit

Permalink
Enable CosmosDB Account Updates (#526)
Browse files Browse the repository at this point in the history
* Adding update schema

* DRY cleanup and implement update

* Cleanup, Actually call deployer.Update
  • Loading branch information
jeremyrickard authored and krancour committed Aug 1, 2018
1 parent 47739e5 commit ab0b831
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 30 deletions.
5 changes: 5 additions & 0 deletions pkg/services/cosmosdb/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (m *module) GetCatalog() (service.Catalog, error) {
Schemas: service.PlanSchemas{
ServiceInstances: service.InstanceSchemas{
ProvisioningParametersSchema: generateProvisioningParamsSchema(), // nolint: lll
UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll
},
},
}),
Expand Down Expand Up @@ -77,6 +78,7 @@ func (m *module) GetCatalog() (service.Catalog, error) {
Schemas: service.PlanSchemas{
ServiceInstances: service.InstanceSchemas{
ProvisioningParametersSchema: generateProvisioningParamsSchema(), // nolint: lll
UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll
},
},
}),
Expand Down Expand Up @@ -149,6 +151,7 @@ func (m *module) GetCatalog() (service.Catalog, error) {
Schemas: service.PlanSchemas{
ServiceInstances: service.InstanceSchemas{
ProvisioningParametersSchema: generateProvisioningParamsSchema(), // nolint: lll
UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll
},
},
}),
Expand Down Expand Up @@ -188,6 +191,7 @@ func (m *module) GetCatalog() (service.Catalog, error) {
Schemas: service.PlanSchemas{
ServiceInstances: service.InstanceSchemas{
ProvisioningParametersSchema: generateProvisioningParamsSchema(), // nolint: lll
UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll
},
},
}),
Expand Down Expand Up @@ -226,6 +230,7 @@ func (m *module) GetCatalog() (service.Catalog, error) {
Schemas: service.PlanSchemas{
ServiceInstances: service.InstanceSchemas{
ProvisioningParametersSchema: generateProvisioningParamsSchema(), // nolint: lll
UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll
},
},
}),
Expand Down
17 changes: 0 additions & 17 deletions pkg/services/cosmosdb/common-update.go

This file was deleted.

59 changes: 59 additions & 0 deletions pkg/services/cosmosdb/common_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cosmosdb

import (
"fmt"

"github.com/Azure/open-service-broker-azure/pkg/service"
)

func (c *cosmosAccountManager) updateDeployment(
pp *service.ProvisioningParameters,
up *service.ProvisioningParameters,
dt *cosmosdbInstanceDetails,
kind string,
capability string,
additionalTags map[string]string,
) error {
p, err := c.buildGoTemplateParams(up, dt, kind)
if err != nil {
return err
}
if capability != "" {
p["capability"] = capability
}
tags := getTags(pp)
for k, v := range additionalTags {
tags[k] = v
}
err = c.deployUpdatedARMTemplate(
up,
dt,
p,
tags,
)
if err != nil {
return fmt.Errorf("error deploying ARM template: %s", err)
}
return nil
}

func (c *cosmosAccountManager) deployUpdatedARMTemplate(
pp *service.ProvisioningParameters,
dt *cosmosdbInstanceDetails,
goParams map[string]interface{},
tags map[string]string,
) error {
_, err := c.armDeployer.Update(
dt.ARMDeploymentName,
pp.GetString("resourceGroup"),
pp.GetString("location"),
armTemplateBytes,
goParams, // Go template params
map[string]interface{}{},
tags,
)
if err != nil {
return fmt.Errorf("error deploying ARM template: %s", err)
}
return nil
}
43 changes: 43 additions & 0 deletions pkg/services/cosmosdb/graph-api-update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cosmosdb

import (
"context"
"fmt"

"github.com/Azure/open-service-broker-azure/pkg/service"
)

func (g *graphAccountManager) ValidateUpdatingParameters(
instance service.Instance,
) error {
return nil
}

func (g *graphAccountManager) GetUpdater(
service.Plan,
) (service.Updater, error) {
// There isn't a need to do any "pre-provision here. just the update step"
return service.NewUpdater(
service.NewUpdatingStep("updateARMTemplate", g.updateARMTemplate),
)
}

func (g *graphAccountManager) updateARMTemplate(
_ context.Context,
instance service.Instance,
) (service.InstanceDetails, error) {
err := g.cosmosAccountManager.updateDeployment(
instance.ProvisioningParameters,
instance.UpdatingParameters,
instance.Details.(*cosmosdbInstanceDetails),
"GlobalDocumentDB",
"EnableGremlin",
map[string]string{
"defaultExperience": "Graph",
},
)
if err != nil {
return nil, fmt.Errorf("error deploying ARM template: %s", err)
}
return instance.Details, nil
}
41 changes: 41 additions & 0 deletions pkg/services/cosmosdb/mongodb-update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cosmosdb

import (
"context"
"fmt"

"github.com/Azure/open-service-broker-azure/pkg/service"
)

func (m *mongoAccountManager) ValidateUpdatingParameters(
instance service.Instance,
) error {
return nil
}

func (m *mongoAccountManager) GetUpdater(
service.Plan,
) (service.Updater, error) {
// There isn't a need to do any "pre-provision here. just the update step"
return service.NewUpdater(
service.NewUpdatingStep("updateARMTemplate", m.updateARMTemplate),
)
}

func (m *mongoAccountManager) updateARMTemplate(
_ context.Context,
instance service.Instance,
) (service.InstanceDetails, error) {
err := m.cosmosAccountManager.updateDeployment(
instance.ProvisioningParameters,
instance.UpdatingParameters,
instance.Details.(*cosmosdbInstanceDetails),
"MongoDB",
"",
map[string]string{},
)
if err != nil {
return nil, fmt.Errorf("error deploying ARM template: %s", err)
}
return instance.Details, nil
}
38 changes: 25 additions & 13 deletions pkg/services/cosmosdb/plan_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,13 @@ import (
"github.com/Azure/open-service-broker-azure/pkg/service"
)

func generateProvisioningParamsSchema() service.InputParametersSchema {
func generateUpdatingParamsSchema() service.InputParametersSchema {
const maxStalenessPrefixMin = 1
const maxStalenessPrefixMax = 2147483647
const maxIntervalInSecondsMin = 5
const maxIntervalInSecondsMax = 86400
return service.InputParametersSchema{
RequiredProperties: []string{"location", "resourceGroup"},
PropertySchemas: map[string]service.PropertySchema{
"location": &service.StringPropertySchema{
Title: "Location",
Description: "The Azure region in which to provision" +
" applicable resources.",
CustomPropertyValidator: azure.LocationValidator,
},
"resourceGroup": &service.StringPropertySchema{
Title: "Resource group",
Description: "The (new or existing) resource group with which" +
" to associate new resources.",
},
"ipFilters": &service.ObjectPropertySchema{
Title: "IP filters",
Description: "IP Range Filter to be applied to new CosmosDB account",
Expand Down Expand Up @@ -119,6 +107,30 @@ func generateProvisioningParamsSchema() service.InputParametersSchema {
}
}

func generateProvisioningParamsSchema() service.InputParametersSchema {
propertySchemas := map[string]service.PropertySchema{
"location": &service.StringPropertySchema{
Title: "Location",
Description: "The Azure region in which to provision" +
" applicable resources.",
CustomPropertyValidator: azure.LocationValidator,
},
"resourceGroup": &service.StringPropertySchema{
Title: "Resource group",
Description: "The (new or existing) resource group with which" +
" to associate new resources.",
},
}
sharedSchema := generateUpdatingParamsSchema()
for k, v := range sharedSchema.PropertySchemas {
propertySchemas[k] = v
}
return service.InputParametersSchema{
RequiredProperties: []string{"location", "resourceGroup"},
PropertySchemas: propertySchemas,
}
}

func ipRangeValidator(context, value string) error {
ip := net.ParseIP(value)
if ip == nil {
Expand Down
41 changes: 41 additions & 0 deletions pkg/services/cosmosdb/sql-account-only-update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cosmosdb

import (
"context"
"fmt"

"github.com/Azure/open-service-broker-azure/pkg/service"
)

func (s *sqlAccountManager) ValidateUpdatingParameters(
instance service.Instance,
) error {
return nil
}

func (s *sqlAccountManager) GetUpdater(service.Plan) (service.Updater, error) {
// There isn't a need to do any "pre-provision here. just the update step"
return service.NewUpdater(
service.NewUpdatingStep("updateARMTemplate", s.updateARMTemplate),
)
}

func (s *sqlAccountManager) updateARMTemplate(
_ context.Context,
instance service.Instance,
) (service.InstanceDetails, error) {
err := s.cosmosAccountManager.updateDeployment(
instance.ProvisioningParameters,
instance.UpdatingParameters,
instance.Details.(*cosmosdbInstanceDetails),
"GlobalDocumentDB",
"",
map[string]string{
"defaultExperience": "DocumentDB",
},
)
if err != nil {
return nil, fmt.Errorf("error deploying ARM template: %s", err)
}
return instance.Details, nil
}
42 changes: 42 additions & 0 deletions pkg/services/cosmosdb/sql-all-in-one-update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cosmosdb

import (
"context"
"fmt"

"github.com/Azure/open-service-broker-azure/pkg/service"
)

func (s *sqlAllInOneManager) ValidateUpdatingParameters(
instance service.Instance,
) error {
return nil
}

func (s *sqlAllInOneManager) GetUpdater(service.Plan) (service.Updater, error) {
// There isn't a need to do any "pre-provision here. just the update step"
return service.NewUpdater(
service.NewUpdatingStep("updateARMTemplate", s.updateARMTemplate),
)
}

func (s *sqlAllInOneManager) updateARMTemplate(
_ context.Context,
instance service.Instance,
) (service.InstanceDetails, error) {
dt := instance.Details.(*sqlAllInOneInstanceDetails)
err := s.cosmosAccountManager.updateDeployment(
instance.ProvisioningParameters,
instance.UpdatingParameters,
&dt.cosmosdbInstanceDetails,
"GlobalDocumentDB",
"",
map[string]string{
"defaultExperience": "DocumentDB",
},
)
if err != nil {
return nil, fmt.Errorf("error deploying ARM template: %s", err)
}
return instance.Details, nil
}
15 changes: 15 additions & 0 deletions pkg/services/cosmosdb/sql-database-only-update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cosmosdb

import (
"github.com/Azure/open-service-broker-azure/pkg/service"
)

func (s *sqlDatabaseManager) ValidateUpdatingParameters(
service.Instance,
) error {
return nil
}

func (s *sqlDatabaseManager) GetUpdater(service.Plan) (service.Updater, error) {
return service.NewUpdater()
}
Loading

0 comments on commit ab0b831

Please sign in to comment.