##// END OF EJS Templates
Cluster management is now working....
Brian Granger -
Show More
@@ -77,6 +77,7 class ClusterManager(LoggingConfigurable):
77 'launcher': launcher,
77 'launcher': launcher,
78 'n': n
78 'n': n
79 }
79 }
80 return self.profile_info(profile)
80
81
81 def stop_cluster(self, profile):
82 def stop_cluster(self, profile):
82 """Stop a cluster for a given profile."""
83 """Stop a cluster for a given profile."""
@@ -84,6 +85,7 class ClusterManager(LoggingConfigurable):
84 raise web.HTTPError(409, u'cluster not running')
85 raise web.HTTPError(409, u'cluster not running')
85 launcher = self.profiles.pop(profile)['launcher']
86 launcher = self.profiles.pop(profile)['launcher']
86 launcher.stop()
87 launcher.stop()
88 return self.profile_info(profile)
87
89
88 def stop_all_clusters(self):
90 def stop_all_clusters(self):
89 for p in self.profiles.values():
91 for p in self.profiles.values():
@@ -691,10 +691,10 class ClusterActionHandler(AuthenticatedHandler):
691 cm = self.application.cluster_manager
691 cm = self.application.cluster_manager
692 if action == 'start':
692 if action == 'start':
693 n = int(self.get_argument('n', default=4))
693 n = int(self.get_argument('n', default=4))
694 cm.start_cluster(profile, n)
694 data = cm.start_cluster(profile, n)
695 if action == 'stop':
695 if action == 'stop':
696 cm.stop_cluster(profile)
696 data = cm.stop_cluster(profile)
697 self.finish()
697 self.finish(jsonapi.dumps(data))
698
698
699
699
700 #-----------------------------------------------------------------------------
700 #-----------------------------------------------------------------------------
@@ -38,6 +38,8
38 padding: 3px 5px;
38 padding: 3px 5px;
39 }
39 }
40
40
41
42
41 .list_item {
43 .list_item {
42 height: 25px;
44 height: 25px;
43 line-height: 25px;
45 line-height: 25px;
@@ -48,6 +50,23
48 text-decoration: none;
50 text-decoration: none;
49 }
51 }
50
52
53 .profile_col {
54 }
55
56 .status_col {
57 float: right;
58 width: 325px;
59 }
60
61 .engines_col {
62 float: right;
63 width: 325px;
64 }
65
66 .action_col {
67 float: right;
68 }
69
51 .item_buttons {
70 .item_buttons {
52 float: right;
71 float: right;
53 }
72 }
@@ -24,7 +24,11 var IPython = (function (IPython) {
24 $('#cluster_toolbar').addClass('list_toolbar');
24 $('#cluster_toolbar').addClass('list_toolbar');
25 $('#cluster_list_info').addClass('toolbar_info');
25 $('#cluster_list_info').addClass('toolbar_info');
26 $('#cluster_buttons').addClass('toolbar_buttons');
26 $('#cluster_buttons').addClass('toolbar_buttons');
27 $('div#cluster_header').addClass('list_header ui-widget ui-widget-header');
27 $('div#cluster_header').addClass('list_header ui-widget ui-widget-header ui-helper-clearfix');
28 $('div#cluster_header').children().eq(0).addClass('profile_col');
29 $('div#cluster_header').children().eq(1).addClass('action_col');
30 $('div#cluster_header').children().eq(2).addClass('engines_col');
31 $('div#cluster_header').children().eq(3).addClass('status_col');
28 $('#refresh_cluster_list').button({
32 $('#refresh_cluster_list').button({
29 icons : {primary: 'ui-icon-arrowrefresh-1-s'},
33 icons : {primary: 'ui-icon-arrowrefresh-1-s'},
30 text : false
34 text : false
@@ -58,17 +62,13 var IPython = (function (IPython) {
58 }
62 }
59
63
60 ClusterList.prototype.load_list_success = function (data, status, xhr) {
64 ClusterList.prototype.load_list_success = function (data, status, xhr) {
61 console.log(data);
62 this.clear_list();
65 this.clear_list();
63 var len = data.length;
66 var len = data.length;
64 for (var i=0; i<len; i++) {
67 for (var i=0; i<len; i++) {
65 var item_div = $('<div/>');
68 var item_div = $('<div/>');
66 item_div.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix');
67 item_div.css('border-top-style','none');
68 var item = new ClusterItem(item_div);
69 var item = new ClusterItem(item_div);
69 item.update_state(data[i]);
70 item.update_state(data[i]);
70 item_div.data('item', item);
71 item_div.data('item', item);
71 console.log('appending item', item);
72 this.element.append(item_div);
72 this.element.append(item_div);
73 };
73 };
74 };
74 };
@@ -77,9 +77,15 var IPython = (function (IPython) {
77 var ClusterItem = function (element) {
77 var ClusterItem = function (element) {
78 this.element = $(element);
78 this.element = $(element);
79 this.data = null;
79 this.data = null;
80 this.style();
80 };
81 };
81
82
82
83
84 ClusterItem.prototype.style = function () {
85 this.element.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix');
86 this.element.css('border-top-style','none');
87 }
88
83 ClusterItem.prototype.update_state = function (data) {
89 ClusterItem.prototype.update_state = function (data) {
84 this.data = data;
90 this.data = data;
85 if (data.status === 'running') {
91 if (data.status === 'running') {
@@ -92,29 +98,78 var IPython = (function (IPython) {
92
98
93
99
94 ClusterItem.prototype.state_stopped = function () {
100 ClusterItem.prototype.state_stopped = function () {
95 var item_name = $('<span/>').addClass('item_name').text(this.data.profile);
101 var that = this;
96 var item_buttons = $('<span/>').addClass('item_buttons');
102 this.element.empty();
103 var profile_col = $('<span/>').addClass('profile_col').text(this.data.profile);
104 var status_col = $('<span/>').addClass('status_col').html('stopped');
105 var engines_col = $('<span/>').addClass('engines_col');
106 var label = $('<label/>').addClass('engine_num_label').html('# of engines:');
107 var input = $('<input/>').attr('type','text').
108 attr('size',3).addClass('engine_num_input');
109 engines_col.append(label).append(input);
110 var action_col = $('<span/>').addClass('action_col');
97 var start_button = $('<button>Start</button>').button();
111 var start_button = $('<button>Start</button>').button();
98 item_buttons.append(start_button);
112 action_col.append(start_button);
99 this.element.append(item_name).append(item_buttons);
113 this.element.append(profile_col).
114 append(action_col).
115 append(engines_col).
116 append(status_col);
100 start_button.click(function (e) {
117 start_button.click(function (e) {
101 console.log('start');
118 var n = that.element.find('.engine_num_input').val();
119 console.log(n);
120 if (!/^\d+$/.test(n)) {
121 status_col.html('invalid engine #');
122 } else {
123 console.log('ajax...');
124 var settings = {
125 cache : false,
126 data : {n:n},
127 type : "POST",
128 dataType : "json",
129 success : function (data, status, xhr) {
130 that.update_state(data);
131 },
132 error : function (data, status, xhr) {
133 status_col.html("error starting cluster")
134 }
135 };
136 status_col.html('starting');
137 var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/start';
138 $.ajax(url, settings);
139 };
102 });
140 });
103 }
104
105
106 ClusterItem.prototype.start_success = function () {
107
108 };
141 };
109
142
143
110 ClusterItem.prototype.state_running = function () {
144 ClusterItem.prototype.state_running = function () {
111 var item_name = $('<span/>').addClass('item_name').text(this.data.profile);
145 this.element.empty();
112 var item_buttons = $('<span/>').addClass('item_buttons');
146 var that = this;
147 var profile_col = $('<span/>').addClass('profile_col').text(this.data.profile);
148 var status_col = $('<span/>').addClass('status_col').html('running');
149 var engines_col = $('<span/>').addClass('engines_col').html(this.data.n);
150 var action_col = $('<span/>').addClass('action_col');
113 var stop_button = $('<button>Stop</button>').button();
151 var stop_button = $('<button>Stop</button>').button();
114 item_buttons.append(start_button);
152 action_col.append(stop_button);
115 this.element.append(item_name).append(item_buttons);
153 this.element.append(profile_col).
116 start_button.click(function (e) {
154 append(action_col).
117 console.log('stop');
155 append(engines_col).
156 append(status_col);
157 stop_button.click(function (e) {
158 var settings = {
159 cache : false,
160 type : "POST",
161 dataType : "json",
162 success : function (data, status, xhr) {
163 that.update_state(data);
164 },
165 error : function (data, status, xhr) {
166 console.log('error',data);
167 status_col.html("error stopping cluster")
168 }
169 };
170 status_col.html('stopping')
171 var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/stop';
172 $.ajax(url, settings);
118 });
173 });
119 };
174 };
120
175
@@ -55,7 +55,12 data-read-only={{read_only}}
55 </div>
55 </div>
56
56
57 <div id="cluster_list">
57 <div id="cluster_list">
58 <div id="cluster_header"><h2>Clusters</h2></div>
58 <div id="cluster_header">
59 <span>profile</span>
60 <span>action</span>
61 <span>engines</span>
62 <span>status</span>
63 </div>
59 </div>
64 </div>
60
65
61 </div>
66 </div>
General Comments 0
You need to be logged in to leave comments. Login now