示例#1
0
文件: LVResize.java 项目: npk/lcmc
 /** Check if it is DRBD device and if it could be resized. */
 private boolean checkDRBD() {
   if (blockDevInfo.getBlockDevice().isDrbd()) {
     final DrbdVolumeInfo dvi = blockDevInfo.getDrbdVolumeInfo();
     final BlockDevInfo oBDI = blockDevInfo.getOtherBlockDevInfo();
     if (!dvi.isConnected(false)) {
       printErrorAndRetry("Not resizing. DRBD resource is not connected.");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (dvi.isSyncing()) {
       printErrorAndRetry("Not resizing. DRBD resource is syncing.");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (!oBDI.getBlockDevice().isAttached()) {
       printErrorAndRetry(
           "Not resizing. DRBD resource is not attached on " + oBDI.getHost() + ".");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (!blockDevInfo.getBlockDevice().isAttached()) {
       printErrorAndRetry(
           "Not resizing. DRBD resource is not attached on " + blockDevInfo.getHost() + ".");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (!oBDI.getBlockDevice().isPrimary() && !blockDevInfo.getBlockDevice().isPrimary()) {
       printErrorAndRetry("Not resizing. Must be primary at least on one node.");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     }
   }
   return true;
 }
示例#2
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;
  }
示例#3
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;
 }
示例#4
0
文件: LVResize.java 项目: npk/lcmc
 /** Set combo boxes with new values. */
 private void setComboBoxes() {
   final String oldBlockSize = blockDevInfo.getBlockDevice().getBlockSize();
   final String maxBlockSize = getMaxBlockSize();
   oldSizeWi.setValue(Tools.convertKilobytes(oldBlockSize));
   sizeWi.setValue(
       Tools.convertKilobytes(
           Long.toString((Long.parseLong(oldBlockSize) + Long.parseLong(maxBlockSize)) / 2)));
   maxSizeWi.setValue(Tools.convertKilobytes(maxBlockSize));
 }
示例#5
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;
  }
示例#6
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;
 }
示例#7
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;
  }