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