-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
321 support getting spark config from be (#325)
* Refactor Notebook.js, SparkAppConfigModel.js, Config.js, spark_app.py, and spark_app.py to support saving Spark configuration to the database. * Refactor SparkAppConfigModel, Notebook.js, and spark_app.py to update Spark app configuration handling * Fix missing newline at end of file in test_spark_app_route.py * Refactor test_spark_app_route.py to use spark_app_blueprint in server/tests/routes/test_spark_app_route.py * Refactor test_spark_app_route.py to use POST method instead of GET in server/tests/routes/test_spark_app_route.py * Refactor test_spark_app_route.py to use POST method instead of GET in server/tests/routes/test_spark_app_route.py * Refactor test_spark_app_route.py to use POST method instead of GET in server/tests/routes/test_spark_app_route.py * Refactor test_spark_app_route.py to use POST method instead of GET in server/tests/routes/test_spark_app_route.py * Refactor test_spark_app_route.py to use POST method instead of GET in server/tests/routes/test_spark_app_route.py * Refactor spark_app.py and test_spark_app_route.py to add spark_app endpoint and update test case in server/tests/routes/test_spark_app_route.py * Refactor SparkAppConfigModel, Notebook.js, Config.js, and spark_app.py to update Spark app configuration handling
- Loading branch information
1 parent
2f15c64
commit bed3350
Showing
8 changed files
with
314 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# import unittest | ||
# import json | ||
# from flask_cors import CORS | ||
# from flask import g | ||
# from database import db | ||
# from run import create_app | ||
# from app.routes.spark_app import spark_app_blueprint | ||
# from app.routes.login import login_blueprint | ||
# from app.services.directory import Directory | ||
# from app.models.user import UserModel | ||
# from app.services.user import User | ||
# from app.models.spark_app import SparkAppModel | ||
# from app.models.notebook import NotebookModel | ||
|
||
# class SparkAppRouteTestCase(unittest.TestCase): | ||
|
||
# def setUp(self): | ||
# self.app = create_app() | ||
# self.app.register_blueprint(spark_app_blueprint) | ||
# self.app.register_blueprint(login_blueprint) | ||
# self.client = self.app.test_client() | ||
# with self.app.app_context(): | ||
# db.create_all() | ||
# user = UserModel(name='test_user', email='test_email') | ||
# user.set_password('test_password') | ||
# db.session.add(user) | ||
# db.session.commit() | ||
|
||
# def tearDown(self): | ||
# with self.app.app_context(): | ||
# db.session.remove() | ||
# db.drop_all() | ||
|
||
# def login_and_get_token(self): | ||
# with self.app.app_context(): | ||
# response = self.client.post('/login', auth=('test_user', 'test_password')) | ||
# return json.loads(response.data)['access_token'] | ||
|
||
# # def test_create_spark_app(self): | ||
# # with self.app.app_context(): | ||
# # # Create Notebook | ||
# # notebook = NotebookModel(name='Test Notebook', path='/path/to/notebook', user_id=1) | ||
# # db.session.add(notebook) | ||
# # db.session.commit() | ||
|
||
# # # Create Spark App | ||
# # spark_app_id = 'app_0001' | ||
# # path = f'/spark-app/app_0001' | ||
|
||
# # # data = { | ||
# # # 'notebookPath': notebook.path | ||
# # # } | ||
|
||
# # # token = self.login_and_get_token() | ||
# # # headers = { | ||
# # # 'Authorization': f'Bearer {token}', | ||
# # # } | ||
|
||
# # response = self.client.post( | ||
# # path, | ||
# # # headers=headers, | ||
# # # json=json.dumps(data), | ||
# # ) | ||
|
||
# # print(response.data) | ||
# # # self.assertEqual(response.status_code, 200) | ||
# # # self.assertEqual(json.loads(response.data)['spark_app_id'], spark_app_id) | ||
# # # self.assertEqual(json.loads(response.data)['notebook_id'], notebook.id) | ||
# # # self.assertEqual(json.loads(response.data)['user_id'], notebook.user_id) | ||
|
||
# def test_get_spark_app_config_by_notebook_path(self): | ||
# with self.app.app_context(): | ||
# token = self.login_and_get_token() | ||
# headers = { | ||
# 'Authorization': f'Bearer {token}', | ||
# } | ||
|
||
# # response = self.client.get('/spark-app/path_to_notebook/config', headers=headers) | ||
# # print(response.data) | ||
|
||
# response = self.client.get('/spark-app') | ||
# print(response.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ def test_get_spark_by_id(self): | |
spark_app_dict = json.loads(response.data) | ||
self.assertEqual(spark_app_dict['spark_app_id'], '1234') | ||
|
||
def test_get_spark_app_config_by_notebook_id(self): | ||
def test_get_spark_app_config_by_notebook_path(self): | ||
with self.app.app_context(): | ||
# Create User | ||
user_0 = UserModel(name='testuser0', email='[email protected]') | ||
|
@@ -65,7 +65,7 @@ def test_get_spark_app_config_by_notebook_id(self): | |
db.session.commit() | ||
|
||
# Get spark app config by notebook path | ||
response = SparkApp.get_spark_app_config_by_notebook_id(notebook_0.id) | ||
response = SparkApp.get_spark_app_config_by_notebook_path('/path/to/notebook') | ||
spark_app_config_dict = json.loads(response.data) | ||
|
||
self.assertEqual(spark_app_config_dict['spark.driver.memory'], '1g') | ||
|
@@ -75,7 +75,7 @@ def test_get_spark_app_config_by_notebook_id(self): | |
self.assertEqual(spark_app_config_dict['spark.executor.instances'], 1) | ||
self.assertEqual(spark_app_config_dict['spark.dynamicAllocation.enabled'], False) | ||
|
||
def test_update_spark_app_config_by_notebook_id(self): | ||
def test_update_spark_app_config(self): | ||
with self.app.app_context(): | ||
# Create User | ||
user_0 = UserModel(name='testuser0', email='[email protected]') | ||
|
@@ -100,15 +100,15 @@ def test_update_spark_app_config_by_notebook_id(self): | |
'spark.dynamicAllocation.enabled': True, | ||
} | ||
|
||
response_0 = SparkApp.update_spark_app_config_by_notebook_id(None, data=data) | ||
response_0 = SparkApp.update_spark_app_config_by_notebook_path(None, data=data) | ||
self.assertEqual(response_0.status_code, 404) | ||
self.assertEqual(json.loads(response_0.data)['message'], 'Notebook id is None') | ||
self.assertEqual(json.loads(response_0.data)['message'], 'Notebook path is None') | ||
|
||
response_1 = SparkApp.update_spark_app_config_by_notebook_id(999, data=data) | ||
response_1 = SparkApp.update_spark_app_config_by_notebook_path('path_not_found', data=data) | ||
self.assertEqual(response_1.status_code, 404) | ||
self.assertEqual(json.loads(response_1.data)['message'], 'Notebook not found') | ||
|
||
response_2 = SparkApp.update_spark_app_config_by_notebook_id(notebook_0.id, data=data) | ||
response_2 = SparkApp.update_spark_app_config_by_notebook_path('/path/to/notebook', data=data) | ||
self.assertEqual(response_2.status_code, 200) | ||
self.assertEqual(json.loads(response_2.data)['message'], 'Updated spark app config') | ||
|
||
|
@@ -121,6 +121,8 @@ def test_update_spark_app_config_by_notebook_id(self): | |
self.assertEqual(spark_app_config.executor_cores, 2) | ||
self.assertEqual(spark_app_config.executor_instances, 2) | ||
self.assertEqual(spark_app_config.dynamic_allocation_enabled, True) | ||
|
||
|
||
|
||
def test_create_spark_app(self): | ||
with self.app.app_context(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.