Skip to content

Commit

Permalink
[DM] cloud_sql: refactoring (#62)
Browse files Browse the repository at this point in the history
#54

- Added version, links to docs
- Switched to using type provider
- Added enum for "databaseVersion", "region", "settings.pricingPlan",
"settings.replicationType"
- Added additionalProperties: false for nested object
- Fixed "users" schema
- Added basic schemas unit tests
  • Loading branch information
bohdanyurov-gl authored and ocsig committed May 31, 2019
1 parent bdae3f2 commit 5564290
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 23 deletions.
13 changes: 10 additions & 3 deletions dm/templates/cloud_sql/cloud_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def get_instance(res_name, project_id, properties):

instance = {
'name': name,
'type': 'sqladmin.v1beta4.instance',
# https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances
'type': 'gcp-types/sqladmin-v1beta4:instances',
'properties': instance_properties
}

Expand All @@ -88,6 +89,10 @@ def get_instance(res_name, project_id, properties):
'name': 'connectionName',
'value': '$(ref.{}.connectionName)'.format(name)
},
{
'name': 'backendType',
'value': '$(ref.{}.backendType)'.format(name)
},
]

return DMBundle(instance, outputs)
Expand Down Expand Up @@ -116,7 +121,8 @@ def get_database(instance_name, project_id, properties):

database = {
'name': res_name,
'type': 'sqladmin.v1beta4.database',
# https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/databases
'type': 'gcp-types/sqladmin-v1beta4:databases',
'properties': db_properties
}

Expand Down Expand Up @@ -160,7 +166,8 @@ def get_user(instance_name, project_id, properties):

user = {
'name': res_name,
'type': 'sqladmin.v1beta4.user',
# https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/users
'type': 'gcp-types/sqladmin-v1beta4:users',
'properties': user_properties
}

Expand Down
99 changes: 79 additions & 20 deletions dm/templates/cloud_sql/cloud_sql.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
info:
title: Cloud SQL
author: Sourced Group Inc.
version: 1.0.0
description: |
Supports creation of a Cloud SQL instance with database and user resources.
For more information, see https://cloud.google.com/sql/docs/.
Expand All @@ -29,16 +30,32 @@ required:
- settings

properties:
name:
type: string
description: |
The name of the Cloud SQL instance. This does not include the project ID.
Resource name would be used if omitted.
project:
type: string
description: |
The project ID of the project containing the Cloud SQL instance. The
Google apps domain is prefixed if applicable.
databaseVersion:
type: string
description: |
The database engine type and version.
The value of this field cannot be changed after instance creation.
Supports MySQL Second Generation instances MYSQL_5_7 | MYSQL_5_6,
First Generation instances MYSQL_5_6 | MYSQL_5_5, and
PostgreSQL instances POSTGRES_9_6.
The databaseVersion field can not be changed after instance creation.
MySQL Second Generation instances: MYSQL_5_7 (default) or MYSQL_5_6.
PostgreSQL instances: POSTGRES_9_6
MySQL First Generation instances: MYSQL_5_6 (default) or MYSQL_5_5
enum:
- MYSQL_5_5 # Deprecated
- MYSQL_5_6
- MYSQL_5_7
- POSTGRES_9_6
failoverReplica:
type: object
additionalProperties: false
description: |
The name and status of the failover replica. Applicable only to Second
Generation instances.
Expand Down Expand Up @@ -71,27 +88,28 @@ properties:
maxDiskSize:
type: number
description: The maximum disk size of the instance in bytes.
name:
type: string
description: |
The name of the Cloud SQL instance. This does not include the project ID.
onPremisesConfiguration:
type: object
additionalProperties: false
description: |
Configuration specific to on-premises instances.
requires:
- hostPort
- kind
properties:
hostPort:
type: string
description: |
The host and port of the on-premises instance in the host:port
format.
project:
type: string
description: |
The project ID of the project containing the Cloud SQL instance. The
Google apps domain is prefixed if applicable.
kind:
type: string
const: "sql#onPremisesConfiguration"
description: |
This is always sql#onPremisesConfiguration.
replicaConfiguration:
type: object
additionalProperties: false
description: |
Configuration specific to failover replicas and read replicas.
properties:
Expand All @@ -106,6 +124,7 @@ properties:
instance.
mysqlReplicaConfiguration:
type: object
additionalProperties: false
description: |
MySQL-specific configuration when replicating from an MySQL
on-premises master. Replication configuration information such as the
Expand Down Expand Up @@ -166,12 +185,13 @@ properties:
type: object
description: SSL configuration.
serviceAccountEmailAddress:
type: object
type: string
description: |
The service account's email address assigned to the instance. Applicable
only to Second Generation instances.
The service account email address assigned to the instance. This property is applicable only
to Second Generation instances.
settings:
type: object
additionalProperties: false
description: User settings.
required:
- tier
Expand Down Expand Up @@ -214,6 +234,7 @@ properties:
- REGIONAL
backupConfiguration:
type: object
additionalProperties: false
description: The daily backup configuration for the instance.
properties:
binaryLogEnabled:
Expand Down Expand Up @@ -257,6 +278,7 @@ properties:
Database flags passed to the instance at startup.
items:
type: object
additionalProperties: false
properties:
name:
type: string
Expand All @@ -279,6 +301,7 @@ properties:
specific to read replica instances. Writable.
ipConfiguration:
type: object
additionalProperties: false
description: |
Settings for IP Management. This allows to enable or disable the
instance IP and to define which external networks can connect to the
Expand All @@ -293,6 +316,7 @@ properties:
notation (e.g., 192.168.100.0/24). Writable.
items:
type: object
additionalProperties: false
properties:
expirationTime:
type: string
Expand Down Expand Up @@ -327,6 +351,7 @@ properties:
Defines whether SSL connections over IP must be enforced.
locationPreference:
type: object
additionalProperties: false
description: |
Location preference settings. This allows the instance to be
located as near as possible to either an App Engine app or Compute
Expand All @@ -345,6 +370,7 @@ properties:
us-central1-b, etc.).
maintenanceWindow:
type: object
additionalProperties: false
description: |
The maintenance window for the instance. Specifies when the instance
can be restarted for maintenance purposes. Not used for First
Expand All @@ -365,11 +391,16 @@ properties:
description: |
The pricing plan for the instance: PER_USE or PACKAGE. Only PER_USE
is supported for Second Generation instances.
enum:
- PER_USE
- PACKAGE
replicationType:
type: string
description: |
The type of replication the instance uses: ASYNCHRONOUS or
SYNCHRONOUS.
The type of replication the instance uses: ASYNCHRONOUS or SYNCHRONOUS.
enum:
- ASYNCHRONOUS
- SYNCHRONOUS
settingsVersion:
type: number
description: |
Expand Down Expand Up @@ -409,13 +440,37 @@ properties:
on the instance type (First Generation or Second Generation/PostgreSQL).
For a complete list of valid values, see Instance Locations. The region
cannot be changed after instance creation.
See https://cloud.google.com/sql/docs/mysql/locations
enum:
- northamerica-northeast1
- us-central
- us-central1
- us-east1
- us-east4
- us-west1
- us-west2
- southamerica-east1
- europe-north1
- europe-west1
- europe-west2
- europe-west3
- europe-west4
- europe-west6
- asia-east1
- asia-east2
- asia-northeast1
- asia-northeast2
- asia-south1
- asia-southeast1
- australia-southeast1
databases:
type: array
description: SQL Databases to create in the new instance.
required:
- name
items:
type: object
additionalProperties: false
properties:
name:
type: string
Expand All @@ -430,10 +485,11 @@ properties:
users:
type: array
description: Cloud SQL users to create in the new instance.
required:
- name
items:
type: object
additionalProperties: false
required:
- name
properties:
name:
type: string
Expand Down Expand Up @@ -493,6 +549,9 @@ outputs:
- databaseNames:
type: array
description: The names of the created databases.
- backendType:
type: string
description: Database generation.
- databaseSelfLinks:
type: array
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
region: us-central1
settings:
tier: db-n1-standard-1
foo: bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
region: us-central1
settings:
tier: db-n1-standard-1
foo: bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
settings:
tier: db-n1-standard-1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
region: us-central1
5 changes: 5 additions & 0 deletions dm/templates/cloud_sql/tests/schemas/valid_basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
region: us-central1
settings:
tier: db-n1-standard-1
name: foo
project: foo
17 changes: 17 additions & 0 deletions dm/templates/cloud_sql/tests/schemas/valid_complex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
region: us-central1
settings:
tier: db-n1-standard-1
backupConfiguration:
startTime: '02:00'
enabled: true
binaryLogEnabled: true
locationPreference:
zone: us-central1-c
users:
- name: user-1
host: 10.1.1.1
- name: user-2
host: 10.1.1.2
databases:
- name: db-1
- name: db-2

0 comments on commit 5564290

Please sign in to comment.