Autopsy  4.20.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.getModuleDisplayName();
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.tier"),
175  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.numProcessed"),
176  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.filesPerSec"),
177  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.inProgress"),
178  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.filesQueued"),
179  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.dirQueued"),
180  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.rootQueued"),
181  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.streamingQueued"),
182  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.dsQueued"),
183  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.artifactsQueued"),
184  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.resultsQueued")};
185 
186  private List<IngestJobProgressSnapshot> jobSnapshots;
187 
189  refresh();
190  }
191 
192  private void refresh() {
193  jobSnapshots = snapshotProvider.getIngestJobSnapshots();
194  fireTableDataChanged();
195  }
196 
197  @Override
198  public int getRowCount() {
199  return jobSnapshots.size();
200  }
201 
202  @Override
203  public int getColumnCount() {
204  return columnNames.length;
205  }
206 
207  @Override
208  public String getColumnName(int col) {
209  return columnNames[col];
210  }
211 
212  @Override
213  public Object getValueAt(int rowIndex, int columnIndex) {
214  IngestJobProgressSnapshot snapShot = jobSnapshots.get(rowIndex);
215  Object cellValue;
216  switch (columnIndex) {
217  case 0:
218  cellValue = snapShot.getJobId();
219  break;
220  case 1:
221  cellValue = snapShot.getDataSource();
222  break;
223  case 2:
224  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
225  cellValue = dateFormat.format(new Date(snapShot.getJobStartTime()));
226  break;
227  case 3:
228  cellValue = snapShot.getCurrentIngestModuleTier();
229  break;
230  case 4:
231  cellValue = snapShot.getFilesProcessed();
232  break;
233  case 5:
234  cellValue = snapShot.getFilesProcessedPerSec();
235  break;
236  case 6:
237  cellValue = snapShot.getRunningListSize();
238  break;
239  case 7:
240  cellValue = snapShot.getFileQueueSize();
241  break;
242  case 8:
243  cellValue = snapShot.getDirQueueSize();
244  break;
245  case 9:
246  cellValue = snapShot.getRootQueueSize();
247  break;
248  case 10:
249  cellValue = snapShot.getStreamingQueueSize();
250  break;
251  case 11:
252  cellValue = snapShot.getDsQueueSize();
253  break;
254  case 12:
255  cellValue = snapShot.getDataArtifactTasksQueueSize();
256  break;
257  case 13:
258  cellValue = snapShot.getAnalysisResultTasksQueueSize();
259  break;
260  default:
261  cellValue = null;
262  break;
263  }
264  return cellValue;
265  }
266  }
267 
268  private class ModuleTableModel extends AbstractTableModel {
269 
270  private static final long serialVersionUID = 1L;
271 
272  private class ModuleStats implements Comparable<ModuleStats> {
273 
274  private final String name;
275  private final long duration;
276 
277  ModuleStats(String name, long duration) {
278  this.name = name;
279  this.duration = duration;
280  }
281 
285  protected String getName() {
286  return name;
287  }
288 
292  protected long getDuration() {
293  return duration;
294  }
295 
296  @Override
297  public int compareTo(ModuleStats o) {
298  if (duration > o.getDuration()) {
299  return -1;
300  } else if (duration == o.getDuration()) {
301  return 0;
302  } else {
303  return 1;
304  }
305  }
306 
307  }
308  private final String[] columnNames = {NbBundle.getMessage(this.getClass(), "ModuleTableModel.colName.module"),
309  NbBundle.getMessage(this.getClass(),
310  "ModuleTableModel.colName.duration")};
311  private final List<ModuleStats> moduleStats = new ArrayList<>();
312  private long totalTime;
313 
314  private ModuleTableModel() {
315  refresh();
316  }
317 
318  private void refresh() {
319  Map<String, Long> moduleStatMap = snapshotProvider.getModuleRunTimes();
320  moduleStats.clear();
321  totalTime = 0;
322  for (String k : moduleStatMap.keySet()) {
323  moduleStats.add(new ModuleStats(k, moduleStatMap.get(k)));
324  totalTime += moduleStatMap.get(k);
325  }
326  Collections.sort(moduleStats);
327  fireTableDataChanged();
328  }
329 
330  @Override
331  public int getRowCount() {
332  return moduleStats.size();
333  }
334 
335  @Override
336  public int getColumnCount() {
337  return columnNames.length;
338  }
339 
340  @Override
341  public String getColumnName(int col) {
342  return columnNames[col];
343  }
344 
345  @Override
346  public Object getValueAt(int rowIndex, int columnIndex) {
347  ModuleStats moduleStat = moduleStats.get(rowIndex);
348  Object cellValue;
349  switch (columnIndex) {
350  case 0:
351  cellValue = moduleStat.getName();
352  break;
353  case 1:
354  cellValue = DurationFormatUtils.formatDurationHMS(moduleStat.getDuration()) + " (" + (moduleStat.getDuration() * 100) / totalTime + "%)";
355  break;
356 
357  default:
358  cellValue = null;
359  break;
360  }
361  return cellValue;
362  }
363  }
364 
370  @SuppressWarnings("unchecked")
371  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
372  private void initComponents() {
373  java.awt.GridBagConstraints gridBagConstraints;
374 
375  snapshotsScrollPane = new javax.swing.JScrollPane();
376  threadActivitySnapshotsTable = new javax.swing.JTable();
377  jobScrollPane = new javax.swing.JScrollPane();
378  jobTable = new javax.swing.JTable();
379  refreshButton = new javax.swing.JButton();
380  closeButton = new javax.swing.JButton();
381  moduleScrollPane = new javax.swing.JScrollPane();
382  moduleTable = new javax.swing.JTable();
383  jPanel1 = new javax.swing.JPanel();
384 
385  setMinimumSize(new java.awt.Dimension(500, 500));
386  setPreferredSize(new java.awt.Dimension(1500, 700));
387  setLayout(new java.awt.GridBagLayout());
388 
389  threadActivitySnapshotsTable.setModel(new javax.swing.table.DefaultTableModel(
390  new Object [][] {
391 
392  },
393  new String [] {
394 
395  }
396  ));
397  snapshotsScrollPane.setViewportView(threadActivitySnapshotsTable);
398 
399  gridBagConstraints = new java.awt.GridBagConstraints();
400  gridBagConstraints.gridx = 0;
401  gridBagConstraints.gridy = 0;
402  gridBagConstraints.gridwidth = 2;
403  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
404  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
405  gridBagConstraints.weightx = 1.0;
406  gridBagConstraints.weighty = 1.0;
407  gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 10);
408  add(snapshotsScrollPane, gridBagConstraints);
409 
410  jobTable.setModel(new javax.swing.table.DefaultTableModel(
411  new Object [][] {
412 
413  },
414  new String [] {
415 
416  }
417  ));
418  jobScrollPane.setViewportView(jobTable);
419 
420  gridBagConstraints = new java.awt.GridBagConstraints();
421  gridBagConstraints.gridx = 0;
422  gridBagConstraints.gridy = 1;
423  gridBagConstraints.gridwidth = 2;
424  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
425  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
426  gridBagConstraints.weightx = 1.0;
427  gridBagConstraints.weighty = 1.0;
428  gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
429  add(jobScrollPane, gridBagConstraints);
430 
431  org.openide.awt.Mnemonics.setLocalizedText(refreshButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.refreshButton.text")); // NOI18N
432  refreshButton.addActionListener(new java.awt.event.ActionListener() {
433  public void actionPerformed(java.awt.event.ActionEvent evt) {
434  refreshButtonActionPerformed(evt);
435  }
436  });
437  gridBagConstraints = new java.awt.GridBagConstraints();
438  gridBagConstraints.gridx = 0;
439  gridBagConstraints.gridy = 3;
440  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
441  gridBagConstraints.weightx = 1.0;
442  add(refreshButton, gridBagConstraints);
443 
444  org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.closeButton.text")); // NOI18N
445  closeButton.addActionListener(new java.awt.event.ActionListener() {
446  public void actionPerformed(java.awt.event.ActionEvent evt) {
447  closeButtonActionPerformed(evt);
448  }
449  });
450  gridBagConstraints = new java.awt.GridBagConstraints();
451  gridBagConstraints.gridx = 1;
452  gridBagConstraints.gridy = 3;
453  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
454  gridBagConstraints.insets = new java.awt.Insets(6, 6, 11, 10);
455  add(closeButton, gridBagConstraints);
456 
457  moduleTable.setModel(new javax.swing.table.DefaultTableModel(
458  new Object [][] {
459 
460  },
461  new String [] {
462 
463  }
464  ));
465  moduleScrollPane.setViewportView(moduleTable);
466 
467  gridBagConstraints = new java.awt.GridBagConstraints();
468  gridBagConstraints.gridx = 0;
469  gridBagConstraints.gridy = 2;
470  gridBagConstraints.gridwidth = 2;
471  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
472  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
473  gridBagConstraints.weightx = 1.0;
474  gridBagConstraints.weighty = 1.0;
475  gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
476  add(moduleScrollPane, gridBagConstraints);
477  add(jPanel1, new java.awt.GridBagConstraints());
478  }// </editor-fold>//GEN-END:initComponents
479 
480  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
481  parent.dispose();
482  }//GEN-LAST:event_closeButtonActionPerformed
483 
484  private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
485  threadActivityTableModel.refresh();
486  jobTableModel.refresh();
487  moduleTableModel.refresh();
488  }//GEN-LAST:event_refreshButtonActionPerformed
489  // Variables declaration - do not modify//GEN-BEGIN:variables
490  private javax.swing.JButton closeButton;
491  private javax.swing.JPanel jPanel1;
492  private javax.swing.JScrollPane jobScrollPane;
493  private javax.swing.JTable jobTable;
494  private javax.swing.JScrollPane moduleScrollPane;
495  private javax.swing.JTable moduleTable;
496  private javax.swing.JButton refreshButton;
497  private javax.swing.JScrollPane snapshotsScrollPane;
498  private javax.swing.JTable threadActivitySnapshotsTable;
499  // End of variables declaration//GEN-END:variables
500 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.