Пример #1
0
  /**
   * Creates body of the dialog. You can redefine getDialogTitle(), getDescription(), getInputPane()
   * methods to customize this body.
   */
  protected final JPanel body() {
    final JPanel pane = new JPanel();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    final JEditorPane descPane =
        new JEditorPane(
            Tools.MIME_TYPE_TEXT_HTML,
            "<span style='font:bold italic;font-family:Dialog; font-size:"
                + Tools.getConfigData().scaled(14)
                + ";'>"
                + getDialogTitle()
                + "</span><br>"
                + "<span style='font-family:Dialog; font-size:"
                + Tools.getConfigData().scaled(12)
                + ";'>"
                + getDescription()
                + "</span>");
    descPane.setSize(300, Integer.MAX_VALUE);

    descPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
    descPane.setEditable(false);
    final JScrollPane descSP = new JScrollPane(descPane);
    descSP.setBorder(null);
    descSP.setAlignmentX(Component.LEFT_ALIGNMENT);
    descSP.setMinimumSize(new Dimension(0, 50));
    pane.add(descSP);
    final JComponent inputPane = getInputPane();
    if (inputPane != null) {
      inputPane.setMinimumSize(new Dimension(Short.MAX_VALUE, INPUT_PANE_HEIGHT));
      inputPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
      inputPane.setAlignmentX(Component.LEFT_ALIGNMENT);
      pane.add(inputPane);
    }
    pane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
    return pane;
  }
Пример #2
0
  /** Loads info from xml that is supplied as an argument to the internal data objects. */
  public void loadXML(final String xml) {
    final Document document = getXMLDocument(xml);
    if (document == null) {
      return;
    }
    /* get root <drbdgui> */
    final Node rootNode = getChildNode(document, "drbdgui");
    final Map<String, List<Host>> hostMap = new LinkedHashMap<String, List<Host>>();
    if (rootNode != null) {
      /* download area */
      final String downloadUser = getAttribute(rootNode, DOWNLOAD_USER_ATTR);
      final String downloadPasswd = getAttribute(rootNode, DOWNLOAD_PASSWD_ATTR);
      if (downloadUser != null && downloadPasswd != null) {
        Tools.getConfigData().setDownloadLogin(downloadUser, downloadPasswd, true);
      }
      /* hosts */
      final Node hostsNode = getChildNode(rootNode, "hosts");
      if (hostsNode != null) {
        final NodeList hosts = hostsNode.getChildNodes();
        if (hosts != null) {
          for (int i = 0; i < hosts.getLength(); i++) {
            final Node hostNode = hosts.item(i);
            if (hostNode.getNodeName().equals(HOST_NODE_STRING)) {
              final String nodeName = getAttribute(hostNode, HOST_NAME_ATTR);
              final String sshPort = getAttribute(hostNode, HOST_SSHPORT_ATTR);
              final String color = getAttribute(hostNode, HOST_COLOR_ATTR);
              final String useSudo = getAttribute(hostNode, HOST_USESUDO_ATTR);
              final Node ipNode = getChildNode(hostNode, "ip");
              String ip = null;
              if (ipNode != null) {
                ip = getText(ipNode);
              }
              final Node usernameNode = getChildNode(hostNode, "user");
              final String username = getText(usernameNode);
              setHost(
                  hostMap, username, nodeName, ip, sshPort, color, "true".equals(useSudo), true);
            }
          }
        }
      }

      /* clusters */
      final Node clustersNode = getChildNode(rootNode, "clusters");
      if (clustersNode != null) {
        final NodeList clusters = clustersNode.getChildNodes();
        if (clusters != null) {
          for (int i = 0; i < clusters.getLength(); i++) {
            final Node clusterNode = clusters.item(i);
            if (clusterNode.getNodeName().equals("cluster")) {
              final String clusterName = getAttribute(clusterNode, CLUSTER_NAME_ATTR);
              final Cluster cluster = new Cluster();
              cluster.setName(clusterName);
              Tools.getConfigData().addClusterToClusters(cluster);
              loadClusterHosts(clusterNode, cluster, hostMap);
            }
          }
        }
      }
    }
  }
Пример #3
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);
    }
  }
Пример #4
0
  static void start(final int count) {
    slowFactor = 0.5f;
    aborted = false;
    final int gx = 235;
    final int gy = 207;
    disableStonith();
    for (int i = count; i > 0; i--) {
      if (i % 5 == 0) {
        info("testA I: " + i);
      }
      checkTest("testA", 1);
      /* group with dummy resources */
      moveTo(gx, gy);
      sleep(1000);
      rightClick(); /* popup */
      sleep(1000);
      moveTo(Tools.getString("ClusterBrowser.Hb.AddGroup"));
      leftClick();
      sleep(3000);
      /* create dummy */
      moveTo(gx + 46, gy + 11);
      rightClick(); /* group popup */
      sleep(2000);
      moveTo(Tools.getString("ClusterBrowser.Hb.AddGroupService"));
      sleep(1000);
      moveTo("OCF Resource Agents");
      sleep(1000);
      typeDummy();
      sleep(300);
      setTimeouts(true);
      moveTo(Tools.getString("Browser.ApplyResource"));
      sleep(6000);
      leftClick();
      sleep(6000);
      checkTest("testA", 2);
      stopResource(gx, gy);
      sleep(6000);
      checkTest("testA", 3);

      /* copy/paste */
      moveTo(gx + 10, gy + 10);
      leftClick();
      robot.keyPress(KeyEvent.VK_CONTROL);
      press(KeyEvent.VK_C);
      press(KeyEvent.VK_V);
      robot.keyRelease(KeyEvent.VK_CONTROL);
      moveTo(gx + 10, gy + 90);
      leftClick();
      moveTo(Tools.getString("Browser.ApplyGroup"));
      sleep(4000);
      leftClick();
      checkTest("testA", 4);

      removeResource(gx, gy, CONFIRM_REMOVE);
      removeResource(gx, gy + 90, CONFIRM_REMOVE);
      resetTerminalAreas();
    }
    System.gc();
  }
Пример #5
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));
 }
Пример #6
0
 /** Returns device parameters. */
 @Override
 protected Map<String, String> getHWParameters(final boolean allParams) {
   Tools.invokeAndWait(
       new Runnable() {
         @Override
         public void run() {
           getInfoPanel();
         }
       });
   final String[] params = getRealParametersFromXML();
   final Map<String, String> parameters = new LinkedHashMap<String, String>();
   for (final String param : params) {
     final String value = getComboBoxValue(param);
     if (DiskData.TYPE.equals(param)) {
       parameters.put(param, value);
     } else if (DiskData.TARGET_BUS_TYPE.equals(param)) {
       if (value == null) {
         parameters.put(DiskData.TARGET_BUS, null);
         parameters.put(DiskData.TARGET_TYPE, null);
       } else {
         final String[] values = value.split("/");
         if (values.length == 2) {
           parameters.put(DiskData.TARGET_BUS, values[0]);
           parameters.put(DiskData.TARGET_TYPE, values[1]);
         } else {
           LOG.appWarning("getHWParameters: cannot parse: " + param + " = " + value);
         }
       }
     } else if (allParams) {
       if (Tools.areEqual(getParamDefault(param), value)) {
         parameters.put(param, null);
       } else {
         parameters.put(param, value);
       }
     } else if (!Tools.areEqual(getParamSaved(param), value)
         || DiskData.SOURCE_FILE.equals(param)
         || DiskData.SOURCE_DEVICE.equals(param)
         || DiskData.SOURCE_PROTOCOL.equals(param)
         || DiskData.SOURCE_NAME.equals(param)
         || DiskData.SOURCE_HOST_NAME.equals(param)
         || DiskData.SOURCE_HOST_PORT.equals(param)
         || DiskData.AUTH_USERNAME.equals(param)
         || DiskData.AUTH_SECRET_TYPE.equals(param)
         || DiskData.AUTH_SECRET_UUID.equals(param)) {
       if (Tools.areEqual(getParamDefault(param), value)) {
         parameters.put(param, null);
       } else {
         parameters.put(param, value);
       }
     }
   }
   parameters.put(DiskData.SAVED_TARGET_DEVICE, getName());
   setName(getParamSaved(DiskData.TARGET_DEVICE));
   return parameters;
 }
Пример #7
0
  /** Applies the changes. */
  @Override
  void apply(final boolean testOnly) {
    if (testOnly) {
      return;
    }
    Tools.invokeAndWait(
        new Runnable() {
          @Override
          public void run() {
            getApplyButton().setEnabled(false);
            getRevertButton().setEnabled(false);
            getInfoPanel();
          }
        });
    waitForInfoPanel();
    final Map<String, String> parameters = getHWParameters(getResource().isNew());
    final String[] params = getRealParametersFromXML();
    for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
      final VMSXML vmsxml = getBrowser().getVMSXML(h);
      if (vmsxml != null) {
        final String domainName = getVMSVirtualDomainInfo().getDomainName();
        final Node domainNode = vmsxml.getDomainNode(domainName);
        /* fix host ports */

        fixSourceHostParams(parameters);
        final String fixedNames = parameters.get(DiskData.SOURCE_HOST_NAME);
        final String fixedPorts = parameters.get(DiskData.SOURCE_HOST_PORT);

        for (final String p : sourceHostNameWi.keySet()) {
          sourceHostNameWi.get(p).setValueAndWait(fixedNames);
        }
        for (final String p : sourceHostPortWi.keySet()) {
          sourceHostPortWi.get(p).setValueAndWait(fixedPorts);
        }
        modifyXML(vmsxml, domainNode, domainName, parameters);
        final String virshOptions = getVMSVirtualDomainInfo().getVirshOptions();
        vmsxml.saveAndDefine(domainNode, domainName, virshOptions);
      }
    }
    getResource().setNew(false);
    getBrowser().reload(getNode(), false);
    getBrowser().periodicalVMSUpdate(getVMSVirtualDomainInfo().getDefinedOnHosts());
    Tools.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            tablePanel.setVisible(true);
          }
        });
    if (!testOnly) {
      storeComboBoxValues(params);
    }
    checkResourceFieldsChanged(null, params);
  }
Пример #8
0
 /** Prepares a new <code>CusterBrowser</code> object. */
 EmptyBrowser() {
   super();
   /* Load the default file */
   final String saveFile = Tools.getConfigData().getSaveFile();
   String xml = Tools.loadFile(saveFile, false);
   if (xml == null) {
     final String saveFileOld = Tools.getConfigData().getSaveFileOld();
     xml = Tools.loadFile(saveFileOld, false);
   }
   if (xml != null) {
     Tools.loadXML(xml);
   }
   setTreeTop();
 }
Пример #9
0
 /** Inits the dialog after it becomes visible. */
 @Override
 protected void initDialogAfterVisible() {
   final DrbdResourceInfo dri = getDrbdVolumeInfo().getDrbdResourceInfo();
   final boolean ch = dri.checkResourceFieldsChanged(null, PARAMS);
   final boolean cor = dri.checkResourceFieldsCorrect(null, PARAMS);
   if (cor) {
     enableComponents();
   } else {
     /* don't enable */
     enableComponents(new JComponent[] {buttonClass(nextButton())});
   }
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           makeDefaultButton(buttonClass(nextButton()));
         }
       });
   if (Tools.getConfigData().getAutoOptionGlobal("autodrbd") != null) {
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             pressNextButton();
           }
         });
   }
 }
Пример #10
0
 @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);
     }
   }
 }
Пример #11
0
  /** Prepares a new <code>MainPanel</code> object. */
  public MainPanel() {
    super(new BorderLayout());
    // TODO: not new Host() but null
    final TerminalPanel terminalPanel = new TerminalPanel(new Host());
    final JSplitPane splitPane =
        new JSplitPane(JSplitPane.VERTICAL_SPLIT, new ClustersPanel(), terminalPanel);
    Tools.getGUIData().setTerminalSplitPane(splitPane);

    splitPane.setContinuousLayout(true);
    splitPane.setResizeWeight(1);
    splitPane.setOneTouchExpandable(true);

    splitPane.addHierarchyListener(
        new HierarchyListener() {
          public void hierarchyChanged(final HierarchyEvent e) {
            mExpanding.lock();
            if (!expandingDone && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {

              expandingDone = true;
              mExpanding.unlock();
              Tools.getGUIData().expandTerminalSplitPane(1);
            } else {
              mExpanding.unlock();
            }
          }
        });
    add(splitPane, BorderLayout.CENTER);
  }
Пример #12
0
 /**
  * Adds service to this group. Adds it in the submenu in the menu tree and initializes it.
  *
  * @param newServiceInfo service info object of the new service
  */
 void addGroupServicePanel(final ServiceInfo newServiceInfo, final boolean reloadNode) {
   final DefaultMutableTreeNode gn = getNode();
   if (gn == null) {
     return;
   }
   newServiceInfo
       .getService()
       .setResourceClass(newServiceInfo.getResourceAgent().getResourceClass());
   newServiceInfo.setGroupInfo(this);
   getBrowser().addNameToServiceInfoHash(newServiceInfo);
   getBrowser().addToHeartbeatIdList(newServiceInfo);
   final DefaultMutableTreeNode newServiceNode = new DefaultMutableTreeNode(newServiceInfo);
   newServiceInfo.setNode(newServiceNode);
   Tools.invokeLater(
       !Tools.CHECK_SWING_THREAD,
       new Runnable() {
         @Override
         public void run() {
           gn.add(newServiceNode);
           if (reloadNode) {
             getBrowser().reloadAndWait(gn, false);
             getBrowser().reloadAndWait(newServiceNode, true);
           }
         }
       });
 }
Пример #13
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);
  }
Пример #14
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());
 }
Пример #15
0
 /** prints error text in the answer pane, reenables buttons and adds retry button. */
 public final void printErrorAndRetry(String text, final String ans, final int exitCode) {
   if (ans != null) {
     text += "\n" + Tools.getString("Dialog.Dialog.PrintErrorAndRetry") + exitCode + "\n" + ans;
   }
   answerPaneSetTextError(text);
   addRetryButton();
   if (buttonClass(retryButton()) != null) {
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             buttonClass(retryButton()).requestFocus();
           }
         });
   }
   if (buttonClass(nextButton()) != null) {
     enableComponents(new JComponent[] {buttonClass(nextButton())});
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             buttonClass(nextButton()).setEnabled(false);
           }
         });
   }
 }
Пример #16
0
  /** 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;
  }
Пример #17
0
  /** Removes this group from the cib. */
  @Override
  public void removeMyself(final boolean testOnly) {
    if (getService().isNew()) {
      removeMyselfNoConfirm(getBrowser().getDCHost(), testOnly);
      getService().setNew(false);
      super.removeInfo();
      getService().doneRemoving();
      return;
    }
    String desc = Tools.getString("ClusterBrowser.confirmRemoveGroup.Description");

    final StringBuilder services = new StringBuilder();

    @SuppressWarnings("unchecked")
    final Enumeration<DefaultMutableTreeNode> e = getNode().children();
    try {
      while (e.hasMoreElements()) {
        final DefaultMutableTreeNode n = e.nextElement();
        final ServiceInfo child = (ServiceInfo) n.getUserObject();
        services.append(child.toString());
        if (e.hasMoreElements()) {
          services.append(", ");
        }
      }
    } catch (java.util.NoSuchElementException ele) {
      LOG.info("removeMyself: removing aborted");
      return;
    }

    desc = desc.replaceAll("@GROUP@", "'" + Matcher.quoteReplacement(toString()) + "'");
    desc = desc.replaceAll("@SERVICES@", Matcher.quoteReplacement(services.toString()));
    if (Tools.confirmDialog(
        Tools.getString("ClusterBrowser.confirmRemoveGroup.Title"),
        desc,
        Tools.getString("ClusterBrowser.confirmRemoveGroup.Yes"),
        Tools.getString("ClusterBrowser.confirmRemoveGroup.No"))) {
      if (!testOnly) {
        getService().setRemoved(true);
      }
      removeMyselfNoConfirm(getBrowser().getDCHost(), testOnly);
      super.removeInfo();
      getService().setNew(false);
    }
    getService().doneRemoving();
  }
Пример #18
0
 /** Returns panel with checkbox. */
 protected final JPanel getComponentPanel(final String text, final JComponent component) {
   final JPanel mp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
   mp.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
   mp.add(new JLabel(text));
   mp.add(new JLabel(" "));
   mp.add(component);
   mp.setAlignmentX(Component.LEFT_ALIGNMENT);
   return mp;
 }
Пример #19
0
 /** Enables and disabled buttons. */
 protected void checkButtons() {
   boolean enable = true;
   for (final Host h : hostCheckBoxes.keySet()) {
     if (hostCheckBoxes.get(h).isSelected() && !hostHasPVS(h)) {
       enable = false;
       break;
     }
   }
   Tools.invokeLater(new EnableCreateRunnable(enable));
 }
Пример #20
0
    @Override
    public void run() {
      boolean e = enable;
      if (enable) {
        final long oldSize = Tools.convertToKilobytes(oldSizeWi.getStringValue());
        final long size = Tools.convertToKilobytes(sizeWi.getStringValue());
        final String maxBlockSize = getMaxBlockSize();
        final long maxSize = Long.parseLong(maxBlockSize);
        maxSizeWi.setValue(Tools.convertKilobytes(maxBlockSize));

        if (oldSize >= size || size > maxSize) {
          e = false;
          sizeWi.wrongValue();
        } else {
          sizeWi.setBackground("", "", true);
        }
      }
      resizeButton.setEnabled(e);
    }
Пример #21
0
 /** 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;
 }
Пример #22
0
  /** Removes this hardware from the libvirt with confirmation dialog. */
  @Override
  public final void removeMyself(final boolean testOnly) {
    if (getResource().isNew()) {
      super.removeMyself(testOnly);
      getResource().setNew(false);
      removeNode();
      return;
    }
    String desc = Tools.getString("VMSHardwareInfo.confirmRemove.Description");

    desc = desc.replaceAll("@HW@", Matcher.quoteReplacement(toString()));
    if (Tools.confirmDialog(
        Tools.getString("VMSHardwareInfo.confirmRemove.Title"),
        desc,
        Tools.getString("VMSHardwareInfo.confirmRemove.Yes"),
        Tools.getString("VMSHardwareInfo.confirmRemove.No"))) {
      removeMyselfNoConfirm(testOnly);
      getResource().setNew(false);
    }
  }
Пример #23
0
  /** Create host object and initialize it from user config. */
  public void setHost(
      final Map<String, List<Host>> hostMap,
      String username,
      final String nodeName,
      final String ip,
      String sshPort,
      final String color,
      final boolean sudo,
      final boolean savable) {
    Tools.getConfigData().setLastEnteredUser(username);
    final Host host = new Host();
    host.setSavable(savable);
    host.setHostname(nodeName);
    if (sshPort == null) {
      sshPort = "22";
    }
    host.setSSHPort(sshPort);
    Tools.getConfigData().setLastEnteredSSHPort(sshPort);
    if (color != null) {
      host.setSavedColor(color);
    }
    host.setUseSudo(sudo);
    Tools.getConfigData().setLastEnteredUseSudo(sudo);
    Tools.getConfigData().addHostToHosts(host);

    new TerminalPanel(host);
    host.setIp(ip);
    if (username == null && sudo) {
      username = System.getProperty("user.name");
    }
    if (username == null) {
      username = Host.ROOT_USER;
    }
    host.setUsername(username);
    List<Host> hostList = hostMap.get(nodeName);
    if (hostList == null) {
      hostList = new ArrayList<Host>();
      hostMap.put(nodeName, hostList);
    }
    hostList.add(host);
  }
Пример #24
0
 /** Returns device parameters. */
 protected Map<String, String> getHWParameters(final boolean allParams) {
   Tools.invokeAndWait(
       new Runnable() {
         public void run() {
           getInfoPanel();
         }
       });
   final String[] params = getParametersFromXML();
   final Map<String, String> parameters = new HashMap<String, String>();
   for (final String param : getParametersFromXML()) {
     final String value = getComboBoxValue(param);
     if (allParams || !Tools.areEqual(getParamSaved(param), value)) {
       if (Tools.areEqual(getParamDefault(param), value)) {
         parameters.put(param, null);
       } else {
         parameters.put(param, value);
       }
     }
   }
   return parameters;
 }
Пример #25
0
  /** Returns list of menu items. */
  @Override
  public final List<UpdatableItem> createPopup() {
    final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
    final boolean testOnly = false;
    /* remove service */
    final MyMenuItem removeMenuItem =
        new MyMenuItem(
            Tools.getString("VMSHardwareInfo.Menu.Remove"),
            ClusterBrowser.REMOVE_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            Tools.getString("VMSHardwareInfo.Menu.Cancel"),
            ClusterBrowser.REMOVE_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean predicate() {
            return !getResource().isNew();
          }

          @Override
          public String enablePredicate() {
            if (getResource().isNew()) {
              return null;
            }
            return isRemoveable();
          }

          @Override
          public void action() {
            hidePopup();
            removeMyself(false);
          }
        };
    addMouseOverListener(removeMenuItem, null);
    items.add((UpdatableItem) removeMenuItem);
    return items;
  }
Пример #26
0
  /** Fix ports. Make the number of ports delimited with "," to match the host names. */
  private static void fixSourceHostParams(final Map<String, String> params) {
    final String names = params.get(DiskData.SOURCE_HOST_NAME);
    String ports = params.get(DiskData.SOURCE_HOST_PORT);
    if (names == null) {
      params.put(DiskData.SOURCE_HOST_PORT, null);
      return;
    }
    if ("".equals(names)) {
      params.put(DiskData.SOURCE_HOST_PORT, "");
      return;
    }

    if (ports == null || "".equals(ports)) {
      ports = DEFAULT_SOURCE_HOST_PORT;
    }

    final String[] namesA = names.trim().split("\\s*,\\s*");
    final String[] portsA = ports.trim().split("\\s*,\\s*");

    final String lastPort = portsA[portsA.length - 1];

    final String fixedNames = Tools.join(", ", namesA);
    String fixedPorts;
    if (namesA.length == portsA.length) {
      fixedPorts = Tools.join(", ", portsA);
    } else if (portsA.length < namesA.length) {
      /* add ports */
      fixedPorts = Tools.join(", ", portsA);
      for (int i = 0; i < namesA.length - portsA.length; i++) {
        fixedPorts += ", " + lastPort;
      }
    } else {
      /* remove ports */
      fixedPorts = Tools.join(", ", portsA, namesA.length);
    }
    params.put(DiskData.SOURCE_HOST_NAME, fixedNames);
    params.put(DiskData.SOURCE_HOST_PORT, fixedPorts);
  }
Пример #27
0
 /** Starts specified clusters and connects to the hosts of this clusters. */
 public void startClusters(final List<Cluster> selectedClusters) {
   final Set<Cluster> clusters = Tools.getConfigData().getClusters().getClusterSet();
   if (clusters != null) {
     /* clusters */
     for (final Cluster cluster : clusters) {
       if (selectedClusters != null && !selectedClusters.contains(cluster)) {
         continue;
       }
       Tools.getGUIData().addClusterTab(cluster);
       if (cluster.getHosts().isEmpty()) {
         continue;
       }
       final boolean ok = cluster.connect(null, true, 1);
       if (!ok) {
         Tools.getGUIData().getClustersPanel().removeTab(cluster);
         continue;
       }
       final Runnable runnable =
           new Runnable() {
             @Override
             public void run() {
               for (final Host host : cluster.getHosts()) {
                 host.waitOnLoading();
               }
               cluster.getClusterTab().addClusterView();
               SwingUtilities.invokeLater(
                   new Runnable() {
                     public void run() {
                       cluster.getClusterTab().requestFocus();
                     }
                   });
             }
           };
       final Thread thread = new Thread(runnable);
       thread.start();
     }
   }
 }
Пример #28
0
 /** Returns answer pane in a scroll pane. */
 protected final JScrollPane getAnswerPane(final String initialText) {
   answerPane = new JEditorPane(Tools.MIME_TYPE_TEXT_PLAIN, initialText);
   answerPane.setBackground(Tools.getDefaultColor("ConfigDialog.AnswerPane"));
   answerPane.setForeground(java.awt.Color.WHITE);
   // answerPane.setBackground(
   //                    Tools.getDefaultColor("ConfigDialog.AnswerPane"));
   // descSP.setBorder(null);
   answerPane.setEditable(false);
   final JScrollPane scrollPane = new JScrollPane(answerPane);
   scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   scrollPane.setMaximumSize(new Dimension(Short.MAX_VALUE, 80));
   scrollPane.setPreferredSize(new Dimension(Short.MAX_VALUE, 80));
   return scrollPane;
 }
Пример #29
0
 /** Update menus with positions and calles their update methods. */
 @Override
 void updateMenus(final Point2D pos) {
   super.updateMenus(pos);
   if (!Tools.getConfigData().isSlow()) {
     final ClusterStatus cs = getBrowser().getClusterStatus();
     final List<String> resources = cs.getGroupResources(getHeartbeatId(false), false);
     if (resources != null) {
       for (final String hbId : resources) {
         final ServiceInfo si = getBrowser().getServiceInfoFromCRMId(hbId);
         if (si != null) {
           si.updateMenus(pos);
         }
       }
     }
   }
 }
Пример #30
0
 /** Adds disk table with only this disk to the main panel. */
 @Override
 protected void addHardwareTable(final JPanel mainPanel) {
   tablePanel =
       getTablePanel(
           "Disk", VMSVirtualDomainInfo.DISK_TABLE, getNewBtn(getVMSVirtualDomainInfo()));
   if (getResource().isNew()) {
     Tools.invokeLater(
         !Tools.CHECK_SWING_THREAD,
         new Runnable() {
           @Override
           public void run() {
             tablePanel.setVisible(false);
           }
         });
   }
   mainPanel.add(tablePanel);
 }