示例#1
0
  /** Executes the specified command, if the host is connected. */
  void execCommand(final String command) {
    final String hostName = host.getName();

    if (!host.isConnected()) {
      return;
    }
    if (!"".equals(command)) {
      Tools.startProgressIndicator(hostName, "Executing command");
    }
    host.execCommandRaw(
        command,
        new ExecCallback() {
          @Override
          public void done(final String ans) {
            if (!"".equals(command)) {
              Tools.stopProgressIndicator(hostName, "Executing command");
            }
          }

          @Override
          public void doneError(final String ans, final int exitCode) {
            if (!"".equals(command)) {
              Tools.stopProgressIndicator(hostName, "Executing command");
            }
          }
        },
        true,
        false,
        SSH.DEFAULT_COMMAND_TIMEOUT);
  }
示例#2
0
文件: VGCreate.java 项目: rdndnl/lcmc
 @Override
 public void run() {
   Tools.invokeAndWait(new EnableCreateRunnable(false));
   disableComponents();
   getProgressBar().start(CREATE_TIMEOUT * hostCheckBoxes.size());
   boolean oneFailed = false;
   for (final Host h : hostCheckBoxes.keySet()) {
     if (hostCheckBoxes.get(h).isSelected()) {
       final List<String> pvNames = new ArrayList<String>();
       for (final String pv : pvCheckBoxes.keySet()) {
         if (pvCheckBoxes.get(pv).isSelected()) {
           pvNames.add(pv);
         }
       }
       final boolean ret = vgCreate(h, vgNameWi.getStringValue(), pvNames);
       if (!ret) {
         oneFailed = true;
       }
     }
   }
   enableComponents();
   if (oneFailed) {
     for (final Host h : hostCheckBoxes.keySet()) {
       h.getBrowser().getClusterBrowser().updateHWInfo(h);
     }
     checkButtons();
     progressBarDoneError();
   } else {
     progressBarDone();
     disposeDialog();
     for (final Host h : hostCheckBoxes.keySet()) {
       h.getBrowser().getClusterBrowser().updateHWInfo(h);
     }
   }
 }
示例#3
0
 /** Returns possible choices for drop down lists. */
 @Override
 protected Object[] getParamPossibleChoices(final String param) {
   if (DiskData.SOURCE_FILE.equals(param)) {
     final Set<String> sourceFileDirs = new TreeSet<String>();
     sourceFileDirs.add(LIBVIRT_IMAGE_LOCATION);
     for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
       final VMSXML vmsxml = getBrowser().getVMSXML(h);
       if (vmsxml != null) {
         sourceFileDirs.addAll(vmsxml.getsourceFileDirs());
       }
     }
     return sourceFileDirs.toArray(new String[sourceFileDirs.size()]);
   } else if (DiskData.SOURCE_DEVICE.equals(param)) {
     for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
       final VMSXML vmsxml = getBrowser().getVMSXML(h);
       final List<String> bds = new ArrayList<String>();
       bds.add(null);
       if (vmsxml != null) {
         for (final BlockDevInfo bdi : h.getBrowser().getBlockDevInfos()) {
           if (bdi.getBlockDevice().isDrbd()) {
             bds.add(bdi.getDrbdVolumeInfo().getDeviceByRes());
           } else {
             bds.add(bdi.getName());
           }
         }
         return bds.toArray(new String[bds.size()]);
       }
     }
   }
   return POSSIBLE_VALUES.get(param);
 }
示例#4
0
文件: LVResize.java 项目: npk/lcmc
  /** Returns maximum block size available in the group. */
  private String getMaxBlockSize() {
    final long free = blockDevInfo.getFreeInVolumeGroup() / 1024;

    String maxBlockSize = "0";
    try {
      final long taken = Long.parseLong(blockDevInfo.getBlockDevice().getBlockSize());
      final BlockDevInfo oBDI = blockDevInfo.getOtherBlockDevInfo();
      long max = free + taken;
      final String lvm = blockDevInfo.getBlockDevice().getName();
      if (hostCheckBoxes != null) {
        for (final Host h : hostCheckBoxes.keySet()) {
          if (blockDevInfo.getHost() == h) {
            continue;
          }
          if (hostCheckBoxes.get(h).isSelected()) {
            for (final BlockDevice b : h.getBlockDevices()) {
              if (lvm.equals(b.getName()) || (oBDI != null && oBDI.getBlockDevice() == b)) {
                final long oFree = h.getFreeInVolumeGroup(b.getVolumeGroup()) / 1024;
                final long oTaken = Long.parseLong(b.getBlockSize());
                if (oFree + oTaken < max) {
                  /* take the smaller maximum. */
                  max = oFree + oTaken;
                }
              }
            }
          }
        }
      }
      maxBlockSize = Long.toString(max);
    } catch (final Exception e) {
      Tools.appWarning("could not get max size");
      /* ignore */
    }
    return maxBlockSize;
  }
示例#5
0
  /**
   * Starts file chooser.
   *
   * @param dir whether it needs dir or file
   */
  protected void startFileChooser(
      final Widget paramWi, final String directory, final boolean dirOnly) {
    final Host host = getFirstConnectedHost();
    if (host == null) {
      Tools.appError("Connection to host lost.");
      return;
    }
    final VMSHardwareInfo thisClass = this;
    final JFileChooser fc =
        new JFileChooser(getLinuxDir(directory, host), getFileSystemView(host, directory)) {
          /** Serial version UID. */
          private static final long serialVersionUID = 1L;

          @Override
          public final void setCurrentDirectory(final File dir) {
            super.setCurrentDirectory(new LinuxFile(thisClass, host, dir.toString(), "d", 0, 0));
          }
        };
    fc.setBackground(ClusterBrowser.STATUS_BACKGROUND);
    fc.setDialogType(JFileChooser.CUSTOM_DIALOG);
    if (dirOnly) {
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }
    fc.setDialogTitle(Tools.getString("VMSDiskInfo.FileChooserTitle") + host.getName());
    //        fc.setApproveButtonText(Tools.getString("VMSDiskInfo.Approve"));
    fc.setApproveButtonToolTipText(Tools.getString("VMSDiskInfo.Approve.ToolTip"));
    fc.putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
    final int ret =
        fc.showDialog(Tools.getGUIData().getMainFrame(), Tools.getString("VMSDiskInfo.Approve"));
    linuxFileCache.clear();
    if (ret == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
      final String name = fc.getSelectedFile().getAbsolutePath();
      paramWi.setValue(name);
    }
  }
示例#6
0
文件: VGCreate.java 项目: rdndnl/lcmc
 @Override
 public void run() {
   boolean e = enable;
   if (enable) {
     boolean vgNameCorrect = true;
     if ("".equals(vgNameWi.getStringValue())) {
       vgNameCorrect = false;
     } else if (hostCheckBoxes != null) {
       for (final Host h : hostCheckBoxes.keySet()) {
         if (hostCheckBoxes.get(h).isSelected()) {
           final Set<String> vgs = h.getVolumeGroupNames();
           if (vgs != null && vgs.contains(vgNameWi.getStringValue())) {
             vgNameCorrect = false;
             break;
           }
         }
       }
     }
     if (vgNameCorrect) {
       vgNameWi.setBackground("", "", true);
     } else {
       e = false;
       vgNameWi.wrongValue();
     }
   }
   createButton.setEnabled(e);
 }
示例#7
0
文件: Connect.java 项目: rdndnl/lcmc
 /** Connects all cluster hosts. */
 protected void connectHosts() {
   getCluster().connect(getDialogPanel(), true, 1);
   for (final Host host : getCluster().getHosts()) {
     host.waitOnLoading();
   }
   checkHosts();
 }
示例#8
0
 /** Returns a prompt. */
 private String prompt() {
   if (host.isConnected()) {
     return "[" + host.getUserAtHost() + ":~#] ";
   } else {
     return "# ";
   }
 }
示例#9
0
 /** Get first host that has this vm and is connected. */
 protected final Host getFirstConnectedHost() {
   for (final Host h : getBrowser().getClusterHosts()) {
     final VMSXML vmsxml = getBrowser().getVMSXML(h);
     if (vmsxml != null && h.isConnected()) {
       return h;
     }
   }
   return null;
 }
示例#10
0
文件: LVResize.java 项目: npk/lcmc
 /** LVM Resize and DRBD Resize. */
 private boolean resize(final String size) {
   final boolean ret =
       LVM.resize(blockDevInfo.getHost(), blockDevInfo.getBlockDevice().getName(), size, false);
   if (ret) {
     answerPaneSetText(
         "Lodical volume was successfully resized on " + blockDevInfo.getHost() + ".");
     /* resize lvm volume on the other node. */
     final String lvm = blockDevInfo.getBlockDevice().getName();
     final BlockDevInfo oBDI = blockDevInfo.getOtherBlockDevInfo();
     boolean resizingFailed = false;
     for (final Host h : hostCheckBoxes.keySet()) {
       if (h == blockDevInfo.getHost() || !hostCheckBoxes.get(h).isSelected()) {
         continue;
       }
       for (final BlockDevice b : h.getBlockDevices()) {
         if (lvm.equals(b.getName()) || (oBDI != null && oBDI.getBlockDevice() == b)) {
           /* drbd or selected other host */
           final boolean oRet = LVM.resize(h, b.getName(), size, false);
           if (oRet) {
             answerPaneAddText(
                 "Lodical volume was successfully" + " resized on " + h.getName() + ".");
           } else {
             answerPaneAddTextError(
                 "Resizing of " + b.getName() + " on host " + h.getName() + " failed.");
             resizingFailed = true;
           }
           break;
         }
         if (resizingFailed) {
           break;
         }
       }
     }
     if (oBDI != null && !resizingFailed) {
       final boolean dRet = blockDevInfo.resizeDrbd(false);
       if (dRet) {
         answerPaneAddText(
             "DRBD resource "
                 + blockDevInfo.getDrbdVolumeInfo().getName()
                 + " was successfully resized.");
       } else {
         answerPaneAddTextError(
             "DRBD resource " + blockDevInfo.getDrbdVolumeInfo().getName() + " resizing failed.");
       }
     }
   } else {
     answerPaneAddTextError(
         "Resizing of "
             + blockDevInfo.getName()
             + " on host "
             + blockDevInfo.getHost()
             + " failed.");
   }
   return ret;
 }
示例#11
0
文件: Connect.java 项目: rdndnl/lcmc
  /** Returns the connect hosts dialog content. */
  @Override
  protected JComponent getInputPane() {
    final JPanel pane = new JPanel(new SpringLayout());
    final StringBuilder text = new StringBuilder();
    for (final Host host : getCluster().getHosts()) {
      text.append(host.getName());
      text.append(" connecting...\n");
    }
    pane.add(getAnswerPane(text.toString()));

    SpringUtilities.makeCompactGrid(
        pane, 1, 1, // rows, cols
        1, 1, // initX, initY
        1, 1); // xPad, yPad
    return pane;
  }
示例#12
0
 /** Returns a host icon for the menu. */
 @Override
 public ImageIcon getMenuIcon(final boolean testOnly) {
   final Cluster cl = host.getCluster();
   if (cl != null) {
     return HostBrowser.HOST_IN_CLUSTER_ICON_RIGHT_SMALL;
   }
   return HostBrowser.HOST_ICON;
 }
示例#13
0
文件: VGCreate.java 项目: rdndnl/lcmc
 /** Create VG. */
 private boolean vgCreate(final Host host, final String vgName, final List<String> pvNames) {
   for (final String pv : pvNames) {
     final BlockDevInfo bdi =
         host.getBrowser().getDrbdGraph().findBlockDevInfo(host.getName(), pv);
     if (bdi != null) {
       bdi.getBlockDevice().setVolumeGroupOnPhysicalVolume(vgName);
       bdi.getBrowser().getDrbdGraph().startAnimation(bdi);
     }
   }
   final boolean ret = LVM.vgCreate(host, vgName, pvNames, false);
   if (ret) {
     answerPaneAddText(
         "Volume group " + vgName + " was successfully created " + " on " + host.getName() + ".");
   } else {
     answerPaneAddTextError("Creating of volume group " + vgName + " failed.");
   }
   return ret;
 }
示例#14
0
文件: VGCreate.java 项目: rdndnl/lcmc
 /** Returns array of volume group checkboxes. */
 private Map<String, JCheckBox> getPVCheckBoxes(final Set<String> selectedPVs) {
   final Map<String, JCheckBox> components = new LinkedHashMap<String, JCheckBox>();
   for (final BlockDevice pv : host.getPhysicalVolumes()) {
     final String pvName = pv.getName();
     final JCheckBox button = new JCheckBox(pvName, selectedPVs.contains(pvName));
     button.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
     components.put(pvName, button);
   }
   return components;
 }
示例#15
0
文件: Connect.java 项目: rdndnl/lcmc
  /** Checks hosts, if they are connected and if not reconnects them. */
  protected void checkHosts() {
    final StringBuilder text = new StringBuilder();
    boolean pending = false;
    boolean oneFailed = false;
    for (final Host host : getCluster().getHosts()) {
      String status;
      if (host.getSSH().isConnectionFailed()) {
        status = "failed.";
        oneFailed = true;
      } else if (host.isConnected()) {
        status = "connected.";
      } else {
        pending = true;
        status = "connecting...";
      }
      text.append(host.getName() + " " + status + "\n");
    }
    LOG.debug("checkHosts: pending: " + pending + ", one failed: " + oneFailed);
    if (pending) {
      answerPaneSetText(text.toString());
    } else if (oneFailed) {
      printErrorAndRetry(text.toString());
    } else {
      answerPaneSetText(text.toString());
      try {
        Thread.sleep(1000);
      } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
      }

      Tools.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              buttonClass(nextButton()).pressButton();
            }
          });
    }
  }
示例#16
0
 /** Returns text that appears in the corner of the graph. */
 public Subtext getRightCornerTextForGraph(final boolean testOnly) {
   if (getHost().isCommLayerStopping()) {
     return STOPPING_SUBTEXT;
   } else if (getHost().isCommLayerStarting()) {
     return STARTING_SUBTEXT;
   } else if (getHost().isPcmkStarting()) {
     return STARTING_SUBTEXT;
   }
   final ClusterStatus cs = getClusterStatus();
   if (cs != null && cs.isFencedNode(host.getName())) {
     return FENCED_SUBTEXT;
   } else if (getHost().isClStatus()) {
     if (isStandby(testOnly)) {
       return STANDBY_SUBTEXT;
     } else {
       return ONLINE_SUBTEXT;
     }
   } else if (getHost().isConnected()) {
     final Boolean running = getHost().getCorosyncHeartbeatRunning();
     if (running == null) {
       return UNKNOWN_SUBTEXT;
     } else if (!running) {
       return CORO_STOPPED_SUBTEXT;
     }
     if (cs != null && cs.isPendingNode(host.getName())) {
       return PENDING_SUBTEXT;
     } else if (!getHost().isPcmkRunning()) {
       return PCMK_STOPPED_SUBTEXT;
     } else if (cs != null && "no".equals(cs.isOnlineNode(host.getName()))) {
       return OFFLINE_SUBTEXT;
     } else {
       return UNKNOWN_SUBTEXT;
     }
   }
   return null;
 }
示例#17
0
文件: VGCreate.java 项目: rdndnl/lcmc
 /** Returns true if the specified host has specified PVs without VGs. */
 private boolean hostHasPVS(final Host host) {
   final Map<String, BlockDevice> oPVS = new HashMap<String, BlockDevice>();
   for (final BlockDevice bd : host.getPhysicalVolumes()) {
     oPVS.put(bd.getName(), bd);
   }
   final Set<String> pvs = pvCheckBoxes.keySet();
   int selected = 0;
   for (final String pv : pvs) {
     if (!pvCheckBoxes.get(pv).isSelected()) {
       continue;
     }
     selected++;
     final BlockDevice opv = oPVS.get(pv);
     if (opv == null) {
       return false;
     }
     if (!opv.isPhysicalVolume() || opv.isVolumeGroupOnPhysicalVolume()) {
       return false;
     }
   }
   return selected > 0;
 }
示例#18
0
  /** Starts action after cheat was entered. */
  private void startCheat(final String cheat) {
    if (!editEnabled) {
      addCommand(cheat);
    }
    if (!editEnabled && GOD_ON.equals(cheat)) {
      editEnabled = true;
      Tools.getGUIData().godModeChanged(editEnabled);
    } else if (editEnabled && GOD_OFF.equals(cheat)) {
      editEnabled = false;
      Tools.getGUIData().godModeChanged(editEnabled);
    } else if (CHEAT_LIST.equals(cheat)) {
      final StringBuilder list = new StringBuilder();
      for (final String ch : CHEATS_MAP.keySet()) {
        list.append(ch);
        list.append('\n');
      }
      addCommandOutput(list.toString());
    } else if (RUN_GC.equals(cheat)) {
      System.gc();
      Tools.info("run gc");
    } else if (ALLOCATE_10.equals(cheat)) {
      final Thread t =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  Tools.info("allocate mem");
                  Byte[] b = new Byte[1024000];
                  Tools.info("allocate mem done.");

                  System.gc();
                  Tools.info("run gc");
                  Tools.sleep(60000);
                  Tools.info("free mem.");
                }
              });
      t.start();
    } else if (CLICKTEST_SHORT.equals(cheat)) {
      RoboTest.startClicker(1, false);
    } else if (CLICKTEST_LONG.equals(cheat)) {
      RoboTest.startClicker(8 * 60, false);
    } else if (CLICKTEST_LAZY_SHORT.equals(cheat)) {
      RoboTest.startClicker(1, true);
    } else if (CLICKTEST_LAZY_LONG.equals(cheat)) {
      RoboTest.startClicker(8 * 60, true); /* 8 hours */
    } else if (RIGHT_CLICKTEST_SHORT.equals(cheat)) {
      RoboTest.startRightClicker(1, false);
    } else if (RIGHT_CLICKTEST_LONG.equals(cheat)) {
      RoboTest.startRightClicker(8 * 60, false);
    } else if (RIGHT_CLICKTEST_LAZY_SHORT.equals(cheat)) {
      RoboTest.startRightClicker(1, true);
    } else if (RIGHT_CLICKTEST_LAZY_LONG.equals(cheat)) {
      RoboTest.startRightClicker(8 * 60, true); /* 8 hours */
    } else if (MOVETEST_SHORT.equals(cheat)) {
      RoboTest.startMover(1, false);
    } else if (MOVETEST_LONG.equals(cheat)) {
      RoboTest.startMover(8 * 60, false);
    } else if (MOVETEST_LAZY_SHORT.equals(cheat)) {
      RoboTest.startMover(1, true);
    } else if (MOVETEST_LAZY_LONG.equals(cheat)) {
      RoboTest.startMover(8 * 60, true);
    } else if (DEBUG_INC.equals(cheat)) {
      Tools.incrementDebugLevel();
    } else if (DEBUG_DEC.equals(cheat)) {
      Tools.decrementDebugLevel();
    } else if (TESTS.containsKey(cheat)) {
      RoboTest.startTest(TESTS.get(cheat), host.getCluster());
    } else if (REGISTER_MOVEMENT.equals(cheat)) {
      RoboTest.registerMovement();
    }
    nextCommand();
  }
示例#19
0
文件: LVResize.java 项目: npk/lcmc
  /** Returns the input pane. */
  protected JComponent getInputPane() {
    resizeButton.setEnabled(false);
    final JPanel pane = new JPanel(new SpringLayout());
    final JPanel inputPane = new JPanel(new SpringLayout());
    inputPane.setBackground(Browser.BUTTON_PANEL_BACKGROUND);
    /* old size */
    final JLabel oldSizeLabel = new JLabel("Current Size");
    oldSizeLabel.setEnabled(false);

    final String oldBlockSize = blockDevInfo.getBlockDevice().getBlockSize();
    oldSizeWi =
        new TextfieldWithUnit(
            Tools.convertKilobytes(oldBlockSize),
            getUnits(),
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    oldSizeWi.setEnabled(false);
    inputPane.add(oldSizeLabel);
    inputPane.add(oldSizeWi);
    inputPane.add(new JLabel());

    final String maxBlockSize = getMaxBlockSize();
    /* size */
    final String newBlockSize =
        Long.toString((Long.parseLong(oldBlockSize) + Long.parseLong(maxBlockSize)) / 2);
    final JLabel sizeLabel = new JLabel("New Size");

    sizeWi =
        new TextfieldWithUnit(
            Tools.convertKilobytes(newBlockSize),
            getUnits(),
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    inputPane.add(sizeLabel);
    inputPane.add(sizeWi);
    resizeButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (checkDRBD()) {
                          Tools.invokeAndWait(new EnableResizeRunnable(false));
                          disableComponents();
                          getProgressBar().start(RESIZE_TIMEOUT * hostCheckBoxes.size());
                          final boolean ret = resize(sizeWi.getStringValue());
                          final Host host = blockDevInfo.getHost();
                          host.getBrowser().getClusterBrowser().updateHWInfo(host);
                          setComboBoxes();
                          if (ret) {
                            progressBarDone();
                          } else {
                            progressBarDoneError();
                          }
                          enableComponents();
                        }
                      }
                    });
            thread.start();
          }
        });

    inputPane.add(resizeButton);
    /* max size */
    final JLabel maxSizeLabel = new JLabel("Max Size");
    maxSizeLabel.setEnabled(false);
    maxSizeWi =
        new TextfieldWithUnit(
            Tools.convertKilobytes(maxBlockSize),
            getUnits(),
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    maxSizeWi.setEnabled(false);
    inputPane.add(maxSizeLabel);
    inputPane.add(maxSizeWi);
    inputPane.add(new JLabel());
    sizeWi.addListeners(
        new WidgetListener() {
          @Override
          public void check(final Object value) {
            checkButtons();
          }
        });

    SpringUtilities.makeCompactGrid(
        inputPane, 3, 3, /* rows, cols */ 1, 1, /* initX, initY */ 1, 1); /* xPad, yPad */

    pane.add(inputPane);
    final JPanel hostsPane = new JPanel(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
    final Cluster cluster = blockDevInfo.getHost().getCluster();
    hostCheckBoxes = Tools.getHostCheckBoxes(cluster);
    hostsPane.add(new JLabel("Select Hosts: "));
    final Host host = blockDevInfo.getHost();
    final String lv = blockDevInfo.getBlockDevice().getLogicalVolume();
    for (final Host h : hostCheckBoxes.keySet()) {
      final Set<String> allLVS = h.getAllLogicalVolumes();
      hostCheckBoxes
          .get(h)
          .addItemListener(
              new ItemListener() {
                @Override
                public void itemStateChanged(final ItemEvent e) {
                  checkButtons();
                }
              });
      if (host == h) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(true);
      } else if (blockDevInfo.getBlockDevice().isDrbd()
          && blockDevInfo.getOtherBlockDevInfo().getHost() == h) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(true);
      } else if (!blockDevInfo.getBlockDevice().isDrbd() && !allLVS.contains(lv)) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(false);
      } else {
        hostCheckBoxes.get(h).setEnabled(true);
        hostCheckBoxes.get(h).setSelected(false);
      }
      hostsPane.add(hostCheckBoxes.get(h));
    }
    final javax.swing.JScrollPane sp = new javax.swing.JScrollPane(hostsPane);
    sp.setPreferredSize(new java.awt.Dimension(0, 45));
    pane.add(sp);
    pane.add(getProgressBarPane(null));
    pane.add(getAnswerPane(""));
    SpringUtilities.makeCompactGrid(
        pane, 4, 1, /* rows, cols */ 0, 0, /* initX, initY */ 0, 0); /* xPad, yPad */
    checkButtons();
    return pane;
  }
示例#20
0
 /**
  * Compares this host info name with specified hostinfo's name.
  *
  * @param otherHI other host info
  * @return true if they are equal
  */
 boolean equals(final HostInfo otherHI) {
   if (otherHI == null) {
     return false;
   }
   return otherHI.toString().equals(host.getName());
 }
示例#21
0
 /** Prepares a new <code>HostInfo</code> object. */
 public HostInfo(final Host host, final Browser browser) {
   super(host.getName(), browser);
   this.host = host;
 }
示例#22
0
文件: VGCreate.java 项目: rdndnl/lcmc
  /** Returns the input pane. */
  @Override
  protected JComponent getInputPane() {
    createButton.setEnabled(false);
    final JPanel pane = new JPanel(new SpringLayout());
    /* vg name */
    final JPanel inputPane = new JPanel(new SpringLayout());
    inputPane.setBackground(Browser.BUTTON_PANEL_BACKGROUND);

    /* find next free group volume name */
    String defaultName;
    final Set<String> volumeGroups = host.getVolumeGroupNames();
    int i = 0;
    while (true) {
      defaultName = "vg" + String.format("%02d", i);
      if (volumeGroups == null || !volumeGroups.contains(defaultName)) {
        break;
      }
      i++;
    }
    vgNameWi =
        WidgetFactory.createInstance(
            Widget.Type.TEXTFIELD,
            defaultName,
            Widget.NO_ITEMS,
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    inputPane.add(new JLabel("VG Name"));
    inputPane.add(vgNameWi);

    createButton.addActionListener(new CreateActionListener());
    inputPane.add(createButton);
    SpringUtilities.makeCompactGrid(
        inputPane, 1, 3, /* rows, cols */ 1, 1, /* initX, initY */ 1, 1); /* xPad, yPad */

    pane.add(inputPane);
    /* Volume groups. */
    final JPanel pvsPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    final Set<String> selectedPVs = new HashSet<String>();
    final Set<Host> selectedHosts = new HashSet<Host>();
    for (final BlockDevInfo sbdi : selectedBlockDevInfos) {
      if (sbdi.getBlockDevice().isDrbd()) {
        selectedPVs.add(sbdi.getBlockDevice().getDrbdBlockDevice().getName());
      } else {
        selectedPVs.add(sbdi.getName());
      }
      selectedHosts.add(sbdi.getHost());
    }
    pvCheckBoxes = getPVCheckBoxes(selectedPVs);
    pvsPane.add(new JLabel("Select physical volumes: "));
    for (final String pvName : pvCheckBoxes.keySet()) {
      pvCheckBoxes.get(pvName).addItemListener(new ItemChangeListener(true));
      pvsPane.add(pvCheckBoxes.get(pvName));
    }
    final JScrollPane pvSP = new JScrollPane(pvsPane);
    pvSP.setPreferredSize(new Dimension(0, 45));
    pane.add(pvSP);

    final JPanel hostsPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    final Cluster cluster = host.getCluster();
    hostCheckBoxes = Tools.getHostCheckBoxes(cluster);
    hostsPane.add(new JLabel("Select Hosts: "));
    for (final Host h : hostCheckBoxes.keySet()) {
      hostCheckBoxes.get(h).addItemListener(new ItemChangeListener(true));
      if (host == h) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(true);
      } else if (isOneDrbd(selectedBlockDevInfos)) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(false);
      } else if (hostHasPVS(h)) {
        hostCheckBoxes.get(h).setEnabled(true);
        hostCheckBoxes.get(h).setSelected(selectedHosts.contains(h));
      } else {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(false);
      }
      hostsPane.add(hostCheckBoxes.get(h));
    }
    final JScrollPane sp = new JScrollPane(hostsPane);
    sp.setPreferredSize(new Dimension(0, 45));
    pane.add(sp);
    pane.add(getProgressBarPane(null));
    pane.add(getAnswerPane(""));
    SpringUtilities.makeCompactGrid(
        pane, 5, 1, /* rows, cols */ 0, 0, /* initX, initY */ 0, 0); /* xPad, yPad */
    checkButtons();
    return pane;
  }
示例#23
0
  /** Returns info panel. */
  @Override
  public JComponent getInfoPanel() {
    if (getBrowser().getClusterBrowser() == null) {
      return new JPanel();
    }
    final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(12));
    crmShowInProgress = true;
    final JTextArea ta = new JTextArea(Tools.getString("HostInfo.crmShellLoading"));
    ta.setEditable(false);
    ta.setFont(f);

    final MyButton crmConfigureCommitButton =
        new MyButton(Tools.getString("HostInfo.crmShellCommitButton"), Browser.APPLY_ICON);
    registerComponentEnableAccessMode(
        crmConfigureCommitButton, new AccessMode(ConfigData.AccessType.ADMIN, false));
    final MyButton hostInfoButton = new MyButton(Tools.getString("HostInfo.crmShellStatusButton"));
    hostInfoButton.miniButton();

    final MyButton crmConfigureShowButton =
        new MyButton(Tools.getString("HostInfo.crmShellShowButton"));
    crmConfigureShowButton.miniButton();
    crmConfigureCommitButton.setEnabled(false);
    final ExecCallback execCallback =
        new ExecCallback() {
          @Override
          public void done(final String ans) {
            ta.setText(ans);
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    crmConfigureShowButton.setEnabled(true);
                    hostInfoButton.setEnabled(true);
                    crmShowInProgress = false;
                  }
                });
          }

          @Override
          public void doneError(final String ans, final int exitCode) {
            ta.setText(ans);
            Tools.sshError(host, "", ans, "", exitCode);
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    crmConfigureCommitButton.setEnabled(false);
                  }
                });
          }
        };
    hostInfoButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            registerComponentEditAccessMode(ta, new AccessMode(ConfigData.AccessType.GOD, false));
            crmInfo = true;
            hostInfoButton.setEnabled(false);
            crmConfigureCommitButton.setEnabled(false);
            String command = "HostBrowser.getHostInfo";
            if (!host.isCsInit()) {
              command = "HostBrowser.getHostInfoHeartbeat";
            }
            host.execCommand(
                command,
                execCallback,
                null, /* ConvertCmdCallback */
                false, /* outputVisible */
                SSH.DEFAULT_COMMAND_TIMEOUT);
          }
        });
    host.registerEnableOnConnect(hostInfoButton);

    crmConfigureShowButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            registerComponentEditAccessMode(ta, new AccessMode(ConfigData.AccessType.ADMIN, false));
            updateAdvancedPanels();
            crmShowInProgress = true;
            crmInfo = false;
            crmConfigureShowButton.setEnabled(false);
            crmConfigureCommitButton.setEnabled(false);
            host.execCommand(
                "HostBrowser.getCrmConfigureShow",
                execCallback,
                null, /* ConvertCmdCallback */
                false, /* outputVisible */
                SSH.DEFAULT_COMMAND_TIMEOUT);
          }
        });
    final CRMGraph crmg = getBrowser().getClusterBrowser().getCRMGraph();
    final Document taDocument = ta.getDocument();
    taDocument.addDocumentListener(
        new DocumentListener() {
          private void update() {
            if (!crmShowInProgress && !crmInfo) {
              crmConfigureCommitButton.setEnabled(true);
            }
          }

          public void changedUpdate(final DocumentEvent documentEvent) {
            update();
          }

          public void insertUpdate(final DocumentEvent documentEvent) {
            update();
          }

          public void removeUpdate(final DocumentEvent documentEvent) {
            update();
          }
        });

    final ButtonCallback buttonCallback =
        new ButtonCallback() {
          private volatile boolean mouseStillOver = false;

          /** Whether the whole thing should be enabled. */
          @Override
          public boolean isEnabled() {
            if (Tools.versionBeforePacemaker(host)) {
              return false;
            }
            return true;
          }

          @Override
          public void mouseOut() {
            if (!isEnabled()) {
              return;
            }
            mouseStillOver = false;
            crmg.stopTestAnimation(crmConfigureCommitButton);
            crmConfigureCommitButton.setToolTipText(null);
          }

          @Override
          public void mouseOver() {
            if (!isEnabled()) {
              return;
            }
            mouseStillOver = true;
            crmConfigureCommitButton.setToolTipText(ClusterBrowser.STARTING_PTEST_TOOLTIP);
            crmConfigureCommitButton.setToolTipBackground(
                Tools.getDefaultColor("ClusterBrowser.Test.Tooltip.Background"));
            Tools.sleep(250);
            if (!mouseStillOver) {
              return;
            }
            mouseStillOver = false;
            final CountDownLatch startTestLatch = new CountDownLatch(1);
            crmg.startTestAnimation(crmConfigureCommitButton, startTestLatch);
            final Host dcHost = getBrowser().getClusterBrowser().getDCHost();
            getBrowser().getClusterBrowser().ptestLockAcquire();
            final ClusterStatus clStatus = getBrowser().getClusterBrowser().getClusterStatus();
            clStatus.setPtestData(null);
            CRM.crmConfigureCommit(host, ta.getText(), true);
            final PtestData ptestData = new PtestData(CRM.getPtest(dcHost));
            crmConfigureCommitButton.setToolTipText(ptestData.getToolTip());
            clStatus.setPtestData(ptestData);
            getBrowser().getClusterBrowser().ptestLockRelease();
            startTestLatch.countDown();
          }
        };
    addMouseOverListener(crmConfigureCommitButton, buttonCallback);
    crmConfigureCommitButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            crmConfigureCommitButton.setEnabled(false);
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        getBrowser().getClusterBrowser().clStatusLock();
                        final String ret = CRM.crmConfigureCommit(host, ta.getText(), false);
                        getBrowser().getClusterBrowser().clStatusUnlock();
                      }
                    });
            thread.start();
          }
        });

    final JPanel mainPanel = new JPanel();
    mainPanel.setBackground(HostBrowser.PANEL_BACKGROUND);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    final JPanel buttonPanel = new JPanel(new BorderLayout());
    buttonPanel.setBackground(HostBrowser.BUTTON_PANEL_BACKGROUND);
    buttonPanel.setMinimumSize(new Dimension(0, 50));
    buttonPanel.setPreferredSize(new Dimension(0, 50));
    buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 50));
    mainPanel.add(buttonPanel);

    /* Actions */
    buttonPanel.add(getActionsButton(), BorderLayout.EAST);
    final JPanel p = new JPanel(new SpringLayout());
    p.setBackground(HostBrowser.BUTTON_PANEL_BACKGROUND);

    p.add(hostInfoButton);
    p.add(crmConfigureShowButton);
    p.add(crmConfigureCommitButton);

    p.add(new JLabel(""));
    SpringUtilities.makeCompactGrid(
        p, 1, 3, // rows, cols
        1, 1, // initX, initY
        1, 1); // xPad, yPad
    mainPanel.setMinimumSize(
        new Dimension(
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Width"),
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Height")));
    mainPanel.setPreferredSize(
        new Dimension(
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Width"),
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Height")));
    buttonPanel.add(p);
    mainPanel.add(new JLabel(Tools.getString("HostInfo.crmShellInfo")));
    mainPanel.add(new JScrollPane(ta));
    String command = "HostBrowser.getHostInfo";
    if (!host.isCsInit()) {
      command = "HostBrowser.getHostInfoHeartbeat";
    }
    host.execCommand(
        command,
        execCallback,
        null, /* ConvertCmdCallback */
        false, /* outputVisible */
        SSH.DEFAULT_COMMAND_TIMEOUT);
    return mainPanel;
  }
示例#24
0
  /** Prepares a new <code>TerminalPanel</code> object. */
  public TerminalPanel(final Host host) {
    super();
    this.host = host;
    host.setTerminalPanel(this);
    /* Sets terminal some of the output colors. This is in no way complete
     * or correct and probably doesn't have to be. */
    terminalColor.put("0", Tools.getDefaultColor("TerminalPanel.TerminalWhite"));
    terminalColor.put("30", Tools.getDefaultColor("TerminalPanel.TerminalBlack"));
    terminalColor.put("31", Tools.getDefaultColor("TerminalPanel.TerminalRed"));
    terminalColor.put("32", Tools.getDefaultColor("TerminalPanel.TerminalGreen"));
    terminalColor.put("33", Tools.getDefaultColor("TerminalPanel.TerminalYellow"));
    terminalColor.put("34", Tools.getDefaultColor("TerminalPanel.TerminalBlue"));
    terminalColor.put("35", Tools.getDefaultColor("TerminalPanel.TerminalPurple"));
    terminalColor.put("36", Tools.getDefaultColor("TerminalPanel.TerminalCyan"));
    final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(14));
    terminalArea = new JTextPane();
    terminalArea.setStyledDocument(new MyDocument());
    final DefaultCaret caret =
        new DefaultCaret() {
          private static final long serialVersionUID = 1L;

          @Override
          protected synchronized void damage(final Rectangle r) {
            if (r != null) {
              x = r.x;
              y = r.y;
              width = 8;
              height = r.height;
              repaint();
            }
          }

          @Override
          public void paint(final Graphics g) {
            /* painting cursor. If it is not visible it is out of focus, we
             * make it barely visible. */
            try {
              TextUI mapper = getComponent().getUI();
              Rectangle r = mapper.modelToView(getComponent(), getDot(), getDotBias());
              if (r == null) {
                return;
              }
              g.setColor(getComponent().getCaretColor());
              if (isVisible() && editEnabled) {
                g.fillRect(r.x, r.y, 8, r.height);
              } else {
                g.drawRect(r.x, r.y, 8, r.height);
              }
            } catch (BadLocationException e) {
              Tools.appError("Drawing of cursor failed", e);
            }
          }
        };
    terminalArea.setCaret(caret);
    terminalArea.addCaretListener(
        new CaretListener() {
          @Override
          public void caretUpdate(final CaretEvent e) {
            /* don't do this if caret moved because of selection */
            mPosLock.lock();
            try {
              if (e != null && e.getDot() < commandOffset && e.getDot() == e.getMark()) {
                terminalArea.setCaretPosition(commandOffset);
              }
            } finally {
              mPosLock.unlock();
            }
          }
        });

    /* set font and colors */
    terminalArea.setFont(f);
    terminalArea.setBackground(Tools.getDefaultColor("TerminalPanel.Background"));

    commandColor = new SimpleAttributeSet();
    StyleConstants.setForeground(commandColor, Tools.getDefaultColor("TerminalPanel.Command"));

    errorColor = new SimpleAttributeSet();
    StyleConstants.setForeground(errorColor, Tools.getDefaultColor("TerminalPanel.Error"));

    outputColor = new SimpleAttributeSet();
    defaultOutputColor = Tools.getDefaultColor("TerminalPanel.Output");
    StyleConstants.setForeground(outputColor, defaultOutputColor);

    promptColor = new SimpleAttributeSet();
    StyleConstants.setForeground(promptColor, host.getPmColors()[0]);

    append(prompt(), promptColor);
    terminalArea.setEditable(true);
    getViewport().add(terminalArea, BorderLayout.PAGE_END);
    setPreferredSize(
        new Dimension(Short.MAX_VALUE, Tools.getDefaultInt("MainPanel.TerminalPanelHeight")));
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
  }
示例#25
0
 /** Returns name of the host. */
 @Override
 public String getName() {
   return host.getName();
 }
示例#26
0
 /** Sets the prompt color to the host's color when it is added to the cluster. */
 public void resetPromptColor() {
   StyleConstants.setForeground(promptColor, host.getPmColors()[0]);
   addCommand("");
   nextCommand();
 }