final Application.RunMode runMode = Application.RunMode.LIVE;
final MyMenu repMenuItem = menuFactory.createMenu(
Tools.getString("HostBrowser.Drbd.AddDrbdResource"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
final DrbdXml dxml = getClusterBrowser().getDrbdXml();
if (getDrbdVolumeInfo() != null) {
return "it is already a drbd resouce";
} else if (!getHost().isConnected()) {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
} else if (!getHost().isDrbdLoaded()) {
return "drbd is not loaded";
} else if (getBlockDevice().isMounted()) {
return "is mounted";
} else if (getBlockDevice().isVolumeGroupOnPhysicalVolume()) {
return "is volume group";
} else if (!getBlockDevice().isAvailable()) {
return "not available";
} else if (dxml.isDrbdDisabled()) {
return "disabled because of config";
} else {
final String noavail = getClusterBrowser().isDrbdAvailable(getHost());
if (noavail != null) {
return "DRBD installation problem: " + noavail;
}
}
return null;
}
});
repMenuItem.onUpdate(new Runnable() {
@Override
public void run() {
repMenuItem.updateMenuComponents();
final Cluster cluster = getHost().getCluster();
final Host[] otherHosts = cluster.getHostsArray();
final Collection<MyMenu> hostMenus = new ArrayList<MyMenu>();
for (final Host oHost : otherHosts) {
if (oHost == getHost()) {
continue;
}
final MyMenu hostMenu = menuFactory.createMenu(oHost.getName(),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
final DrbdXml dxml = getClusterBrowser().getDrbdXml();
if (!oHost.isConnected()) {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
} else if (!oHost.isDrbdLoaded()) {
return "drbd is not loaded";
} else {
final String noavail = getClusterBrowser().isDrbdAvailable(getHost());
if (noavail != null) {
return "DRBD installation problem: " + noavail;
}
return null;
}
}
});
hostMenu.onUpdate(new Runnable() {
@Override
public void run() {
hostMenu.updateMenuComponents();
hostMenu.removeAll();
final Set<BlockDevInfo> blockDevInfos = oHost.getBrowser().getSortedBlockDevInfos();
final List<BlockDevInfo> blockDevInfosS = new ArrayList<BlockDevInfo>();
for (final BlockDevInfo oBdi : blockDevInfos) {
if (oBdi.getName().equals(getBlockDevice().getName())) {
blockDevInfosS.add(0, oBdi);
} else {
blockDevInfosS.add(oBdi);
}
}
for (final BlockDevInfo oBdi : blockDevInfosS) {
if (oBdi.getDrbdVolumeInfo() == null && oBdi.getBlockDevice().isAvailable()) {
hostMenu.add(addDrbdResourceMenuItem(oBdi, runMode));
}
if (oBdi.getName().equals(getBlockDevice().getName())) {
hostMenu.addSeparator();
}
}
hostMenu.processAccessMode();
}
});
hostMenu.updateAndWait();
hostMenus.add(hostMenu);
}
repMenuItem.removeAll();
for (final MyMenu hostMenu : hostMenus) {
repMenuItem.add(hostMenu);
}
repMenuItem.processAccessMode();
}
});
items.add(repMenuItem);
items.add(getPVCreateItem());
items.add(getPVRemoveItem());
items.add(getVGCreateItem());
items.add(getVGRemoveItem());
items.add(getLVCreateItem());
items.add(getLVRemoveItem());
items.add(getLVResizeItem());
items.add(getLVSnapshotItem());
final MyMenuItem attachMenu =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.Detach"),
BlockDevInfo.NO_HARDDISK_ICON_LARGE,
Tools.getString("HostBrowser.Drbd.Detach.ToolTip"),
Tools.getString("HostBrowser.Drbd.Attach"),
BlockDevInfo.HARDDISK_DRBD_ICON_LARGE,
Tools.getString("HostBrowser.Drbd.Attach.ToolTip"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.predicate(new Predicate() {
@Override
public boolean check() {
return !getBlockDevice().isDrbd() || getBlockDevice().isAttached();
}
})
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (getBlockDevice().isSyncing()) {
return VolumeInfo.IS_SYNCING_STRING;
}
return null;
}
});
attachMenu.addAction(new MenuAction() {
@Override
public void run(final String text) {
if (attachMenu.getText().equals(Tools.getString("HostBrowser.Drbd.Attach"))) {
blockDevInfo.attach(runMode);
} else {
blockDevInfo.detach(runMode);
}
}
});
final ClusterBrowser cb = getClusterBrowser();
if (cb != null) {
final ButtonCallback attachItemCallback = cb.new DRBDMenuItemCallback(getHost())
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
if (blockDevInfo.isDiskless(Application.RunMode.LIVE)) {
blockDevInfo.attach(Application.RunMode.TEST);
} else {
blockDevInfo.detach(Application.RunMode.TEST);
}
}
});
blockDevInfo.addMouseOverListener(attachMenu, attachItemCallback);
}
items.add(attachMenu);
/* connect / disconnect */
final MyMenuItem connectMenu =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.Disconnect"),
null,
Tools.getString("HostBrowser.Drbd.Disconnect"),
Tools.getString("HostBrowser.Drbd.Connect"),
null,
Tools.getString("HostBrowser.Drbd.Connect"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.predicate(new Predicate() {
@Override
public boolean check() {
return blockDevInfo.isConnectedOrWF(runMode);
}
})
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (!getBlockDevice().isSyncing()
|| ((getBlockDevice().isPrimary()
&& getBlockDevice().isSyncSource())
|| (blockDevInfo.getOtherBlockDevInfo().getBlockDevice().isPrimary()
&& getBlockDevice().isSyncTarget()))) {
return null;
} else {
return VolumeInfo.IS_SYNCING_STRING;
}
}
});
connectMenu.addAction(new MenuAction() {
@Override
public void run(final String text) {
if (connectMenu.getText().equals(Tools.getString("HostBrowser.Drbd.Connect"))) {
blockDevInfo.connect(runMode);
} else {
blockDevInfo.disconnect(runMode);
}
}
});
if (cb != null) {
final ButtonCallback connectItemCallback =
cb.new DRBDMenuItemCallback(getHost())
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
if (blockDevInfo.isConnectedOrWF(Application.RunMode.LIVE)) {
blockDevInfo.disconnect(Application.RunMode.TEST);
} else {
blockDevInfo.connect(Application.RunMode.TEST);
}
}
});
blockDevInfo.addMouseOverListener(connectMenu, connectItemCallback);
}
items.add(connectMenu);
/* set primary */
final UpdatableItem setPrimaryItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.SetPrimaryOtherSecondary"),
null,
Tools.getString("HostBrowser.Drbd.SetPrimaryOtherSecondary"),
Tools.getString("HostBrowser.Drbd.SetPrimary"),
null,
Tools.getString("HostBrowser.Drbd.SetPrimary"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.predicate(new Predicate() {
@Override
public boolean check() {
if (!getBlockDevice().isDrbd()) {
return false;
}
return getBlockDevice().isSecondary()
&& blockDevInfo.getOtherBlockDevInfo().getBlockDevice().isPrimary();
}
})
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (!getBlockDevice().isSecondary()) {
return "cannot do that to the primary";
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
final BlockDevInfo oBdi = blockDevInfo.getOtherBlockDevInfo();
if (oBdi != null
&& oBdi.getBlockDevice().isPrimary()
&& !"yes".equals(getDrbdResourceInfo().getParamSaved(
BlockDevInfo.ALLOW_TWO_PRIMARIES).getValueForConfig())) {
oBdi.setSecondary(runMode);
}
blockDevInfo.setPrimary(runMode);
}
});
items.add(setPrimaryItem);
/* set secondary */
final UpdatableItem setSecondaryItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.SetSecondary"),
null,
Tools.getString("HostBrowser.Drbd.SetSecondary.ToolTip"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (!getBlockDevice().isPrimary()) {
return "cannot do that to the secondary";
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
blockDevInfo.setSecondary(runMode);
}
});
items.add(setSecondaryItem);
/* force primary */
final UpdatableItem forcePrimaryItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ForcePrimary"),
null,
Tools.getString("HostBrowser.Drbd.ForcePrimary"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
blockDevInfo.forcePrimary(runMode);
}
});
items.add(forcePrimaryItem);
/* invalidate */
final UpdatableItem invalidateItem =
menuFactory.createMenuItem(
Tools.getString("HostBrowser.Drbd.Invalidate"),
null,
Tools.getString("HostBrowser.Drbd.Invalidate.ToolTip"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (getBlockDevice().isSyncing()) {
return VolumeInfo.IS_SYNCING_STRING;
}
if (getDrbdVolumeInfo().isVerifying()) {
return VolumeInfo.IS_VERIFYING_STRING;
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
blockDevInfo.invalidateBD(runMode);
}
});
items.add(invalidateItem);
/* resume / pause sync */
final MyMenuItem resumeSyncItem =
menuFactory.createMenuItem(
Tools.getString("HostBrowser.Drbd.ResumeSync"),
null,
Tools.getString("HostBrowser.Drbd.ResumeSync.ToolTip"),
Tools.getString("HostBrowser.Drbd.PauseSync"),
null,
Tools.getString("HostBrowser.Drbd.PauseSync.ToolTip"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.predicate(new Predicate() {
@Override
public boolean check() {
return getBlockDevice().isSyncing() && getBlockDevice().isPausedSync();
}
})
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (!getBlockDevice().isSyncing()) {
return "it is not being synced";
}
return null;
}
});
resumeSyncItem.addAction(new MenuAction() {
@Override
public void run(final String text) {
if (resumeSyncItem.getText().equals(Tools.getString("HostBrowser.Drbd.ResumeSync"))) {
blockDevInfo.resumeSync(runMode);
} else {
blockDevInfo.pauseSync(runMode);
}
}
});
items.add(resumeSyncItem);
/* resize */
final UpdatableItem resizeItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.Resize"),
null,
Tools.getString("HostBrowser.Drbd.Resize.ToolTip"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (getBlockDevice().isSyncing()) {
return VolumeInfo.IS_SYNCING_STRING;
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
blockDevInfo.resizeDrbd(runMode);
}
});
items.add(resizeItem);
/* discard my data */
final UpdatableItem discardDataItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.DiscardData"),
null,
Tools.getString("HostBrowser.Drbd.DiscardData.ToolTip"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
if (!application.isAdvancedMode() && getDrbdResourceInfo().isUsedByCRM()) {
return VolumeInfo.IS_USED_BY_CRM_STRING;
}
if (getBlockDevice().isSyncing()) {
return VolumeInfo.IS_SYNCING_STRING;
}
if (getBlockDevice().isPrimary()) {
return "cannot do that to the primary";
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
blockDevInfo.discardData(runMode);
}
});
items.add(discardDataItem);
/* proxy up/down */
final UpdatableItem proxyItem =
menuFactory.createMenuItem(Tools.getString("BlockDevInfo.Drbd.ProxyDown"),
null,
getMenuToolTip("DRBD.proxyDown"),
Tools.getString("BlockDevInfo.Drbd.ProxyUp"),
null,
getMenuToolTip("DRBD.proxyUp"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
if (!getBlockDevice().isDrbd()) {
return false;
}
return getDrbdResourceInfo().isProxy(getHost());
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!getBlockDevice().isDrbd()) {
return BlockDevInfo.NO_DRBD_RESOURCE_STRING;
}
final ResourceInfo dri = getDrbdResourceInfo();
final Host pHost = dri.getProxyHost(getHost(), !ResourceInfo.WIZARD);
if (pHost == null) {
return "not a proxy";
}
if (!pHost.isConnected()) {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
}
if (!pHost.isDrbdProxyRunning()) {
return "proxy daemon is not running";
}
return null;
}
})
.predicate(new Predicate() {
@Override
public boolean check() {
if (!getBlockDevice().isDrbd()) {
return false;
}
final ResourceInfo dri = getDrbdResourceInfo();
final Host pHost = dri.getProxyHost(getHost(), !ResourceInfo.WIZARD);
if (pHost == null) {
return false;
}
if (getBlockDevice().isDrbd()) {
return pHost.isDrbdProxyUp(getDrbdResourceInfo().getName());
} else {
return true;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
final ResourceInfo dri = getDrbdResourceInfo();
final Host pHost = dri.getProxyHost(getHost(), !ResourceInfo.WIZARD);
if (pHost.isDrbdProxyUp(getDrbdResourceInfo().getName())) {
DRBD.proxyDown(pHost, getDrbdResourceInfo().getName(), getDrbdVolumeInfo().getName(), runMode);
} else {
DRBD.proxyUp(pHost, getDrbdResourceInfo().getName(), getDrbdVolumeInfo().getName(), runMode);
}
getClusterBrowser().updateProxyHWInfo(pHost);
}
});
items.add(proxyItem);
/* view log */
final UpdatableItem viewDrbdLogItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ViewDrbdLog"),
BlockDevInfo.LOGFILE_ICON,
null,
new AccessMode(AccessMode.RO, AccessMode.NORMAL),
new AccessMode(AccessMode.RO, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return getBlockDevice().isDrbd();
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
return null;
}
})