si.startResource(dcHost, Application.RunMode.LIVE);
}
}
});
final ButtonCallback startItemCallback = getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.startResource(dcHost, Application.RunMode.TEST);
}
}
});
pcmkMultiSelectionInfo.addMouseOverListener(startMenuItem, startItemCallback);
items.add((UpdatableItem) startMenuItem);
/* stop resources */
final ComponentWithTest stopMenuItem =
menuFactory.createMenuItem(Tools.getString("PcmkMultiSelectionInfo.StopSelectedResources"),
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 (getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
boolean allStopped = true;
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
if (!si.isStopped(Application.RunMode.LIVE)) {
allStopped = false;
}
final String avail = si.getService().isAvailableWithText();
if (avail != null) {
return avail;
}
}
if (allStopped) {
return Tools.getString("ServiceInfo.AlreadyStopped");
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
final Host dcHost = getBrowser().getDCHost();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.stopResource(dcHost, Application.RunMode.LIVE);
}
}
});
final ButtonCallback stopItemCallback = getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.stopResource(dcHost, Application.RunMode.TEST);
}
}
});
pcmkMultiSelectionInfo.addMouseOverListener(stopMenuItem, stopItemCallback);
items.add((UpdatableItem) stopMenuItem);
/* clean up resource */
final UpdatableItem cleanupMenuItem =
menuFactory.createMenuItem(
Tools.getString("PcmkMultiSelectionInfo.CleanUpFailedResource"),
ServiceInfo.SERVICE_RUNNING_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
Tools.getString("PcmkMultiSelectionInfo.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() {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.getService().isAvailable() && si.isOneFailed(Application.RunMode.LIVE)) {
return true;
}
}
return false;
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
boolean failCount = false;
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
if (si.isOneFailedCount(Application.RunMode.LIVE)) {
failCount = true;
}
}
if (!failCount) {
return "no fail count";
}
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
final String avail = si.getService().isAvailableWithText();
if (avail != null) {
return avail;
}
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
final Host dcHost = getBrowser().getDCHost();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.cleanupResource(dcHost, Application.RunMode.LIVE);
}
}
});
/* cleanup ignores CIB_file */
items.add(cleanupMenuItem);
/* manage resource */
final ComponentWithTest manageMenuItem =
menuFactory.createMenuItem(
Tools.getString("PcmkMultiSelectionInfo.ManageResource"),
ServiceInfo.MANAGE_BY_CRM_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
if (!si.isManaged(Application.RunMode.LIVE)) {
return true;
}
}
return false;
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
final String avail = si.getService().isAvailableWithText();
if (avail != null) {
return avail;
}
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
final Host dcHost = getBrowser().getDCHost();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.setManaged(true, dcHost, Application.RunMode.LIVE);
}
}
});
final ButtonCallback manageItemCallback = getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.setManaged(true, dcHost, Application.RunMode.TEST);
}
}
});
pcmkMultiSelectionInfo.addMouseOverListener(manageMenuItem, manageItemCallback);
items.add((UpdatableItem) manageMenuItem);
/* unmanage resource */
final ComponentWithTest unmanageMenuItem =
menuFactory.createMenuItem(
Tools.getString("PcmkMultiSelectionInfo.UnmanageResource"),
ServiceInfo.UNMANAGE_BY_CRM_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
if (si.isManaged(Application.RunMode.LIVE)) {
return true;
}
}
return false;
}
})
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
final String avail = si.getService().isAvailableWithText();
if (avail != null) {
return avail;
}
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
final Host dcHost = getBrowser().getDCHost();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.setManaged(false, dcHost, Application.RunMode.LIVE);
}
}
});
final ButtonCallback unmanageItemCallback = getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.setManaged(false, dcHost, Application.RunMode.TEST);
}
}
});
pcmkMultiSelectionInfo.addMouseOverListener(unmanageMenuItem, unmanageItemCallback);
items.add((UpdatableItem) unmanageMenuItem);
/* migrate resource */
for (final Host host : getBrowser().getClusterHosts()) {
final String hostName = host.getName();
final MyMenuItem migrateFromMenuItem =
menuFactory.createMenuItem(Tools.getString("PcmkMultiSelectionInfo.MigrateFromResource")
+ ' ' + hostName,
ServiceInfo.MIGRATE_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
Tools.getString("PcmkMultiSelectionInfo.MigrateFromResource")
+ ' ' + hostName + " (offline)",
ServiceInfo.MIGRATE_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 host.isCrmStatusOk();
}
})
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
if (!host.isCrmStatusOk()) {
return false;
}
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
if (getBrowser().crmStatusFailed() || !host.isCrmStatusOk()) {
return false;
}
final List<String> runningOnNodes = si.getRunningOnNodes(Application.RunMode.LIVE);
if (runningOnNodes == null || runningOnNodes.size() < 1) {
return false;
}
boolean runningOnNode = false;
for (final String ron : runningOnNodes) {
if (hostName.toLowerCase(Locale.US).equals(ron.toLowerCase(Locale.US))) {
runningOnNode = true;
break;
}
}
if (si.getService().isAvailable() && runningOnNode) {
} else {
return false;
}
}
return true;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
final Host dcHost = getBrowser().getDCHost();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.migrateFromResource(dcHost, hostName, Application.RunMode.LIVE);
}
}
});
final ButtonCallback migrateItemCallback = getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.migrateFromResource(dcHost, hostName, Application.RunMode.TEST);
}
}
});
pcmkMultiSelectionInfo.addMouseOverListener(migrateFromMenuItem, migrateItemCallback);
items.add(migrateFromMenuItem);
}
/* unmigrate resource */
final ComponentWithTest unmigrateMenuItem =
menuFactory.createMenuItem(
Tools.getString("PcmkMultiSelectionInfo.UnmigrateResource"),
ServiceInfo.UNMIGRATE_ICON,
ClusterBrowser.STARTING_PTEST_TOOLTIP,
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
if (!getBrowser().crmStatusFailed()
&& si.getService().isAvailable()
&& (si.getMigratedTo(Application.RunMode.LIVE) != null
|| si.getMigratedFrom(Application.RunMode.LIVE) != null)) {
} else {
return false;
}
}
return true;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
final Host dcHost = getBrowser().getDCHost();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.unmigrateResource(dcHost, Application.RunMode.LIVE);
}
}
});
final ButtonCallback unmigrateItemCallback = getBrowser().new ClMenuItemCallback(null)
.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
if (si.isConstraintPlaceholder() || si.getService().isNew() || si.getService().isOrphaned()) {
continue;
}
si.unmigrateResource(dcHost, Application.RunMode.TEST);
}
}
});
pcmkMultiSelectionInfo.addMouseOverListener(unmigrateMenuItem, unmigrateItemCallback);
items.add((UpdatableItem) unmigrateMenuItem);
/* remove service */
final ComponentWithTest removeMenuItem = menuFactory.createMenuItem(
Tools.getString("PcmkMultiSelectionInfo.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 (getBrowser().crmStatusFailed()) {
return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
}
final ClusterStatus cs = getBrowser().getClusterStatus();
for (final ServiceInfo si : selectedServiceInfos) {
if (si.getService().isNew()) {
continue;
} else if (si.getService().isRemoved()) {
return ServiceInfo.IS_BEING_REMOVED_STRING;
} else if (si.isRunning(Application.RunMode.LIVE) && !application.isAdvancedMode()) {
return "cannot remove running resource<br>(advanced mode only)";
}
final GroupInfo gi = si.getGroupInfo();
if (gi == null) {
continue;
}
final List<String> gr = cs.getGroupResources(
gi.getHeartbeatId(Application.RunMode.LIVE),
Application.RunMode.LIVE);
if (gr == null || gr.size() <= 1) {
return "you can remove the group";
}
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
pcmkMultiSelectionInfo.hidePopup();
if (!application.confirmDialog(
Tools.getString("PcmkMultiSelectionInfo.confirmRemove.Title"),
Tools.getString("PcmkMultiSelectionInfo.confirmRemove.Desc"),
Tools.getString("PcmkMultiSelectionInfo.confirmRemove.Yes"),
Tools.getString("PcmkMultiSelectionInfo.confirmRemove.No"))) {
return;
}
final Host dcHost = getBrowser().getDCHost();
for (ServiceInfo si : selectedServiceInfos) {
final ServiceInfo cs = si.getContainedService();
if (cs != null) {
si = cs;
}
if (si.getService().isOrphaned()) {
si.cleanupResource(dcHost, Application.RunMode.LIVE);
} else {
si.removeMyselfNoConfirm(dcHost, Application.RunMode.LIVE);
}
}
getBrowser().getCrmGraph().repaint();
}
});
final ClusterBrowser.ClMenuItemCallback removeItemCallback = getBrowser().new ClMenuItemCallback(null) {
public boolean isEnabled() {
if (!super.isEnabled()) {
return false;
}
for (final ServiceInfo si : selectedServiceInfos) {
if (si.getService().isNew()) {
return false;
}
}
return true;
}
};
removeItemCallback.addAction(new CallbackAction() {
@Override
public void run(final Host dcHost) {
for (final ServiceInfo si : selectedServiceInfos) {
si.removeMyselfNoConfirm(dcHost, Application.RunMode.TEST);
}