Source code for airflow.providers.google.cloud.operators.cloud_composer
## 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.fromtypingimportTYPE_CHECKING,Dict,Optional,Sequence,Tuple,Unionfromgoogle.api_core.exceptionsimportAlreadyExistsfromgoogle.api_core.gapic_v1.methodimportDEFAULT,_MethodDefaultfromgoogle.api_core.retryimportRetryfromgoogle.cloud.orchestration.airflow.service_v1importImageVersionfromgoogle.cloud.orchestration.airflow.service_v1.typesimportEnvironmentfromgoogle.protobuf.field_mask_pb2importFieldMaskfromairflowimportAirflowExceptionfromairflow.modelsimportBaseOperatorfromairflow.providers.google.cloud.hooks.cloud_composerimportCloudComposerHookfromairflow.providers.google.cloud.links.baseimportBaseGoogleLinkfromairflow.providers.google.cloud.triggers.cloud_composerimportCloudComposerExecutionTriggerfromairflow.providers.google.common.constsimportGOOGLE_DEFAULT_DEFERRABLE_METHOD_NAMEifTYPE_CHECKING:fromairflow.utils.contextimportContext
[docs]classCloudComposerCreateEnvironmentOperator(BaseOperator):""" Create a new environment. :param project_id: Required. The ID of the Google Cloud project that the service belongs to. :param region: Required. The ID of the Google Cloud region that the service belongs to. :param environment_id: Required. The ID of the Google Cloud environment that the service belongs to. :param environment: The environment to create. :param gcp_conn_id: :param impersonation_chain: Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated). :param delegate_to: The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled. :param retry: Designation of what errors, if any, should be retried. :param timeout: The timeout for this request. :param metadata: Strings which should be sent along with the request as metadata. :param deferrable: Run operator in the deferrable mode :param pooling_period_seconds: Optional: Control the rate of the poll for the result of deferrable run. By default the trigger will poll every 30 seconds. """
[docs]defexecute_complete(self,context:"Context",event:dict):ifevent["operation_done"]:hook=CloudComposerHook(gcp_conn_id=self.gcp_conn_id,impersonation_chain=self.impersonation_chain,delegate_to=self.delegate_to,)env=hook.get_environment(project_id=self.project_id,region=self.region,environment_id=self.environment_id,retry=self.retry,timeout=self.timeout,metadata=self.metadata,)returnEnvironment.to_dict(env)else:raiseAirflowException(f"Unexpected error in the operation: {event['operation_name']}")
[docs]classCloudComposerDeleteEnvironmentOperator(BaseOperator):""" Delete an environment. :param project_id: Required. The ID of the Google Cloud project that the service belongs to. :param region: Required. The ID of the Google Cloud region that the service belongs to. :param environment_id: Required. The ID of the Google Cloud environment that the service belongs to. :param retry: Designation of what errors, if any, should be retried. :param timeout: The timeout for this request. :param metadata: Strings which should be sent along with the request as metadata. :param gcp_conn_id: :param impersonation_chain: Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated). :param delegate_to: The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled. :param deferrable: Run operator in the deferrable mode :param pooling_period_seconds: Optional: Control the rate of the poll for the result of deferrable run. By default the trigger will poll every 30 seconds. """
[docs]classCloudComposerGetEnvironmentOperator(BaseOperator):""" Get an existing environment. :param project_id: Required. The ID of the Google Cloud project that the service belongs to. :param region: Required. The ID of the Google Cloud region that the service belongs to. :param environment_id: Required. The ID of the Google Cloud environment that the service belongs to. :param retry: Designation of what errors, if any, should be retried. :param timeout: The timeout for this request. :param metadata: Strings which should be sent along with the request as metadata. :param gcp_conn_id: :param impersonation_chain: Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated). :param delegate_to: The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled. """
[docs]classCloudComposerListEnvironmentsOperator(BaseOperator):""" List environments. :param project_id: Required. The ID of the Google Cloud project that the service belongs to. :param region: Required. The ID of the Google Cloud region that the service belongs to. :param page_size: The maximum number of environments to return. :param page_token: The next_page_token value returned from a previous List request, if any. :param retry: Designation of what errors, if any, should be retried. :param timeout: The timeout for this request. :param metadata: Strings which should be sent along with the request as metadata. :param gcp_conn_id: :param impersonation_chain: Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated). :param delegate_to: The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled. """
[docs]classCloudComposerUpdateEnvironmentOperator(BaseOperator):r""" Update an environment. :param project_id: Required. The ID of the Google Cloud project that the service belongs to. :param region: Required. The ID of the Google Cloud region that the service belongs to. :param environment_id: Required. The ID of the Google Cloud environment that the service belongs to. :param environment: A patch environment. Fields specified by the ``updateMask`` will be copied from the patch environment into the environment under update. :param update_mask: Required. A comma-separated list of paths, relative to ``Environment``, of fields to update. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.protobuf.field_mask_pb2.FieldMask` :param retry: Designation of what errors, if any, should be retried. :param timeout: The timeout for this request. :param metadata: Strings which should be sent along with the request as metadata. :param gcp_conn_id: :param impersonation_chain: Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated). :param delegate_to: The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled. :param deferrable: Run operator in the deferrable mode :param pooling_period_seconds: Optional: Control the rate of the poll for the result of deferrable run. By default the trigger will poll every 30 seconds. """
[docs]defexecute_complete(self,context:"Context",event:dict):ifevent["operation_done"]:hook=CloudComposerHook(gcp_conn_id=self.gcp_conn_id,impersonation_chain=self.impersonation_chain,delegate_to=self.delegate_to,)env=hook.get_environment(project_id=self.project_id,region=self.region,environment_id=self.environment_id,retry=self.retry,timeout=self.timeout,metadata=self.metadata,)returnEnvironment.to_dict(env)else:raiseAirflowException(f"Unexpected error in the operation: {event['operation_name']}")
[docs]classCloudComposerListImageVersionsOperator(BaseOperator):""" List ImageVersions for provided location. :param request: The request object. List ImageVersions in a project and location. :param retry: Designation of what errors, if any, should be retried. :param timeout: The timeout for this request. :param metadata: Strings which should be sent along with the request as metadata. :param gcp_conn_id: :param impersonation_chain: Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account (templated). :param delegate_to: The account to impersonate using domain-wide delegation of authority, if any. For this to work, the service account making the request must have domain-wide delegation enabled. """