} 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";
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
hostInfo.getHost().disconnect();
final ClusterBrowser b = hostInfo.getBrowser().getClusterBrowser();
if (b != null) {
guiData.unregisterAllHostsUpdate(b.getClusterViewPanel());
}
application.removeHostFromHosts(hostInfo.getHost());
guiData.allHostsUpdate();
}
});