From e3c2315fce57f9427689c4b52531dd9bae37ed10 Mon Sep 17 00:00:00 2001 From: Wenyi Xu Date: Tue, 10 Dec 2024 16:54:16 +0800 Subject: [PATCH] Implement Spark app status endpoint and enhance logging in SparkModel.js - Added a new endpoint to retrieve the status of a Spark application by its ID in spark_app.py, improving the API's functionality. - Enhanced logging in SparkModel.js to provide better visibility during the storage process of Spark application information, including status checks and error handling. - Improved validation for Spark application IDs to ensure only valid IDs are processed, contributing to more robust error management. --- server/app/routes/spark_app.py | 14 +++++++++++++- webapp/src/models/SparkModel.js | 12 +++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server/app/routes/spark_app.py b/server/app/routes/spark_app.py index c3b2799..c4ac297 100644 --- a/server/app/routes/spark_app.py +++ b/server/app/routes/spark_app.py @@ -25,4 +25,16 @@ def update_spark_app_config(notbook_path): def create_spark_session(): data = request.get_json() notebook_path = data.get('notebookPath') - return SparkApp.create_spark_session(notebook_path) \ No newline at end of file + return SparkApp.create_spark_session(notebook_path) + +@spark_app_blueprint.route('/spark_app//status', methods=['GET']) +def get_spark_app_status(spark_app_id): + logging.info(f"Getting spark app status for app id: {spark_app_id}") + try: + spark_app = SparkAppModel.query.get(spark_app_id) + if spark_app: + return jsonify({'status': spark_app.status}), 200 + return jsonify({'message': 'Spark application not found'}), 404 + except Exception as e: + logging.error(f"Error getting spark app status: {e}") + return jsonify({'message': str(e)}), 500 \ No newline at end of file diff --git a/webapp/src/models/SparkModel.js b/webapp/src/models/SparkModel.js index f8e24d6..89b7203 100644 --- a/webapp/src/models/SparkModel.js +++ b/webapp/src/models/SparkModel.js @@ -27,20 +27,26 @@ class SparkModel { } static async storeSparkInfo(sparkAppId, notebookPath) { + console.log('Attempting to store spark info for:', sparkAppId); // Only store if it's an actual Spark application ID if (!sparkAppId.startsWith('app-')) { - console.log('Not a valid Spark application ID:', sparkAppId); - return; + console.log('Not a valid Spark application ID:', sparkAppId); + return; } try { const checkResponse = await fetch(`${config.serverBaseUrl}/spark_app/${sparkAppId}/status`); + console.log('Status check response:', checkResponse.status); if (checkResponse.ok) { console.log('Spark app ID already exists:', sparkAppId); return; } } catch (error) { - console.log('App ID does not exist, proceeding with storage'); + console.log('Status check failed:', error); + if (error.response?.status !== 404) { + console.log('Unexpected error, skipping storage'); + return; + } } const response = await fetch(`${config.serverBaseUrl}/spark_app/${sparkAppId}`, {