}});
multiSelectionInfo.addMouseOverListener(disconnectMenu, disconnectItemCallback);
items.add(disconnectMenu);
/* set primary */
final UpdatableItem setPrimaryItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.SetPrimary"),
null,
Tools.getString("MultiSelectionInfo.SetPrimary"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean oneSecondary = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!application.isAdvancedMode() && bdi.getDrbdVolumeInfo().isUsedByCRM()) {
continue;
}
final BlockDevInfo oBdi = bdi.getOtherBlockDevInfo();
if (bdi.getBlockDevice().isSecondary()
&& ((!oBdi.getBlockDevice().isPrimary() && !selectedBlockDevInfos.contains(oBdi))
|| bdi.allowTwoPrimaries())) {
oneSecondary = true;
}
}
if (!oneSecondary) {
return "nothing to promote";
}
return null;
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& !bdi.getBlockDevice().isPrimary()
&& (application.isAdvancedMode() || !bdi.getDrbdVolumeInfo().isUsedByCRM())) {
final BlockDevInfo oBdi = bdi.getOtherBlockDevInfo();
if (oBdi != null
&& oBdi.getBlockDevice().isPrimary()
&& !selectedBlockDevInfos.contains(oBdi)
&& !bdi.allowTwoPrimaries()) {
continue;
}
bdi.setPrimary(Application.RunMode.LIVE);
}
}
}});
items.add(setPrimaryItem);
/* set secondary */
final UpdatableItem setSecondaryItem =
menuFactory.createMenuItem(
Tools.getString("MultiSelectionInfo.SetSecondary"),
null,
Tools.getString("MultiSelectionInfo.SetSecondary"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean onePrimary = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!application.isAdvancedMode() && bdi.getDrbdVolumeInfo().isUsedByCRM()) {
continue;
}
if (bdi.getBlockDevice().isPrimary()) {
onePrimary = true;
}
}
if (!onePrimary) {
return "nothing to demote";
}
return null;
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& bdi.getBlockDevice().isPrimary()
&& (application.isAdvancedMode() || !bdi.getDrbdVolumeInfo().isUsedByCRM())) {
bdi.setSecondary(Application.RunMode.LIVE);
}
}
}});
items.add(setSecondaryItem);
/* force primary */
final UpdatableItem forcePrimaryItem =
menuFactory.createMenuItem(
Tools.getString("MultiSelectionInfo.ForcePrimary"),
null,
Tools.getString("MultiSelectionInfo.ForcePrimary"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean oneSecondary = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!application.isAdvancedMode() && bdi.getDrbdVolumeInfo().isUsedByCRM()) {
continue;
}
final BlockDevInfo oBdi = bdi.getOtherBlockDevInfo();
if (bdi.getBlockDevice().isSecondary()
&& ((!oBdi.getBlockDevice().isPrimary() && !selectedBlockDevInfos.contains(oBdi))
|| bdi.allowTwoPrimaries())) {
oneSecondary = true;
}
}
if (!oneSecondary) {
return "nothing to promote";
}
return null;
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& !bdi.getBlockDevice().isPrimary()
&& (application.isAdvancedMode() || !bdi.getDrbdVolumeInfo().isUsedByCRM())) {
final BlockDevInfo oBdi = bdi.getOtherBlockDevInfo();
if (oBdi != null
&& oBdi.getBlockDevice().isPrimary()
&& !selectedBlockDevInfos.contains(oBdi)
&& !bdi.allowTwoPrimaries()) {
continue;
}
bdi.forcePrimary(Application.RunMode.LIVE);
}
}
}});
items.add(forcePrimaryItem);
/* invalidate */
final UpdatableItem invalidateItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.Invalidate"),
null,
Tools.getString("MultiSelectionInfo.Invalidate"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean canInvalidate = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!application.isAdvancedMode() && bdi.getDrbdVolumeInfo().isUsedByCRM()) {
continue;
}
if (bdi.getBlockDevice().isSyncing()) {
continue;
}
if (bdi.getDrbdVolumeInfo().isVerifying()) {
continue;
}
if (selectedBlockDevInfos.contains(bdi.getOtherBlockDevInfo())) {
continue;
}
canInvalidate = true;
}
if (canInvalidate) {
return null;
} else {
return "nothing to invalidate";
}
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& !bdi.getBlockDevice().isSyncing()
&& !bdi.getDrbdVolumeInfo().isVerifying()
&& !selectedBlockDevInfos.contains(bdi.getOtherBlockDevInfo())
&& (application.isAdvancedMode() || !bdi.getDrbdVolumeInfo().isUsedByCRM())) {
bdi.invalidateBD(Application.RunMode.LIVE);
}
}
}});
items.add(invalidateItem);
/* resume */
final UpdatableItem resumeSyncItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.ResumeSync"),
null,
Tools.getString("MultiSelectionInfo.ResumeSync"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean resumable = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!bdi.getBlockDevice().isSyncing()) {
continue;
}
if (bdi.getBlockDevice().isSyncTarget() || bdi.getBlockDevice().isSyncSource()) {
continue;
}
resumable = true;
}
if (!resumable) {
return "nothing to resume";
}
return null;
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& bdi.getBlockDevice().isSyncing()
&& !bdi.getBlockDevice().isSyncTarget()
&& !bdi.getBlockDevice().isSyncSource()) {
bdi.resumeSync(Application.RunMode.LIVE);
}
}
}});
items.add(resumeSyncItem);
/* pause sync */
final UpdatableItem pauseSyncItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.PauseSync"),
null,
Tools.getString("MultiSelectionInfo.PauseSync"),
new AccessMode(AccessMode.OP, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean pausable = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!bdi.getBlockDevice().isSyncTarget() && !bdi.getBlockDevice().isSyncSource()) {
continue;
}
pausable = true;
}
if (!pausable) {
return "nothing to pause";
}
return null;
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& (bdi.getBlockDevice().isSyncTarget() || bdi.getBlockDevice().isSyncSource())) {
bdi.pauseSync(Application.RunMode.LIVE);
}
}
}});
items.add(pauseSyncItem);
/* resize */
final UpdatableItem resizeItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.Resize"),
null,
Tools.getString("MultiSelectionInfo.Resize"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean resizable = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (bdi.getBlockDevice().isSyncing()) {
continue;
}
if (selectedBlockDevInfos.contains(bdi.getOtherBlockDevInfo())) {
continue;
}
resizable = true;
}
if (resizable) {
return null;
} else {
return "nothing to resize";
}
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& !selectedBlockDevInfos.contains(bdi.getOtherBlockDevInfo())
&& !bdi.getBlockDevice().isSyncing()) {
bdi.resizeDrbd(Application.RunMode.LIVE);
}
}
}});
items.add(resizeItem);
/* discard my data */
final UpdatableItem discardDataItem =
menuFactory.createMenuItem(
Tools.getString("MultiSelectionInfo.DiscardData"),
null,
Tools.getString("MultiSelectionInfo.DiscardData"),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
boolean discardable = false;
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
if (!application.isAdvancedMode() && bdi.getDrbdVolumeInfo().isUsedByCRM()) {
continue;
}
if (bdi.getBlockDevice().isSyncing()) {
continue;
}
if (bdi.getBlockDevice().isPrimary()) {
continue;
}
if (selectedBlockDevInfos.contains(bdi.getOtherBlockDevInfo())) {
continue;
}
discardable = true;
}
if (discardable) {
return null;
} else {
return "nothing to discard";
}
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (bdi.getBlockDevice().isDrbd()
&& !selectedBlockDevInfos.contains(bdi.getOtherBlockDevInfo())
&& (application.isAdvancedMode() || !bdi.getDrbdVolumeInfo().isUsedByCRM())
&& !bdi.getBlockDevice().isSyncing()
&& !bdi.getBlockDevice().isPrimary()) {
bdi.discardData(Application.RunMode.LIVE);
}
}
}});
items.add(discardDataItem);
/* proxy down */
final UpdatableItem proxyDownItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.ProxyDown"),
null,
Tools.getString("MultiSelectionInfo.ProxyDown"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
final ResourceInfo dri = bdi.getDrbdVolumeInfo().getDrbdResourceInfo();
final Host pHost = dri.getProxyHost(bdi.getHost(), !ResourceInfo.WIZARD);
if (pHost == null) {
return false;
}
if (pHost.isDrbdProxyUp(dri.getName())) {
return true;
}
}
return false;
}})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
final ResourceInfo dri = bdi.getDrbdVolumeInfo().getDrbdResourceInfo();
final Host pHost = dri.getProxyHost(bdi.getHost(), !ResourceInfo.WIZARD);
if (pHost == null) {
return "";
}
if (!pHost.isConnected()) {
return Host.PROXY_NOT_CONNECTED_MENU_TOOLTIP_TEXT;
}
}
return null;
}})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
final Collection<Host> hosts = new HashSet<Host>();
for (final BlockDevInfo bdi : selectedBlockDevInfos) {
if (!bdi.getBlockDevice().isDrbd()) {
continue;
}
final ResourceInfo dri = bdi.getDrbdVolumeInfo().getDrbdResourceInfo();
final Host pHost = dri.getProxyHost(bdi.getHost(), !ResourceInfo.WIZARD);
if (pHost.isDrbdProxyUp(dri.getName())) {
DRBD.proxyDown(pHost,
dri.getName(),
bdi.getDrbdVolumeInfo().getName(),
Application.RunMode.LIVE);
hosts.add(pHost);
}
}
for (final Host h : hosts) {
getBrowser().updateProxyHWInfo(h);
}
}});
items.add(proxyDownItem);
/* proxy up */
final UpdatableItem proxyUpItem =
menuFactory.createMenuItem(Tools.getString("MultiSelectionInfo.ProxyUp"),
null,
Tools.getString("MultiSelectionInfo.ProxyUp"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))