Package lcmc.common.domain

Examples of lcmc.common.domain.AccessMode


                                    hostsArray[0],
                                    hostsArray,
                                    Widget.NO_REGEXP,
                                    COMBOBOX_WIDTH,
                                    Widget.NO_ABBRV,
                                    new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                                    Widget.NO_BUTTON);
        inputPane.add(hostLabel);
        inputPane.add(hostWithBetterDataWidget.getComponent());
        resolveButton = widgetFactory.createButton(Tools.getString("Dialog.Drbd.SplitBrain.ResolveButton"));
        resolveButton.addActionListener(new ActionListener() {
View Full Code Here


        ta.setFont(f);

        final MyButton crmConfigureCommitButton =
                      widgetFactory.createButton(Tools.getString("HostInfo.crmShellCommitButton"), Browser.APPLY_ICON);
        registerComponentEnableAccessMode(crmConfigureCommitButton,
                                          new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL));
        final MyButton hostInfoButton = widgetFactory.createButton(Tools.getString("HostInfo.crmShellStatusButton"));
        application.makeMiniButton(hostInfoButton);

        final MyButton crmConfigureShowButton =
                                           widgetFactory.createButton(Tools.getString("HostInfo.crmShellShowButton"));
        application.makeMiniButton(crmConfigureShowButton);
        crmConfigureCommitButton.setEnabled(false);
        final ExecCallback execCallback =
            new ExecCallback() {
                @Override
                public void done(final String answer) {
                    ta.setText(answer);
                    application.invokeLater(new Runnable() {
                    @Override
                        public void run() {
                            crmConfigureShowButton.setEnabled(true);
                            hostInfoButton.setEnabled(true);
                            crmShowInProgress = false;
                        }
                    });
                }

                @Override
                public void doneError(final String answer, final int errorCode) {
                    ta.setText(answer);
                    LOG.sshError(host, "", answer, "", errorCode);
                    application.invokeLater(new Runnable() {
                    @Override
                        public void run() {
                            crmConfigureCommitButton.setEnabled(false);
                        }
                    });
                }

            };
        hostInfoButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                registerComponentEditAccessMode(ta, new AccessMode(AccessMode.GOD, AccessMode.NORMAL));
                crmInfoShowing = true;
                hostInfoButton.setEnabled(false);
                crmConfigureCommitButton.setEnabled(false);
                String command = "HostBrowser.getHostInfo";
                if (!host.hasCorosyncInitScript()) {
                    command = "HostBrowser.getHostInfoHeartbeat";
                }
                host.execCommand(new ExecCommandConfig().commandString(command)
                                                        .execCallback(execCallback)
                                                        .silentCommand()
                                                        .silentOutput()
                                                        .sshCommandTimeout(Ssh.DEFAULT_COMMAND_TIMEOUT));
            }
        });
        host.registerEnableOnConnect(hostInfoButton);

        crmConfigureShowButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                registerComponentEditAccessMode(ta, new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL));
                updateAdvancedPanels();
                crmShowInProgress = true;
                crmInfoShowing = false;
                crmConfigureShowButton.setEnabled(false);
                crmConfigureCommitButton.setEnabled(false);
View Full Code Here

                                   selectedValue,
                                   commonBlockDevInfos,
                                   Widget.NO_REGEXP,
                                   width,
                                   Widget.NO_ABBRV,
                                   new AccessMode(getAccessType(param), isEnabledOnlyInAdvancedMode(param)),
                                   Widget.NO_BUTTON);
            blockDeviceParamWidget.setAlwaysEditable(true);
            paramWi = blockDeviceParamWidget;
            addParamComboListeners(paramWi);
            widgetAdd(param, prefix, paramWi);
        } else if ("fstype".equals(param)) {
            final Value defaultValue =
              new StringValue() {
                  @Override
                  public String getNothingSelected() {
                      return Tools.getString("ClusterBrowser.SelectFilesystem");
                  }
              };

            Value selectedValue = getPreviouslySelected(param, prefix);
            if (selectedValue == null) {
                selectedValue = getParamSaved(param);
            }
            if (selectedValue == null || selectedValue.isNothingSelected()) {
                selectedValue = defaultValue;
            }

            paramWi = widgetFactory.createInstance(
                              Widget.GUESS_TYPE,
                              selectedValue,
                              getBrowser().getCommonFileSystems(defaultValue),
                              Widget.NO_REGEXP,
                              width,
                              Widget.NO_ABBRV,
                              new AccessMode(getAccessType(param), isEnabledOnlyInAdvancedMode(param)),
                              Widget.NO_BUTTON);
            fstypeParamWidget = paramWi;

            widgetAdd(param, prefix, paramWi);
            paramWi.setEditable(false);
        } else if ("directory".equals(param)) {
            final String[] cmp = getBrowser().getCommonMountPoints();
            final Value[] items = new Value[cmp.length + 1];
            final Value defaultValue = new StringValue() {
                              @Override
                              public String getNothingSelected() {
                                  return Tools.getString("ClusterBrowser.SelectMountPoint");
                              }
                          };
            items[0] = defaultValue;
            int i = 1;
            for (final String c : cmp) {
                items[i] = new StringValue(c);
                i++;
            }

            getResource().setPossibleChoices(param, items);
            Value selectedValue = getPreviouslySelected(param, prefix);
            if (selectedValue == null) {
                selectedValue = getParamSaved(param);
            }
            if (selectedValue == null || selectedValue.isNothingSelected()) {
                selectedValue = defaultValue;
            }
            final String regexp = "^.+$";
            paramWi = widgetFactory.createInstance(
                                 Widget.GUESS_TYPE,
                                 selectedValue,
                                 items,
                                 regexp,
                                 width,
                                 Widget.NO_ABBRV,
                                 new AccessMode(getAccessType(param), isEnabledOnlyInAdvancedMode(param)),
                                 Widget.NO_BUTTON);
            widgetAdd(param, prefix, paramWi);
            paramWi.setAlwaysEditable(true);
        } else {
            paramWi = super.createWidget(param, prefix, width);
View Full Code Here

                                                  MCAST_TYPE,
                                                  types,
                                                  Widget.NO_REGEXP,
                                                  TYPE_COMBOBOX_WIDTH,
                                                  Widget.NO_ABBRV,
                                                  new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                                                  Widget.NO_BUTTON);
        typeWidget.setEnabled(false);

        final NetInterface[] ni = netInterfaceService.getNetInterfacesWithBridges(hosts[0]);
        NetInterface defaultNi = null;
        for (final NetInterface n : ni) {
            /* skip lo */
            if (!n.isLocalHost()) {
                defaultNi = n;
                break;
            }
        }
        if (defaultNi == null) {
            LOG.appError("getInputPane: " + hosts[0].getName() + ": missing network interfaces");
        }
        ifaceWidget = widgetFactory.createInstance(
                                          Widget.Type.COMBOBOX,
                                          defaultNi,
                                          ni,
                                          Widget.NO_REGEXP,
                                          INTERFACE_COMBOBOX_WIDTH,
                                          Widget.NO_ABBRV,
                                          new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                                          Widget.NO_BUTTON);

        /* this matches something like this: 225.0.0.43 694 1 0
         * if you think that the regexp is too complicated for that, consider,
         * that it must match also during the thing is written.
         */
        final String regexp = "^[\\d.]+$";
        addrWidget = widgetFactory.createInstance(
                              Widget.GUESS_TYPE,
                              new StringValue(Tools.getDefault("Dialog.Cluster.CoroConfig.DefaultMCastAddress")),
                              Widget.NO_ITEMS,
                              regexp,
                              ADDR_COMBOBOX_WIDTH,
                              Widget.NO_ABBRV,
                              new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                              Widget.NO_BUTTON);

        typeWidget.addListeners(new WidgetListener() {
            @Override
            public void check(final Value value) {
                checkInterface();
            }
        });

        ifaceWidget.addListeners(new WidgetListener() {
            @Override
            public void check(final Value value) {
                checkInterface();
            }
        });

        final String portRegexp = "^\\d+$";
        portWidget = widgetFactory.createInstance(
                Widget.GUESS_TYPE,
                new StringValue(Tools.getDefault("Dialog.Cluster.CoroConfig.DefaultMCastPort")),
                Widget.NO_ITEMS,
                portRegexp,
                PORT_COMBOBOX_WIDTH,
                Widget.NO_ABBRV,
                new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                Widget.NO_BUTTON);
        portWidget.addListeners(new WidgetListener() {
            @Override
            public void check(final Value value) {
                checkInterface();
View Full Code Here

                                 ip,
                                 networks,
                                 regexp,
                                 width,
                                 Widget.NO_ABBRV,
                                 new AccessMode(getAccessType(param), isEnabledOnlyInAdvancedMode(param)),
                                 Widget.NO_BUTTON);

            paramWi.setAlwaysEditable(true);
            widgetAdd(param, prefix, paramWi);
        } else {
View Full Code Here

                    defaultValue,
                    Widget.NO_ITEMS,
                    Widget.NO_REGEXP,
                    application.getServiceFieldWidth() * 2,
                    Widget.NO_ABBRV,
                    new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                    hostBtn);
            Widget rpwi = null;
            if (prefix == null) {
                definedOnHostComboBoxHash.put(host.getName(), wi);
            } else {
View Full Code Here

                                      Widget.NO_DEFAULT,
                                      Widget.NO_ITEMS,
                                      Widget.NO_REGEXP,
                                      0,    /* width */
                                      Widget.NO_ABBRV,
                                      new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                                      Widget.NO_BUTTON);

        //drbdTarballCombo.setEnabled(false);
        pane.add(drbdTarballCombo.getComponent());

View Full Code Here

        /* Command log */
        final MyMenuItem cmdLogMenuItem = menuFactory.createMenuItem(
                Tools.getString("HostBrowser.CmdLog"),
                Info.LOGFILE_ICON,
                "",
                new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))

                .enablePredicate(new EnablePredicate() {
                    @Override
                    public String check() {
                        if (!host.isConnected()) {
                            return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
                        }
                        return null;
                    }
                })

                .addAction(new MenuAction() {
                    @Override
                    public void run(final String text) {
                        final CmdLog cmdLog = cmdLogProvider.get();
                        cmdLog.init(host);
                        cmdLog.showDialog();
                    }
                });
        submenu.add(cmdLogMenuItem);

        /* panic */
        final MyMenuItem panicMenuItem = menuFactory.createMenuItem(
                Tools.getString("HostBrowser.MakeKernelPanic") + host.getName(),
                null,
                new AccessMode(AccessMode.GOD, AccessMode.NORMAL),
                new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                .enablePredicate(new EnablePredicate() {
                    @Override
                    public String check() {
                        if (!host.isConnected()) {
                            return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
                        }
                        return null;
                    }
                })
                .addAction(new MenuAction() {
                    @Override
                    public void run(final String text) {
                        final String hostName = host.getName();
                        final String command = "MakeKernelPanic";
                        guiData.startProgressIndicator(hostName, host.getDistString(command));
                        host.execCommand(new ExecCommandConfig().commandString(command));
                        guiData.stopProgressIndicator(hostName, host.getDistString(command));
                    }
                });
        submenu.add(panicMenuItem);

        /* reboot */
        final MyMenuItem rebootMenuItem = menuFactory.createMenuItem(
                Tools.getString("HostBrowser.MakeKernelReboot") + host.getName(),
                null,
                new AccessMode(AccessMode.GOD, AccessMode.NORMAL),
                new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                .enablePredicate(new EnablePredicate() {
                    @Override
                    public String check() {
                        if (!host.isConnected()) {
                            return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
View Full Code Here

                                          new Value[]{new StringValue(Application.HEARTBEAT_NAME),
                                                      new StringValue(Application.COROSYNC_NAME)},
                                          Widget.NO_REGEXP,
                                          500,
                                          Widget.NO_ABBRV,
                                          new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                                          Widget.NO_BUTTON);
        chooseStackCombo.setEnabled(Application.COROSYNC_NAME, false);
        chooseStackCombo.setEnabled(Application.HEARTBEAT_NAME, false);
        chooseStackCombo.setBackgroundColor(Color.WHITE);
        inputPane.add(getProgressBarPane(null));
View Full Code Here

        /* host wizard */
        final MyMenuItem hostWizardItem =
                menuFactory.createMenuItem(Tools.getString("HostBrowser.HostWizard"),
                        HostBrowser.HOST_ICON_LARGE,
                        "",
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL))
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                editHostDialog.showDialogs(hostInfo.getHost());
                            }
                        });
        items.add(hostWizardItem);
        guiData.registerAddHostButton(hostWizardItem);
        /* cluster manager standby on/off */
        final Application.RunMode runMode = Application.RunMode.LIVE;
        final MyMenuItem standbyItem =
                menuFactory.createMenuItem(Tools.getString("HostBrowser.CRM.StandByOn"),
                        HostInfo.HOST_STANDBY_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        Tools.getString("HostBrowser.CRM.StandByOff"),
                        HostInfo.HOST_STANDBY_OFF_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,
                        new AccessMode(AccessMode.OP, AccessMode.NORMAL),
                        new AccessMode(AccessMode.OP, AccessMode.NORMAL))
                        .predicate(new Predicate() {
                            @Override
                            public boolean check() {
                                return !hostInfo.isStandby(runMode);
                            }
                        })
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                if (!hostInfo.getHost().isCrmStatusOk()) {
                                    return HostInfo.NO_PCMK_STATUS_STRING;
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                final Host dcHost = hostInfo.getBrowser().getClusterBrowser().getDCHost();
                                if (hostInfo.isStandby(runMode)) {
                                    CRM.standByOff(dcHost, hostInfo.getHost(), runMode);
                                } else {
                                    CRM.standByOn(dcHost, hostInfo.getHost(), runMode);
                                }
                            }
                        });
        final ClusterBrowser cb = hostInfo.getBrowser().getClusterBrowser();
        if (cb != null) {
            final ButtonCallback standbyItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            if (hostInfo.isStandby(Application.RunMode.LIVE)) {
                                CRM.standByOff(dcHost, hostInfo.getHost(), Application.RunMode.TEST);
                            } else {
                                CRM.standByOn(dcHost, hostInfo.getHost(), Application.RunMode.TEST);
                            }
                        }
                    });
            hostInfo.addMouseOverListener(standbyItem, standbyItemCallback);
        }
        items.add(standbyItem);

        /* Migrate all services from this host. */
        final MyMenuItem allMigrateFromItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.CRM.AllMigrateFrom"),
                        HostInfo.HOST_STANDBY_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,
                        new AccessMode(AccessMode.OP, AccessMode.NORMAL),
                        new AccessMode(AccessMode.OP, AccessMode.NORMAL))
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                if (!hostInfo.getHost().isCrmStatusOk()) {
                                    return HostInfo.NO_PCMK_STATUS_STRING;
                                }
                                if (hostInfo.getBrowser().getClusterBrowser().getExistingServiceList(null).isEmpty()) {
                                    return "there are no services to migrate";
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                for (final ServiceInfo si : cb.getExistingServiceList(null)) {
                                    if (!si.isConstraintPlaceholder() && si.getGroupInfo() == null && si.getCloneInfo() == null) {
                                        final List<String> runningOnNodes = si.getRunningOnNodes(Application.RunMode.LIVE);
                                        if (runningOnNodes != null && runningOnNodes.contains(hostInfo.getHost().getName())) {
                                            final Host dcHost = hostInfo.getHost();
                                            si.migrateFromResource(dcHost, hostInfo.getHost().getName(), Application.RunMode.LIVE);
                                        }
                                    }
                                }
                            }
                        });
        if (cb != null) {
            final ButtonCallback allMigrateFromItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            for (final ServiceInfo si : cb.getExistingServiceList(null)) {
                                if (!si.isConstraintPlaceholder() && si.getGroupInfo() == null) {
                                    final List<String> runningOnNodes = si.getRunningOnNodes(Application.RunMode.LIVE);
                                    if (runningOnNodes != null && runningOnNodes.contains(hostInfo.getHost().getName())) {
                                        si.migrateFromResource(dcHost, hostInfo.getHost().getName(), Application.RunMode.TEST);
                                    }
                                }
                            }
                        }
                    });
            hostInfo.addMouseOverListener(allMigrateFromItem, allMigrateFromItemCallback);
        }
        items.add(allMigrateFromItem);
        /* Stop corosync/openais. */
        final MyMenuItem stopCorosyncItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.StopCorosync"),
                        HostInfo.HOST_STOP_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        Tools.getString("HostInfo.StopOpenais"),
                        HostInfo.HOST_STOP_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                final Host h = hostInfo.getHost();
                                if (!h.isInCluster()) {
                                    return NOT_IN_CLUSTER;
                                }
                                return null;
                            }
                        })
                        .predicate(new Predicate() {
                            @Override
                            public boolean check() {
                    /* when both are running it's openais. */
                                return hostInfo.getHost().isCorosyncRunning() && !hostInfo.getHost().isOpenaisRunning();
                            }
                        })
                        .visiblePredicate(new VisiblePredicate() {
                            @Override
                            public boolean check() {
                                return hostInfo.getHost().isCorosyncRunning() || hostInfo.getHost().isOpenaisRunning();
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                if (application.confirmDialog(Tools.getString("HostInfo.confirmCorosyncStop.Title"),
                                        Tools.getString("HostInfo.confirmCorosyncStop.Desc"),
                                        Tools.getString("HostInfo.confirmCorosyncStop.Yes"),
                                        Tools.getString("HostInfo.confirmCorosyncStop.No"))) {
                                    final Host thisHost = hostInfo.getHost();
                                    thisHost.setCommLayerStopping(true);
                                    if (!thisHost.isPcmkStartedByCorosync()
                                            && thisHost.hasPacemakerInitScript()
                                            && thisHost.isPacemakerRunning()) {
                                        if (hostInfo.getHost().isCorosyncRunning() && !hostInfo.getHost().isOpenaisRunning()) {
                                            Corosync.stopCorosyncWithPcmk(thisHost);
                                        } else {
                                            Openais.stopOpenaisWithPcmk(thisHost);
                                        }
                                    } else {
                                        if (hostInfo.getHost().isCorosyncRunning() && !hostInfo.getHost().isOpenaisRunning()) {
                                            Corosync.stopCorosync(thisHost);
                                        } else {
                                            Openais.stopOpenais(thisHost);
                                        }
                                    }
                                    updateClusterView(thisHost, hostInfo);
                                }
                            }
                        });
        if (cb != null) {
            final ButtonCallback stopCorosyncItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            if (!hostInfo.isStandby(Application.RunMode.LIVE)) {
                                CRM.standByOn(dcHost, hostInfo.getHost(), Application.RunMode.TEST);
                            }
                        }
                    });
            hostInfo.addMouseOverListener(stopCorosyncItem, stopCorosyncItemCallback);
        }
        items.add(stopCorosyncItem);
        /* Stop heartbeat. */
        final MyMenuItem stopHeartbeatItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.StopHeartbeat"),
                        HostInfo.HOST_STOP_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                        .visiblePredicate(new VisiblePredicate() {
                            @Override
                            public boolean check() {
                                return hostInfo.getHost().isHeartbeatRunning();
                            }
                        })
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                final Host h = hostInfo.getHost();
                                if (!h.isInCluster()) {
                                    return NOT_IN_CLUSTER;
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                if (application.confirmDialog(Tools.getString("HostInfo.confirmHeartbeatStop.Title"),
                                        Tools.getString("HostInfo.confirmHeartbeatStop.Desc"),
                                        Tools.getString("HostInfo.confirmHeartbeatStop.Yes"),
                                        Tools.getString("HostInfo.confirmHeartbeatStop.No"))) {
                                    hostInfo.getHost().setCommLayerStopping(true);
                                    Heartbeat.stopHeartbeat(hostInfo.getHost());
                                    updateClusterView(hostInfo.getHost(), hostInfo);
                                }
                            }
                        });
        if (cb != null) {
            final ButtonCallback stopHeartbeatItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            if (!hostInfo.isStandby(Application.RunMode.LIVE)) {
                                CRM.standByOn(dcHost, hostInfo.getHost(), Application.RunMode.TEST);
                            }
                        }
                    });
            hostInfo.addMouseOverListener(stopHeartbeatItem, stopHeartbeatItemCallback);
        }
        items.add(stopHeartbeatItem);
        /* Start corosync. */
        final MyMenuItem startCorosyncItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.StartCorosync"),
                        HostInfo.HOST_START_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                        .visiblePredicate(new VisiblePredicate() {
                            @Override
                            public boolean check() {
                                final Host h = hostInfo.getHost();
                                return h.isCorosyncInstalled()
                                        && h.hasCorosyncInitScript()
                                        && h.corosyncOrOpenaisConfigExists()
                                        && !h.isCorosyncRunning()
                                        && !h.isOpenaisRunning()
                                        && !h.isHeartbeatRunning()
                                        && !h.isHeartbeatInRc();
                            }
                        })
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                final Host h = hostInfo.getHost();
                                if (!h.isInCluster()) {
                                    return NOT_IN_CLUSTER;
                                }
                                if (h.isOpenaisInRc() && !h.isCorosyncInRc()) {
                                    return "Openais is in rc.d";
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                hostInfo.getHost().setCommLayerStarting(true);
                                if (hostInfo.getHost().isPacemakerInRc()) {
                                    Corosync.startCorosyncWithPcmk(hostInfo.getHost());
                                } else {
                                    Corosync.startCorosync(hostInfo.getHost());
                                }
                                updateClusterView(hostInfo.getHost(), hostInfo);
                            }
                        });
        if (cb != null) {
            final ButtonCallback startCorosyncItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            //TODO
                        }
                    });
            hostInfo.addMouseOverListener(startCorosyncItem, startCorosyncItemCallback);
        }
        items.add(startCorosyncItem);
        /* Start openais. */
        final MyMenuItem startOpenaisItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.StartOpenais"),
                        HostInfo.HOST_START_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                        .visiblePredicate(new VisiblePredicate() {
                            @Override
                            public boolean check() {
                                final Host h = hostInfo.getHost();
                                return h.hasOpenaisInitScript()
                                        && h.corosyncOrOpenaisConfigExists()
                                        && !h.isCorosyncRunning()
                                        && !h.isOpenaisRunning()
                                        && !h.isHeartbeatRunning()
                                        && !h.isHeartbeatInRc();
                            }
                        })
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                final Host h = hostInfo.getHost();
                                if (!h.isInCluster()) {
                                    return NOT_IN_CLUSTER;
                                }
                                if (h.isCorosyncInRc() && !h.isOpenaisInRc()) {
                                    return "Corosync is in rc.d";
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                hostInfo.getHost().setCommLayerStarting(true);
                                Openais.startOpenais(hostInfo.getHost());
                                updateClusterView(hostInfo.getHost(), hostInfo);
                            }
                        });
        if (cb != null) {
            final ButtonCallback startOpenaisItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            //TODO
                        }
                    });
            hostInfo.addMouseOverListener(startOpenaisItem, startOpenaisItemCallback);
        }
        items.add(startOpenaisItem);
        /* Start heartbeat. */
        final MyMenuItem startHeartbeatItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.StartHeartbeat"),
                        HostInfo.HOST_START_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                        .visiblePredicate(new VisiblePredicate() {
                            @Override
                            public boolean check() {
                                final Host h = hostInfo.getHost();
                                return h.hasHeartbeatInitScript()
                                        && h.heartbeatConfigExists()
                                        && !h.isCorosyncRunning()
                                        && !h.isOpenaisRunning()
                                        && !h.isHeartbeatRunning();
                                //&& !h.isAisRc()
                                //&& !h.isCsRc(); TODO should check /etc/defaults/
                            }
                        })
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                final Host h = hostInfo.getHost();
                                if (!h.isInCluster()) {
                                    return NOT_IN_CLUSTER;
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                hostInfo.getHost().setCommLayerStarting(true);
                                Heartbeat.startHeartbeat(hostInfo.getHost());
                                updateClusterView(hostInfo.getHost(), hostInfo);
                            }
                        });
        if (cb != null) {
            final ButtonCallback startHeartbeatItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            //TODO
                        }
                    });
            hostInfo.addMouseOverListener(startHeartbeatItem, startHeartbeatItemCallback);
        }
        items.add(startHeartbeatItem);

        /* Start pacemaker. */
        final MyMenuItem startPcmkItem =
                menuFactory.createMenuItem(Tools.getString("HostInfo.StartPacemaker"),
                        HostInfo.HOST_START_COMM_LAYER_ICON,
                        ClusterBrowser.STARTING_PTEST_TOOLTIP,

                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
                        new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
                        .visiblePredicate(new VisiblePredicate() {
                            @Override
                            public boolean check() {
                                final Host h = hostInfo.getHost();
                                return !h.isPcmkStartedByCorosync()
                                        && !h.isPacemakerRunning()
                                        && (h.isCorosyncRunning() || h.isOpenaisRunning())
                                        && !h.isHeartbeatRunning();
                            }
                        })
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                final Host h = hostInfo.getHost();
                                if (!h.isInCluster()) {
                                    return NOT_IN_CLUSTER;
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                hostInfo.getHost().setPacemakerStarting(true);
                                Corosync.startPacemaker(hostInfo.getHost());
                                updateClusterView(hostInfo.getHost(), hostInfo);
                            }
                        });
        if (cb != null) {
            final ButtonCallback startPcmkItemCallback = cb.new ClMenuItemCallback(hostInfo.getHost())
                    .addAction(new CallbackAction() {
                        @Override
                        public void run(final Host dcHost) {
                            //TODO
                        }
                    });
            hostInfo.addMouseOverListener(startPcmkItem, startPcmkItemCallback);
        }
        items.add(startPcmkItem);
        /* change host color */
        final UpdatableItem changeHostColorItem =
                menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ChangeHostColor"),
                        null,
                        "",
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL))
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                final Color newColor = JColorChooser.showDialog(
                                        guiData.getMainFrame(),
                                        "Choose " + hostInfo.getHost().getName() + " color",
                                        hostInfo.getHost().getPmColors()[0]);
                                if (newColor != null) {
                                    hostInfo.getHost().setSavedHostColorInGraphs(newColor);
                                }
                            }
                        });
        items.add(changeHostColorItem);

        /* view logs */
        final UpdatableItem viewLogsItem =
                menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ViewLogs"),
                        HostInfo.LOGFILE_ICON,
                        "",
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL))
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                if (!hostInfo.getHost().isConnected()) {
                                    return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
                                }
                                return null;
                            }
                        })
                        .addAction(new MenuAction() {
                            @Override
                            public void run(final String text) {
                                final HostLogs hostLogs = hostLogsProvider.get();
                                hostLogs.init(hostInfo.getHost());
                                hostLogs.showDialog();
                            }
                        });
        items.add(viewLogsItem);
        /* advacend options */
        final MyMenu hostAdvancedSubmenu = menuFactory.createMenu(Tools.getString("HostBrowser.AdvancedSubmenu"),
                new AccessMode(AccessMode.OP, AccessMode.NORMAL),
                new AccessMode(AccessMode.OP, AccessMode.NORMAL))
                .enablePredicate(new EnablePredicate() {
                    @Override
                    public String check() {
                        if (!hostInfo.getHost().isConnected()) {
                            return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
                        }
                        return null;
                    }
                });
        hostAdvancedSubmenu.onUpdate(new Runnable() {
            @Override
            public void run() {
                hostAdvancedSubmenu.updateMenuComponents();
                hostInfo.getBrowser().addAdvancedMenu(hostAdvancedSubmenu);
            }
        });
        items.add(hostAdvancedSubmenu);

        /* remove host from gui */
        final UpdatableItem removeHostItem =
                menuFactory.createMenuItem(Tools.getString("HostBrowser.RemoveHost"),
                        HostBrowser.HOST_REMOVE_ICON,
                        Tools.getString("HostBrowser.RemoveHost"),
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL),
                        new AccessMode(AccessMode.RO, AccessMode.NORMAL))
                        .enablePredicate(new EnablePredicate() {
                            @Override
                            public String check() {
                                if (hostInfo.getHost().isInCluster()) {
                                    return "it is a member of a cluster";
View Full Code Here

TOP

Related Classes of lcmc.common.domain.AccessMode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.