Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestProgressSnapshotPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.ingest;
20 
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.Map;
27 import javax.swing.JDialog;
28 import javax.swing.table.AbstractTableModel;
29 import javax.swing.table.TableColumn;
30 import org.apache.commons.lang3.time.DurationFormatUtils;
31 import org.openide.util.NbBundle;
32 
36 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
37 class IngestProgressSnapshotPanel extends javax.swing.JPanel {
38 
39  private final JDialog parent;
40  private final IngestProgressSnapshotProvider snapshotProvider;
41  private final IngestThreadActivitySnapshotsTableModel threadActivityTableModel;
42  private final IngestJobTableModel jobTableModel;
43  private final ModuleTableModel moduleTableModel;
44 
45  IngestProgressSnapshotPanel(JDialog parent, IngestProgressSnapshotProvider snapshotProvider) {
46  this.parent = parent;
47  this.snapshotProvider = snapshotProvider;
48  threadActivityTableModel = new IngestThreadActivitySnapshotsTableModel();
49  jobTableModel = new IngestJobTableModel();
50  moduleTableModel = new ModuleTableModel();
51  initComponents();
52  customizeComponents();
53  }
54 
55  private void customizeComponents() {
56  threadActivitySnapshotsTable.setModel(threadActivityTableModel);
57  jobTable.setModel(jobTableModel);
58  moduleTable.setModel(moduleTableModel);
59 
60  int width = snapshotsScrollPane.getPreferredSize().width;
61  for (int i = 0; i < threadActivitySnapshotsTable.getColumnCount(); ++i) {
62  TableColumn column = threadActivitySnapshotsTable.getColumnModel().getColumn(i);
63  switch (i) {
64  case 0:
65  column.setPreferredWidth(((int) (width * 0.02)));
66  break;
67  case 1:
68  column.setPreferredWidth(((int) (width * 0.20)));
69  break;
70  case 2:
71  column.setPreferredWidth(((int) (width * 0.15)));
72  break;
73  case 3:
74  column.setPreferredWidth(((int) (width * 0.35)));
75  break;
76  case 4:
77  column.setPreferredWidth(((int) (width * 0.18)));
78  break;
79  case 5:
80  column.setPreferredWidth(((int) (width * 0.10)));
81  break;
82  }
83  }
84 
85  threadActivitySnapshotsTable.setFillsViewportHeight(true);
86  }
87 
88  private class IngestThreadActivitySnapshotsTableModel extends AbstractTableModel {
89 
90  private final String[] columnNames = {NbBundle.getMessage(this.getClass(),
91  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.threadID"),
92  NbBundle.getMessage(this.getClass(),
93  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.activity"),
94  NbBundle.getMessage(this.getClass(),
95  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.dataSource"),
96  NbBundle.getMessage(this.getClass(),
97  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.file"),
98  NbBundle.getMessage(this.getClass(),
99  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.startTime"),
100  NbBundle.getMessage(this.getClass(),
101  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.elapsedTime"),
102  NbBundle.getMessage(this.getClass(),
103  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.jobID")};
105 
107  refresh();
108  }
109 
110  private void refresh() {
111  snapshots = snapshotProvider.getIngestThreadActivitySnapshots();
112  fireTableDataChanged();
113  }
114 
115  @Override
116  public int getRowCount() {
117  return snapshots.size();
118  }
119 
120  @Override
121  public int getColumnCount() {
122  return columnNames.length;
123  }
124 
125  @Override
126  public String getColumnName(int col) {
127  return columnNames[col];
128  }
129 
130  @Override
131  public Object getValueAt(int rowIndex, int columnIndex) {
132  IngestManager.IngestThreadActivitySnapshot snapshot = snapshots.get(rowIndex);
133  Object cellValue;
134  switch (columnIndex) {
135  case 0:
136  cellValue = snapshot.getThreadId();
137  break;
138  case 1:
139  cellValue = snapshot.getActivity();
140  break;
141  case 2:
142  cellValue = snapshot.getDataSourceName();
143  break;
144  case 3:
145  cellValue = snapshot.getFileName();
146  break;
147  case 4:
148  cellValue = snapshot.getStartTime();
149  break;
150  case 5:
151  Date now = new Date();
152  long elapsedTime = now.getTime() - snapshot.getStartTime().getTime();
153  cellValue = DurationFormatUtils.formatDurationHMS(elapsedTime);
154  break;
155  case 6:
156  cellValue = snapshot.getIngestJobId();
157  break;
158  default:
159  cellValue = null;
160  break;
161  }
162  return cellValue;
163  }
164  }
165 
166  private class IngestJobTableModel extends AbstractTableModel {
167 
168  private static final long serialVersionUID = 1L;
169 
170  private final String[] columnNames = {
171  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.jobID"),
172  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.dataSource"),
173  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.start"),
174  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.numProcessed"),
175  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.filesPerSec"),
176  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.inProgress"),
177  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.filesQueued"),
178  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.dirQueued"),
179  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.rootQueued"),
180  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.streamingQueued"),
181  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.dsQueued"),
182  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.artifactsQueued")};
183 
184  private List<Snapshot> jobSnapshots;
185 
187  refresh();
188  }
189 
190  private void refresh() {
191  jobSnapshots = snapshotProvider.getIngestJobSnapshots();
192  fireTableDataChanged();
193  }
194 
195  @Override
196  public int getRowCount() {
197  return jobSnapshots.size();
198  }
199 
200  @Override
201  public int getColumnCount() {
202  return columnNames.length;
203  }
204 
205  @Override
206  public String getColumnName(int col) {
207  return columnNames[col];
208  }
209 
210  @Override
211  public Object getValueAt(int rowIndex, int columnIndex) {
212  Snapshot snapShot = jobSnapshots.get(rowIndex);
213  Object cellValue;
214  switch (columnIndex) {
215  case 0:
216  cellValue = snapShot.getJobId();
217  break;
218  case 1:
219  cellValue = snapShot.getDataSource();
220  break;
221  case 2:
222  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
223  cellValue = dateFormat.format(new Date(snapShot.getJobStartTime()));
224  break;
225  case 3:
226  cellValue = snapShot.getFilesProcessed();
227  break;
228  case 4:
229  cellValue = snapShot.getSpeed();
230  break;
231  case 5:
232  cellValue = snapShot.getRunningListSize();
233  break;
234  case 6:
235  cellValue = snapShot.getFileQueueSize();
236  break;
237  case 7:
238  cellValue = snapShot.getDirQueueSize();
239  break;
240  case 8:
241  cellValue = snapShot.getRootQueueSize();
242  break;
243  case 9:
244  cellValue = snapShot.getStreamingQueueSize();
245  break;
246  case 10:
247  cellValue = snapShot.getDsQueueSize();
248  break;
249  case 11:
250  cellValue = snapShot.getArtifactTasksQueueSize();
251  break;
252  default:
253  cellValue = null;
254  break;
255  }
256  return cellValue;
257  }
258  }
259 
260  private class ModuleTableModel extends AbstractTableModel {
261 
262  private static final long serialVersionUID = 1L;
263 
264  private class ModuleStats implements Comparable<ModuleStats> {
265 
266  private final String name;
267  private final long duration;
268 
269  ModuleStats(String name, long duration) {
270  this.name = name;
271  this.duration = duration;
272  }
273 
277  protected String getName() {
278  return name;
279  }
280 
284  protected long getDuration() {
285  return duration;
286  }
287 
288  @Override
289  public int compareTo(ModuleStats o) {
290  if (duration > o.getDuration()) {
291  return -1;
292  } else if (duration == o.getDuration()) {
293  return 0;
294  } else {
295  return 1;
296  }
297  }
298 
299  }
300  private final String[] columnNames = {NbBundle.getMessage(this.getClass(), "ModuleTableModel.colName.module"),
301  NbBundle.getMessage(this.getClass(),
302  "ModuleTableModel.colName.duration")};
303  private final List<ModuleStats> moduleStats = new ArrayList<>();
304  private long totalTime;
305 
306  private ModuleTableModel() {
307  refresh();
308  }
309 
310  private void refresh() {
311  Map<String, Long> moduleStatMap = snapshotProvider.getModuleRunTimes();
312  moduleStats.clear();
313  totalTime = 0;
314  for (String k : moduleStatMap.keySet()) {
315  moduleStats.add(new ModuleStats(k, moduleStatMap.get(k)));
316  totalTime += moduleStatMap.get(k);
317  }
318  Collections.sort(moduleStats);
319  fireTableDataChanged();
320  }
321 
322  @Override
323  public int getRowCount() {
324  return moduleStats.size();
325  }
326 
327  @Override
328  public int getColumnCount() {
329  return columnNames.length;
330  }
331 
332  @Override
333  public String getColumnName(int col) {
334  return columnNames[col];
335  }
336 
337  @Override
338  public Object getValueAt(int rowIndex, int columnIndex) {
339  ModuleStats moduleStat = moduleStats.get(rowIndex);
340  Object cellValue;
341  switch (columnIndex) {
342  case 0:
343  cellValue = moduleStat.getName();
344  break;
345  case 1:
346  cellValue = DurationFormatUtils.formatDurationHMS(moduleStat.getDuration()) + " (" + (moduleStat.getDuration() * 100) / totalTime + "%)";
347  break;
348 
349  default:
350  cellValue = null;
351  break;
352  }
353  return cellValue;
354  }
355  }
356 
362  @SuppressWarnings("unchecked")
363  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
364  private void initComponents() {
365  java.awt.GridBagConstraints gridBagConstraints;
366 
367  snapshotsScrollPane = new javax.swing.JScrollPane();
368  threadActivitySnapshotsTable = new javax.swing.JTable();
369  jobScrollPane = new javax.swing.JScrollPane();
370  jobTable = new javax.swing.JTable();
371  refreshButton = new javax.swing.JButton();
372  closeButton = new javax.swing.JButton();
373  moduleScrollPane = new javax.swing.JScrollPane();
374  moduleTable = new javax.swing.JTable();
375 
376  setMinimumSize(new java.awt.Dimension(500, 500));
377  setPreferredSize(new java.awt.Dimension(1100, 500));
378  setLayout(new java.awt.GridBagLayout());
379 
380  threadActivitySnapshotsTable.setModel(new javax.swing.table.DefaultTableModel(
381  new Object [][] {
382 
383  },
384  new String [] {
385 
386  }
387  ));
388  snapshotsScrollPane.setViewportView(threadActivitySnapshotsTable);
389 
390  gridBagConstraints = new java.awt.GridBagConstraints();
391  gridBagConstraints.gridx = 0;
392  gridBagConstraints.gridy = 0;
393  gridBagConstraints.gridwidth = 2;
394  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
395  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
396  gridBagConstraints.weightx = 1.0;
397  gridBagConstraints.weighty = 1.0;
398  gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 10);
399  add(snapshotsScrollPane, gridBagConstraints);
400 
401  jobTable.setModel(new javax.swing.table.DefaultTableModel(
402  new Object [][] {
403 
404  },
405  new String [] {
406 
407  }
408  ));
409  jobScrollPane.setViewportView(jobTable);
410 
411  gridBagConstraints = new java.awt.GridBagConstraints();
412  gridBagConstraints.gridx = 0;
413  gridBagConstraints.gridy = 1;
414  gridBagConstraints.gridwidth = 2;
415  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
416  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
417  gridBagConstraints.weightx = 1.0;
418  gridBagConstraints.weighty = 1.0;
419  gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
420  add(jobScrollPane, gridBagConstraints);
421 
422  org.openide.awt.Mnemonics.setLocalizedText(refreshButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.refreshButton.text")); // NOI18N
423  refreshButton.addActionListener(new java.awt.event.ActionListener() {
424  public void actionPerformed(java.awt.event.ActionEvent evt) {
425  refreshButtonActionPerformed(evt);
426  }
427  });
428  gridBagConstraints = new java.awt.GridBagConstraints();
429  gridBagConstraints.gridx = 0;
430  gridBagConstraints.gridy = 3;
431  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
432  gridBagConstraints.weightx = 1.0;
433  add(refreshButton, gridBagConstraints);
434 
435  org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.closeButton.text")); // NOI18N
436  closeButton.addActionListener(new java.awt.event.ActionListener() {
437  public void actionPerformed(java.awt.event.ActionEvent evt) {
438  closeButtonActionPerformed(evt);
439  }
440  });
441  gridBagConstraints = new java.awt.GridBagConstraints();
442  gridBagConstraints.gridx = 1;
443  gridBagConstraints.gridy = 3;
444  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
445  gridBagConstraints.insets = new java.awt.Insets(6, 6, 11, 10);
446  add(closeButton, gridBagConstraints);
447 
448  moduleTable.setModel(new javax.swing.table.DefaultTableModel(
449  new Object [][] {
450 
451  },
452  new String [] {
453 
454  }
455  ));
456  moduleScrollPane.setViewportView(moduleTable);
457 
458  gridBagConstraints = new java.awt.GridBagConstraints();
459  gridBagConstraints.gridx = 0;
460  gridBagConstraints.gridy = 2;
461  gridBagConstraints.gridwidth = 2;
462  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
463  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
464  gridBagConstraints.weightx = 1.0;
465  gridBagConstraints.weighty = 1.0;
466  gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
467  add(moduleScrollPane, gridBagConstraints);
468  }// </editor-fold>//GEN-END:initComponents
469 
470  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
471  parent.dispose();
472  }//GEN-LAST:event_closeButtonActionPerformed
473 
474  private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
475  threadActivityTableModel.refresh();
476  jobTableModel.refresh();
477  moduleTableModel.refresh();
478  }//GEN-LAST:event_refreshButtonActionPerformed
479  // Variables declaration - do not modify//GEN-BEGIN:variables
480  private javax.swing.JButton closeButton;
481  private javax.swing.JScrollPane jobScrollPane;
482  private javax.swing.JTable jobTable;
483  private javax.swing.JScrollPane moduleScrollPane;
484  private javax.swing.JTable moduleTable;
485  private javax.swing.JButton refreshButton;
486  private javax.swing.JScrollPane snapshotsScrollPane;
487  private javax.swing.JTable threadActivitySnapshotsTable;
488  // End of variables declaration//GEN-END:variables
489 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.