Skip to content

Commit

Permalink
Implement Spark app status endpoint and enhance logging in SparkModel.js
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
xuwenyihust committed Dec 10, 2024
1 parent d77552e commit e3c2315
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
14 changes: 13 additions & 1 deletion server/app/routes/spark_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
return SparkApp.create_spark_session(notebook_path)

@spark_app_blueprint.route('/spark_app/<spark_app_id>/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
12 changes: 9 additions & 3 deletions webapp/src/models/SparkModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, {
Expand Down

0 comments on commit e3c2315

Please sign in to comment.