def refresh_dag(self, base_response): logging.info("Executing custom 'refresh_dag' function") dag_id = request.args.get('dag_id') logging.info("dag_id to refresh: '" + str(dag_id) + "'") if self.is_arg_not_provided(dag_id): return REST_API_Response_Util.get_400_error_response( base_response, "dag_id should be provided") elif " " in dag_id: return REST_API_Response_Util.get_400_error_response( base_response, "dag_id contains spaces and is therefore an illegal argument") try: from airflow.www.views import Airflow # NOTE: The request argument 'dag_id' is required for the refresh() function to get the dag_id refresh_result = Airflow().refresh() logging.info("Refresh Result: " + str(refresh_result)) except Exception as e: error_message = "An error occurred while trying to Refresh the DAG '" + str( dag_id) + "': " + str(e) logging.error(error_message) return REST_API_Response_Util.get_500_error_response( base_response, error_message) return REST_API_Response_Util.get_200_response( base_response=base_response, output="DAG [{}] is now fresh as a daisy".format(dag_id))
def get_task_stats(): logging.info("Executing custom 'get_task_stats' function") try: # Recall Airflow Delete URL from airflow.www.views import Airflow return Airflow().task_stats() except Exception as e: error_message = "An error occurred while trying to task_stats'" + "': " + str(e) logging.error(error_message) return ApiResponse.server_error(error_message)
def refresh_dag(dag_id): logging.info("Executing custom 'refresh_dag' function") try: from airflow.www.views import Airflow # NOTE: The request argument 'dag_id' is required for the refresh() function to get the dag_id refresh_result = Airflow().refresh() logging.info("Refresh Result: " + str(refresh_result)) except Exception as e: error_message = "An error occurred while trying to Refresh the DAG '" + str(dag_id) + "': " + str(e) logging.error(error_message) return ApiResponse.server_error(error_message) return ApiResponse.success("DAG [{}] is now fresh as a daisy".format(dag_id))
def get_dag_log(): logging.info("Executing custom 'get_dag_log' function") try: # Recall Airflow Delete URL from airflow.www.views import Airflow # NOTE: The request argument 'dag_id', 'task_id' and 'execution_date' is required for the delete() function to get the dag_id return Airflow().get_logs_with_metadata() # logging.info("Get Dag Log Result: " + str(json.dumps(result))) # return ApiResponse.success(str(json.dumps(result))) except Exception as e: dag_id = request.args.get('dag_id', "none") error_message = "An error occurred while trying to get_logs_with_metadata of DAG '" + str(dag_id) + "': " + str( e) logging.error(error_message) return ApiResponse.server_error(error_message)
def delete_dag(dag_id): logging.info("Executing custom 'delete_dag' function") try: # Pause Dag ApiUtil.pause_dag(dag_id) # Remove Dag File ApiUtil.remove_dag(dag_id) # Recall Airflow Delete URL from airflow.www.views import Airflow # NOTE: The request argument 'dag_id' is required for the delete() function to get the dag_id delete_result = Airflow().delete() logging.info("Delete Result: " + str(delete_result)) except Exception as e: error_message = "An error occurred while trying to Delete the DAG '" + str(dag_id) + "': " + str(e) logging.error(error_message) return ApiResponse.server_error(error_message) return ApiResponse.success("DAG [{}] has been deleted".format(dag_id))