[jira] [Commented] (AIRFLOW-3433) Create Google Cloud Spanner Hook

2018-12-06 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-3433?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16712048#comment-16712048
 ] 

ASF GitHub Bot commented on AIRFLOW-3433:
-

ryanyuan closed pull request #4284: [AIRFLOW-3433] Create Google Cloud Spanner 
Hook
URL: https://github.com/apache/incubator-airflow/pull/4284
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/contrib/hooks/gcp_spanner_hook.py 
b/airflow/contrib/hooks/gcp_spanner_hook.py
new file mode 100644
index 00..5f98cced9a
--- /dev/null
+++ b/airflow/contrib/hooks/gcp_spanner_hook.py
@@ -0,0 +1,500 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+from airflow import AirflowException
+from airflow.contrib.hooks.gcp_api_base_hook import GoogleCloudBaseHook
+from apiclient.discovery import HttpError, build
+
+
+class SpannerHook(GoogleCloudBaseHook):
+"""
+Interact with Google Cloud Spanner. This hook uses the Google Cloud 
Platform
+connection.
+
+This object is not threads safe. If you want to make multiple requests
+simultaneously, you will need to create a hook per thread.
+"""
+
+def __init__(
+self, gcp_conn_id="google_cloud_default", delegate_to=None, 
version="v1"
+):
+super(SpannerHook, self).__init__(gcp_conn_id, delegate_to)
+self.version = version
+
+def get_conn(self):
+"""
+Returns a Google Cloud Spanner service object.
+"""
+http_authorized = self._authorize()
+return build(
+"spanner", self.version, http=http_authorized, 
cache_discovery=False
+)
+
+def list_instance_configs(self, project_id):
+"""
+Lists the supported instance configurations for a given project.
+
+.. seealso::
+For more information, see:
+
https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instanceConfigs/list
+
+:param project_id: The name of the project for which a list of 
supported instance
+configurations is requested
+:type project_id: str
+"""
+
+project_id = project_id if project_id is not None else self.project_id
+
+self.log.info("Retrieving Spanner instance configs")
+
+try:
+resp = (
+self.get_conn()
+.projects()
+.instanceConfigs()
+.list(parent="projects/{}".format(project_id))
+.execute()
+)
+
+self.log.info("Spanner instance configs retrieved successfully")
+
+return resp
+except HttpError as err:
+raise AirflowException(
+"BigQuery job failed. Error was: {}".format(err.content)
+)
+
+def create_instance(self, project_id, body):
+"""
+Method to create a Cloud Spanner instance and begins preparing it to 
begin serving.
+If the named instance already exists, it will return 409 Instance 
Already Exists.
+
+.. seealso::
+For more information, see:
+
https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances/create
+
+:param project_id: The name of the project in which to create the 
instance
+:type project_id: str
+:param body: the request body containing instance creation data
+:type rows: dict
+
+**Example or body**:
+body = {
+"instanceId": "spanner-instance-1",
+"instance": {
+"nodeCount": 1,
+"config": "projects/spanner-project/instanceConfigs/eur3",
+"displayName": "Spanner Instance 1",
+},
+}
+"""
+
+project_id = project_id if project_id is not None else self.project_id
+
+if "instanceId" not in body:
+raise ValueError("instanceId is undefined in the body")

[jira] [Commented] (AIRFLOW-3433) Create Google Cloud Spanner Hook

2018-12-05 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-3433?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16711003#comment-16711003
 ] 

ASF GitHub Bot commented on AIRFLOW-3433:
-

ryanyuan opened a new pull request #4284: [AIRFLOW-3433] Create Google Cloud 
Spanner Hook
URL: https://github.com/apache/incubator-airflow/pull/4284
 
 
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [ ] My PR addresses the following 
[Airflow-3433](https://issues.apache.org/jira/browse/AIRFLOW-3433) issues and 
references them in the PR title.
   
   ### Description
   
   - [ ] Here are some details about my PR, including screenshots of any UI 
changes:
   Add a hook to connect to GCP Cloud Spanner and perform operations.
   
   ### Tests
   
   - [ ] My PR adds the following unit tests __OR__ does not need testing for 
this extremely good reason:
   tests.contrib.hooks.test_gcp_spanner_hook
   
   ### Commits
   
   - [ ] My commits all reference Jira issues in their subject lines, and I 
have squashed multiple commits if they address the same issue. In addition, my 
commits follow the guidelines from "[How to write a good git commit 
message](http://chris.beams.io/posts/git-commit/)":
 1. Subject is separated from body by a blank line
 1. Subject is limited to 50 characters (not including Jira issue reference)
 1. Subject does not end with a period
 1. Subject uses the imperative mood ("add", not "adding")
 1. Body wraps at 72 characters
 1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes 
how to use it.
 - When adding new operators/hooks/sensors, the autoclass documentation 
generation needs to be added.
   
   ### Code Quality
   
   - [ ] Passes `flake8`
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Create Google Cloud Spanner Hook
> 
>
> Key: AIRFLOW-3433
> URL: https://issues.apache.org/jira/browse/AIRFLOW-3433
> Project: Apache Airflow
>  Issue Type: New Feature
>Reporter: Ryan Yuan
>Assignee: Ryan Yuan
>Priority: Major
>
> Add Google Cloud Spanner hook to Airflow 
> (https://cloud.google.com/spanner/docs/apis)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)