peter-volkov commented on a change in pull request #7252: [AIRFLOW-6531] 
Initial Yandex.Cloud Dataproc support
URL: https://github.com/apache/airflow/pull/7252#discussion_r379461908
 
 

 ##########
 File path: airflow/providers/yandex/operators/yandexcloud_dataproc_operator.py
 ##########
 @@ -0,0 +1,334 @@
+# 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.providers.yandex.hooks.yandexcloud_dataproc_hook import 
DataprocHook
+from airflow.providers.yandex.operators import YandexCloudBaseOperator
+from airflow.utils.decorators import apply_defaults
+
+
+class DataprocCreateClusterOperator(YandexCloudBaseOperator):
+    """Creates Yandex.Cloud Data Proc cluster."""
+
+    # pylint: disable=too-many-instance-attributes
+    # pylint: disable=too-many-arguments
+    # pylint: disable=too-many-locals
+
+    @apply_defaults
+    def __init__(self,
+                 folder_id=None,
+                 connection_id=None,
+                 cluster_name=None,
+                 cluster_description='',
+                 cluster_image_version='1.1',
+                 ssh_public_keys=None,
+                 subnet_id=None,
+                 services=('HDFS', 'YARN', 'MAPREDUCE', 'HIVE', 'SPARK'),
+                 s3_bucket=None,
+                 zone='ru-central1-b',
+                 service_account_id=None,
+                 masternode_resource_preset='s2.small',
+                 masternode_disk_size=15,
+                 masternode_disk_type='network-ssd',
+                 datanode_resource_preset='s2.small',
+                 datanode_disk_size=15,
+                 datanode_disk_type='network-ssd',
+                 datanode_count=2,
+                 computenode_resource_preset='s2.small',
+                 computenode_disk_size=15,
+                 computenode_disk_type='network-ssd',
+                 computenode_count=0,
+                 *arguments,
+                 **kwargs):
+        super().__init__(*arguments, **kwargs)
+        self.folder_id = folder_id
+        self.connection_id = connection_id
+        self.cluster_name = cluster_name
+        self.cluster_description = cluster_description
+        self.cluster_image_version = cluster_image_version
+        self.ssh_public_keys = ssh_public_keys
+        self.subnet_id = subnet_id
+        self.services = services
+        self.s3_bucket = s3_bucket
+        self.zone = zone
+        self.service_account_id = service_account_id
+        self.masternode_resource_preset = masternode_resource_preset
+        self.masternode_disk_size = masternode_disk_size
+        self.masternode_disk_type = masternode_disk_type
+        self.datanode_resource_preset = datanode_resource_preset
+        self.datanode_disk_size = datanode_disk_size
+        self.datanode_disk_type = datanode_disk_type
+        self.datanode_count = datanode_count
+        self.computenode_resource_preset = computenode_resource_preset
+        self.computenode_disk_size = computenode_disk_size
+        self.computenode_disk_type = computenode_disk_type
+        self.computenode_count = computenode_count
+
+    def execute(self, context):
+        self.hook = DataprocHook(
+            connection_id=self.connection_id,
+        )
+        operation_result = self.hook.client.create_cluster(
+            folder_id=self.folder_id,
+            cluster_name=self.cluster_name,
+            cluster_description=self.cluster_description,
+            cluster_image_version=self.cluster_image_version,
+            ssh_public_keys=self.ssh_public_keys,
+            subnet_id=self.subnet_id,
+            services=self.services,
+            s3_bucket=self.s3_bucket,
+            zone=self.zone,
+            service_account_id=self.service_account_id,
+            masternode_resource_preset=self.masternode_resource_preset,
+            masternode_disk_size=self.masternode_disk_size,
+            masternode_disk_type=self.masternode_disk_type,
+            datanode_resource_preset=self.datanode_resource_preset,
+            datanode_disk_size=self.datanode_disk_size,
+            datanode_disk_type=self.datanode_disk_type,
+            datanode_count=self.datanode_count,
+            computenode_resource_preset=self.computenode_resource_preset,
+            computenode_disk_size=self.computenode_disk_size,
+            computenode_disk_type=self.computenode_disk_type,
+            computenode_count=self.computenode_count,
+        )
+        context['task_instance'].xcom_push(key='cluster_id', 
value=operation_result.response.id)
+        context['task_instance'].xcom_push(key='yandexcloud_connection_id', 
value=self.connection_id)
+
+
+class DataprocDeleteClusterOperator(YandexCloudBaseOperator):
+    """Deletes Yandex.Cloud Data Proc cluster."""
 
 Review comment:
   PyCharm shows arguments and docstring-based type hints for operator 
initialization, taking them from the corresponding methods in yandexcloud 
package.
   ![Screenshot from 2020-02-14 
17-31-46](https://user-images.githubusercontent.com/5512671/74539951-fcc4fb80-4f4f-11ea-9ea1-e09ac5b92cee.png)
   
   But I can copy the hints here if you still think that this will help the 
users as well as py3 type annotations.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to