-
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.
Add Spark app configuration support in database and API routes
- Loading branch information
1 parent
d46421f
commit 27f60a7
Showing
6 changed files
with
176 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from database import db | ||
|
||
class SparkAppConfigModel(db.Model): | ||
|
||
__tablename__ = 'spark_app_config' | ||
|
||
id = db.Column(db.Integer, primary_key=True, nullable=False) | ||
notebook_id = db.Column(db.Integer, db.ForeignKey('notebooks.id'), nullable=False) | ||
driver_memory = db.Column(db.Integer, nullable=True) | ||
driver_memory_overhead = db.Column(db.Integer, nullable=True) | ||
driver_cores = db.Column(db.Integer, nullable=True) | ||
|
||
executor_memory = db.Column(db.Integer, nullable=True) | ||
executor_memory_overhead = db.Column(db.Integer, nullable=True) | ||
executor_memory_fraction = db.Column(db.Float, nullable=True) | ||
executor_cores = db.Column(db.Integer, nullable=True) | ||
executor_instances = db.Column(db.Integer, nullable=True) | ||
|
||
dynamic_allocation_enabled = db.Column(db.Boolean, nullable=True) | ||
executor_instances_min = db.Column(db.Integer, nullable=True) | ||
executor_instances_max = db.Column(db.Integer, nullable=True) | ||
|
||
shuffle_service_enabled = db.Column(db.Boolean, nullable=True) | ||
executor_idle_timeout = db.Column(db.Integer, nullable=True) | ||
queue = db.Column(db.String, nullable=True) | ||
|
||
def __init__(self, notebook_id, driver_memory=None, driver_memory_overhead=None, driver_cores=None, | ||
executor_memory=None, executor_memory_overhead=None, executor_memory_fraction=None, | ||
executor_cores=None, executor_instances=None, dynamic_allocation_enabled=None, | ||
executor_instances_min=None, executor_instances_max=None, shuffle_service_enabled=None, | ||
executor_idle_timeout=None, queue=None): | ||
self.notebook_id = notebook_id | ||
self.driver_memory = driver_memory | ||
self.driver_memory_overhead = driver_memory_overhead | ||
self.driver_cores = driver_cores | ||
self.executor_memory = executor_memory | ||
self.executor_memory_overhead = executor_memory_overhead | ||
self.executor_memory_fraction = executor_memory_fraction | ||
self.executor_cores = executor_cores | ||
self.executor_instances = executor_instances | ||
self.dynamic_allocation_enabled = dynamic_allocation_enabled | ||
self.executor_instances_min = executor_instances_min | ||
self.executor_instances_max = executor_instances_max | ||
self.shuffle_service_enabled = shuffle_service_enabled | ||
self.executor_idle_timeout = executor_idle_timeout | ||
self.queue = queue | ||
|
||
def to_dict(self): | ||
return { | ||
'notebook_id': self.notebook_id, | ||
'driver_memory': self.driver_memory, | ||
'driver_memory_overhead': self.driver_memory_overhead, | ||
'driver_cores': self.driver_cores, | ||
'executor_memory': self.executor_memory, | ||
'executor_memory_overhead': self.executor_memory_overhead, | ||
'executor_memory_fraction': self.executor_memory_fraction, | ||
'executor_cores': self.executor_cores, | ||
'executor_instances': self.executor_instances, | ||
'dynamic_allocation_enabled': self.dynamic_allocation_enabled, | ||
'executor_instances_min': self.executor_instances_min, | ||
'executor_instances_max': self.executor_instances_max, | ||
'shuffle_service_enabled': self.shuffle_service_enabled, | ||
'executor_idle_timeout': self.executor_idle_timeout, | ||
'queue': self.queue | ||
} |
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,57 @@ | ||
import unittest | ||
from flask_cors import CORS | ||
from run import create_app | ||
from database import db | ||
from app.models.spark_app_config import SparkAppConfigModel | ||
|
||
class SparkAppConfigModelTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.app = create_app() | ||
self.client = self.app.test_client() | ||
with self.app.app_context(): | ||
db.create_all() | ||
|
||
def tearDown(self): | ||
with self.app.app_context(): | ||
db.session.remove() | ||
db.drop_all() | ||
|
||
def test_spark_app_config_model(self): | ||
with self.app.app_context(): | ||
spark_app_config = SparkAppConfigModel( | ||
notebook_id=1, | ||
driver_memory=1, | ||
driver_memory_overhead=1, | ||
driver_cores=1, | ||
executor_memory=1, | ||
executor_memory_overhead=1, | ||
executor_memory_fraction=1.0, | ||
executor_cores=1, | ||
executor_instances=1, | ||
dynamic_allocation_enabled=True, | ||
executor_instances_min=1, | ||
executor_instances_max=1, | ||
shuffle_service_enabled=True, | ||
executor_idle_timeout=1, | ||
queue='test_queue' | ||
) | ||
db.session.add(spark_app_config) | ||
db.session.commit() | ||
|
||
spark_app_config_dict = spark_app_config.to_dict() | ||
self.assertEqual(spark_app_config_dict['notebook_id'], 1) | ||
self.assertEqual(spark_app_config_dict['driver_memory'], 1) | ||
self.assertEqual(spark_app_config_dict['driver_memory_overhead'], 1) | ||
self.assertEqual(spark_app_config_dict['driver_cores'], 1) | ||
self.assertEqual(spark_app_config_dict['executor_memory'], 1) | ||
self.assertEqual(spark_app_config_dict['executor_memory_overhead'], 1) | ||
self.assertEqual(spark_app_config_dict['executor_memory_fraction'], 1.0) | ||
self.assertEqual(spark_app_config_dict['executor_cores'], 1) | ||
self.assertEqual(spark_app_config_dict['executor_instances'], 1) | ||
self.assertEqual(spark_app_config_dict['dynamic_allocation_enabled'], True) | ||
self.assertEqual(spark_app_config_dict['executor_instances_min'], 1) | ||
self.assertEqual(spark_app_config_dict['executor_instances_max'], 1) | ||
self.assertEqual(spark_app_config_dict['shuffle_service_enabled'], True) | ||
self.assertEqual(spark_app_config_dict['executor_idle_timeout'], 1) | ||
self.assertEqual(spark_app_config_dict['queue'], 'test_queue') |
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