def execute(self, context: 'Context') -> Optional[bool]: self._validate_body_fields() database = self.body.get("name") if not database: self.log.error( "Body doesn't contain 'name'. Cannot check if the" " database already exists in the instance %s.", self.instance, ) return False hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) if self._check_if_db_exists(database, hook): self.log.info( "Cloud SQL instance with ID %s already contains database '%s'. Aborting database insert.", self.instance, database, ) return True else: return hook.create_database(project_id=self.project_id, instance=self.instance, body=self.body)
def execute(self, context): self._validate_body_fields() hook = CloudSQLHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) return hook.import_instance(project_id=self.project_id, instance=self.instance, body=self.body)
def execute(self, context: 'Context') -> None: hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) self._validate_body_fields() if not self._check_if_instance_exists(self.instance, hook): hook.create_instance(project_id=self.project_id, body=self.body) else: self.log.info( "Cloud SQL instance with ID %s already exists. Aborting create.", self.instance) CloudSQLInstanceLink.persist( context=context, task_instance=self, cloud_sql_instance=self.instance, project_id=self.project_id or hook.project_id, ) instance_resource = hook.get_instance(project_id=self.project_id, instance=self.instance) service_account_email = instance_resource["serviceAccountEmailAddress"] task_instance = context['task_instance'] task_instance.xcom_push(key="service_account_email", value=service_account_email)
def execute(self, context) -> None: self._validate_body_fields() hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) return hook.export_instance(project_id=self.project_id, instance=self.instance, body=self.body)
def execute(self, context) -> Optional[bool]: hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) if not self._check_if_instance_exists(self.instance, hook): print(f"Cloud SQL instance with ID {self.instance} does not exist. Aborting delete.") return True else: return hook.delete_instance(project_id=self.project_id, instance=self.instance)
def execute(self, context): hook = CloudSQLHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) if not self._check_if_instance_exists(self.instance, hook): print( "Cloud SQL instance with ID {} does not exist. Aborting delete." .format(self.instance)) return True else: return hook.delete_instance(project_id=self.project_id, instance=self.instance)
def execute(self, context): hook = CloudSQLHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) if not self._check_if_instance_exists(self.instance, hook): raise AirflowException( 'Cloud SQL instance with ID {} does not exist. ' 'Please specify another instance to patch.'.format( self.instance)) else: return hook.patch_instance(project_id=self.project_id, body=self.body, instance=self.instance)
def execute(self, context): hook = CloudSQLHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) if not self._check_if_db_exists(self.database, hook): print( "Cloud SQL instance with ID {} does not contain database '{}'. " "Aborting database delete.".format(self.instance, self.database)) return True else: return hook.delete_database(project_id=self.project_id, instance=self.instance, database=self.database)
def execute(self, context: 'Context'): hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) if not self._check_if_instance_exists(self.instance, hook): raise AirflowException( f'Cloud SQL instance with ID {self.instance} does not exist. ' 'Please specify another instance to patch.' ) else: return hook.patch_instance(project_id=self.project_id, body=self.body, instance=self.instance)
def execute(self, context: 'Context') -> Optional[bool]: hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) if not self._check_if_db_exists(self.database, hook): print( f"Cloud SQL instance with ID {self.instance!r} does not contain database {self.database!r}. " f"Aborting database delete.") return True else: return hook.delete_database(project_id=self.project_id, instance=self.instance, database=self.database)
def execute(self, context): self._validate_body_fields() hook = CloudSQLHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) if not self._check_if_db_exists(self.database, hook): raise AirflowException( "Cloud SQL instance with ID {instance} does not contain " "database '{database}'. " "Please specify another database to patch.".format( instance=self.instance, database=self.database)) else: return hook.patch_database(project_id=self.project_id, instance=self.instance, database=self.database, body=self.body)
def execute(self, context: 'Context') -> None: self._validate_body_fields() hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) if not self._check_if_db_exists(self.database, hook): raise AirflowException( f"Cloud SQL instance with ID {self.instance} does not contain database '{self.database}'. " "Please specify another database to patch.") else: return hook.patch_database(project_id=self.project_id, instance=self.instance, database=self.database, body=self.body)
def execute(self, context): hook = CloudSQLHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) self._validate_body_fields() if not self._check_if_instance_exists(self.instance, hook): hook.create_instance(project_id=self.project_id, body=self.body) else: self.log.info( "Cloud SQL instance with ID %s already exists. " "Aborting create.", self.instance) instance_resource = hook.get_instance(project_id=self.project_id, instance=self.instance) service_account_email = instance_resource["serviceAccountEmailAddress"] task_instance = context['task_instance'] task_instance.xcom_push(key="service_account_email", value=service_account_email)
def execute(self, context: 'Context') -> None: self._validate_body_fields() hook = CloudSQLHook( gcp_conn_id=self.gcp_conn_id, api_version=self.api_version, impersonation_chain=self.impersonation_chain, ) CloudSQLInstanceLink.persist( context=context, task_instance=self, cloud_sql_instance=self.instance, project_id=self.project_id or hook.project_id, ) FileDetailsLink.persist( context=context, task_instance=self, uri=self.body["importContext"]["uri"][5:], project_id=self.project_id or hook.project_id, ) return hook.import_instance(project_id=self.project_id, instance=self.instance, body=self.body)