@Override public void run() { Tools.invokeAndWait(new EnableCreateRunnable(false)); disableComponents(); getProgressBar().start(CREATE_TIMEOUT * hostCheckBoxes.size()); boolean oneFailed = false; for (final Host h : hostCheckBoxes.keySet()) { if (hostCheckBoxes.get(h).isSelected()) { final List<String> pvNames = new ArrayList<String>(); for (final String pv : pvCheckBoxes.keySet()) { if (pvCheckBoxes.get(pv).isSelected()) { pvNames.add(pv); } } final boolean ret = vgCreate(h, vgNameWi.getStringValue(), pvNames); if (!ret) { oneFailed = true; } } } enableComponents(); if (oneFailed) { for (final Host h : hostCheckBoxes.keySet()) { h.getBrowser().getClusterBrowser().updateHWInfo(h); } checkButtons(); progressBarDoneError(); } else { progressBarDone(); disposeDialog(); for (final Host h : hostCheckBoxes.keySet()) { h.getBrowser().getClusterBrowser().updateHWInfo(h); } } }
/** 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; }
/** 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); }
/** Returns device parameters. */ protected Map<String, String> getHWParameters(final boolean allParams) { Tools.invokeAndWait( new Runnable() { public void run() { getInfoPanel(); } }); final String[] params = getParametersFromXML(); final Map<String, String> parameters = new HashMap<String, String>(); for (final String param : getParametersFromXML()) { final String value = getComboBoxValue(param); if (allParams || !Tools.areEqual(getParamSaved(param), value)) { if (Tools.areEqual(getParamDefault(param), value)) { parameters.put(param, null); } else { parameters.put(param, value); } } } return parameters; }
/** * 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(); }
/** Applies the the whole group if for example an order has changed. */ void applyWhole( final Host dcHost, final boolean createGroup, final List<String> newOrder, final boolean testOnly) { final String[] params = getParametersFromXML(); if (!testOnly) { Tools.invokeAndWait( new Runnable() { @Override public void run() { final MyButton ab = getApplyButton(); if (ab != null) { ab.setEnabled(false); } } }); } getInfoPanel(); waitForInfoPanel(); final Map<String, String> groupMetaArgs = new LinkedHashMap<String, String>(); for (String param : params) { if (GUI_ID.equals(param) || PCMK_ID.equals(param)) { continue; } String value = getComboBoxValue(param); if (value == null) { value = ""; } if (value.equals(getParamDefault(param))) { continue; } if (!"".equals(value)) { if (CRMXML.GROUP_ORDERED_META_ATTR.equals(param)) { groupMetaArgs.put("ordered", value); } else { groupMetaArgs.put(param, value); } } } final Map<String, Map<String, String>> pacemakerResAttrs = new HashMap<String, Map<String, String>>(); final Map<String, Map<String, String>> pacemakerResArgs = new HashMap<String, Map<String, String>>(); final Map<String, Map<String, String>> pacemakerMetaArgs = new HashMap<String, Map<String, String>>(); final Map<String, String> instanceAttrId = new HashMap<String, String>(); final Map<String, Map<String, String>> nvpairIdsHash = new HashMap<String, Map<String, String>>(); final Map<String, Map<String, Map<String, String>>> pacemakerOps = new HashMap<String, Map<String, Map<String, String>>>(); final Map<String, String> operationsId = new HashMap<String, String>(); final Map<String, String> metaAttrsRefId = new HashMap<String, String>(); final Map<String, String> operationsRefId = new HashMap<String, String>(); final Map<String, Boolean> stonith = new HashMap<String, Boolean>(); final ClusterStatus cs = getBrowser().getClusterStatus(); for (final String resId : newOrder) { final ServiceInfo gsi = getBrowser().getServiceInfoFromCRMId(resId); if (gsi == null) { continue; } Tools.invokeAndWait( new Runnable() { @Override public void run() { gsi.getInfoPanel(); } }); } Tools.waitForSwing(); for (final String resId : newOrder) { final ServiceInfo gsi = getBrowser().getServiceInfoFromCRMId(resId); if (gsi == null) { continue; } pacemakerResAttrs.put(resId, gsi.getPacemakerResAttrs(testOnly)); pacemakerResArgs.put(resId, gsi.getPacemakerResArgs()); pacemakerMetaArgs.put(resId, gsi.getPacemakerMetaArgs()); instanceAttrId.put(resId, cs.getResourceInstanceAttrId(resId)); nvpairIdsHash.put(resId, cs.getParametersNvpairsIds(resId)); pacemakerOps.put(resId, gsi.getOperations(resId)); operationsId.put(resId, cs.getOperationsId(resId)); metaAttrsRefId.put(resId, gsi.getMetaAttrsRefId()); operationsRefId.put(resId, gsi.getOperationsRefId()); stonith.put(resId, gsi.getResourceAgent().isStonith()); } final CloneInfo ci = getCloneInfo(); String cloneId = null; boolean master = false; final Map<String, String> cloneMetaArgs = new LinkedHashMap<String, String>(); String cloneMetaAttrsRefIds = null; if (createGroup && ci != null) { cloneId = ci.getHeartbeatId(testOnly); final String[] cloneParams = ci.getParametersFromXML(); master = ci.getService().isMaster(); cloneMetaAttrsRefIds = ci.getMetaAttrsRefId(); for (String param : cloneParams) { if (GUI_ID.equals(param) || PCMK_ID.equals(param)) { continue; } final String value = ci.getComboBoxValue(param); if (value.equals(ci.getParamDefault(param))) { continue; } if (!GUI_ID.equals(param) && !"".equals(value)) { cloneMetaArgs.put(param, value); } } } CRM.replaceGroup( createGroup, dcHost, cloneId, master, cloneMetaArgs, cloneMetaAttrsRefIds, newOrder, groupMetaArgs, getHeartbeatId(testOnly), pacemakerResAttrs, pacemakerResArgs, pacemakerMetaArgs, instanceAttrId, nvpairIdsHash, pacemakerOps, operationsId, metaAttrsRefId, getMetaAttrsRefId(), operationsRefId, stonith, testOnly); if (!testOnly) { storeComboBoxValues(params); getBrowser().reload(getNode(), false); } getBrowser().getCRMGraph().repaint(); }
/** Applies the changes to the group parameters. */ @Override void apply(final Host dcHost, final boolean testOnly) { if (!testOnly) { Tools.invokeAndWait( new Runnable() { @Override public void run() { getApplyButton().setEnabled(false); getRevertButton().setEnabled(false); } }); } getInfoPanel(); waitForInfoPanel(); final String[] params = getParametersFromXML(); if (!testOnly) { Tools.invokeLater( new Runnable() { @Override public void run() { getApplyButton().setToolTipText(""); final Widget idField = getWidget(GUI_ID, null); idField.setEnabled(false); } }); /* add myself to the hash with service name and id as * keys */ getBrowser().removeFromServiceInfoHash(this); final String oldHeartbeatId = getHeartbeatId(testOnly); if (oldHeartbeatId != null) { getBrowser().mHeartbeatIdToServiceLock(); getBrowser().getHeartbeatIdToServiceInfo().remove(oldHeartbeatId); getBrowser().mHeartbeatIdToServiceUnlock(); } if (getService().isNew()) { final String id = getComboBoxValue(GUI_ID); getService().setIdAndCrmId(id); if (getTypeRadioGroup() != null) { getTypeRadioGroup().setEnabled(false); } } getBrowser().addNameToServiceInfoHash(this); getBrowser().addToHeartbeatIdList(this); } /* MSG_ADD_GRP group param_id1 param_name1 param_value1 param_id2 param_name2 param_value2 ... param_idn param_namen param_valuen */ final String heartbeatId = getHeartbeatId(testOnly); if (getService().isNew()) { final Set<ServiceInfo> parents = getBrowser().getCRMGraph().getParents(this); final List<Map<String, String>> colAttrsList = new ArrayList<Map<String, String>>(); final List<Map<String, String>> ordAttrsList = new ArrayList<Map<String, String>>(); final List<String> parentIds = new ArrayList<String>(); for (final ServiceInfo parentInfo : parents) { final String parentId = parentInfo.getService().getHeartbeatId(); parentIds.add(parentId); final Map<String, String> colAttrs = new LinkedHashMap<String, String>(); final Map<String, String> ordAttrs = new LinkedHashMap<String, String>(); colAttrs.put(CRMXML.SCORE_STRING, CRMXML.INFINITY_STRING); ordAttrs.put(CRMXML.SCORE_STRING, CRMXML.INFINITY_STRING); if (getService().isMaster()) { colAttrs.put("with-rsc-role", "Master"); ordAttrs.put("first-action", "promote"); ordAttrs.put("then-action", "start"); } colAttrsList.add(colAttrs); ordAttrsList.add(ordAttrs); } CRM.setOrderAndColocation( dcHost, heartbeatId, parentIds.toArray(new String[parentIds.size()]), colAttrsList, ordAttrsList, testOnly); @SuppressWarnings("unchecked") final Enumeration<DefaultMutableTreeNode> e = getNode().children(); final List<String> newOrder = new ArrayList<String>(); while (e.hasMoreElements()) { final DefaultMutableTreeNode n = e.nextElement(); final ServiceInfo child = (ServiceInfo) n.getUserObject(); newOrder.add(child.getHeartbeatId(testOnly)); } applyWhole(dcHost, true, newOrder, testOnly); if (!testOnly) { setApplyButtons(null, params); } getBrowser().getCRMGraph().repaint(); return; } else { final Map<String, String> groupMetaArgs = new LinkedHashMap<String, String>(); for (String param : params) { if (GUI_ID.equals(param) || PCMK_ID.equals(param)) { continue; } final String value = getComboBoxValue(param); if (value.equals(getParamDefault(param))) { continue; } if (!"".equals(value)) { if (CRMXML.GROUP_ORDERED_META_ATTR.equals(param)) { groupMetaArgs.put("ordered", value); } else { groupMetaArgs.put(param, value); } } } CRM.setParameters( dcHost, "-R", null, /* crm id */ null, /* TODO: clone id */ false, /* master */ null, /* cloneMetaArgs, */ groupMetaArgs, heartbeatId, /* group id */ null, /* pacemakerResAttrs, */ null, /* pacemakerResArgs, */ null, /* pacemakerMetaArgs, */ null, /* cs.getResourceInstanceAttrId(heartbeatId), */ null, /* cs.getParametersNvpairsIds(heartbeatId), */ null, /* getOperations(heartbeatId), */ null, /* cs.getOperationsId(heartbeatId), */ null, /* getMetaAttrsRefId(), */ null, /* cloneMetaAttrsRefIds, */ getMetaAttrsRefId(), null, /* getOperationsRefId(), */ false, /* stonith */ testOnly); } final CloneInfo ci = getCloneInfo(); if (ci == null) { setLocations(heartbeatId, dcHost, testOnly); } else { ci.setLocations(heartbeatId, dcHost, testOnly); } if (!testOnly) { storeComboBoxValues(params); getBrowser().reload(getNode(), false); } 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 && gsi.checkResourceFieldsCorrect(null, gsi.getParametersFromXML(), false, false, true) && gsi.checkResourceFieldsChanged( null, gsi.getParametersFromXML(), false, false, true)) { gsi.apply(dcHost, testOnly); } } } if (!testOnly) { setApplyButtons(null, params); } getBrowser().getCRMGraph().repaint(); }