Exemplo n.º 1
0
 /** 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;
 }
Exemplo n.º 2
0
 /** Updates parameters. */
 @Override
 void updateParameters() {
   final Map<String, DiskData> disks = getVMSVirtualDomainInfo().getDisks();
   if (disks != null) {
     final DiskData diskData = disks.get(getName());
     if (diskData != null) {
       for (final String param : getParametersFromXML()) {
         final String oldValue = getParamSaved(param);
         String value = getParamSaved(param);
         final Widget wi = getWidget(param, null);
         for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
           final VMSXML vmsxml = getBrowser().getVMSXML(h);
           if (vmsxml != null) {
             final String savedValue = diskData.getValue(param);
             if (savedValue != null) {
               value = savedValue;
             }
           }
         }
         if (!Tools.areEqual(value, oldValue)) {
           getResource().setValue(param, value);
           if (wi != null) {
             /* only if it is not changed by user. */
             wi.setValue(value);
           }
         }
       }
     }
   }
   updateTable(VMSVirtualDomainInfo.HEADER_TABLE);
   updateTable(VMSVirtualDomainInfo.DISK_TABLE);
   // checkResourceFieldsChanged(null, getParametersFromXML());
   setApplyButtons(null, getRealParametersFromXML());
 }
Exemplo n.º 3
0
 /** 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));
 }
Exemplo n.º 4
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);
    }
  }
Exemplo n.º 5
0
  /**
   * Add listener to the field. The checkFields(field) will be called on every insert, update and
   * remove event.
   */
  protected final void addCheckField(final Widget field) {
    field
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              @Override
              public void insertUpdate(final DocumentEvent e) {
                final Thread t =
                    new Thread(
                        new Runnable() {
                          @Override
                          public void run() {
                            checkFields(field);
                          }
                        });
                t.start();
              }

              @Override
              public void removeUpdate(final DocumentEvent e) {
                final Thread t =
                    new Thread(
                        new Runnable() {
                          @Override
                          public void run() {
                            checkFields(field);
                          }
                        });
                t.start();
              }

              @Override
              public void changedUpdate(final DocumentEvent e) {
                final Thread t =
                    new Thread(
                        new Runnable() {
                          @Override
                          public void run() {
                            checkFields(field);
                          }
                        });
                t.start();
              }
            });
  }
Exemplo n.º 6
0
  /** 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;
  }
Exemplo n.º 7
0
 /** Returns combo box for parameter. */
 @Override
 protected Widget createWidget(final String param, final String prefix, final int width) {
   String prefixS;
   if (prefix == null) {
     prefixS = "";
   } else {
     prefixS = prefix;
   }
   if (DiskData.SOURCE_FILE.equals(param)) {
     final String sourceFile = getParamSaved(DiskData.SOURCE_FILE);
     final String regexp = ".*[^/]$";
     final MyButton fileChooserBtn = new MyButton("Browse...");
     fileChooserBtn.miniButton();
     final Widget paramWi =
         WidgetFactory.createInstance(
             getFieldType(param),
             sourceFile,
             getParamPossibleChoices(param),
             regexp,
             width,
             Widget.NO_ABBRV,
             new AccessMode(getAccessType(param), false), /* only adv. mode */
             fileChooserBtn);
     paramWi.setAlwaysEditable(true);
     sourceFileWi.put(prefixS, paramWi);
     if (Tools.isWindows()) {
       /* does not work on windows and I tried, ultimately because
          FilePane.usesShellFolder(fc) in BasicFileChooserUI returns
          true and it is not possible to descent into a directory.
          TODO: It may work in the future.
       */
       paramWi.setTFButtonEnabled(false);
     }
     fileChooserBtn.addActionListener(
         new ActionListener() {
           @Override
           public void actionPerformed(final ActionEvent e) {
             final Thread t =
                 new Thread(
                     new Runnable() {
                       @Override
                       public void run() {
                         String file;
                         final String oldFile = paramWi.getStringValue();
                         if (oldFile == null || "".equals(oldFile)) {
                           file = LIBVIRT_IMAGE_LOCATION;
                         } else {
                           file = oldFile;
                         }
                         startFileChooser(paramWi, file, FILECHOOSER_FILE_ONLY);
                       }
                     });
             t.start();
           }
         });
     widgetAdd(param, prefix, paramWi);
     return paramWi;
   } else {
     final Widget paramWi = super.createWidget(param, prefix, width);
     if (DiskData.TYPE.equals(param) || DiskData.TARGET_BUS_TYPE.equals(param)) {
       paramWi.setAlwaysEditable(false);
     } else if (DiskData.SOURCE_DEVICE.equals(param)) {
       paramWi.setAlwaysEditable(true);
       sourceDeviceWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_NAME.equals(param)) {
       sourceNameWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_PROTOCOL.equals(param)) {
       sourceProtocolWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_HOST_NAME.equals(param)) {
       sourceHostNameWi.put(prefixS, paramWi);
     } else if (DiskData.SOURCE_HOST_PORT.equals(param)) {
       sourceHostPortWi.put(prefixS, paramWi);
     } else if (DiskData.AUTH_USERNAME.equals(param)) {
       authUsernameWi.put(prefixS, paramWi);
     } else if (DiskData.AUTH_SECRET_TYPE.equals(param)) {
       authSecretTypeWi.put(prefixS, paramWi);
     } else if (DiskData.AUTH_SECRET_UUID.equals(param)) {
       authSecretUuidWi.put(prefixS, paramWi);
     } else if (DiskData.TARGET_DEVICE.equals(param)) {
       paramWi.setAlwaysEditable(true);
       targetDeviceWi.put(prefixS, paramWi);
     } else if (DiskData.DRIVER_NAME.equals(param)) {
       driverNameWi.put(prefixS, paramWi);
     } else if (DiskData.DRIVER_TYPE.equals(param)) {
       driverTypeWi.put(prefixS, paramWi);
     } else if (DiskData.DRIVER_CACHE.equals(param)) {
       driverCacheWi.put(prefixS, paramWi);
     } else if (DiskData.READONLY.equals(param)) {
       readonlyWi.put(prefixS, paramWi);
     }
     return paramWi;
   }
 }