Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reroute AutoML operator links to Google Translation links #39668

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions airflow/providers/google/cloud/links/automl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

from typing import TYPE_CHECKING

from deprecated import deprecated

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.google.cloud.links.base import BaseGoogleLink

if TYPE_CHECKING:
Expand All @@ -44,6 +47,13 @@
)


@deprecated(
reason=(
"Class `AutoMLDatasetLink` has been deprecated and will be removed after 31.12.2024. "
"Please use `TranslationLegacyDatasetLink` from `airflow/providers/google/cloud/links/translate.py` instead."
),
category=AirflowProviderDeprecationWarning,
)
class AutoMLDatasetLink(BaseGoogleLink):
"""Helper class for constructing AutoML Dataset link."""

Expand All @@ -65,6 +75,13 @@ def persist(
)


@deprecated(
reason=(
"Class `AutoMLDatasetListLink` has been deprecated and will be removed after 31.12.2024. "
"Please use `TranslationDatasetListLink` from `airflow/providers/google/cloud/links/translate.py` instead."
),
category=AirflowProviderDeprecationWarning,
)
class AutoMLDatasetListLink(BaseGoogleLink):
"""Helper class for constructing AutoML Dataset List link."""

Expand All @@ -87,6 +104,13 @@ def persist(
)


@deprecated(
reason=(
"Class `AutoMLModelLink` has been deprecated and will be removed after 31.12.2024. "
"Please use `TranslationLegacyModelLink` from `airflow/providers/google/cloud/links/translate.py` instead."
),
category=AirflowProviderDeprecationWarning,
)
class AutoMLModelLink(BaseGoogleLink):
"""Helper class for constructing AutoML Model link."""

Expand Down Expand Up @@ -114,6 +138,13 @@ def persist(
)


@deprecated(
reason=(
"Class `AutoMLModelTrainLink` has been deprecated and will be removed after 31.12.2024. "
"Please use `TranslationLegacyModelTrainLink` from `airflow/providers/google/cloud/links/translate.py` instead."
),
category=AirflowProviderDeprecationWarning,
)
class AutoMLModelTrainLink(BaseGoogleLink):
"""Helper class for constructing AutoML Model Train link."""

Expand All @@ -138,6 +169,13 @@ def persist(
)


@deprecated(
reason=(
"Class `AutoMLModelPredictLink` has been deprecated and will be removed after 31.12.2024. "
"Please use `TranslationLegacyModelPredictLink` from `airflow/providers/google/cloud/links/translate.py` instead."
),
category=AirflowProviderDeprecationWarning,
)
class AutoMLModelPredictLink(BaseGoogleLink):
"""Helper class for constructing AutoML Model Predict link."""

Expand Down
180 changes: 180 additions & 0 deletions airflow/providers/google/cloud/links/translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# 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.
"""This module contains Google Translate links."""

from __future__ import annotations

from typing import TYPE_CHECKING

from airflow.providers.google.cloud.links.base import BASE_LINK, BaseGoogleLink

if TYPE_CHECKING:
from airflow.utils.context import Context


TRANSLATION_BASE_LINK = BASE_LINK + "/translation"
TRANSLATION_LEGACY_DATASET_LINK = (
TRANSLATION_BASE_LINK + "/locations/{location}/datasets/{dataset_id}/sentences?project={project_id}"
)
TRANSLATION_DATASET_LIST_LINK = TRANSLATION_BASE_LINK + "/datasets?project={project_id}"
TRANSLATION_LEGACY_MODEL_LINK = (
TRANSLATION_BASE_LINK
+ "/locations/{location}/datasets/{dataset_id}/evaluate;modelId={model_id}?project={project_id}"
)
TRANSLATION_LEGACY_MODEL_TRAIN_LINK = (
TRANSLATION_BASE_LINK + "/locations/{location}/datasets/{dataset_id}/train?project={project_id}"
)
TRANSLATION_LEGACY_MODEL_PREDICT_LINK = (
TRANSLATION_BASE_LINK
+ "/locations/{location}/datasets/{dataset_id}/predict;modelId={model_id}?project={project_id}"
)


class TranslationLegacyDatasetLink(BaseGoogleLink):
"""
Helper class for constructing Legacy Translation Dataset link.

Legacy Datasets are created and managed by AutoML API.
"""

name = "Translation Legacy Dataset"
key = "translation_legacy_dataset"
format_str = TRANSLATION_LEGACY_DATASET_LINK

@staticmethod
def persist(
context: Context,
task_instance,
dataset_id: str,
project_id: str,
):
task_instance.xcom_push(
context,
key=TranslationLegacyDatasetLink.key,
value={"location": task_instance.location, "dataset_id": dataset_id, "project_id": project_id},
)


class TranslationDatasetListLink(BaseGoogleLink):
"""Helper class for constructing Translation Dataset List link."""

name = "Translation Dataset List"
key = "translation_dataset_list"
format_str = TRANSLATION_DATASET_LIST_LINK

@staticmethod
def persist(
context: Context,
task_instance,
project_id: str,
):
task_instance.xcom_push(
context,
key=TranslationDatasetListLink.key,
value={
"project_id": project_id,
},
)


class TranslationLegacyModelLink(BaseGoogleLink):
"""
Helper class for constructing Translation Legacy Model link.

Legacy Models are created and managed by AutoML API.
"""

name = "Translation Legacy Model"
key = "translation_legacy_model"
format_str = TRANSLATION_LEGACY_MODEL_LINK

@staticmethod
def persist(
context: Context,
task_instance,
dataset_id: str,
model_id: str,
project_id: str,
):
task_instance.xcom_push(
context,
key=TranslationLegacyModelLink.key,
value={
"location": task_instance.location,
"dataset_id": dataset_id,
"model_id": model_id,
"project_id": project_id,
},
)


class TranslationLegacyModelTrainLink(BaseGoogleLink):
"""
Helper class for constructing Translation Legacy Model Train link.

Legacy Models are created and managed by AutoML API.
"""

name = "Translation Legacy Model Train"
key = "translation_legacy_model_train"
format_str = TRANSLATION_LEGACY_MODEL_TRAIN_LINK

@staticmethod
def persist(
context: Context,
task_instance,
project_id: str,
):
task_instance.xcom_push(
context,
key=TranslationLegacyModelTrainLink.key,
value={
"location": task_instance.location,
"dataset_id": task_instance.model["dataset_id"],
"project_id": project_id,
},
)


class TranslationLegacyModelPredictLink(BaseGoogleLink):
"""
Helper class for constructing Translation Legacy Model Predict link.

Legacy Models are created and managed by AutoML API.
"""

name = "Translation Legacy Model Predict"
key = "translation_legacy_model_predict"
format_str = TRANSLATION_LEGACY_MODEL_PREDICT_LINK

@staticmethod
def persist(
context: Context,
task_instance,
model_id: str,
project_id: str,
):
task_instance.xcom_push(
context,
key=TranslationLegacyModelPredictLink.key,
value={
"location": task_instance.location,
"dataset_id": task_instance.model.dataset_id,
"model_id": model_id,
"project_id": project_id,
},
)
Loading