You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/02/11 16:08:54 UTC

[GitHub] [airflow] MarkYHZhang opened a new pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

MarkYHZhang opened a new pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400
 
 
   Added `MLEngineTrainingJobFailureOperator` with `cancel_job` hook for MLEngine. 
   
   ---
   Issue link: WILL BE INSERTED BY [boring-cyborg](https://github.com/kaxil/boring-cyborg)
   
   Make sure to mark the boxes below before creating PR: [x]
   
   - [x] Description above provides context of the change
   - [x] Commit message/PR title starts with `[AIRFLOW-NNNN]`. AIRFLOW-NNNN = JIRA ID<sup>*</sup>
   - [x] Unit tests coverage for changes (not needed for documentation changes)
   - [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [x] Relevant documentation is updated including usage instructions.
   - [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   <sup>*</sup> For document-only changes commit message can start with `[AIRFLOW-XXXX]`.
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377745677
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
+
+    @apply_defaults
+    def __init__(self,
+                 job_id: str,
+                 project_id: Optional[str] = None,
+                 gcp_conn_id: str = 'google_cloud_default',
+                 delegate_to: Optional[str] = None,
+                 *args,
+                 **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self._project_id = project_id
+        self._job_id = job_id
+        self._gcp_conn_id = gcp_conn_id
+        self._delegate_to = delegate_to
+
+        if not self._project_id:
+            raise AirflowException('Google Cloud project id is required.')
+        if not self._job_id:
+            raise AirflowException(
 
 Review comment:
   ```suggestion
   
   ```
   No need for that as `job_id` is required parameter. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] MarkYHZhang commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
MarkYHZhang commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377767498
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
+
+    @apply_defaults
+    def __init__(self,
+                 job_id: str,
+                 project_id: Optional[str] = None,
+                 gcp_conn_id: str = 'google_cloud_default',
+                 delegate_to: Optional[str] = None,
+                 *args,
+                 **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self._project_id = project_id
+        self._job_id = job_id
+        self._gcp_conn_id = gcp_conn_id
+        self._delegate_to = delegate_to
+
+        if not self._project_id:
+            raise AirflowException('Google Cloud project id is required.')
+        if not self._job_id:
+            raise AirflowException(
 
 Review comment:
   Uhmm, I'm not super sure why it was raised either, but I see the same checking in `MLEngineStartBatchPredictionJobOperator` and `MLEngineStartTrainingJobOperator`. And I thought I better include it as well 😅 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] codecov-io edited a comment on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#issuecomment-584739074
 
 
   # [Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=h1) Report
   > Merging [#7400](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/a0fa964c5e128e3297e61826fae6e3d7a074a263?src=pr&el=desc) will **decrease** coverage by `0.31%`.
   > The diff coverage is `87.09%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/airflow/pull/7400/graphs/tree.svg?width=650&token=WdLKlKHOAU&height=150&src=pr)](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #7400      +/-   ##
   ==========================================
   - Coverage    86.5%   86.19%   -0.32%     
   ==========================================
     Files         873      878       +5     
     Lines       40725    41189     +464     
   ==========================================
   + Hits        35231    35504     +273     
   - Misses       5494     5685     +191
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [airflow/providers/google/cloud/hooks/mlengine.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL2hvb2tzL21sZW5naW5lLnB5) | `82.25% <82.35%> (ø)` | :arrow_up: |
   | [...rflow/providers/google/cloud/operators/mlengine.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL29wZXJhdG9ycy9tbGVuZ2luZS5weQ==) | `89.66% <92.85%> (+0.15%)` | :arrow_up: |
   | [...w/providers/apache/hive/operators/mysql\_to\_hive.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2hpdmUvb3BlcmF0b3JzL215c3FsX3RvX2hpdmUucHk=) | `35.84% <0%> (-64.16%)` | :arrow_down: |
   | [airflow/kubernetes/volume\_mount.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZV9tb3VudC5weQ==) | `44.44% <0%> (-55.56%)` | :arrow_down: |
   | [airflow/kubernetes/volume.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZS5weQ==) | `52.94% <0%> (-47.06%)` | :arrow_down: |
   | [airflow/security/kerberos.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9zZWN1cml0eS9rZXJiZXJvcy5weQ==) | `30.43% <0%> (-45.66%)` | :arrow_down: |
   | [airflow/kubernetes/pod\_launcher.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3BvZF9sYXVuY2hlci5weQ==) | `47.18% <0%> (-45.08%)` | :arrow_down: |
   | [airflow/providers/mysql/operators/mysql.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvbXlzcWwvb3BlcmF0b3JzL215c3FsLnB5) | `55% <0%> (-45%)` | :arrow_down: |
   | [...viders/cncf/kubernetes/operators/kubernetes\_pod.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvY25jZi9rdWJlcm5ldGVzL29wZXJhdG9ycy9rdWJlcm5ldGVzX3BvZC5weQ==) | `69.38% <0%> (-24.23%)` | :arrow_down: |
   | [airflow/kubernetes/refresh\_config.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3JlZnJlc2hfY29uZmlnLnB5) | `50.98% <0%> (-23.53%)` | :arrow_down: |
   | ... and [32 more](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=footer). Last update [a0fa964...e815aac](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] MarkYHZhang commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
MarkYHZhang commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377767498
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
+
+    @apply_defaults
+    def __init__(self,
+                 job_id: str,
+                 project_id: Optional[str] = None,
+                 gcp_conn_id: str = 'google_cloud_default',
+                 delegate_to: Optional[str] = None,
+                 *args,
+                 **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self._project_id = project_id
+        self._job_id = job_id
+        self._gcp_conn_id = gcp_conn_id
+        self._delegate_to = delegate_to
+
+        if not self._project_id:
+            raise AirflowException('Google Cloud project id is required.')
+        if not self._job_id:
+            raise AirflowException(
 
 Review comment:
   Uhmm, I'm not super sure why it was raised either, but I see the same checking in `MLEngineStartBatchPredictionJobOperator` and `MLEngineStartTrainingJobOperator`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] codecov-io commented on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#issuecomment-584739074
 
 
   # [Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=h1) Report
   > Merging [#7400](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/a0fa964c5e128e3297e61826fae6e3d7a074a263?src=pr&el=desc) will **decrease** coverage by `54.32%`.
   > The diff coverage is `21.21%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/airflow/pull/7400/graphs/tree.svg?width=650&token=WdLKlKHOAU&height=150&src=pr)](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff             @@
   ##           master    #7400       +/-   ##
   ===========================================
   - Coverage    86.5%   32.18%   -54.33%     
   ===========================================
     Files         873      872        -1     
     Lines       40725    40745       +20     
   ===========================================
   - Hits        35231    13114    -22117     
   - Misses       5494    27631    +22137
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [airflow/providers/google/cloud/hooks/mlengine.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL2hvb2tzL21sZW5naW5lLnB5) | `19.35% <11.76%> (-62.9%)` | :arrow_down: |
   | [...rflow/providers/google/cloud/operators/mlengine.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL29wZXJhdG9ycy9tbGVuZ2luZS5weQ==) | `53.97% <31.25%> (-35.54%)` | :arrow_down: |
   | [...low/contrib/operators/wasb\_delete\_blob\_operator.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9jb250cmliL29wZXJhdG9ycy93YXNiX2RlbGV0ZV9ibG9iX29wZXJhdG9yLnB5) | `0% <0%> (-100%)` | :arrow_down: |
   | [...ing\_platform/example\_dags/example\_display\_video.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL21hcmtldGluZ19wbGF0Zm9ybS9leGFtcGxlX2RhZ3MvZXhhbXBsZV9kaXNwbGF5X3ZpZGVvLnB5) | `0% <0%> (-100%)` | :arrow_down: |
   | [airflow/contrib/hooks/vertica\_hook.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9jb250cmliL2hvb2tzL3ZlcnRpY2FfaG9vay5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
   | [airflow/contrib/sensors/\_\_init\_\_.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9jb250cmliL3NlbnNvcnMvX19pbml0X18ucHk=) | `0% <0%> (-100%)` | :arrow_down: |
   | [airflow/hooks/mssql\_hook.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9ob29rcy9tc3NxbF9ob29rLnB5) | `0% <0%> (-100%)` | :arrow_down: |
   | [airflow/hooks/webhdfs\_hook.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9ob29rcy93ZWJoZGZzX2hvb2sucHk=) | `0% <0%> (-100%)` | :arrow_down: |
   | [airflow/contrib/sensors/emr\_base\_sensor.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9jb250cmliL3NlbnNvcnMvZW1yX2Jhc2Vfc2Vuc29yLnB5) | `0% <0%> (-100%)` | :arrow_down: |
   | [...irflow/contrib/operators/slack\_webhook\_operator.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9jb250cmliL29wZXJhdG9ycy9zbGFja193ZWJob29rX29wZXJhdG9yLnB5) | `0% <0%> (-100%)` | :arrow_down: |
   | ... and [746 more](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=footer). Last update [a0fa964...7e13a62](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] boring-cyborg[bot] commented on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#issuecomment-584712021
 
 
   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, pylint and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/master/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/master/docs/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/master/BREEZE.rst) for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://apache-airflow-slack.herokuapp.com/
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin merged pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin merged pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] joeyfreund commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
joeyfreund commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377742121
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/mlengine.py
 ##########
 @@ -148,6 +148,51 @@ def create_job(
 
         return self._wait_for_job_done(project_id, job_id)
 
+    @CloudBaseHook.fallback_to_default_project_id
+    def cancel_job(
+        self,
+        job_id,
+        project_id: Optional[str] = None
+    ) -> Dict:
+
+        """
+        Cancels a MLEngine job.
+
+        :param project_id: The Google Cloud project id within which MLEngine
+            job will be launched. If set to None or missing, the default project_id from the GCP
 
 Review comment:
   This comment (describing the behaviour when `project_id` is `None`) is inconsistent with the code below.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] joeyfreund commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
joeyfreund commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377743755
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
 
 Review comment:
   Same as the comment above, it seems like the code raises an error if `project_id` is none/missing.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377744740
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/mlengine.py
 ##########
 @@ -148,6 +148,51 @@ def create_job(
 
         return self._wait_for_job_done(project_id, job_id)
 
+    @CloudBaseHook.fallback_to_default_project_id
+    def cancel_job(
+        self,
+        job_id,
+        project_id: Optional[str] = None
+    ) -> Dict:
+
+        """
+        Cancels a MLEngine job.
+
+        :param project_id: The Google Cloud project id within which MLEngine
+            job will be launched. If set to None or missing, the default project_id from the GCP
+            connection is used.
+        :type project_id: str
+        :param job_id: A unique id for the want-to-be cancelled Google MLEngine training job.
+        :type job_id: str
+
+        :return: Empty dict if cancelled successfully
+        :rtype: dict
+        :raises: googleapiclient.errors.HttpError
+        """
+
+        if not project_id:
+            raise ValueError("The project_id should be set")
+
+        hook = self.get_conn()
+
+        request = hook.projects().jobs().cancel(  # pylint: disable=no-member
+            name='projects/{}/jobs/{}'.format(project_id, job_id))
 
 Review comment:
   ```suggestion
               name=f'projects/{project_id}/jobs/{job_id}')
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377737240
 
 

 ##########
 File path: airflow/providers/google/cloud/hooks/mlengine.py
 ##########
 @@ -148,6 +148,51 @@ def create_job(
 
         return self._wait_for_job_done(project_id, job_id)
 
+    @CloudBaseHook.fallback_to_default_project_id
+    def cancel_job(
+        self,
+        job_id,
 
 Review comment:
   ```suggestion
           job_id: str,
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] mik-laj commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377755518
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
 
 Review comment:
   All operators except BigQuery allow passing project_id as a parameter. However, if this parameter is omitted, the default value will be read from the credentials.
   https://github.com/apache/airflow/blob/97a429f/airflow/providers/google/cloud/hooks/base.py#L334-L360
   It is very difficult to authorize and not get project_id.  This is not even possible with production deployment. You may not have project_id when using gcloud for authorization only. 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r378238926
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
+
+    @apply_defaults
+    def __init__(self,
+                 job_id: str,
+                 project_id: Optional[str] = None,
+                 gcp_conn_id: str = 'google_cloud_default',
+                 delegate_to: Optional[str] = None,
+                 *args,
+                 **kwargs) -> None:
+        super().__init__(*args, **kwargs)
+        self._project_id = project_id
+        self._job_id = job_id
+        self._gcp_conn_id = gcp_conn_id
+        self._delegate_to = delegate_to
+
+        if not self._project_id:
+            raise AirflowException('Google Cloud project id is required.')
+        if not self._job_id:
+            raise AirflowException(
 
 Review comment:
   MLEngineOperators are not best ones :D

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377745225
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
 
 Review comment:
   Let use tuple here :)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] boring-cyborg[bot] commented on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#issuecomment-586908741
 
 
   Awesome work, congrats on your first merged pull request!
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r378238724
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
 
 Review comment:
   It varies. But in my opinion, this is immutable field :)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] codecov-io edited a comment on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#issuecomment-584739074
 
 
   # [Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=h1) Report
   > Merging [#7400](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/a0fa964c5e128e3297e61826fae6e3d7a074a263?src=pr&el=desc) will **decrease** coverage by `0.13%`.
   > The diff coverage is `87.09%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/airflow/pull/7400/graphs/tree.svg?width=650&token=WdLKlKHOAU&height=150&src=pr)](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #7400      +/-   ##
   ==========================================
   - Coverage    86.5%   86.37%   -0.14%     
   ==========================================
     Files         873      878       +5     
     Lines       40725    41189     +464     
   ==========================================
   + Hits        35231    35576     +345     
   - Misses       5494     5613     +119
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [airflow/providers/google/cloud/hooks/mlengine.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL2hvb2tzL21sZW5naW5lLnB5) | `82.25% <82.35%> (ø)` | :arrow_up: |
   | [...rflow/providers/google/cloud/operators/mlengine.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL29wZXJhdG9ycy9tbGVuZ2luZS5weQ==) | `89.66% <92.85%> (+0.15%)` | :arrow_up: |
   | [airflow/kubernetes/volume\_mount.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZV9tb3VudC5weQ==) | `44.44% <0%> (-55.56%)` | :arrow_down: |
   | [airflow/kubernetes/volume.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZS5weQ==) | `52.94% <0%> (-47.06%)` | :arrow_down: |
   | [airflow/kubernetes/pod\_launcher.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3BvZF9sYXVuY2hlci5weQ==) | `47.18% <0%> (-45.08%)` | :arrow_down: |
   | [...viders/cncf/kubernetes/operators/kubernetes\_pod.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvY25jZi9rdWJlcm5ldGVzL29wZXJhdG9ycy9rdWJlcm5ldGVzX3BvZC5weQ==) | `69.38% <0%> (-24.23%)` | :arrow_down: |
   | [airflow/kubernetes/refresh\_config.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3JlZnJlc2hfY29uZmlnLnB5) | `50.98% <0%> (-23.53%)` | :arrow_down: |
   | [airflow/utils/sqlalchemy.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy91dGlscy9zcWxhbGNoZW15LnB5) | `84.93% <0%> (-11.74%)` | :arrow_down: |
   | [airflow/config\_templates/airflow\_local\_settings.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9jb25maWdfdGVtcGxhdGVzL2FpcmZsb3dfbG9jYWxfc2V0dGluZ3MucHk=) | `65.38% <0%> (-6.36%)` | :arrow_down: |
   | [airflow/stats.py](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree#diff-YWlyZmxvdy9zdGF0cy5weQ==) | `85.29% <0%> (-5.19%)` | :arrow_down: |
   | ... and [28 more](https://codecov.io/gh/apache/airflow/pull/7400/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=footer). Last update [a0fa964...e815aac](https://codecov.io/gh/apache/airflow/pull/7400?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] MarkYHZhang commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs

Posted by GitBox <gi...@apache.org>.
MarkYHZhang commented on a change in pull request #7400: [AIRFLOW-6759] Added MLEngine operator/hook to cancel MLEngine jobs
URL: https://github.com/apache/airflow/pull/7400#discussion_r377766618
 
 

 ##########
 File path: airflow/providers/google/cloud/operators/mlengine.py
 ##########
 @@ -1015,3 +1015,58 @@ def check_existing_job(existing_job):
         if finished_training_job['state'] != 'SUCCEEDED':
             self.log.error('MLEngine training job failed: %s', str(finished_training_job))
             raise RuntimeError(finished_training_job['errorMessage'])
+
+
+class MLEngineTrainingJobFailureOperator(BaseOperator):
+
+    """
+    Operator for cleaning up failed MLEngine training job.
+
+    :param job_id: A unique templated id for the submitted Google MLEngine
+        training job. (templated)
+    :type job_id: str
+    :param project_id: The Google Cloud project name within which MLEngine training job should run.
+        If set to None or missing, the default project_id from the GCP connection is used. (templated)
+    :type project_id: str
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :type gcp_conn_id: str
+    :param delegate_to: The account to impersonate, if any.
+        For this to work, the service account making the request must have
+        domain-wide delegation enabled.
+    :type delegate_to: str
+    """
+
+    template_fields = [
+        '_project_id',
+        '_job_id',
+    ]
 
 Review comment:
   That's an option, but I thought it'd be better to maintain consistency between the operators (all other ones uses an array). Unless, there is some other non-style related reasons?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services