Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72f6763

Browse files
author
Rebecca Taylor
committed
Merge branch 'master' into tmp-generated-samples
2 parents 1acc945 + 950d97a commit 72f6763

File tree

126 files changed

+1288
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1288
-196
lines changed

.kokoro/common.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build_file: "python-docs-samples/.kokoro/trampoline.sh"
99
# Use the Python worker docker image.
1010
env_vars: {
1111
key: "TRAMPOLINE_IMAGE"
12-
value: "gcr.io/cloud-devrel-kokoro-resources/python@sha256:e11a459d01e5dcd3613fda35c7c94edfecfe911ed79c078580ff59de300b1938"
12+
value: "gcr.io/cloud-devrel-kokoro-resources/python@sha256:9f83a3711eef244a4d45ac25028e200c87c4d4060d445438683a1ed4d3f093b6"
1313
}
1414

1515
# Specify project ID

.kokoro/presubmit_tests_container_engine.cfg renamed to .kokoro/presubmit_tests_kubernetes_engine.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ env_vars: {
1111

1212
env_vars: {
1313
key: "NOX_SESSION"
14-
value: "container_engine and py36 and not appengine"
14+
value: "kubernetes_engine and py36 and not appengine"
1515
}

.kokoro/system_tests_container_engine.cfg renamed to .kokoro/system_tests_kubernetes_engine.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ env_vars: {
1111

1212
env_vars: {
1313
key: "NOX_SESSION"
14-
value: "container_engine and py36 and not appengine"
14+
value: "kubernetes_engine and py36 and not appengine"
1515
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This repository holds the samples used in the python documentation on [cloud.goo
1010
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/python-docs-samples.svg)](https://travis-ci.org/GoogleCloudPlatform/python-docs-samples)
1111
[![Coverage Status](https://coveralls.io/repos/github/GoogleCloudPlatform/python-docs-samples/badge.svg?branch=HEAD)](https://coveralls.io/github/GoogleCloudPlatform/python-docs-samples?branch=HEAD)
1212

13-
For more detailed introduction to a product, check the README.md in the
13+
For a more detailed introduction to a product, check the README.md in the
1414
corresponding folder.
1515

1616
## Contributing changes

appengine/flexible/django_cloudsql/mysite/settings.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,34 @@
7878
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
7979

8080
# [START dbconfig]
81+
82+
# The following DATABASES configuration is for PostgreSQL. If you are using
83+
# MySQL, use the commented-out block that follows this one instead. In this
84+
# case, please also follow the commented instructions in requirements.txt.
85+
8186
DATABASES = {
8287
'default': {
83-
# If you are using Cloud SQL for MySQL rather than PostgreSQL, set
84-
# 'ENGINE': 'django.db.backends.mysql' instead of the following.
8588
'ENGINE': 'django.db.backends.postgresql',
8689
'NAME': 'polls',
8790
'USER': '<your-database-user>',
8891
'PASSWORD': '<your-database-password>',
89-
# For MySQL, set 'PORT': '3306' instead of the following. Any Cloud
90-
# SQL Proxy instances running locally must also be set to tcp:3306.
9192
'PORT': '5432',
9293
}
9394
}
95+
96+
# Uncomment this DATABASES block and use it instead of the above if you are
97+
# using MySQL. Also follow the commented instructions in requirements.txt.
98+
99+
# DATABASES = {
100+
# 'default': {
101+
# 'ENGINE': 'django.db.backends.mysql',
102+
# 'NAME': 'polls',
103+
# 'USER': '<your-database-user>',
104+
# 'PASSWORD': '<your-database-password>',
105+
# 'PORT': '3306',
106+
# }
107+
# }
108+
94109
# In the flexible environment, you connect to CloudSQL using a unix socket.
95110
# Locally, you can use the CloudSQL proxy to proxy a localhost connection
96111
# to the instance
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Django==2.1.5
2-
mysqlclient==1.4.1
1+
Django==2.1.9
2+
# mysqlclient==1.4.1 # Uncomment this line if using MySQL
33
wheel==0.32.3
44
gunicorn==19.9.0
5-
psycopg2==2.7.7
5+
psycopg2==2.7.7 # Comment this line out if using MySQL
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Django==2.1.5
1+
Django==2.1.9
22
gunicorn==19.9.0

appengine/flexible/tasks/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,29 @@ App Engine task attempts.
2525

2626
Please refer to [Setting Up a Python Development Environment](https://cloud.google.com/python/setup).
2727

28-
## Authentication
28+
### Authentication
2929

3030
To set up authentication, please refer to our
3131
[authentication getting started guide](https://cloud.google.com/docs/authentication/getting-started).
3232

33+
### Install Dependencies
34+
35+
To install the dependencies for this sample, use the following command:
36+
37+
```
38+
pip install -r requirements.txt
39+
```
40+
41+
This sample uses the common protos in the [googleapis](https://github.com/googleapis/googleapis)
42+
repository. For more info, see
43+
[Protocol Buffer Basics](https://developers.google.com/protocol-buffers/docs/pythontutorial).
44+
3345
## Creating a queue
3446

3547
To create a queue using the Cloud SDK, use the following gcloud command:
3648

3749
```
38-
gcloud beta tasks queues create-app-engine-queue my-appengine-queue
50+
gcloud tasks queues create my-appengine-queue
3951
```
4052

4153
Note: A newly created queue will route to the default App Engine service and
@@ -79,14 +91,14 @@ export PROJECT_ID=my-project-id
7991
```
8092

8193
Then the queue ID, as specified at queue creation time. Queue IDs already
82-
created can be listed with `gcloud beta tasks queues list`.
94+
created can be listed with `gcloud tasks queues list`.
8395

8496
```
8597
export QUEUE_ID=my-appengine-queue
8698
```
8799

88100
And finally the location ID, which can be discovered with
89-
`gcloud beta tasks queues describe $QUEUE_ID`, with the location embedded in
101+
`gcloud tasks queues describe $QUEUE_ID`, with the location embedded in
90102
the "name" value (for instance, if the name is
91103
"projects/my-project/locations/us-central1/queues/my-appengine-queue", then the
92104
location is "us-central1").
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Flask==1.0.2
22
gunicorn==19.9.0
3-
google-cloud-tasks==0.7.0
3+
google-cloud-tasks==1.1.0
4+
googleapis-common-protos==1.6.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Django==2.1.5
1+
Django==2.1.9
22
PyMySQL==0.9.3

bigtable/metricscaler/metricscaler_test.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,27 @@ def test_scale_bigtable():
4646

4747
scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, True)
4848

49-
time.sleep(10)
50-
cluster.reload()
51-
52-
new_node_count = cluster.serve_nodes
53-
assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP))
49+
for n in range(10):
50+
time.sleep(10)
51+
cluster.reload()
52+
new_node_count = cluster.serve_nodes
53+
try:
54+
assert (new_node_count == (original_node_count + SIZE_CHANGE_STEP))
55+
except AssertionError:
56+
if n == 9:
57+
raise
5458

5559
scale_bigtable(BIGTABLE_INSTANCE, BIGTABLE_INSTANCE, False)
56-
time.sleep(10)
57-
cluster.reload()
58-
final_node_count = cluster.serve_nodes
59-
assert final_node_count == original_node_count
60+
61+
for n in range(10):
62+
time.sleep(10)
63+
cluster.reload()
64+
final_node_count = cluster.serve_nodes
65+
try:
66+
assert final_node_count == original_node_count
67+
except AssertionError:
68+
if n == 9:
69+
raise
6070

6171

6272
# Unit test for logic
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-bigtable==0.32.1
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2019, Google LLC
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# [START bigtable_writes_batch]
16+
import datetime
17+
18+
from google.cloud import bigtable
19+
20+
21+
def write_batch(project_id, instance_id, table_id):
22+
client = bigtable.Client(project=project_id, admin=True)
23+
instance = client.instance(instance_id)
24+
table = instance.table(table_id)
25+
26+
timestamp = datetime.datetime.utcnow()
27+
column_family_id = "stats_summary"
28+
29+
rows = [table.row("tablet#a0b81f74#20190501"),
30+
table.row("tablet#a0b81f74#20190502")]
31+
32+
rows[0].set_cell(column_family_id,
33+
"connected_wifi",
34+
1,
35+
timestamp)
36+
rows[0].set_cell(column_family_id,
37+
"os_build",
38+
"12155.0.0-rc1",
39+
timestamp)
40+
rows[1].set_cell(column_family_id,
41+
"connected_wifi",
42+
1,
43+
timestamp)
44+
rows[1].set_cell(column_family_id,
45+
"os_build",
46+
"12145.0.0-rc6",
47+
timestamp)
48+
49+
response = table.mutate_rows(rows)
50+
for i, status in enumerate(response):
51+
if status.code != 0:
52+
print("Error writing row: {}".format(status.message))
53+
54+
print('Successfully wrote 2 rows.')
55+
# [END bigtable_writes_batch]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2019, Google LLC
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# [START bigtable_writes_conditional]
16+
import datetime
17+
18+
from google.cloud import bigtable
19+
from google.cloud.bigtable import row_filters
20+
21+
22+
def write_conditional(project_id, instance_id, table_id):
23+
client = bigtable.Client(project=project_id, admin=True)
24+
instance = client.instance(instance_id)
25+
table = instance.table(table_id)
26+
27+
timestamp = datetime.datetime.utcnow()
28+
column_family_id = "stats_summary"
29+
30+
row_key = "phone#4c410523#20190501"
31+
32+
row_filter = row_filters.RowFilterChain(
33+
filters=[row_filters.FamilyNameRegexFilter(column_family_id),
34+
row_filters.ColumnQualifierRegexFilter('os_build'),
35+
row_filters.ValueRegexFilter("PQ2A\\..*")])
36+
row = table.row(row_key, filter_=row_filter)
37+
row.set_cell(column_family_id,
38+
"os_name",
39+
"android",
40+
timestamp)
41+
row.commit()
42+
43+
print('Successfully updated row\'s os_name.')
44+
# [END bigtable_writes_conditional]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2019, Google LLC
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# [START bigtable_writes_increment]
16+
from google.cloud import bigtable
17+
18+
19+
def write_increment(project_id, instance_id, table_id):
20+
client = bigtable.Client(project=project_id, admin=True)
21+
instance = client.instance(instance_id)
22+
table = instance.table(table_id)
23+
24+
column_family_id = "stats_summary"
25+
26+
row_key = "phone#4c410523#20190501"
27+
row = table.row(row_key, append=True)
28+
29+
# Decrement the connected_wifi value by 1.
30+
row.increment_cell_value(column_family_id, "connected_wifi", -1)
31+
row.commit()
32+
33+
print('Successfully updated row {}.'.format(row_key))
34+
# [END bigtable_writes_increment]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2019, Google LLC
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# [START bigtable_writes_simple]
16+
import datetime
17+
from google.cloud import bigtable
18+
19+
20+
def write_simple(project_id, instance_id, table_id):
21+
client = bigtable.Client(project=project_id, admin=True)
22+
instance = client.instance(instance_id)
23+
table = instance.table(table_id)
24+
25+
timestamp = datetime.datetime.utcnow()
26+
column_family_id = "stats_summary"
27+
28+
row_key = "phone#4c410523#20190501"
29+
30+
row = table.row(row_key)
31+
row.set_cell(column_family_id,
32+
"connected_cell",
33+
1,
34+
timestamp)
35+
row.set_cell(column_family_id,
36+
"connected_wifi",
37+
1,
38+
timestamp)
39+
row.set_cell(column_family_id,
40+
"os_build",
41+
"PQ2A.190405.003",
42+
timestamp)
43+
44+
row.commit()
45+
46+
print('Successfully wrote row {}.'.format(row_key))
47+
# [END bigtable_writes_simple]

0 commit comments

Comments
 (0)