1
1
2
2
import React , { useEffect , useState } from 'react' ;
3
3
import { Box , Card , CardHeader , CardContent , CardActions , Button , Typography , List , ListItem , ListItemText , TextField , Select , MenuItem } from '@mui/material' ;
4
+ import SparkAppConfigModel from '../../../models/SparkAppConfigModel' ;
4
5
5
- function Config ( { notebook } ) {
6
+ function Config ( { notebookPath } ) {
6
7
7
- const [ executorCores , setExecutorCores ] = useState ( '1' ) ;
8
- const [ executorInstances , setExecutorInstances ] = useState ( '1' ) ;
8
+ const [ loading , setLoading ] = useState ( true ) ;
9
9
10
- const [ executorMemory , setExecutorMemory ] = useState ( '512' ) ;
10
+ const [ executorCores , setExecutorCores ] = useState ( null ) ;
11
+ const [ executorInstances , setExecutorInstances ] = useState ( null ) ;
12
+
13
+ const [ executorMemory , setExecutorMemory ] = useState ( null ) ;
11
14
const [ executorMemoryUnit , setExecutorMemoryUnit ] = useState ( 'm' ) ;
12
15
13
16
useEffect ( ( ) => {
14
- // const fetchSparkConfig = async () => {
17
+ const fetchSparkConfig = async ( ) => {
18
+ const config = await SparkAppConfigModel . getSparkAppConfigByNotebookPath ( notebookPath ) ;
19
+ console . log ( 'config: ' , config ) ;
20
+
21
+ setExecutorCores ( config . executor_cores ) ;
22
+ setExecutorInstances ( config . executor_instances ) ;
23
+ setExecutorMemory ( config . executor_memory ) ;
24
+ setExecutorMemoryUnit ( config . executor_memory_unit ) ;
15
25
16
- // };
17
- // fetchSparkConfig() ;
18
- console . log ( 'notebook:' , notebook ) ;
19
- } , [ notebook ] ) ;
26
+ setLoading ( false ) ;
27
+ } ;
28
+ fetchSparkConfig ( ) ;
29
+ } , [ notebookPath ] ) ;
20
30
21
31
const handleExecutorMemoryUnitChange = ( event ) => {
22
32
setExecutorMemoryUnit ( event . target . value ) ;
@@ -28,85 +38,89 @@ function Config({ notebook }) {
28
38
console . log ( 'executorMemory:' , executorMemory + executorMemoryUnit ) ;
29
39
}
30
40
31
- return (
32
- < Box sx = { {
33
- marginTop : 5 ,
34
- marginRight : 5 ,
35
- marginLeft : 2 ,
36
- } } >
37
- < Card
38
- sx = { {
39
- display : 'flex' ,
40
- flexDirection : 'column' ,
41
- } } >
42
- < CardHeader
43
- title = {
44
- < Typography
45
- variant = "body1"
46
- style = { { marginLeft : 10 } }
47
- color = "textSecondary" >
48
- Spark Configuration
49
- </ Typography >
50
- }
51
- sx = { {
52
- backgroundColor : '#f5f5f5' ,
53
- borderBottom : 1 ,
54
- borderBottomColor : '#f5f5f5' ,
55
- } } />
56
- < CardContent >
57
- < List >
58
- < ListItem >
59
- < ListItemText primary = "executor.memory" />
60
- < TextField
61
- defaultValue = { executorMemory }
62
- variant = "outlined"
63
- size = "small"
64
- onInput = { ( e ) => e . target . value = e . target . value . replace ( / [ ^ 0 - 9 ] / g, '' ) }
65
- onChange = { ( e ) => {
66
- setExecutorMemory ( e . target . value )
67
- } } />
68
- < Box m = { 1 } />
69
- < Select value = { executorMemoryUnit }
70
- size = "small"
71
- onChange = { handleExecutorMemoryUnitChange } >
72
- < MenuItem value = { 'm' } > MB</ MenuItem >
73
- < MenuItem value = { 'g' } > GB</ MenuItem >
74
- </ Select >
75
- </ ListItem >
41
+ if ( loading ) {
42
+ return < div > Loading...</ div > ;
43
+ } else {
44
+ return (
45
+ < Box sx = { {
46
+ marginTop : 5 ,
47
+ marginRight : 5 ,
48
+ marginLeft : 2 ,
49
+ } } >
50
+ < Card
51
+ sx = { {
52
+ display : 'flex' ,
53
+ flexDirection : 'column' ,
54
+ } } >
55
+ < CardHeader
56
+ title = {
57
+ < Typography
58
+ variant = "body1"
59
+ style = { { marginLeft : 10 } }
60
+ color = "textSecondary" >
61
+ Spark Configuration
62
+ </ Typography >
63
+ }
64
+ sx = { {
65
+ backgroundColor : '#f5f5f5' ,
66
+ borderBottom : 1 ,
67
+ borderBottomColor : '#f5f5f5' ,
68
+ } } />
69
+ < CardContent >
70
+ < List >
71
+ < ListItem >
72
+ < ListItemText primary = "spark.executor.memory" />
73
+ < TextField
74
+ defaultValue = { executorMemory }
75
+ variant = "outlined"
76
+ size = "small"
77
+ onInput = { ( e ) => e . target . value = e . target . value . replace ( / [ ^ 0 - 9 ] / g, '' ) }
78
+ onChange = { ( e ) => {
79
+ setExecutorMemory ( e . target . value )
80
+ } } />
81
+ < Box m = { 1 } />
82
+ < Select value = { executorMemoryUnit }
83
+ size = "small"
84
+ onChange = { handleExecutorMemoryUnitChange } >
85
+ < MenuItem value = { 'm' } > MB</ MenuItem >
86
+ < MenuItem value = { 'g' } > GB</ MenuItem >
87
+ </ Select >
88
+ </ ListItem >
76
89
77
- < ListItem >
78
- < ListItemText primary = "executor.cores" />
79
- < TextField
80
- defaultValue = { executorCores }
81
- variant = "outlined"
82
- size = "small"
83
- onChange = { ( e ) => setExecutorCores ( e . target . value ) } />
84
- </ ListItem >
90
+ < ListItem >
91
+ < ListItemText primary = "spark. executor.cores" />
92
+ < TextField
93
+ defaultValue = { executorCores }
94
+ variant = "outlined"
95
+ size = "small"
96
+ onChange = { ( e ) => setExecutorCores ( e . target . value ) } />
97
+ </ ListItem >
85
98
86
- < ListItem >
87
- < ListItemText primary = "spark.executor.instances" />
88
- < TextField
89
- defaultValue = { executorInstances }
90
- variant = "outlined"
91
- size = "small"
92
- onChange = { ( e ) => setExecutorInstances ( e . target . value ) } />
93
- </ ListItem >
94
- </ List >
95
- </ CardContent >
96
- < CardActions >
97
- < Button
98
- variant = "outlined"
99
- style = { {
100
- marginLeft : '20px' ,
101
- borderColor : 'lightgrey' ,
102
- color : 'grey' } }
103
- onClick = { handleSave } >
104
- Save
105
- </ Button >
106
- </ CardActions >
107
- </ Card >
108
- </ Box >
109
- ) ;
99
+ < ListItem >
100
+ < ListItemText primary = "spark.executor.instances" />
101
+ < TextField
102
+ defaultValue = { executorInstances }
103
+ variant = "outlined"
104
+ size = "small"
105
+ onChange = { ( e ) => setExecutorInstances ( e . target . value ) } />
106
+ </ ListItem >
107
+ </ List >
108
+ </ CardContent >
109
+ < CardActions >
110
+ < Button
111
+ variant = "outlined"
112
+ style = { {
113
+ marginLeft : '20px' ,
114
+ borderColor : 'lightgrey' ,
115
+ color : 'grey' } }
116
+ onClick = { handleSave } >
117
+ Save
118
+ </ Button >
119
+ </ CardActions >
120
+ </ Card >
121
+ </ Box >
122
+ ) ;
123
+ }
110
124
}
111
125
112
126
export default Config ;
0 commit comments