serviceInfo.hidePopup();
serviceInfo.startResource(serviceInfo.getBrowser().getDCHost(), runMode);
}
});
final ButtonCallback startItemCallback = serviceInfo.getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
serviceInfo.startResource(dcHost, Application.RunMode.TEST);
}
});
serviceInfo.addMouseOverListener(startMenuItem, startItemCallback);
items.add((UpdatableItem) startMenuItem);
/* stop resource */
final ComponentWithTest stopMenuItem =
menuFactory.createMenuItem(Tools.getString("ClusterBrowser.Hb.StopResource"),
ServiceInfo.STOP_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 (serviceInfo.getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
} else if (serviceInfo.isStopped(runMode)) {
return Tools.getString("ServiceInfo.AlreadyStopped");
} else {
return serviceInfo.getService().isAvailableWithText();
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
serviceInfo.hidePopup();
serviceInfo.stopResource(serviceInfo.getBrowser().getDCHost(), runMode);
}
});
final ButtonCallback stopItemCallback = serviceInfo.getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
serviceInfo.stopResource(dcHost, Application.RunMode.TEST);
}
});
serviceInfo.addMouseOverListener(stopMenuItem, stopItemCallback);
items.add((UpdatableItem) stopMenuItem);
/* up group resource */
final ComponentWithTest upMenuItem =
menuFactory.createMenuItem(Tools.getString("ClusterBrowser.Hb.UpResource"),
ServiceInfo.GROUP_UP_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return serviceInfo.getGroupInfo() != null;
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (serviceInfo.getResource().isNew()) {
return ServiceInfo.IS_NEW_STRING;
}
final GroupInfo gi = serviceInfo.getGroupInfo();
if (gi == null) {
return "no";
}
if (serviceInfo.getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
final DefaultMutableTreeNode giNode = gi.getNode();
if (giNode == null) {
return "no";
}
final DefaultMutableTreeNode node = serviceInfo.getNode();
if (node == null) {
return "no";
}
final int index = treeMenuController.getIndex(giNode, node);
if (index == 0) {
return "already up";
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
serviceInfo.hidePopup();
serviceInfo.upResource(serviceInfo.getBrowser().getDCHost(), runMode);
}
});
final ButtonCallback upItemCallback =
serviceInfo.getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
serviceInfo.upResource(dcHost, Application.RunMode.TEST);
}
});
serviceInfo.addMouseOverListener(upMenuItem, upItemCallback);
items.add((UpdatableItem) upMenuItem);
/* down group resource */
final ComponentWithTest downMenuItem =
menuFactory.createMenuItem(Tools.getString("ClusterBrowser.Hb.DownResource"),
ServiceInfo.GROUP_DOWN_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return serviceInfo.getGroupInfo() != null;
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (serviceInfo.getResource().isNew()) {
return ServiceInfo.IS_NEW_STRING;
}
final GroupInfo gi = serviceInfo.getGroupInfo();
if (gi == null) {
return "no";
}
if (serviceInfo.getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
final DefaultMutableTreeNode giNode = gi.getNode();
if (giNode == null) {
return "no";
}
final DefaultMutableTreeNode node = serviceInfo.getNode();
if (node == null) {
return "no";
}
final int index = treeMenuController.getIndex(giNode, node);
final int groupChildCount = treeMenuController.getChildCount(giNode);
if (index >= groupChildCount - 1) {
return "already down";
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
serviceInfo.hidePopup();
serviceInfo.downResource(serviceInfo.getBrowser().getDCHost(), runMode);
}
});
final ButtonCallback downItemCallback = serviceInfo.getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
serviceInfo.downResource(dcHost, Application.RunMode.TEST);
}
});
serviceInfo.addMouseOverListener(downMenuItem, downItemCallback);
items.add((UpdatableItem) downMenuItem);
/* clean up resource */
final UpdatableItem cleanupMenuItem = menuFactory.createMenuItem(
Tools.getString("ClusterBrowser.Hb.CleanUpFailedResource"),
ServiceInfo.SERVICE_RUNNING_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
Tools.getString("ClusterBrowser.Hb.CleanUpResource"),
ServiceInfo.SERVICE_RUNNING_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 serviceInfo.getService().isAvailable() && serviceInfo.isOneFailed(runMode);
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (serviceInfo.getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
} else if (!serviceInfo.isOneFailedCount(runMode)) {
return "no fail count";
} else {
return serviceInfo.getService().isAvailableWithText();
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
serviceInfo.hidePopup();
serviceInfo.cleanupResource(serviceInfo.getBrowser().getDCHost(), runMode);
}
});
/* cleanup ignores CIB_file */
items.add(cleanupMenuItem);
/* manage resource */
final ComponentWithTest manageMenuItem =
menuFactory.createMenuItem(Tools.getString("ClusterBrowser.Hb.ManageResource"),
ServiceInfo.MANAGE_BY_CRM_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
Tools.getString("ClusterBrowser.Hb.UnmanageResource"),
ServiceInfo.UNMANAGE_BY_CRM_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 !serviceInfo.isManaged(runMode);
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (serviceInfo.getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
} else {
return serviceInfo.getService().isAvailableWithText();
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
serviceInfo.hidePopup();
if (text.equals(Tools.getString("ClusterBrowser.Hb.ManageResource"))) {
serviceInfo.setManaged(true, serviceInfo.getBrowser().getDCHost(), runMode);
} else {
serviceInfo.setManaged(false, serviceInfo.getBrowser().getDCHost(), runMode);
}
}
});
final ButtonCallback manageItemCallback =
serviceInfo.getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
serviceInfo.setManaged(!serviceInfo.isManaged(Application.RunMode.TEST),
dcHost,
Application.RunMode.TEST);
}
});
serviceInfo.addMouseOverListener(manageMenuItem, manageItemCallback);
items.add((UpdatableItem) manageMenuItem);
addMigrateMenuItems(serviceInfo, items);
if (ci == null) {
/* remove service */
final ComponentWithTest removeMenuItem = menuFactory.createMenuItem(
Tools.getString("ClusterBrowser.Hb.RemoveService"),
ClusterBrowser.REMOVE_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (serviceInfo.getService().isNew()) {
return null;
}
if (serviceInfo.getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
} else if (serviceInfo.getService().isRemoved()) {
return ServiceInfo.IS_BEING_REMOVED_STRING;
} else if (serviceInfo.isRunning(runMode) && !application.isAdvancedMode()) {
return "cannot remove running resource<br>(advanced mode only)";
}
if (serviceInfo.getGroupInfo() == null) {
return null;
}
final ClusterStatus cs = serviceInfo.getBrowser().getClusterStatus();
final List<String> gr = cs.getGroupResources(
serviceInfo.getGroupInfo().getHeartbeatId(runMode),
runMode);
if (gr != null && gr.size() > 1) {
return null;
} else {
return "you can remove the group";
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
serviceInfo.hidePopup();
if (serviceInfo.getService().isOrphaned()) {
serviceInfo.cleanupResource(serviceInfo.getBrowser().getDCHost(), runMode);
} else {
serviceInfo.removeMyself(Application.RunMode.LIVE);
}
serviceInfo.getBrowser().getCrmGraph().repaint();
}
});
final ButtonCallback removeItemCallback =
serviceInfo.getBrowser().new ClMenuItemCallback(null) {
@Override
public boolean isEnabled() {
return super.isEnabled() && !serviceInfo.getService().isNew();
}
}
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
serviceInfo.removeMyselfNoConfirm(dcHost, Application.RunMode.TEST);
}
});