This repository has been archived by the owner on Mar 15, 2022. It is now read-only.
/
JobsRuntimePanel.java
357 lines (325 loc) · 14.6 KB
/
JobsRuntimePanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.console.client.shared.subsys.jberet.ui;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.dom.client.Style;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SingleSelectionModel;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.layout.SimpleLayout;
import org.jboss.as.console.client.rbac.SecurityFramework;
import org.jboss.as.console.client.shared.runtime.charts.Column;
import org.jboss.as.console.client.shared.runtime.charts.NumberColumn;
import org.jboss.as.console.client.shared.subsys.jberet.JberetMetricsPresenter;
import org.jboss.as.console.client.shared.subsys.jberet.Job;
import org.jboss.as.console.client.shared.subsys.jberet.store.JberetStore;
import org.jboss.as.console.client.shared.subsys.jberet.store.LoadJobsMetrics;
import org.jboss.as.console.client.shared.subsys.jberet.store.RestartJob;
import org.jboss.as.console.client.shared.subsys.jberet.store.StartJob;
import org.jboss.as.console.client.shared.subsys.jberet.store.StopJob;
import org.jboss.as.console.client.v3.ResourceDescriptionRegistry;
import org.jboss.as.console.client.v3.dmr.ResourceDescription;
import org.jboss.as.console.mbui.widgets.ModelNodeFormBuilder;
import org.jboss.ballroom.client.rbac.SecurityContext;
import org.jboss.ballroom.client.widgets.tables.DefaultCellTable;
import org.jboss.ballroom.client.widgets.tables.DefaultPager;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.dmr.client.ModelDescriptionConstants;
import org.jboss.dmr.client.Property;
import org.jboss.gwt.circuit.Dispatcher;
/**
* @author Claudio Miranda
*/
public class JobsRuntimePanel implements IsWidget {
private final static String[] METRIC_ATTRIBUTES = {
"batch-status",
"create-time",
"end-time",
"exit-status",
"instance-id",
"last-updated-time",
"start-time",
};
private final Dispatcher circuit;
private final ResourceDescriptionRegistry resourceDescriptionRegistry;
private final SecurityFramework securityFramework;
private JberetMetricsPresenter presenter;
private DefaultCellTable<Job> table;
private ListDataProvider<Job> dataProvider;
private SingleSelectionModel<Job> selectionModel;
private List<Job> jobs = new ArrayList<>();
private Column[] columns;
private Grid grid;
private ToolButton btnStart;
private ToolButton btnStop;
private ToolButton btnRestart;
JobsRuntimePanel(final Dispatcher circuit, final ResourceDescriptionRegistry resourceDescriptionRegistry,
final SecurityFramework securityFramework) {
this.circuit = circuit;
this.resourceDescriptionRegistry = resourceDescriptionRegistry;
this.securityFramework = securityFramework;
}
@SuppressWarnings("unchecked")
@Override
public Widget asWidget() {
ProvidesKey<Job> providesKey = job1 -> job1.getDeploymentName() + job1.getName() + job1.getExecutionId();
table = new DefaultCellTable<>(5, providesKey);
dataProvider = new ListDataProvider<>(providesKey);
dataProvider.addDataDisplay(table);
selectionModel = new SingleSelectionModel<>(providesKey);
selectionModel.addSelectionChangeHandler(event -> {
Job job = selectionModel.getSelectedObject();
if (job != null) {
refresh(job);
}
});
table.setSelectionModel(selectionModel);
TextColumn<Job> deploymentColumn = new TextColumn<Job>() {
@Override
public String getValue(Job job) {
String deploymentName = job.getDeploymentName();
if (job.getSubdeploymentName().length() > 0) {
deploymentName = deploymentName + "/" + job.getSubdeploymentName();
}
return deploymentName;
}
};
TextColumn<Job> jobColumn = new TextColumn<Job>() {
@Override
public String getValue(Job node) {
return node.getJobXmlName();
}
};
TextColumn<Job> idColumn = new TextColumn<Job>() {
@Override
public String getValue(Job node) {
return node.getInstanceId();
}
};
TextColumn<Job> executionIdColumn = new TextColumn<Job>() {
@Override
public String getValue(Job node) {
return node.getExecutionId();
}
};
TextColumn<Job> statusColumn = new TextColumn<Job>() {
@Override
public String getValue(Job node) {
return node.getCurrentStatus();
}
};
TextColumn<Job> startColumn = new TextColumn<Job>() {
@Override
public String getValue(Job node) {
return node.getStartTime();
}
};
executionIdColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
idColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
table.addColumn(deploymentColumn, "Deployment");
table.addColumn(jobColumn, "Job-Xml-Name");
table.addColumn(executionIdColumn, "Execution Id");
table.addColumn(idColumn, "Instance Id");
table.addColumn(statusColumn, "Batch Status");
table.addColumn(startColumn, "Start time");
DefaultPager pager = new DefaultPager();
pager.setDisplay(table);
VerticalPanel tableAndPager = new VerticalPanel();
tableAndPager.setStyleName("fill-layout-width");
tableAndPager.add(table);
tableAndPager.add(pager);
SecurityContext securityContext = securityFramework.getSecurityContext(presenter.getProxy().getNameToken());
ResourceDescription jobDescription = resourceDescriptionRegistry.lookup(JberetStore.JOB_DEPLOYMENT_ADDRESS);
ModelNodeFormBuilder.FormAssets formAssets = new ModelNodeFormBuilder()
.setResourceDescription(jobDescription)
.setSecurityContext(securityContext)
.include(METRIC_ATTRIBUTES)
.build();
Widget help = formAssets.getHelp().asWidget();
help.getElement().getStyle().setMarginTop(40, Style.Unit.PX);
HorizontalPanel header = new HorizontalPanel();
header.addStyleName("fill-layout-width");
header.add(new HTML("<h3 class='metric-label-embedded'>Job Status</h3>"));
columns = new Column[]{
new NumberColumn("instance-id", "Instance Id"),
new NumberColumn("batch-status", "Batch Status"),
new NumberColumn("exit-status", "Exit Status"),
new NumberColumn("create-time", "Create Time"),
new NumberColumn("start-time", "Start Time"),
new NumberColumn("end-time", "End Time"),
new NumberColumn("last-updated-time", "Last Updated Time")
};
grid = new Grid(columns.length, 2);
grid.addStyleName("metric-grid");
for (int row = 0; row < columns.length; ++row) {
grid.getCellFormatter().addStyleName(row, 0, "nominal");
grid.getCellFormatter().addStyleName(row, 1, "numerical");
}
VerticalPanel metricsPanel = new VerticalPanel();
metricsPanel.addStyleName("metric-container");
metricsPanel.add(header);
metricsPanel.add(grid);
SimpleLayout layout = new SimpleLayout()
.setPlain(true)
.setHeadline("Job Status")
.setDescription(SafeHtmlUtils.fromString(jobDescription.get(ModelDescriptionConstants.DESCRIPTION).asString()))
.addContent("", buttonsTool())
.addContent("", tableAndPager)
.addContent("", help)
.addContent("", metricsPanel);
return layout.build().asWidget();
}
private ToolStrip buttonsTool() {
ToolStrip tools = new ToolStrip();
final TextBox filter = new TextBox();
filter.setMaxLength(30);
filter.setVisibleLength(20);
filter.getElement().setAttribute("style", "float:right; width:120px;");
filter.addKeyUpHandler(keyUpEvent -> {
String word = filter.getText();
if(word != null && word.trim().length() > 0) {
filter(word);
}
else {
clearFilter();
}
});
this.btnStart = new ToolButton(Console.CONSTANTS.common_label_start(),
event -> {
Job job = selectionModel.getSelectedObject();
circuit.dispatch(
new StartJob(job.getDeploymentName(), job.getSubdeploymentName(),
job.getJobXmlName()));
});
this.btnStop = new ToolButton(Console.CONSTANTS.common_label_stop(),
event -> {
Job job = selectionModel.getSelectedObject();
circuit.dispatch(
new StopJob(job.getDeploymentName(), job.getSubdeploymentName(),
job.getName(), job.getExecutionId()));
});
this.btnRestart = new ToolButton(Console.CONSTANTS.common_label_restart(),
event -> {
Job job = selectionModel.getSelectedObject();
if ("COMPLETED".equals(job.getCurrentStatus())) {
Console.warning(Console.MESSAGES.batch_cannot_restart(job.getExecutionId()));
} else {
circuit.dispatch(
new RestartJob(job.getDeploymentName(), job.getSubdeploymentName(),
job.getName(), job.getExecutionId()));
}
});
final HTML label = new HTML(Console.CONSTANTS.commom_label_filter()+": ");
label.getElement().setAttribute("style", "padding-top:8px;");
tools.addToolWidget(label);
tools.addToolWidget(filter);
tools.addToolButtonRight(new ToolButton(Console.CONSTANTS.common_label_refresh(),
event -> circuit.dispatch(new LoadJobsMetrics())));
tools.addToolButtonRight(btnStart);
tools.addToolButtonRight(btnStop);
tools.addToolButtonRight(btnRestart);
return tools;
}
public void refresh(Job job) {
if (job.getInstanceId().length() > 0) {
if ("STARTED".equals(job.getCurrentStatus())) {
this.btnStop.setEnabled(true);
this.btnRestart.setEnabled(false);
} else {
this.btnStop.setEnabled(false);
this.btnRestart.setEnabled(true);
}
} else {
this.btnRestart.setEnabled(false);
this.btnStop.setEnabled(false);
this.btnStart.setEnabled(true);
}
grid.clear(true);
List<Property> attributes = job.asPropertyList();
for (int i = 0; i < columns.length; i++) {
for (Property attribute : attributes) {
if (attribute.getName().equals(columns[i].getDeytpedName())) {
grid.setText(i, 0, columns[i].getLabel());
String val = "";
if (attribute.getValue().isDefined()) {
val = attribute.getValue().asString();
}
grid.setText(i, 1, val);
}
}
}
}
public void refresh(List<Job> metrics) {
selectionModel.clear();
dataProvider.setList(metrics);
this.jobs.clear();
this.jobs.addAll(metrics);
table.selectDefaultEntity();
grid.clear(true);
if (metrics.size() > 0) {
this.btnRestart.setEnabled(true);
this.btnStop.setEnabled(true);
this.btnStart.setEnabled(true);
} else {
this.btnRestart.setEnabled(false);
this.btnStop.setEnabled(false);
this.btnStart.setEnabled(false);
}
}
public void setPresenter(final JberetMetricsPresenter presenter) {
this.presenter = presenter;
}
public void filter(String word) {
final List<Job> filteredJobList = new ArrayList<>();
word = word.toLowerCase();
for(Job job : jobs) {
if (job.getDeploymentName().toLowerCase().contains(word)
|| job.getSubdeploymentName().toLowerCase().contains(word)
|| job.getCurrentStatus().toLowerCase().contains(word)
|| job.getName().toLowerCase().contains(word)
|| job.getJobXmlName().toLowerCase().contains(word))
filteredJobList.add(job);
}
List<Job> propList = dataProvider.getList();
propList.clear(); // cannot call setList() as that breaks the sort handler
propList.addAll(filteredJobList);
}
public void clearFilter() {
List<Job> propList = dataProvider.getList();
propList.clear(); // cannot call setList() as that breaks the sort handler
propList.addAll(jobs);
}
}