Exemplo n.º 1
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.º 2
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();
  }
Exemplo n.º 3
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);
           }
         });
   }
 }
Exemplo n.º 4
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();
  }
Exemplo n.º 5
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);
    }
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  /** Returns string representation of the ip address. In the form of 'ip (interface)' */
  @Override
  public String toString() {
    final String id = getService().getId();
    if (id == null) {
      return super.toString(); /* this is for 'new IPaddrInfo' */
    }

    final StringBuilder s = new StringBuilder(getName());
    final String inside = id + " / ";
    String ip = getParamSaved("ip");
    if (ip == null || "".equals(ip)) {
      ip = Tools.getString("ClusterBrowser.Ip.Unconfigured");
    }
    s.append(" (");
    s.append(inside);
    s.append(ip);
    s.append(')');
    return s.toString();
  }
Exemplo n.º 8
0
  /** Returns combo box for parameter. */
  @Override
  protected GuiComboBox getParamComboBox(final String param, final String prefix, final int width) {
    GuiComboBox paramCb;
    if ("ip".equals(param)) {
      /* get networks */
      String ip = getPreviouslySelected(param, prefix);
      if (ip == null) {
        ip = getParamSaved(param);
      }
      Info defaultValue;
      if (ip == null || "".equals(ip)) {
        defaultValue =
            new StringInfo(Tools.getString("ClusterBrowser.SelectNetInterface"), ip, getBrowser());
      } else {
        defaultValue = new StringInfo(ip, ip, getBrowser());
      }
      final Info[] networks =
          enumToInfoArray(defaultValue, getName(), getBrowser().getNetworksNode().children());

      final String regexp = "^[\\d.*]*|Select\\.\\.\\.$";
      paramCb =
          new GuiComboBox(
              ip,
              networks,
              null, /* units */
              GuiComboBox.Type.COMBOBOX,
              regexp,
              width,
              null, /* abbrv */
              new AccessMode(getAccessType(param), isEnabledOnlyInAdvancedMode(param)));

      paramCb.setAlwaysEditable(true);
      paramComboBoxAdd(param, prefix, paramCb);
    } else {
      paramCb = super.getParamComboBox(param, prefix, width);
    }
    return paramCb;
  }
Exemplo n.º 9
0
 /**
  * Returns the title of the dialog. It is defined as Dialog.DrbdConfig.Resource.Title in
  * TextResources.
  */
 @Override
 protected String getDialogTitle() {
   return Tools.getString("Dialog.DrbdConfig.Resource.Title");
 }
Exemplo n.º 10
0
 /**
  * Returns the description of the dialog. It is defined as Dialog.DrbdConfig.Resource.Description
  * in TextResources.
  */
 @Override
 protected String getDescription() {
   return Tools.getString("Dialog.DrbdConfig.Resource.Description");
 }
Exemplo n.º 11
0
 /** Returns text that appears above the icon in the graph. */
 public String getIconTextForGraph(final boolean testOnly) {
   if (!getHost().isConnected()) {
     return Tools.getString("HostBrowser.Hb.NoInfoAvailable");
   }
   return null;
 }
Exemplo n.º 12
0
 static {
   TOOLTIP_MAP.put(
       DiskData.SOURCE_HOST_NAME, Tools.getString("VMSDiskInfo.Param.SourceHostName.ToolTip"));
   TOOLTIP_MAP.put(
       DiskData.SOURCE_HOST_PORT, Tools.getString("VMSDiskInfo.Param.SourceHostPort.ToolTip"));
 }
Exemplo n.º 13
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;
  }
Exemplo n.º 14
0
  /** Creates the popup for the host. */
  @Override
  public List<UpdatableItem> createPopup() {
    final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
    final boolean testOnly = false;
    /* host wizard */
    final MyMenuItem hostWizardItem =
        new MyMenuItem(
            Tools.getString("HostBrowser.HostWizard"),
            HostBrowser.HOST_ICON_LARGE,
            "",
            new AccessMode(ConfigData.AccessType.RO, false),
            new AccessMode(ConfigData.AccessType.RO, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public String enablePredicate() {
            return null;
          }

          @Override
          public void action() {
            final EditHostDialog dialog = new EditHostDialog(host);
            dialog.showDialogs();
          }
        };
    items.add(hostWizardItem);
    Tools.getGUIData().registerAddHostButton(hostWizardItem);
    /* cluster manager standby on/off */
    final HostInfo thisClass = this;
    final MyMenuItem standbyItem =
        new MyMenuItem(
            Tools.getString("HostBrowser.CRM.StandByOn"),
            HOST_STANDBY_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            Tools.getString("HostBrowser.CRM.StandByOff"),
            HOST_STANDBY_OFF_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean predicate() {
            return !isStandby(testOnly);
          }

          @Override
          public String enablePredicate() {
            if (!getHost().isClStatus()) {
              return NO_PCMK_STATUS_STRING;
            }
            return null;
          }

          @Override
          public void action() {
            final Host dcHost = getBrowser().getClusterBrowser().getDCHost();
            if (isStandby(testOnly)) {
              CRM.standByOff(dcHost, host, testOnly);
            } else {
              CRM.standByOn(dcHost, host, testOnly);
            }
          }
        };
    final ClusterBrowser cb = getBrowser().getClusterBrowser();
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback standbyItemCallback =
          cb.new ClMenuItemCallback(standbyItem, host) {
            @Override
            public void action(final Host dcHost) {
              if (isStandby(false)) {
                CRM.standByOff(dcHost, host, true);
              } else {
                CRM.standByOn(dcHost, host, true);
              }
            }
          };
      addMouseOverListener(standbyItem, standbyItemCallback);
    }
    items.add(standbyItem);

    /* Migrate all services from this host. */
    final MyMenuItem allMigrateFromItem =
        new MyMenuItem(
            Tools.getString("HostInfo.CRM.AllMigrateFrom"),
            HOST_STANDBY_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean predicate() {
            return true;
          }

          @Override
          public String enablePredicate() {
            if (!getHost().isClStatus()) {
              return NO_PCMK_STATUS_STRING;
            }
            if (getBrowser().getClusterBrowser().getExistingServiceList(null).isEmpty()) {
              return "there are no services to migrate";
            }
            return null;
          }

          @Override
          public void action() {
            for (final ServiceInfo si : cb.getExistingServiceList(null)) {
              if (!si.isConstraintPH() && si.getGroupInfo() == null && si.getCloneInfo() == null) {
                final List<String> runningOnNodes = si.getRunningOnNodes(false);
                if (runningOnNodes != null && runningOnNodes.contains(getHost().getName())) {
                  final Host dcHost = getHost();
                  si.migrateFromResource(dcHost, getHost().getName(), false);
                }
              }
            }
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback allMigrateFromItemCallback =
          cb.new ClMenuItemCallback(allMigrateFromItem, host) {
            @Override
            public void action(final Host dcHost) {
              for (final ServiceInfo si : cb.getExistingServiceList(null)) {
                if (!si.isConstraintPH() && si.getGroupInfo() == null) {
                  final List<String> runningOnNodes = si.getRunningOnNodes(false);
                  if (runningOnNodes != null && runningOnNodes.contains(host.getName())) {
                    si.migrateFromResource(dcHost, host.getName(), true);
                  }
                }
              }
            }
          };
      addMouseOverListener(allMigrateFromItem, allMigrateFromItemCallback);
    }
    items.add(allMigrateFromItem);
    /* Stop corosync/openais. */
    final MyMenuItem stopCorosyncItem =
        new MyMenuItem(
            Tools.getString("HostInfo.StopCorosync"),
            HOST_STOP_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            Tools.getString("HostInfo.StopOpenais"),
            HOST_STOP_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, true),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean predicate() {
            /* when both are running it's openais. */
            return getHost().isCsRunning() && !getHost().isAisRunning();
          }

          @Override
          public boolean visiblePredicate() {
            return getHost().isCsRunning() || getHost().isAisRunning();
          }

          @Override
          public void action() {
            if (Tools.confirmDialog(
                Tools.getString("HostInfo.confirmCorosyncStop.Title"),
                Tools.getString("HostInfo.confirmCorosyncStop.Desc"),
                Tools.getString("HostInfo.confirmCorosyncStop.Yes"),
                Tools.getString("HostInfo.confirmCorosyncStop.No"))) {
              final Host host = getHost();
              host.setCommLayerStopping(true);
              if (!host.isPcmkStartedByCorosync() && host.isPcmkInit() && host.isPcmkRunning()) {
                Corosync.stopCorosyncWithPcmk(host);
              } else {
                Corosync.stopCorosync(host);
              }

              getBrowser().getClusterBrowser().updateHWInfo(host);
            }
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback stopCorosyncItemCallback =
          cb.new ClMenuItemCallback(stopCorosyncItem, host) {
            @Override
            public void action(final Host dcHost) {
              if (!isStandby(false)) {
                CRM.standByOn(dcHost, host, true);
              }
            }
          };
      addMouseOverListener(stopCorosyncItem, stopCorosyncItemCallback);
    }
    items.add(stopCorosyncItem);
    /* Stop heartbeat. */
    final MyMenuItem stopHeartbeatItem =
        new MyMenuItem(
            Tools.getString("HostInfo.StopHeartbeat"),
            HOST_STOP_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, true),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean visiblePredicate() {
            return getHost().isHeartbeatRunning();
          }

          @Override
          public void action() {
            if (Tools.confirmDialog(
                Tools.getString("HostInfo.confirmHeartbeatStop.Title"),
                Tools.getString("HostInfo.confirmHeartbeatStop.Desc"),
                Tools.getString("HostInfo.confirmHeartbeatStop.Yes"),
                Tools.getString("HostInfo.confirmHeartbeatStop.No"))) {
              getHost().setCommLayerStopping(true);
              Heartbeat.stopHeartbeat(getHost());
              getBrowser().getClusterBrowser().updateHWInfo(host);
            }
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback stopHeartbeatItemCallback =
          cb.new ClMenuItemCallback(stopHeartbeatItem, host) {
            @Override
            public void action(final Host dcHost) {
              if (!isStandby(false)) {
                CRM.standByOn(dcHost, host, true);
              }
            }
          };
      addMouseOverListener(stopHeartbeatItem, stopHeartbeatItemCallback);
    }
    items.add(stopHeartbeatItem);
    /* Start corosync. */
    final MyMenuItem startCorosyncItem =
        new MyMenuItem(
            Tools.getString("HostInfo.StartCorosync"),
            HOST_START_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean visiblePredicate() {
            final Host h = getHost();
            return h.isCorosync()
                && h.isCsInit()
                && h.isCsAisConf()
                && !h.isCsRunning()
                && !h.isAisRunning()
                && !h.isHeartbeatRunning()
                && !h.isHeartbeatRc();
          }

          @Override
          public String enablePredicate() {
            final Host h = getHost();
            if (h.isAisRc() && !h.isCsRc()) {
              return "Openais is in rc.d";
            }
            return null;
          }

          @Override
          public void action() {
            getHost().setCommLayerStarting(true);
            if (getHost().isPcmkRc()) {
              Corosync.startCorosyncWithPcmk(getHost());
            } else {
              Corosync.startCorosync(getHost());
            }
            getBrowser().getClusterBrowser().updateHWInfo(host);
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback startCorosyncItemCallback =
          cb.new ClMenuItemCallback(startCorosyncItem, host) {
            @Override
            public void action(final Host host) {
              // TODO
            }
          };
      addMouseOverListener(startCorosyncItem, startCorosyncItemCallback);
    }
    items.add(startCorosyncItem);
    /* Start openais. */
    final MyMenuItem startOpenaisItem =
        new MyMenuItem(
            Tools.getString("HostInfo.StartOpenais"),
            HOST_START_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean visiblePredicate() {
            final Host h = getHost();
            return h.isAisInit()
                && h.isCsAisConf()
                && !h.isCsRunning()
                && !h.isAisRunning()
                && !h.isHeartbeatRunning()
                && !h.isHeartbeatRc();
          }

          @Override
          public String enablePredicate() {
            final Host h = getHost();
            if (h.isCsRc() && !h.isAisRc()) {
              return "Corosync is in rc.d";
            }
            return null;
          }

          @Override
          public void action() {
            getHost().setCommLayerStarting(true);
            Openais.startOpenais(getHost());
            getBrowser().getClusterBrowser().updateHWInfo(host);
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback startOpenaisItemCallback =
          cb.new ClMenuItemCallback(startOpenaisItem, host) {
            @Override
            public void action(final Host host) {
              // TODO
            }
          };
      addMouseOverListener(startOpenaisItem, startOpenaisItemCallback);
    }
    items.add(startOpenaisItem);
    /* Start heartbeat. */
    final MyMenuItem startHeartbeatItem =
        new MyMenuItem(
            Tools.getString("HostInfo.StartHeartbeat"),
            HOST_START_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean visiblePredicate() {
            final Host h = getHost();
            return h.isHeartbeatInit()
                && h.isHeartbeatConf()
                && !h.isCsRunning()
                && !h.isAisRunning()
                && !h.isHeartbeatRunning();
            // && !h.isAisRc()
            // && !h.isCsRc(); TODO should check /etc/defaults/
          }

          @Override
          public void action() {
            getHost().setCommLayerStarting(true);
            Heartbeat.startHeartbeat(getHost());
            getBrowser().getClusterBrowser().updateHWInfo(host);
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback startHeartbeatItemCallback =
          cb.new ClMenuItemCallback(startHeartbeatItem, host) {
            @Override
            public void action(final Host host) {
              // TODO
            }
          };
      addMouseOverListener(startHeartbeatItem, startHeartbeatItemCallback);
    }
    items.add(startHeartbeatItem);

    /* Start pacemaker. */
    final MyMenuItem startPcmkItem =
        new MyMenuItem(
            Tools.getString("HostInfo.StartPacemaker"),
            HOST_START_COMM_LAYER_ICON,
            ClusterBrowser.STARTING_PTEST_TOOLTIP,
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.ADMIN, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean visiblePredicate() {
            final Host h = getHost();
            return !h.isPcmkStartedByCorosync()
                && !h.isPcmkRunning()
                && (h.isCsRunning() || h.isAisRunning())
                && !h.isHeartbeatRunning();
          }

          @Override
          public String enablePredicate() {
            return null;
          }

          @Override
          public void action() {
            host.setPcmkStarting(true);
            Corosync.startPacemaker(host);
            getBrowser().getClusterBrowser().updateHWInfo(host);
          }
        };
    if (cb != null) {
      final ClusterBrowser.ClMenuItemCallback startPcmkItemCallback =
          cb.new ClMenuItemCallback(startPcmkItem, host) {
            @Override
            public void action(final Host host) {
              // TODO
            }
          };
      addMouseOverListener(startPcmkItem, startPcmkItemCallback);
    }
    items.add(startPcmkItem);
    /* change host color */
    final MyMenuItem changeHostColorItem =
        new MyMenuItem(
            Tools.getString("HostBrowser.Drbd.ChangeHostColor"),
            null,
            "",
            new AccessMode(ConfigData.AccessType.RO, false),
            new AccessMode(ConfigData.AccessType.RO, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public String enablePredicate() {
            return null;
          }

          @Override
          public void action() {
            final Color newColor =
                JColorChooser.showDialog(
                    Tools.getGUIData().getMainFrame(),
                    "Choose " + host.getName() + " color",
                    host.getPmColors()[0]);
            if (newColor != null) {
              host.setSavedColor(newColor);
            }
          }
        };
    items.add(changeHostColorItem);

    /* view logs */
    final MyMenuItem viewLogsItem =
        new MyMenuItem(
            Tools.getString("HostBrowser.Drbd.ViewLogs"),
            LOGFILE_ICON,
            "",
            new AccessMode(ConfigData.AccessType.RO, false),
            new AccessMode(ConfigData.AccessType.RO, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public String enablePredicate() {
            if (!getHost().isConnected()) {
              return Host.NOT_CONNECTED_STRING;
            }
            return null;
          }

          @Override
          public void action() {
            HostLogs l = new HostLogs(host);
            l.showDialog();
          }
        };
    items.add(viewLogsItem);
    /* advacend options */
    final MyMenu hostAdvancedSubmenu =
        new MyMenu(
            Tools.getString("HostBrowser.AdvancedSubmenu"),
            new AccessMode(ConfigData.AccessType.OP, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public String enablePredicate() {
            if (!host.isConnected()) {
              return Host.NOT_CONNECTED_STRING;
            }
            return null;
          }

          @Override
          public void update() {
            super.update();
            getBrowser().addAdvancedMenu(this);
          }
        };
    items.add(hostAdvancedSubmenu);

    /* remove host from gui */
    final MyMenuItem removeHostItem =
        new MyMenuItem(
            Tools.getString("HostBrowser.RemoveHost"),
            HostBrowser.HOST_REMOVE_ICON,
            Tools.getString("HostBrowser.RemoveHost"),
            new AccessMode(ConfigData.AccessType.RO, false),
            new AccessMode(ConfigData.AccessType.RO, false)) {
          private static final long serialVersionUID = 1L;

          @Override
          public String enablePredicate() {
            if (getHost().getCluster() != null) {
              return "it is a member of a cluster";
            }
            return null;
          }

          @Override
          public void action() {
            getHost().disconnect();
            Tools.getConfigData().removeHostFromHosts(getHost());
            Tools.getGUIData().allHostsUpdate();
          }
        };
    items.add(removeHostItem);
    return items;
  }
Exemplo n.º 15
0
  static void start(final int count) {
    slowFactor = 0.3f;
    aborted = false;
    disableStonith();
    final String testName = "test3";
    for (int i = count; i > 0; i--) {
      if (i % 5 == 0) {
        info(testName + " I: " + i);
      }
      checkTest(testName, 1);
      /* filesystem/drbd */
      moveTo(577, 205);
      rightClick(); /* popup */
      sleep(1000);
      moveTo(Tools.getString("ClusterBrowser.Hb.AddService"));
      sleep(1000);
      moveTo("Filesystem + Linbit:DRBD");
      leftClick(); /* choose fs */

      moveTo("block device", Widget.MComboBox.class); /* choose drbd */
      leftClick();
      sleep(2000);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_ENTER);

      moveTo("mount point", Widget.MComboBox.class);
      leftClick();
      sleep(2000);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_ENTER);

      moveTo("filesystem type", Widget.MComboBox.class);
      leftClick();
      sleep(2000);
      press(KeyEvent.VK_E);
      sleep(200);
      press(KeyEvent.VK_E);
      sleep(200);
      press(KeyEvent.VK_ENTER);

      moveTo(Tools.getString("Browser.ApplyResource"));
      leftClick();
      sleep(2000);
      checkTest(testName, 2);
      checkNumberOfVertices(testName, 4);
      stopEverything();
      checkTest(testName, 3);
      removeEverything();
      resetTerminalAreas();

      /* filesystem/drbd - with name */
      moveTo(577, 205);
      rightClick(); /* popup */
      sleep(1000);
      moveTo(Tools.getString("ClusterBrowser.Hb.AddService"));
      sleep(1000);
      moveTo("Filesystem + Linbit:DRBD");
      leftClick(); /* choose fs */

      checkTest(testName, 4);
      moveTo("Name", Widget.MTextField.class);
      leftClick();
      press(KeyEvent.VK_X);
      sleep(200);
      press(KeyEvent.VK_Y);
      sleep(200);

      moveTo("block device", Widget.MComboBox.class); /* choose drbd */
      leftClick();
      sleep(2000);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_ENTER);

      moveTo("mount point", Widget.MComboBox.class);
      leftClick();
      sleep(2000);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_DOWN);
      sleep(200);
      press(KeyEvent.VK_ENTER);

      moveTo("filesystem type", Widget.MComboBox.class);
      leftClick();
      sleep(2000);
      press(KeyEvent.VK_E);
      sleep(200);
      press(KeyEvent.VK_E);
      sleep(200);
      press(KeyEvent.VK_ENTER);

      moveTo(Tools.getString("Browser.ApplyResource"));
      leftClick();
      sleep(2000);
      checkTest(testName, 5);
      checkNumberOfVertices(testName, 4);
      stopEverything();
      checkTest(testName, 6);
      removeEverything();
      resetTerminalAreas();
    }
    System.gc();
  }
Exemplo n.º 16
0
  static {
    SHORTNAME_MAP.put(DiskData.TYPE, Tools.getString("VMSDiskInfo.Param.Type"));
    SHORTNAME_MAP.put(DiskData.TARGET_DEVICE, Tools.getString("VMSDiskInfo.Param.TargetDevice"));
    SHORTNAME_MAP.put(DiskData.SOURCE_FILE, Tools.getString("VMSDiskInfo.Param.SourceFile"));
    SHORTNAME_MAP.put(DiskData.SOURCE_DEVICE, Tools.getString("VMSDiskInfo.Param.SourceDevice"));

    SHORTNAME_MAP.put(
        DiskData.SOURCE_PROTOCOL, Tools.getString("VMSDiskInfo.Param.SourceProtocol"));
    SHORTNAME_MAP.put(DiskData.SOURCE_NAME, Tools.getString("VMSDiskInfo.Param.SourceName"));
    SHORTNAME_MAP.put(
        DiskData.SOURCE_HOST_NAME, Tools.getString("VMSDiskInfo.Param.SourceHostName"));
    SHORTNAME_MAP.put(
        DiskData.SOURCE_HOST_PORT, Tools.getString("VMSDiskInfo.Param.SourceHostPort"));

    SHORTNAME_MAP.put(DiskData.AUTH_USERNAME, Tools.getString("VMSDiskInfo.Param.AuthUsername"));
    SHORTNAME_MAP.put(
        DiskData.AUTH_SECRET_TYPE, Tools.getString("VMSDiskInfo.Param.AuthSecretType"));
    SHORTNAME_MAP.put(
        DiskData.AUTH_SECRET_UUID, Tools.getString("VMSDiskInfo.Param.AuthSecretUuid"));

    SHORTNAME_MAP.put(DiskData.TARGET_BUS_TYPE, Tools.getString("VMSDiskInfo.Param.TargetBusType"));
    SHORTNAME_MAP.put(DiskData.DRIVER_NAME, Tools.getString("VMSDiskInfo.Param.DriverName"));
    SHORTNAME_MAP.put(DiskData.DRIVER_TYPE, Tools.getString("VMSDiskInfo.Param.DriverType"));
    SHORTNAME_MAP.put(DiskData.DRIVER_CACHE, Tools.getString("VMSDiskInfo.Param.DriverCache"));
    SHORTNAME_MAP.put(DiskData.READONLY, Tools.getString("VMSDiskInfo.Param.Readonly"));
    SHORTNAME_MAP.put(DiskData.SHAREABLE, Tools.getString("VMSDiskInfo.Param.Shareable"));
  }
Exemplo n.º 17
0
 /**
  * TextResource files contain texts in different languages. Text for every button has to be
  * defined there. If Ok button is used, resource file has to contain ConfigDialog.Ok item.
  */
 protected final String buttonString(final String b) {
   return Tools.getString("Dialog.Dialog." + b);
 }
Exemplo n.º 18
0
  /** Returns items for the group popup. */
  @Override
  public List<UpdatableItem> createPopup() {
    final boolean testOnly = false;
    final GroupInfo thisGroupInfo = this;
    /* add group service */
    final MyMenu addGroupServiceMenuItem =
        new MyMenu(
            Tools.getString("ClusterBrowser.Hb.AddGroupService"),
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
          private static final long serialVersionUID = 1L;
          private final Lock mUpdateLock = new ReentrantLock();

          @Override
          public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
              return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else {
              return null;
            }
          }

          @Override
          public void update() {
            final Thread t =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (mUpdateLock.tryLock()) {
                          try {
                            updateThread();
                          } finally {
                            mUpdateLock.unlock();
                          }
                        }
                      }
                    });
            t.start();
          }

          private void updateThread() {
            Tools.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    setEnabled(false);
                  }
                });
            Tools.invokeAndWait(
                new Runnable() {
                  @Override
                  public void run() {
                    removeAll();
                  }
                });
            final List<JDialog> popups = new ArrayList<JDialog>();
            for (final String cl : ClusterBrowser.HB_CLASSES) {
              final MyMenu classItem =
                  new MyMenu(
                      ClusterBrowser.HB_CLASS_MENU.get(cl),
                      new AccessMode(ConfigData.AccessType.ADMIN, false),
                      new AccessMode(ConfigData.AccessType.OP, false));
              MyListModel<MyMenuItem> dlm = new MyListModel<MyMenuItem>();
              for (final ResourceAgent ra : getAddGroupServiceList(cl)) {
                final MyMenuItem mmi =
                    new MyMenuItem(
                        ra.getMenuName(),
                        null,
                        null,
                        new AccessMode(ConfigData.AccessType.ADMIN, false),
                        new AccessMode(ConfigData.AccessType.OP, false)) {
                      private static final long serialVersionUID = 1L;

                      @Override
                      public void action() {
                        final CloneInfo ci = getCloneInfo();
                        if (ci != null) {
                          ci.hidePopup();
                        }
                        hidePopup();
                        for (final JDialog otherP : popups) {
                          otherP.dispose();
                        }
                        if (ra.isLinbitDrbd() && !getBrowser().linbitDrbdConfirmDialog()) {
                          return;
                        }
                        addGroupServicePanel(ra, true);
                        repaint();
                      }
                    };
                dlm.addElement(mmi);
              }
              final boolean ret =
                  Tools.getScrollingMenu(
                      ClusterBrowser.HB_CLASS_MENU.get(cl),
                      null, /* options */
                      classItem,
                      dlm,
                      new MyList<MyMenuItem>(dlm, getBackground()),
                      thisGroupInfo,
                      popups,
                      null);
              if (!ret) {
                classItem.setEnabled(false);
              }
              Tools.invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      add(classItem);
                    }
                  });
            }
            Tools.waitForSwing();
            super.update();
          }
        };
    final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
    items.add((UpdatableItem) addGroupServiceMenuItem);
    for (final UpdatableItem item : super.createPopup()) {
      items.add(item);
    }

    /* group services */
    if (!Tools.getConfigData().isSlow()) {
      final ClusterStatus cs = getBrowser().getClusterStatus();
      final List<String> resources = cs.getGroupResources(getHeartbeatId(testOnly), testOnly);
      if (resources != null) {
        for (final String hbId : resources) {
          final ServiceInfo gsi = getBrowser().getServiceInfoFromCRMId(hbId);
          if (gsi == null) {
            continue;
          }
          final MyMenu groupServicesMenu =
              new MyMenu(
                  gsi.toString(),
                  new AccessMode(ConfigData.AccessType.RO, false),
                  new AccessMode(ConfigData.AccessType.RO, false)) {
                private static final long serialVersionUID = 1L;
                private final Lock mUpdateLock = new ReentrantLock();

                @Override
                public String enablePredicate() {
                  return null;
                }

                @Override
                public void update() {
                  final Thread t =
                      new Thread(
                          new Runnable() {
                            @Override
                            public void run() {
                              if (mUpdateLock.tryLock()) {
                                try {
                                  updateThread();
                                } finally {
                                  mUpdateLock.unlock();
                                }
                              }
                            }
                          });
                  t.start();
                }

                public void updateThread() {
                  Tools.invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          setEnabled(false);
                        }
                      });
                  Tools.invokeAndWait(
                      new Runnable() {
                        @Override
                        public void run() {
                          removeAll();
                        }
                      });
                  final List<UpdatableItem> serviceMenus = new ArrayList<UpdatableItem>();
                  for (final UpdatableItem u : gsi.createPopup()) {
                    serviceMenus.add(u);
                    u.update();
                  }
                  Tools.invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          for (final UpdatableItem u : serviceMenus) {
                            add((JMenuItem) u);
                          }
                        }
                      });
                  super.update();
                }
              };
          items.add((UpdatableItem) groupServicesMenu);
        }
      }
    }
    return items;
  }
Exemplo n.º 19
0
/** This class holds info about Virtual Disks. */
public final class VMSDiskInfo extends VMSHardwareInfo {
  /** Logger. */
  private static final Logger LOG = LoggerFactory.getLogger(VMSDiskInfo.class);
  /** Source file combo box, so that it can be disabled, depending on type. */
  private final Map<String, Widget> sourceFileWi = new HashMap<String, Widget>();
  /** Source block combo box, so that it can be disabled, depending on type. */
  private final Map<String, Widget> sourceDeviceWi = new HashMap<String, Widget>();

  private final Map<String, Widget> sourceNameWi = new HashMap<String, Widget>();
  private final Map<String, Widget> sourceProtocolWi = new HashMap<String, Widget>();
  private final Map<String, Widget> sourceHostNameWi = new HashMap<String, Widget>();
  private final Map<String, Widget> sourceHostPortWi = new HashMap<String, Widget>();
  private final Map<String, Widget> authUsernameWi = new HashMap<String, Widget>();
  private final Map<String, Widget> authSecretTypeWi = new HashMap<String, Widget>();
  private final Map<String, Widget> authSecretUuidWi = new HashMap<String, Widget>();

  /** Target device combo box, that needs to be reloaded if target type has changed. */
  private final Map<String, Widget> targetDeviceWi = new HashMap<String, Widget>();
  /** Driver name combo box. */
  private final Map<String, Widget> driverNameWi = new HashMap<String, Widget>();
  /** Driver type combo box. */
  private final Map<String, Widget> driverTypeWi = new HashMap<String, Widget>();
  /** Driver cache combo box. */
  private final Map<String, Widget> driverCacheWi = new HashMap<String, Widget>();
  /** Readonly combo box. */
  private final Map<String, Widget> readonlyWi = new HashMap<String, Widget>();
  /** Previous target device value. */
  private String prevTargetBusType = null;
  /** Previous target bus type (disk type) value. */
  private String previousTargetBusType = null;
  /** Parameters. */
  private static final String[] PARAMETERS = {
    DiskData.TYPE,
    DiskData.TARGET_BUS_TYPE,
    DiskData.TARGET_DEVICE,
    DiskData.SOURCE_FILE,
    DiskData.SOURCE_DEVICE,
    DiskData.SOURCE_PROTOCOL,
    DiskData.SOURCE_NAME,
    DiskData.SOURCE_HOST_NAME,
    DiskData.SOURCE_HOST_PORT,
    DiskData.AUTH_USERNAME,
    DiskData.AUTH_SECRET_TYPE,
    DiskData.AUTH_SECRET_UUID,
    DiskData.DRIVER_NAME,
    DiskData.DRIVER_TYPE,
    DiskData.DRIVER_CACHE,
    DiskData.READONLY,
    DiskData.SHAREABLE
  };
  /** Block parameters. */
  private static final String[] BLOCK_PARAMETERS = {
    DiskData.TYPE,
    DiskData.TARGET_BUS_TYPE,
    DiskData.TARGET_DEVICE,
    DiskData.SOURCE_DEVICE,
    DiskData.DRIVER_NAME,
    DiskData.DRIVER_TYPE,
    DiskData.DRIVER_CACHE,
    DiskData.READONLY,
    DiskData.SHAREABLE
  };
  /** File parameters. */
  private static final String[] FILE_PARAMETERS = {
    DiskData.TYPE,
    DiskData.TARGET_DEVICE,
    DiskData.SOURCE_FILE,
    DiskData.TARGET_BUS_TYPE,
    DiskData.DRIVER_NAME,
    DiskData.DRIVER_TYPE,
    DiskData.DRIVER_CACHE,
    DiskData.READONLY,
    DiskData.SHAREABLE
  };

  /** Network parameters. */
  private static final String[] NETWORK_PARAMETERS = {
    DiskData.TYPE,
    DiskData.TARGET_BUS_TYPE,
    DiskData.TARGET_DEVICE,
    DiskData.SOURCE_PROTOCOL,
    DiskData.SOURCE_NAME,
    DiskData.SOURCE_HOST_NAME,
    DiskData.SOURCE_HOST_PORT,
    DiskData.AUTH_USERNAME,
    DiskData.AUTH_SECRET_TYPE,
    DiskData.AUTH_SECRET_UUID,
    DiskData.DRIVER_NAME,
    DiskData.DRIVER_TYPE,
    DiskData.DRIVER_CACHE,
    DiskData.READONLY,
    DiskData.SHAREABLE
  };
  /** Whether the parameter is enabled only in advanced mode. */
  private static final Set<String> IS_ENABLED_ONLY_IN_ADVANCED =
      new HashSet<String>(
          Arrays.asList(
              new String[] {
                DiskData.TARGET_DEVICE,
                DiskData.DRIVER_NAME,
                DiskData.DRIVER_TYPE,
                DiskData.DRIVER_CACHE
              }));
  /** Whether the parameter is required. */
  private static final Set<String> IS_REQUIRED =
      new HashSet<String>(Arrays.asList(new String[] {DiskData.TYPE}));

  static {
    IS_REQUIRED.add(DiskData.SOURCE_PROTOCOL);
    IS_REQUIRED.add(DiskData.SOURCE_NAME);
    IS_REQUIRED.add(DiskData.SOURCE_HOST_NAME);
    IS_REQUIRED.add(DiskData.SOURCE_HOST_PORT);
    IS_REQUIRED.add(DiskData.AUTH_USERNAME);
  }
  /** Field type. */
  private static final Map<String, Widget.Type> FIELD_TYPES = new HashMap<String, Widget.Type>();
  /** Target devices depending on the target type. */
  private static final Map<String, String[]> TARGET_DEVICES_MAP = new HashMap<String, String[]>();

  static {
    FIELD_TYPES.put(DiskData.TYPE, Widget.Type.RADIOGROUP);
    FIELD_TYPES.put(DiskData.SOURCE_FILE, Widget.Type.COMBOBOX);
    FIELD_TYPES.put(DiskData.READONLY, Widget.Type.CHECKBOX);
    FIELD_TYPES.put(DiskData.SHAREABLE, Widget.Type.CHECKBOX);
    FIELD_TYPES.put(DiskData.TARGET_DEVICE, Widget.Type.COMBOBOX);
  }
  /** Short name. */
  private static final Map<String, String> SHORTNAME_MAP = new HashMap<String, String>();

  static {
    SHORTNAME_MAP.put(DiskData.TYPE, Tools.getString("VMSDiskInfo.Param.Type"));
    SHORTNAME_MAP.put(DiskData.TARGET_DEVICE, Tools.getString("VMSDiskInfo.Param.TargetDevice"));
    SHORTNAME_MAP.put(DiskData.SOURCE_FILE, Tools.getString("VMSDiskInfo.Param.SourceFile"));
    SHORTNAME_MAP.put(DiskData.SOURCE_DEVICE, Tools.getString("VMSDiskInfo.Param.SourceDevice"));

    SHORTNAME_MAP.put(
        DiskData.SOURCE_PROTOCOL, Tools.getString("VMSDiskInfo.Param.SourceProtocol"));
    SHORTNAME_MAP.put(DiskData.SOURCE_NAME, Tools.getString("VMSDiskInfo.Param.SourceName"));
    SHORTNAME_MAP.put(
        DiskData.SOURCE_HOST_NAME, Tools.getString("VMSDiskInfo.Param.SourceHostName"));
    SHORTNAME_MAP.put(
        DiskData.SOURCE_HOST_PORT, Tools.getString("VMSDiskInfo.Param.SourceHostPort"));

    SHORTNAME_MAP.put(DiskData.AUTH_USERNAME, Tools.getString("VMSDiskInfo.Param.AuthUsername"));
    SHORTNAME_MAP.put(
        DiskData.AUTH_SECRET_TYPE, Tools.getString("VMSDiskInfo.Param.AuthSecretType"));
    SHORTNAME_MAP.put(
        DiskData.AUTH_SECRET_UUID, Tools.getString("VMSDiskInfo.Param.AuthSecretUuid"));

    SHORTNAME_MAP.put(DiskData.TARGET_BUS_TYPE, Tools.getString("VMSDiskInfo.Param.TargetBusType"));
    SHORTNAME_MAP.put(DiskData.DRIVER_NAME, Tools.getString("VMSDiskInfo.Param.DriverName"));
    SHORTNAME_MAP.put(DiskData.DRIVER_TYPE, Tools.getString("VMSDiskInfo.Param.DriverType"));
    SHORTNAME_MAP.put(DiskData.DRIVER_CACHE, Tools.getString("VMSDiskInfo.Param.DriverCache"));
    SHORTNAME_MAP.put(DiskData.READONLY, Tools.getString("VMSDiskInfo.Param.Readonly"));
    SHORTNAME_MAP.put(DiskData.SHAREABLE, Tools.getString("VMSDiskInfo.Param.Shareable"));
  }
  /** Tool tips. */
  private static final Map<String, String> TOOLTIP_MAP = new HashMap<String, String>();

  static {
    TOOLTIP_MAP.put(
        DiskData.SOURCE_HOST_NAME, Tools.getString("VMSDiskInfo.Param.SourceHostName.ToolTip"));
    TOOLTIP_MAP.put(
        DiskData.SOURCE_HOST_PORT, Tools.getString("VMSDiskInfo.Param.SourceHostPort.ToolTip"));
  }

  /** Sections. */
  private static final Map<String, String> SECTION_MAP = new HashMap<String, String>();

  private static final String SECTION_DISK_OPTIONS =
      Tools.getString("VMSDiskInfo.Section.DiskOptions");
  private static final String SECTION_SOURCE = Tools.getString("VMSDiskInfo.Section.Source");
  private static final String SECTION_AUTHENTICATION =
      Tools.getString("VMSDiskInfo.Section.Authentication");

  static {
    SECTION_MAP.put(DiskData.TYPE, SECTION_SOURCE);
    SECTION_MAP.put(DiskData.SOURCE_FILE, SECTION_SOURCE);
    SECTION_MAP.put(DiskData.SOURCE_DEVICE, SECTION_SOURCE);
    SECTION_MAP.put(DiskData.SOURCE_PROTOCOL, SECTION_SOURCE);
    SECTION_MAP.put(DiskData.SOURCE_NAME, SECTION_SOURCE);
    SECTION_MAP.put(DiskData.SOURCE_HOST_NAME, SECTION_SOURCE);
    SECTION_MAP.put(DiskData.SOURCE_HOST_PORT, SECTION_SOURCE);

    SECTION_MAP.put(DiskData.AUTH_USERNAME, SECTION_AUTHENTICATION);
    SECTION_MAP.put(DiskData.AUTH_SECRET_TYPE, SECTION_AUTHENTICATION);
    SECTION_MAP.put(DiskData.AUTH_SECRET_UUID, SECTION_AUTHENTICATION);
  }

  /** Preferred values. */
  private static final Map<String, String> PREFERRED_MAP = new HashMap<String, String>();
  /** Defaults. */
  private static final Map<String, String> DEFAULTS_MAP = new HashMap<String, String>();
  /** Possible values. */
  private static final Map<String, Object[]> POSSIBLE_VALUES = new HashMap<String, Object[]>();
  /** Default location for libvirt images. */
  public static final String LIBVIRT_IMAGE_LOCATION = "/var/lib/libvirt/images/";
  /**
   * A map from target bus and type as it is saved to the string representation that appears in the
   * menus.
   */
  private static final Map<String, String> TARGET_BUS_TYPES = new HashMap<String, String>();
  /** Disk types. */
  private static final String FILE_TYPE = "file";

  private static final String BLOCK_TYPE = "block";
  private static final String NETWORK_TYPE = "network";

  /** Drivers. */
  private static final String DRIVER_NAME_DEFUALT = null;

  private static final String DRIVER_NAME_FILE = "file";
  private static final String DRIVER_NAME_QEMU = "qemu";
  private static final String DRIVER_NAME_PHY = "phy";

  static {
    POSSIBLE_VALUES.put(
        DiskData.TYPE,
        new StringInfo[] {
          new StringInfo("Image file", FILE_TYPE, null),
          new StringInfo("Disk/block device", BLOCK_TYPE, null),
          new StringInfo("Network", NETWORK_TYPE, null)
        });
    POSSIBLE_VALUES.put(
        DiskData.TARGET_BUS_TYPE,
        new StringInfo[] {
          new StringInfo("IDE Disk", "ide/disk", null),
          new StringInfo("IDE CDROM", "ide/cdrom", null),
          new StringInfo("Floppy Disk", "fdc/floppy", null),
          new StringInfo("SCSI Disk", "scsi/disk", null),
          new StringInfo("USB Disk", "usb/disk", null),
          new StringInfo("Virtio Disk", "virtio/disk", null)
        });
    POSSIBLE_VALUES.put(
        DiskData.DRIVER_NAME,
        new String[] {DRIVER_NAME_DEFUALT, DRIVER_NAME_FILE, DRIVER_NAME_QEMU, DRIVER_NAME_PHY});
    POSSIBLE_VALUES.put(DiskData.DRIVER_TYPE, new String[] {null, "raw"});
    POSSIBLE_VALUES.put(
        DiskData.DRIVER_CACHE,
        new String[] {
          null, "default", "none", "writethrough", "writeback", "directsync", "unsafe"
        });

    POSSIBLE_VALUES.put(
        DiskData.SOURCE_PROTOCOL,
        new String[] {null, "rbd", "nbd", "iscsi", "sheepdog", "gluster"});

    POSSIBLE_VALUES.put(
        DiskData.SOURCE_NAME,
        new String[] {"", "poolname/imagename", "poolname/imagename:rbd_cache=1"});
    POSSIBLE_VALUES.put(DiskData.AUTH_SECRET_TYPE, new String[] {"", "ceph", "iscsi"});
    for (final StringInfo tbt : (StringInfo[]) POSSIBLE_VALUES.get(DiskData.TARGET_BUS_TYPE)) {
      TARGET_BUS_TYPES.put(tbt.getInternalValue(), tbt.toString());
    }
    DEFAULTS_MAP.put(DiskData.READONLY, "False");
    DEFAULTS_MAP.put(DiskData.SHAREABLE, "False");
    PREFERRED_MAP.put(DiskData.DRIVER_NAME, "file");
    TARGET_DEVICES_MAP.put("ide/disk", new String[] {"hda", "hdb", "hdd"});
    TARGET_DEVICES_MAP.put("ide/cdrom", new String[] {"hdc"});
    TARGET_DEVICES_MAP.put("fdc/floppy", new String[] {"fda", "fdb", "fdc", "fdd"});
    TARGET_DEVICES_MAP.put("scsi/disk", new String[] {"sda", "sdb", "sdc", "sdd"});
    TARGET_DEVICES_MAP.put("usb/disk", new String[] {"sda", "sdb", "sdc", "sdd"});
    TARGET_DEVICES_MAP.put("virtio/disk", new String[] {"vda", "vdb", "vdc", "vdd", "vde"});
  }
  /** Default source port if none is specified (and it is needed). */
  public static final String DEFAULT_SOURCE_HOST_PORT = "6789";

  private final List<Map<String, Widget>> checkFieldList = new ArrayList<Map<String, Widget>>();

  /** Table panel. */
  private JComponent tablePanel = null;

  /** Creates the VMSDiskInfo object. */
  VMSDiskInfo(
      final String name, final Browser browser, final VMSVirtualDomainInfo vmsVirtualDomainInfo) {
    super(name, browser, vmsVirtualDomainInfo);

    checkFieldList.add(sourceNameWi);
    checkFieldList.add(sourceProtocolWi);
    checkFieldList.add(sourceHostNameWi);
    checkFieldList.add(sourceHostPortWi);
    checkFieldList.add(authUsernameWi);
    checkFieldList.add(authSecretTypeWi);
    checkFieldList.add(authSecretUuidWi);
  }

  /** 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);
  }

  /** Returns service icon in the menu. */
  @Override
  public ImageIcon getMenuIcon(final boolean testOnly) {
    return BlockDevInfo.HARDDISK_ICON;
  }

  /** Returns long description of the specified parameter. */
  @Override
  protected String getParamLongDesc(final String param) {
    return getParamShortDesc(param);
  }

  /** Returns short description of the specified parameter. */
  @Override
  protected String getParamShortDesc(final String param) {
    final String name = SHORTNAME_MAP.get(param);
    if (name == null) {
      return param;
    }
    return name;
  }

  /** Returns preferred value for specified parameter. */
  @Override
  protected String getParamPreferred(final String param) {
    final String domainType =
        getVMSVirtualDomainInfo().getWidget(VMSXML.VM_PARAM_DOMAIN_TYPE, null).getStringValue();
    if (DiskData.DRIVER_NAME.equals(param)
        && VMSVirtualDomainInfo.DOMAIN_TYPE_KVM.equals(domainType)) {
      return DRIVER_NAME_QEMU;
    }
    return PREFERRED_MAP.get(param);
  }

  /** Returns default value for specified parameter. */
  @Override
  protected String getParamDefault(final String param) {
    return DEFAULTS_MAP.get(param);
  }

  /** Returns parameters. */
  @Override
  public String[] getParametersFromXML() {
    return PARAMETERS.clone();
  }

  /** Returns real parameters. */
  @Override
  public String[] getRealParametersFromXML() {
    if (BLOCK_TYPE.equals(getComboBoxValue(DiskData.TYPE))) {
      return BLOCK_PARAMETERS.clone();
    } else if (FILE_TYPE.equals(getComboBoxValue(DiskData.TYPE))) {
      return FILE_PARAMETERS.clone();
    } else {
      return NETWORK_PARAMETERS.clone();
    }
  }

  /** 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);
  }

  /** Returns section to which the specified parameter belongs. */
  @Override
  protected String getSection(final String param) {
    final String section = SECTION_MAP.get(param);
    if (section == null) {
      return SECTION_DISK_OPTIONS;
    } else {
      return section;
    }
  }

  /** Returns true if the specified parameter is required. */
  @Override
  protected boolean isRequired(final String param) {
    final String type = getComboBoxValue(DiskData.TYPE);
    if ((DiskData.SOURCE_FILE.equals(param) && FILE_TYPE.equals(type))
        || (DiskData.SOURCE_DEVICE.equals(param) && BLOCK_TYPE.equals(type))) {
      if ("ide/cdrom".equals(getComboBoxValue(DiskData.TARGET_BUS_TYPE))
          || "fdc/floppy".equals(getComboBoxValue(DiskData.TARGET_BUS_TYPE))) {
        return false;
      } else {
        return true;
      }
    }
    return IS_REQUIRED.contains(param);
  }

  /** Returns true if the specified parameter is integer. */
  @Override
  protected boolean isInteger(final String param) {
    return false;
  }

  /** Returns true if the specified parameter is label. */
  @Override
  protected boolean isLabel(final String param) {
    return false;
  }

  /** Returns true if the specified parameter is of time type. */
  @Override
  protected boolean isTimeType(final String param) {
    return false;
  }

  /** Returns whether parameter is checkbox. */
  @Override
  protected boolean isCheckBox(final String param) {
    return false;
  }

  /** Returns the type of the parameter. */
  @Override
  protected String getParamType(final String param) {
    return "undef"; // TODO:
  }

  /** Returns type of the field. */
  @Override
  protected Widget.Type getFieldType(final String param) {
    return FIELD_TYPES.get(param);
  }

  /** 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;
  }

  /** 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);
  }

  /** 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);
  }

  /** Modify device xml. */
  @Override
  protected void modifyXML(
      final VMSXML vmsxml,
      final Node node,
      final String domainName,
      final Map<String, String> params) {
    if (vmsxml != null) {
      vmsxml.modifyDiskXML(node, domainName, params);
    }
  }

  /** Returns data for the table. */
  @Override
  protected Object[][] getTableData(final String tableName) {
    if (VMSVirtualDomainInfo.HEADER_TABLE.equals(tableName)) {
      return getVMSVirtualDomainInfo().getMainTableData();
    } else if (VMSVirtualDomainInfo.DISK_TABLE.equals(tableName)) {
      if (getResource().isNew()) {
        return new Object[][] {};
      }
      return new Object[][] {
        getVMSVirtualDomainInfo()
            .getDiskDataRow(getName(), null, getVMSVirtualDomainInfo().getDisks(), true)
      };
    }
    return new Object[][] {};
  }

  /** Returns whether this parameter is advanced. */
  @Override
  protected boolean isAdvanced(final String param) {
    return false;
  }

  /** Returns access type of this parameter. */
  @Override
  protected ConfigData.AccessType getAccessType(final String param) {
    return ConfigData.AccessType.ADMIN;
  }
  /** Returns true if the value of the parameter is ok. */
  @Override
  protected boolean checkParam(final String param, final String newValue) {
    if (DiskData.TYPE.equals(param)) {
      Tools.invokeLater(
          !Tools.CHECK_SWING_THREAD,
          new Runnable() {
            @Override
            public void run() {
              final boolean file = FILE_TYPE.equals(newValue);
              final boolean block = BLOCK_TYPE.equals(newValue);
              final boolean network = NETWORK_TYPE.equals(newValue);
              for (final String p : sourceFileWi.keySet()) {
                sourceFileWi.get(p).setVisible(file);
              }
              for (final String p : sourceDeviceWi.keySet()) {
                sourceDeviceWi.get(p).setVisible(block);
              }
              for (final Map<String, Widget> w : checkFieldList) {
                for (String p : w.keySet()) {
                  w.get(p).setVisible(network);
                }
              }
            }
          });
      checkOneParam(DiskData.SOURCE_FILE);
      checkOneParam(DiskData.SOURCE_DEVICE);
    } else if (DiskData.TARGET_BUS_TYPE.equals(param)) {
      final Set<String> devices = new LinkedHashSet<String>();
      devices.add(null);
      if (newValue != null) {
        final String[] targetDevices = TARGET_DEVICES_MAP.get(newValue);
        if (targetDevices != null) {
          for (final String dev : targetDevices) {
            if (!getVMSVirtualDomainInfo().isDevice(dev)) {
              devices.add(dev);
            }
          }
        }
      }
      final String saved = getParamSaved(DiskData.TARGET_DEVICE);
      String selected = null;
      devices.add(saved);
      if (saved == null || getResource().isNew()) {
        if (devices.size() > 1) {
          selected = devices.toArray(new String[devices.size()])[1];
        }
      } else {
        selected = saved;
      }
      if (prevTargetBusType == null || !prevTargetBusType.equals(newValue)) {
        final String sel = selected;
        for (final String p : targetDeviceWi.keySet()) {
          targetDeviceWi.get(p).reloadComboBox(sel, devices.toArray(new String[devices.size()]));
        }
        prevTargetBusType = newValue;
      }
      final String tbs = getComboBoxValue(DiskData.TARGET_BUS_TYPE);
      if (getParamSaved(DiskData.DRIVER_NAME) == null && !tbs.equals(previousTargetBusType)) {
        if ("ide/cdrom".equals(newValue)) {
          for (final String p : readonlyWi.keySet()) {
            readonlyWi.get(p).setValue("True");
          }
          for (final String p : driverTypeWi.keySet()) {
            if (getResource().isNew()) {
              driverTypeWi.get(p).setValue("raw");
            } else {
              if (driverTypeWi.get(p).getValue() != null) {
                driverTypeWi.get(p).setValue(null);
              }
            }
          }
        } else if ("virtio/disk".equals(newValue)) {
          for (final String p : driverTypeWi.keySet()) {
            driverTypeWi.get(p).setValue("raw");
          }
          for (final String p : driverCacheWi.keySet()) {
            driverCacheWi.get(p).setValue("none");
          }
        } else {
          for (final String p : readonlyWi.keySet()) {
            readonlyWi.get(p).setValue("False");
            driverTypeWi.get(p).setValue("raw");
          }
        }
      }
      previousTargetBusType = tbs;
      checkOneParam(DiskData.SOURCE_FILE);
      checkOneParam(DiskData.SOURCE_DEVICE);
    }
    if (isRequired(param) && (newValue == null || "".equals(newValue))) {
      return false;
    }
    return true;
  }

  /** Whether the parameter should be enabled. */
  @Override
  protected String isEnabled(final String param) {
    return null;
  }

  /** Whether the parameter should be enabled only in advanced mode. */
  @Override
  protected boolean isEnabledOnlyInAdvancedMode(final String param) {
    return IS_ENABLED_ONLY_IN_ADVANCED.contains(param);
  }

  /** 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());
  }

  /** 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;
    }
  }

  /** Removes this disk without confirmation dialog. */
  @Override
  protected void removeMyselfNoConfirm(final boolean testOnly) {
    final String virshOptions = getVMSVirtualDomainInfo().getVirshOptions();
    for (final Host h : getVMSVirtualDomainInfo().getDefinedOnHosts()) {
      final VMSXML vmsxml = getBrowser().getVMSXML(h);
      if (vmsxml != null) {
        final Map<String, String> parameters = new HashMap<String, String>();
        parameters.put(DiskData.SAVED_TARGET_DEVICE, getName());
        vmsxml.removeDiskXML(getVMSVirtualDomainInfo().getDomainName(), parameters, virshOptions);
      }
    }
    getBrowser().periodicalVMSUpdate(getVMSVirtualDomainInfo().getDefinedOnHosts());
    removeNode();
  }

  /** Returns string representation. */
  @Override
  public String toString() {
    final StringBuilder s = new StringBuilder(30);
    final String name = getName();
    if (name == null) {
      return "new disk...";
    }
    s.append(name);
    s.append(" (");
    final String saved = getParamSaved(DiskData.TARGET_BUS_TYPE);
    if (saved == null) {
      s.append("new...");
    } else if (TARGET_BUS_TYPES.containsKey(saved)) {
      s.append(TARGET_BUS_TYPES.get(saved));
    } else {
      s.append(saved);
    }
    s.append(')');
    return s.toString();
  }

  /** Returns whether this item is removeable (null), or string why it isn't. */
  @Override
  protected String isRemoveable() {
    return null;
  }

  /** Returns "add new" button. */
  static MyButton getNewBtn(final VMSVirtualDomainInfo vdi) {
    final MyButton newBtn = new MyButton("Add Disk");
    newBtn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread t =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        vdi.addDiskPanel();
                      }
                    });
            t.start();
          }
        });
    return newBtn;
  }

  /** Returns the regexp of the parameter. */
  @Override
  protected String getParamRegexp(final String param) {
    if (FILE_TYPE.equals(getComboBoxValue(DiskData.TYPE)) && DiskData.SOURCE_FILE.equals(param)) {
      return ".*[^/]$";
    }
    return super.getParamRegexp(param);
  }

  /** Additional tool tip. */
  @Override
  protected String additionalToolTip(final String param) {
    final String tt = TOOLTIP_MAP.get(param);
    if (tt == null) {
      return "";
    }
    return tt;
  }
}
Exemplo n.º 20
0
 /** Returns cluster dialog title. */
 @Override
 protected String getClusterDialogTitle() {
   return Tools.getString("Dialog.Cluster.Connect.Title");
 }
Exemplo n.º 21
0
 /** Returns description. */
 @Override
 protected String getDescription() {
   return Tools.getString("Dialog.Cluster.Connect.Description");
 }
Exemplo n.º 22
0
  /**
   * Shows dialog and wait for answer. Returns next dialog, or null if it there is no next dialog.
   */
  public final ConfigDialog showDialog() {
    /* making non modal dialog */
    dialogGate = new CountDownLatch(1);
    dialogPanel = null; /* TODO: disabled caching because back button
                               wouldn't work with
                               dialogPanel.setContentPane(optionPane) method
                               it would work with optionPane.createDialog...
                               but that causes lockups with old javas and
                               gnome. */
    if (dialogPanel == null) {
      final ImageIcon[] icons = getIcons();
      MyButton defaultButtonClass = null;
      final List<JComponent> allOptions = new ArrayList<JComponent>(additionalOptions);
      if (skipButtonEnabled()) {
        skipButton = new JCheckBox(Tools.getString("Dialog.ConfigDialog.SkipButton"));
        skipButton.setEnabled(false);
        skipButton.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
        skipButton.addItemListener(skipButtonListener());
        allOptions.add(skipButton);
      }
      final String[] buttons = buttons();
      /* populate buttonToObjectMap */
      for (int i = 0; i < buttons.length; i++) {
        options[i] = new MyButton(buttons[i], icons[i]);
        options[i].setBackgroundColor(Tools.getDefaultColor("ConfigDialog.Button"));
        allOptions.add(options[i]);
        buttonToObjectMap.put(buttons[i], options[i]);
        if (buttons[i].equals(defaultButton())) {
          defaultButtonClass = options[i];
        }
      }
      /* create option pane */
      final JPanel b = body();
      final MyButton dbc = defaultButtonClass;
      Tools.invokeAndWait(
          new Runnable() {
            public void run() {
              optionPane =
                  new JOptionPane(
                      b,
                      getMessageType(),
                      JOptionPane.DEFAULT_OPTION,
                      icon(),
                      allOptions.toArray(new JComponent[allOptions.size()]),
                      dbc);
              optionPane.setPreferredSize(new Dimension(dialogWidth(), dialogHeight()));
              optionPane.setMaximumSize(new Dimension(dialogWidth(), dialogHeight()));
              optionPane.setMinimumSize(new Dimension(dialogWidth(), dialogHeight()));

              optionPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Dark"));
              final Container mainFrame = Tools.getGUIData().getMainFrame();
              if (mainFrame instanceof JApplet) {
                final JFrame noframe = new JFrame();
                dialogPanel = new JDialog(noframe);
                dialogPanel.setContentPane(optionPane);
              } else {
                dialogPanel = new JDialog((JFrame) mainFrame);
                dialogPanel.setContentPane(optionPane);
              }
              dialogPanel.setModal(false);
              dialogPanel.setResizable(true);
            }
          });
      /* set location like the previous dialog */
    }
    /* add action listeners */
    final Map<MyButton, OptionPaneActionListener> optionPaneActionListeners =
        new HashMap<MyButton, OptionPaneActionListener>();
    for (final MyButton o : options) {
      final OptionPaneActionListener ol = new OptionPaneActionListener();
      optionPaneActionListeners.put(o, ol);
      o.addActionListener(ol);
    }

    final PropertyChangeListener propertyChangeListener =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent evt) {
            if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName())
                && !"uninitializedValue".equals(evt.getNewValue())) {
              optionPaneAnswer = optionPane.getValue();
              dialogGate.countDown();
            }
          }
        };
    optionPane.addPropertyChangeListener(propertyChangeListener);
    initDialog();
    Tools.invokeAndWait(
        new Runnable() {
          public void run() {
            dialogPanel.setPreferredSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setMaximumSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setMinimumSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrame());
            dialogPanel.setVisible(true);
          }
        });
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrameContentPane());
            /* although the location was set before, it is set again as a
             * workaround for gray dialogs with nothing in it, that appear
             * in some comination of Java and compiz. */
          }
        });
    initDialogAfterVisible();
    try {
      dialogGate.await();
    } catch (InterruptedException ignored) {
      Thread.currentThread().interrupt();
    }

    if (optionPaneAnswer instanceof String) {
      setPressedButton((String) optionPaneAnswer);
    } else {
      setPressedButton(cancelButton());
    }
    optionPane.removePropertyChangeListener(propertyChangeListener);
    /* remove action listeners */
    for (final MyButton o : options) {
      o.removeActionListener(optionPaneActionListeners.get(o));
    }
    dialogPanel.dispose();
    return checkAnswer();
  }
Exemplo n.º 23
0
  /** Prepares a new <code>ClusterViewPanel</code> object. */
  EmptyViewPanel() {
    super();
    browser = new EmptyBrowser();
    Tools.getGUIData().setEmptyBrowser(browser);
    browser.setEmptyViewPanel(this);
    browser.initHosts();

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.setMinimumSize(new Dimension(0, 110));
    buttonPanel.setPreferredSize(new Dimension(0, 110));
    buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 110));
    buttonPanel.setBackground(STATUS_BACKGROUND);
    add(buttonPanel, BorderLayout.NORTH);
    final JPanel logoPanel = new JPanel(new CardLayout());
    logoPanel.setBackground(java.awt.Color.WHITE);
    final ImageIcon logoImage = Tools.createImageIcon("startpage_head.jpg");

    final JLabel logo = new JLabel(logoImage);
    final JPanel lPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    lPanel.setBackground(java.awt.Color.WHITE);
    lPanel.add(logo);
    logoPanel.add(lPanel, LOGO_PANEL_STRING);
    final JPanel smallButtonPanel = new JPanel();
    smallButtonPanel.setBackground(STATUS_BACKGROUND);
    smallButtonPanel.setLayout(new BoxLayout(smallButtonPanel, BoxLayout.Y_AXIS));
    buttonPanel.add(smallButtonPanel);
    /* check for upgrade field. */
    smallButtonPanel.add(Tools.getGUIData().getClustersPanel().registerUpgradeTextField());
    /* add new host button */
    final MyButton addHostButton =
        new MyButton(Tools.getString("ClusterTab.AddNewHost"), HOST_ICON);
    addHostButton.setBackgroundColor(Browser.STATUS_BACKGROUND);
    addHostButton.setPreferredSize(BIG_BUTTON_DIMENSION);
    addHostButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        final AddHostDialog ahd = new AddHostDialog();
                        ahd.showDialogs();
                      }
                    });
            thread.start();
          }
        });
    Tools.getGUIData().registerAddHostButton(addHostButton);
    buttonPanel.add(addHostButton);
    createEmptyView();
    add(logoPanel, BorderLayout.SOUTH);
    Tools.getGUIData().registerAllHostsUpdate(this);
    Tools.getGUIData().allHostsUpdate();

    /* add new cluster button */
    final MyButton addClusterButton =
        new MyButton(Tools.getString("ClusterTab.AddNewCluster"), CLUSTER_ICON);
    addClusterButton.setBackgroundColor(Browser.STATUS_BACKGROUND);
    addClusterButton.setPreferredSize(BIG_BUTTON_DIMENSION);
    addClusterButton.setMinimumSize(BIG_BUTTON_DIMENSION);
    addClusterButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        AddClusterDialog acd = new AddClusterDialog();
                        acd.showDialogs();
                      }
                    });
            thread.start();
          }
        });
    Tools.getGUIData().registerAddClusterButton(addClusterButton);
    Tools.getGUIData().checkAddClusterButtons();
    buttonPanel.add(addClusterButton);
    if (!Tools.getConfigData().getAutoHosts().isEmpty()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              addHostButton.pressButton();
            }
          });
    }
  }