private void generateSvrReport(String path) {
    if (loadConfig(path)) {
      ssoToken = getAdminSSOToken();
      if (ssoToken != null) {
        // All the properties should be loaded at this point
        Properties prop = SystemProperties.getAll();
        Properties amProp = new Properties();
        Properties sysProp = new Properties();

        for (Enumeration e = prop.propertyNames(); e.hasMoreElements(); ) {
          String key = (String) e.nextElement();
          String val = (String) prop.getProperty(key);
          if (key.startsWith(AM_PROP_SUN_SUFFIX)
              || key.startsWith(AM_PROP_SUFFIX)
              || key.startsWith(ENC_PWD_PROPERTY)) {
            amProp.put(key, val);
          } else {
            sysProp.put(key, val);
          }
        }
        printProperties(amProp, DEF_PROP);
        printProperties(sysProp, SYS_PROP);
        getInstanceProperties(ssoToken);
      } else {
        toolOutWriter.printError("rpt-auth-msg");
      }
    } else {
      toolOutWriter.printStatusMsg(false, "rpt-svr-gen");
    }
  }
 private void printProperties(Properties prop, String type) {
   toolOutWriter.printMessage(PARA_SEP);
   toolOutWriter.printMessage(type);
   toolOutWriter.printMessage(PARA_SEP + "\n");
   for (Enumeration e = prop.propertyNames(); e.hasMoreElements(); ) {
     String key = (String) e.nextElement();
     String val = (String) prop.getProperty(key);
     if (key.equals(ENC_PWD_PROPERTY) || key.equals(AM_SERVICES_SECRET)) {
       val = "xxxxxxxxxxxxxxxx";
     }
     String[] params = {key, val};
     toolOutWriter.printMessage("rpt-svr-print-prop", params);
   }
   toolOutWriter.printMessage(SMALL_LINE_SEP + "\n");
 }
 private boolean loadConfig(String path) {
   boolean loaded = false;
   try {
     if (!loadConfigFromBootfile(path).isEmpty()) {
       loaded = true;
     }
   } catch (Exception e) {
     toolOutWriter.printError("cannot-load-properties", new String[] {path});
   }
   return loaded;
 }
Exemplo n.º 4
0
  public MainJPanel() {
    initComponents();
    counterThread = new CounterThread();
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                counterThread.shutdown();
              }
            });
    counterThread.start();
    previousCategorySelectedIndex = -1;
    northPanel = new NorthMainJPanel(rb);
    centerPanel = new CenterMainJPanel(rb);
    southPanel = new ButtonJPanel(this, rb);
    add(northPanel, java.awt.BorderLayout.NORTH);
    add(centerPanel, java.awt.BorderLayout.CENTER);
    add(southPanel, java.awt.BorderLayout.SOUTH);
    tContext = ToolManager.getInstance().getToolContext();
    final IToolOutput outputWriter = tContext.getOutputWriter();
    outputWriter.addMessageListener(
        new MessageListener() {
          public void messagePublished(MessageEvent e) {
            switch (e.getMessageType()) {
              case MessageEvent.RESULT_MESSAGE:
                centerPanel.appendResultMessage(e.getMessage());
                break;
              case MessageEvent.INFO_MESSAGE:
                centerPanel.appendInfoMessage(e.getMessage());
                break;
              case MessageEvent.WARNING_MESSAGE:
                centerPanel.appendWarningMessage(e.getMessage());
                break;
              case MessageEvent.ERROR_MESSAGE:
                centerPanel.appendErrorMessage(e.getMessage());
            }
          }
        });
    final TestsTableModel finalTableModel = (TestsTableModel) centerPanel.getTableModel();
    finalTableModel.addTableModelListener(
        new TableModelListener() {

          public void tableChanged(TableModelEvent e) {
            int type = e.getType();
            switch (type) {
              case TableModelEvent.INSERT:
                southPanel.enableClearAllButton();
                southPanel.enableSaveAllButton();
                break;
              case TableModelEvent.UPDATE:
              case TableModelEvent.DELETE:
                if (finalTableModel.getRowCount() == 0) {
                  southPanel.disableClearAllButton();
                  southPanel.disableSaveAllButton();
                }
            }
          }
        });
    southPanel.addClearAllButtonActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(
                    centerPanel,
                    rb.getString("dlg_clear_txt_msg"),
                    rb.getString("dlg_clear_title_msg"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE)
                == JOptionPane.YES_OPTION) {
              centerPanel.clearAll();
            }
          }
        });
    southPanel.addSaveAllButtonActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            File file = null;
            JFileChooser chooser = new JFileChooser();
            while (chooser.showSaveDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
              file = chooser.getSelectedFile();
              if (!file.getName().endsWith(".html")) {
                file = new File(file.getAbsolutePath() + ".html");
              }
              if (file != null) {
                if (file.exists()) {
                  if (JOptionPane.showConfirmDialog(
                          centerPanel,
                          "Replace file " + file.getName() + " ?",
                          "Replace File",
                          JOptionPane.YES_NO_OPTION)
                      != JOptionPane.YES_OPTION) {
                    continue;
                  }
                }
                FileWriter writer = null;
                try {
                  writer = new FileWriter(file);
                  HTMLWriter htmlWriter =
                      new HTMLWriter(writer, (HTMLDocument) centerPanel.getDocument());
                  htmlWriter.write();
                } catch (IOException ex) {
                  JOptionPane.showMessageDialog(
                      centerPanel, ex.getMessage(), "IO Error", JOptionPane.ERROR_MESSAGE);
                } catch (Exception ex) {
                  JOptionPane.showMessageDialog(
                      centerPanel, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                } finally {
                  if (writer != null) {
                    try {
                      writer.close();
                    } catch (IOException ignored) {
                    }
                  }
                }
              }
              break;
            }
          }
        });
    serviceCategories = tContext.getServiceCategories();
    Set<String> categories = serviceCategories.keySet();
    for (String name : categories) {
      northPanel.addCategory(new ImageListEntry(name, null));
    }
    for (int i = 0; i < WEB_CONTAINERS.length; i++) {
      northPanel.addWebContainer(new ImageListEntry(WEB_CONTAINERS[i], WEB_CONTAINERS_ICON[i]));
    }
    northPanel.addWebContainerItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            ImageListEntry entry = (ImageListEntry) e.getItem();
            String name = entry.getName();
            if (name.equals(rb.getString("dd_sun_app_server"))) {
              northPanel.setContainerBaseLabel(rb.getString("txt_lbl_container_bdir"));
              northPanel.setContainerDomainLabel(rb.getString("txt_lbl_container_ddir"));
            } else {
              if (name.equals(rb.getString("dd_sun_web_server"))) {
                northPanel.setContainerBaseLabel(rb.getString("txt_lbl_container_bdir"));
                northPanel.setContainerDomainLabel(rb.getString("txt_lbl_container_ddir"));
              } else {
                if (name.equals(rb.getString("dd_bea_weblogic"))) {
                  northPanel.setContainerBaseLabel(rb.getString("txt_lbl_container_idir"));
                  northPanel.setContainerDomainLabel(rb.getString("txt_lbl_container_ddir"));
                } else {
                  if (name.equals(rb.getString("dd_ibm_websphere"))) {
                    northPanel.setContainerBaseLabel(rb.getString("txt_lbl_container_pdir"));
                    northPanel.setContainerDomainLabel(rb.getString("txt_lbl_container_sdir"));
                  }
                }
              }
            }
          }
        });
    northPanel.addCategoryListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            JList list = (JList) e.getSource();
            int index = list.getSelectedIndex();
            if (index != previousCategorySelectedIndex) {
              String categoryName = ((ImageListEntry) list.getSelectedValue()).getName();
              HashMap<String, HashMap> serviceNameMap = serviceCategories.get(categoryName);
              Set<String> serviceName = serviceNameMap.keySet();
              centerPanel.removeAllTests();
              for (String name : serviceName) {
                if (!name.equalsIgnoreCase(rb.getString("all").trim())) {
                  centerPanel.addTest(
                      new CheckBoxListEntry(name, SELECTED_ICON, NOT_SELECTED_ICON));
                }
              }
              previousCategorySelectedIndex = index;
            }
          }
        });
    centerPanel.addCheckBoxListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            JList list = (JList) e.getSource();
            if (list.getSelectedIndex() >= 0) {
              northPanel.enableRunSelected();
            } else {
              northPanel.disableRunSelected();
            }
          }
        });
    final MainJPanel mainProgram = this;
    northPanel.addRunSelectedButtonActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ImageListEntry entry = (ImageListEntry) northPanel.getSelectedCategory();
            if (entry != null) {
              ToolService service = null;
              String categoryName = entry.getName();
              final HashMap<String, HashMap> opCodeMap = serviceCategories.get(categoryName);
              Set<String> opNames = opCodeMap.keySet();
              for (String opName : opNames) {
                HashMap<String, String> opToService = opCodeMap.get(opName);
                Set<String> funNames = opToService.keySet();
                for (String funName : funNames) {
                  service = tContext.getService(opToService.get(funName).toLowerCase());
                  break;
                }
                break;
              }
              final Object[] tests = centerPanel.getSelectedTests();
              if ((tests != null) && (tests.length > 0)) {
                mainProgram.disableComponentsWhileRunning();
                TestsTableModel tableModel = (TestsTableModel) centerPanel.getTableModel();
                ListSelectionModel selectionModel = centerPanel.getTableSelectionModel();
                final int[] rowNum = new int[tests.length];
                for (int i = 0; i < tests.length; i++) {
                  CheckBoxListEntry testEntry = (CheckBoxListEntry) tests[i];
                  Object[] values = new Object[tableModel.getColumnCount() + 1];
                  values[TestsTableModel.START_TIME_COLUMN] = new StartTimeTableCell(rb);
                  values[TestsTableModel.Test_COLUMN] = testEntry.getName();
                  values[TestsTableModel.TIME_ELAPSED_COLUMN] = new CounterTableCell();
                  values[TestsTableModel.RESULT_COLUMN] = new ResultTableCell(rb);
                  tableModel.addRow(values);
                  rowNum[i] = tableModel.getRowCount() - 1;
                }
                final ToolService finalService = service;
                final TestsTableModel finalTableModel = tableModel;
                final ListSelectionModel finalSelectionModel = selectionModel;
                Runnable workRunnable =
                    new Runnable() {
                      public void run() {
                        for (int i = 0; i < tests.length; i++) {
                          finalSelectionModel.setSelectionInterval(rowNum[i], rowNum[i]);
                          StartTimeTableCell startTimeCell =
                              (StartTimeTableCell)
                                  finalTableModel.getValueAt(
                                      rowNum[i], TestsTableModel.START_TIME_COLUMN);
                          startTimeCell.start();
                          finalTableModel.fireTableRowsUpdated(rowNum[i], rowNum[i]);
                          CheckBoxListEntry testEntry = (CheckBoxListEntry) tests[i];
                          HashMap<String, String> opToService = opCodeMap.get(testEntry.getName());
                          Set<String> cmds = opToService.keySet();
                          HashSet singleCmdSet = new HashSet();
                          HashMap singleParamSet = new HashMap();
                          for (String cmd : cmds) {
                            singleCmdSet.add(cmd);
                          }
                          ServiceRequest sReq = new ServiceRequest();
                          sReq.setCommand(singleCmdSet);
                          singleParamSet.put(CONFIG_DIR, northPanel.getConfigDir());
                          singleParamSet.put(CONTAINER_DIR, northPanel.getContainerDir());
                          singleParamSet.put(
                              CONTAINER_TYPE,
                              ((ImageListEntry) northPanel.getSelectedWebContainer()).getName());
                          singleParamSet.put(
                              CONTAINER_DOMAIN_DIR, northPanel.getContainerDomainDir());
                          sReq.setData(singleParamSet);
                          ResultTableCell resultCell =
                              (ResultTableCell)
                                  finalTableModel.getValueAt(
                                      rowNum[i], TestsTableModel.RESULT_COLUMN);
                          resultCell.setViewPosition(
                              new Point(0, centerPanel.getCurrentViewPosition().y));
                          resultCell.start();
                          finalTableModel.fireTableRowsUpdated(rowNum[i], rowNum[i]);
                          final CounterTableCell counterCell =
                              (CounterTableCell)
                                  finalTableModel.getValueAt(
                                      rowNum[i], TestsTableModel.TIME_ELAPSED_COLUMN);
                          final int finalRowNum = rowNum[i];
                          CounterRunnable counter =
                              new CounterRunnable(
                                  new Runnable() {
                                    public void run() {
                                      counterCell.increase();
                                      finalTableModel.fireTableRowsUpdated(
                                          finalRowNum, finalRowNum);
                                    }
                                  });
                          counterThread.runTask(counter);
                          try {
                            ServiceResponse sRes = new ServiceResponse();
                            finalService.processRequest(sReq, sRes);
                            if (sRes.getStatus().equals(ServiceResponse.PASS)) {
                              resultCell.setResult(true);
                              finalTableModel.fireTableRowsUpdated(rowNum[i], rowNum[i]);
                            } else {
                              resultCell.setResult(false);
                              finalTableModel.fireTableRowsUpdated(rowNum[i], rowNum[i]);
                            }
                            ToolLogWriter.log(sRes.getMessage());
                            ToolLogWriter.log(sRes.getError());
                            ToolLogWriter.log(sRes.getWarning());
                            ToolLogWriter.log(sRes.getResult(1));
                            ToolLogWriter.log(sRes.getResult(2));
                          } catch (NullPointerException npe) {
                            /**/
                            outputWriter.printError(npe.toString());
                            resultCell.setResult(false);
                            finalTableModel.fireTableRowsUpdated(rowNum[i], rowNum[i]);
                          } catch (Exception ex) {
                            /**/
                            resultCell.setResult(false);
                            outputWriter.printError(ex.toString());
                            finalTableModel.fireTableRowsUpdated(rowNum[i], rowNum[i]);
                          }
                          counter.finished();
                        }
                        SwingUtilities.invokeLater(
                            new Runnable() {
                              public void run() {
                                mainProgram.enableComponentsAfterRunning();
                              }
                            });
                      }
                    };
                Thread workerThread = new Thread(workRunnable);
                workerThread.start();
              }
            }
          }
        });
  }