]>
Commit | Line | Data |
---|---|---|
1 | Ext.define('PVE.window.ReplicaEdit', { | |
2 | extend: 'Proxmox.window.Edit', | |
3 | xtype: 'pveReplicaEdit', | |
4 | ||
5 | subject: gettext('Replication Job'), | |
6 | ||
7 | ||
8 | url: '/cluster/replication', | |
9 | method: 'POST', | |
10 | ||
11 | initComponent: function() { | |
12 | var me = this; | |
13 | ||
14 | var vmid = me.pveSelNode.data.vmid; | |
15 | var nodename = me.pveSelNode.data.node; | |
16 | ||
17 | var items = []; | |
18 | ||
19 | items.push({ | |
20 | xtype: me.isCreate && !vmid?'pveGuestIDSelector':'displayfield', | |
21 | name: 'guest', | |
22 | fieldLabel: 'CT/VM ID', | |
23 | value: vmid || '', | |
24 | }); | |
25 | ||
26 | items.push( | |
27 | { | |
28 | xtype: me.isCreate ? 'pveNodeSelector':'displayfield', | |
29 | name: 'target', | |
30 | disallowedNodes: [nodename], | |
31 | allowBlank: false, | |
32 | onlineValidator: true, | |
33 | fieldLabel: gettext("Target"), | |
34 | }, | |
35 | { | |
36 | xtype: 'pveCalendarEvent', | |
37 | fieldLabel: gettext('Schedule'), | |
38 | emptyText: '*/15 - ' + Ext.String.format(gettext('Every {0} minutes'), 15), | |
39 | name: 'schedule', | |
40 | }, | |
41 | { | |
42 | xtype: 'numberfield', | |
43 | fieldLabel: gettext('Rate limit') + ' (MB/s)', | |
44 | step: 1, | |
45 | minValue: 1, | |
46 | emptyText: gettext('unlimited'), | |
47 | name: 'rate', | |
48 | }, | |
49 | { | |
50 | xtype: 'textfield', | |
51 | fieldLabel: gettext('Comment'), | |
52 | name: 'comment', | |
53 | }, | |
54 | { | |
55 | xtype: 'proxmoxcheckbox', | |
56 | name: 'enabled', | |
57 | defaultValue: 'on', | |
58 | checked: true, | |
59 | fieldLabel: gettext('Enabled'), | |
60 | }, | |
61 | ); | |
62 | ||
63 | me.items = [ | |
64 | { | |
65 | xtype: 'inputpanel', | |
66 | itemId: 'ipanel', | |
67 | onlineHelp: 'pvesr_schedule_time_format', | |
68 | ||
69 | onGetValues: function(values) { | |
70 | let win = this.up('window'); | |
71 | ||
72 | values.disable = values.enabled ? 0 : 1; | |
73 | delete values.enabled; | |
74 | ||
75 | PVE.Utils.delete_if_default(values, 'rate', '', win.isCreate); | |
76 | PVE.Utils.delete_if_default(values, 'disable', 0, win.isCreate); | |
77 | PVE.Utils.delete_if_default(values, 'schedule', '*/15', win.isCreate); | |
78 | PVE.Utils.delete_if_default(values, 'comment', '', win.isCreate); | |
79 | ||
80 | if (win.isCreate) { | |
81 | values.type = 'local'; | |
82 | let vm = vmid || values.guest; | |
83 | let id = -1; | |
84 | if (win.highestids[vm] !== undefined) { | |
85 | id = win.highestids[vm]; | |
86 | } | |
87 | id++; | |
88 | values.id = vm + '-' + id.toString(); | |
89 | delete values.guest; | |
90 | } | |
91 | return values; | |
92 | }, | |
93 | items: items, | |
94 | }, | |
95 | ]; | |
96 | ||
97 | me.callParent(); | |
98 | ||
99 | if (me.isCreate) { | |
100 | me.load({ | |
101 | success: function(response) { | |
102 | var jobs = response.result.data; | |
103 | var highestids = {}; | |
104 | Ext.Array.forEach(jobs, function(job) { | |
105 | var match = /^([0-9]+)-([0-9]+)$/.exec(job.id); | |
106 | if (match) { | |
107 | let jobVMID = parseInt(match[1], 10); | |
108 | let id = parseInt(match[2], 10); | |
109 | if (highestids[jobVMID] === undefined || highestids[jobVMID] < id) { | |
110 | highestids[jobVMID] = id; | |
111 | } | |
112 | } | |
113 | }); | |
114 | me.highestids = highestids; | |
115 | }, | |
116 | }); | |
117 | } else { | |
118 | me.load({ | |
119 | success: function(response, options) { | |
120 | response.result.data.enabled = !response.result.data.disable; | |
121 | me.setValues(response.result.data); | |
122 | me.digest = response.result.data.digest; | |
123 | }, | |
124 | }); | |
125 | } | |
126 | }, | |
127 | }); | |
128 | ||
129 | /* callback is a function and string */ | |
130 | Ext.define('PVE.grid.ReplicaView', { | |
131 | extend: 'Ext.grid.Panel', | |
132 | xtype: 'pveReplicaView', | |
133 | ||
134 | onlineHelp: 'chapter_pvesr', | |
135 | ||
136 | stateful: true, | |
137 | stateId: 'grid-pve-replication-status', | |
138 | ||
139 | controller: { | |
140 | xclass: 'Ext.app.ViewController', | |
141 | ||
142 | addJob: function(button, event, rec) { | |
143 | let me = this; | |
144 | let view = me.getView(); | |
145 | Ext.create('PVE.window.ReplicaEdit', { | |
146 | isCreate: true, | |
147 | method: 'POST', | |
148 | pveSelNode: view.pveSelNode, | |
149 | listeners: { | |
150 | destroy: () => me.reload(), | |
151 | }, | |
152 | autoShow: true, | |
153 | }); | |
154 | }, | |
155 | ||
156 | editJob: function(button, event, { data }) { | |
157 | let me = this; | |
158 | let view = me.getView(); | |
159 | Ext.create('PVE.window.ReplicaEdit', { | |
160 | url: `/cluster/replication/${data.id}`, | |
161 | method: 'PUT', | |
162 | pveSelNode: view.pveSelNode, | |
163 | listeners: { | |
164 | destroy: () => me.reload(), | |
165 | }, | |
166 | autoShow: true, | |
167 | }); | |
168 | }, | |
169 | ||
170 | scheduleJobNow: function(button, event, rec) { | |
171 | let me = this; | |
172 | let view = me.getView(); | |
173 | Proxmox.Utils.API2Request({ | |
174 | url: `/api2/extjs/nodes/${view.nodename}/replication/${rec.data.id}/schedule_now`, | |
175 | method: 'POST', | |
176 | waitMsgTarget: view, | |
177 | callback: () => me.reload(), | |
178 | failure: (response, opts) => Ext.Msg.alert(gettext('Error'), response.htmlStatus), | |
179 | }); | |
180 | }, | |
181 | ||
182 | showLog: function(button, event, rec) { | |
183 | let me = this; | |
184 | let view = this.getView(); | |
185 | ||
186 | let logView = Ext.create('Proxmox.panel.LogView', { | |
187 | border: false, | |
188 | url: `/api2/extjs/nodes/${view.nodename}/replication/${rec.data.id}/log`, | |
189 | }); | |
190 | let task = Ext.TaskManager.newTask({ | |
191 | run: () => logView.requestUpdate(), | |
192 | interval: 1000, | |
193 | }); | |
194 | let win = Ext.create('Ext.window.Window', { | |
195 | items: [logView], | |
196 | layout: 'fit', | |
197 | width: 800, | |
198 | height: 400, | |
199 | modal: true, | |
200 | title: gettext("Replication Log"), | |
201 | listeners: { | |
202 | destroy: function() { | |
203 | task.stop(); | |
204 | me.reload(); | |
205 | }, | |
206 | }, | |
207 | }); | |
208 | task.start(); | |
209 | win.show(); | |
210 | }, | |
211 | ||
212 | reload: function() { | |
213 | this.getView().rstore.load(); | |
214 | }, | |
215 | ||
216 | dblClick: function(grid, record, item) { | |
217 | this.editJob(undefined, undefined, record); | |
218 | }, | |
219 | ||
220 | // currently replication is for cluster only, so disable the whole component for non-cluster | |
221 | checkPrerequisites: function() { | |
222 | let view = this.getView(); | |
223 | if (PVE.data.ResourceStore.getNodes().length < 2) { | |
224 | view.mask(gettext("Replication needs at least two nodes"), ['pve-static-mask']); | |
225 | } | |
226 | }, | |
227 | ||
228 | control: { | |
229 | '#': { | |
230 | itemdblclick: 'dblClick', | |
231 | afterlayout: 'checkPrerequisites', | |
232 | }, | |
233 | }, | |
234 | }, | |
235 | ||
236 | tbar: [ | |
237 | { | |
238 | text: gettext('Add'), | |
239 | itemId: 'addButton', | |
240 | handler: 'addJob', | |
241 | }, | |
242 | { | |
243 | xtype: 'proxmoxButton', | |
244 | text: gettext('Edit'), | |
245 | itemId: 'editButton', | |
246 | handler: 'editJob', | |
247 | disabled: true, | |
248 | }, | |
249 | { | |
250 | xtype: 'proxmoxStdRemoveButton', | |
251 | itemId: 'removeButton', | |
252 | baseurl: '/api2/extjs/cluster/replication/', | |
253 | dangerous: true, | |
254 | callback: 'reload', | |
255 | }, | |
256 | { | |
257 | xtype: 'proxmoxButton', | |
258 | text: gettext('Log'), | |
259 | itemId: 'logButton', | |
260 | handler: 'showLog', | |
261 | disabled: true, | |
262 | }, | |
263 | { | |
264 | xtype: 'proxmoxButton', | |
265 | text: gettext('Schedule now'), | |
266 | itemId: 'scheduleNowButton', | |
267 | handler: 'scheduleJobNow', | |
268 | disabled: true, | |
269 | }, | |
270 | ], | |
271 | ||
272 | initComponent: function() { | |
273 | var me = this; | |
274 | var mode = ''; | |
275 | var url = '/cluster/replication'; | |
276 | ||
277 | me.nodename = me.pveSelNode.data.node; | |
278 | me.vmid = me.pveSelNode.data.vmid; | |
279 | ||
280 | me.columns = [ | |
281 | { | |
282 | text: gettext('Enabled'), | |
283 | dataIndex: 'enabled', | |
284 | xtype: 'checkcolumn', | |
285 | sortable: true, | |
286 | disabled: true, | |
287 | }, | |
288 | { | |
289 | text: 'ID', | |
290 | dataIndex: 'id', | |
291 | width: 60, | |
292 | hidden: true, | |
293 | }, | |
294 | { | |
295 | text: gettext('Guest'), | |
296 | dataIndex: 'guest', | |
297 | width: 75, | |
298 | }, | |
299 | { | |
300 | text: gettext('Job'), | |
301 | dataIndex: 'jobnum', | |
302 | width: 60, | |
303 | }, | |
304 | { | |
305 | text: gettext('Target'), | |
306 | dataIndex: 'target', | |
307 | }, | |
308 | ]; | |
309 | ||
310 | if (!me.nodename) { | |
311 | mode = 'dc'; | |
312 | me.stateId = 'grid-pve-replication-dc'; | |
313 | } else if (!me.vmid) { | |
314 | mode = 'node'; | |
315 | url = `/nodes/${me.nodename}/replication`; | |
316 | } else { | |
317 | mode = 'vm'; | |
318 | url = `/nodes/${me.nodename}/replication?guest=${me.vmid}`; | |
319 | } | |
320 | ||
321 | if (mode !== 'dc') { | |
322 | me.columns.push( | |
323 | { | |
324 | text: gettext('Status'), | |
325 | dataIndex: 'state', | |
326 | minWidth: 160, | |
327 | flex: 1, | |
328 | renderer: function(value, metadata, record) { | |
329 | if (record.data.pid) { | |
330 | metadata.tdCls = 'x-grid-row-loading'; | |
331 | return ''; | |
332 | } | |
333 | ||
334 | let icons = [], states = []; | |
335 | ||
336 | if (record.data.remove_job) { | |
337 | icons.push('<i class="fa fa-ban warning" title="' | |
338 | + gettext("Removal Scheduled") + '"></i>'); | |
339 | states.push(gettext("Removal Scheduled")); | |
340 | } | |
341 | if (record.data.error) { | |
342 | icons.push('<i class="fa fa-times critical" title="' | |
343 | + gettext("Error") + '"></i>'); | |
344 | states.push(record.data.error); | |
345 | } | |
346 | if (icons.length === 0) { | |
347 | icons.push('<i class="fa fa-check good"></i>'); | |
348 | states.push(gettext('OK')); | |
349 | } | |
350 | ||
351 | return icons.join(',') + ' ' + states.join(','); | |
352 | }, | |
353 | }, | |
354 | { | |
355 | text: gettext('Last Sync'), | |
356 | dataIndex: 'last_sync', | |
357 | width: 150, | |
358 | renderer: function(value, metadata, record) { | |
359 | if (!value) { | |
360 | return '-'; | |
361 | } | |
362 | if (record.data.pid) { | |
363 | return gettext('syncing'); | |
364 | } | |
365 | return Proxmox.Utils.render_timestamp(value); | |
366 | }, | |
367 | }, | |
368 | { | |
369 | text: gettext('Duration'), | |
370 | dataIndex: 'duration', | |
371 | width: 60, | |
372 | renderer: Proxmox.Utils.render_duration, | |
373 | }, | |
374 | { | |
375 | text: gettext('Next Sync'), | |
376 | dataIndex: 'next_sync', | |
377 | width: 150, | |
378 | renderer: function(value) { | |
379 | if (!value) { | |
380 | return '-'; | |
381 | } | |
382 | ||
383 | let now = new Date(), next = new Date(value * 1000); | |
384 | if (next < now) { | |
385 | return gettext('pending'); | |
386 | } | |
387 | return Proxmox.Utils.render_timestamp(value); | |
388 | }, | |
389 | }, | |
390 | ); | |
391 | } | |
392 | ||
393 | me.columns.push( | |
394 | { | |
395 | text: gettext('Schedule'), | |
396 | width: 75, | |
397 | dataIndex: 'schedule', | |
398 | }, | |
399 | { | |
400 | text: gettext('Rate limit'), | |
401 | dataIndex: 'rate', | |
402 | renderer: function(value) { | |
403 | if (!value) { | |
404 | return gettext('unlimited'); | |
405 | } | |
406 | ||
407 | return value.toString() + ' MB/s'; | |
408 | }, | |
409 | hidden: true, | |
410 | }, | |
411 | { | |
412 | text: gettext('Comment'), | |
413 | dataIndex: 'comment', | |
414 | renderer: Ext.htmlEncode, | |
415 | }, | |
416 | ); | |
417 | ||
418 | me.rstore = Ext.create('Proxmox.data.UpdateStore', { | |
419 | storeid: 'pve-replica-' + me.nodename + me.vmid, | |
420 | model: mode === 'dc'? 'pve-replication' : 'pve-replication-state', | |
421 | interval: 3000, | |
422 | proxy: { | |
423 | type: 'proxmox', | |
424 | url: "/api2/json" + url, | |
425 | }, | |
426 | }); | |
427 | ||
428 | me.store = Ext.create('Proxmox.data.DiffStore', { | |
429 | rstore: me.rstore, | |
430 | sorters: [ | |
431 | { | |
432 | property: 'guest', | |
433 | }, | |
434 | { | |
435 | property: 'jobnum', | |
436 | }, | |
437 | ], | |
438 | }); | |
439 | ||
440 | me.callParent(); | |
441 | ||
442 | // we cannot access the log and scheduleNow button | |
443 | // in the datacenter, because | |
444 | // we do not know where/if the jobs runs | |
445 | if (mode === 'dc') { | |
446 | me.down('#logButton').setHidden(true); | |
447 | me.down('#scheduleNowButton').setHidden(true); | |
448 | } | |
449 | ||
450 | // if we set the warning mask, we do not want to load | |
451 | // or set the mask on store errors | |
452 | if (PVE.data.ResourceStore.getNodes().length < 2) { | |
453 | return; | |
454 | } | |
455 | ||
456 | Proxmox.Utils.monStoreErrors(me, me.rstore); | |
457 | ||
458 | me.on('destroy', me.rstore.stopUpdate); | |
459 | me.rstore.startUpdate(); | |
460 | }, | |
461 | }, function() { | |
462 | Ext.define('pve-replication', { | |
463 | extend: 'Ext.data.Model', | |
464 | fields: [ | |
465 | 'id', 'target', 'comment', 'rate', 'type', | |
466 | { name: 'guest', type: 'integer' }, | |
467 | { name: 'jobnum', type: 'integer' }, | |
468 | { name: 'schedule', defaultValue: '*/15' }, | |
469 | { name: 'disable', defaultValue: '' }, | |
470 | { name: 'enabled', calculate: function(data) { return !data.disable; } }, | |
471 | ], | |
472 | }); | |
473 | ||
474 | Ext.define('pve-replication-state', { | |
475 | extend: 'pve-replication', | |
476 | fields: [ | |
477 | 'last_sync', 'next_sync', 'error', 'duration', 'state', | |
478 | 'fail_count', 'remove_job', 'pid', | |
479 | ], | |
480 | }); | |
481 | }); |