String areYouSureQuestion = operationType == StorageNodeOperation.OTHER ? question.getMessage(operationName,
selectedAddresses.toString()) : question.getMessage(selectedAddresses.toString());
SC.ask(areYouSureQuestion, new BooleanCallback() {
public void execute(Boolean confirmed) {
if (confirmed) {
final CountDownLatch latch = CountDownLatch.create(selections.length, new Command() {
@Override
public void execute() {
String msgString = null;
if (operationType == StorageNodeOperation.OTHER) {
msgString = success.getMessage(operationName, selectedAddresses.toString());
} else {
msgString = success.getMessage(selectedAddresses.toString());
}
Message msg = new Message(msgString, Message.Severity.Info);
CoreGUI.getMessageCenter().notify(msg);
refreshTableInfo();
}
});
boolean isStopStartOrRestart = Arrays.asList("start", "shutdown", "restart")
.contains(operationName);
for (ListGridRecord storageNodeRecord : selections) {
// NFE should never happen, because of the condition for table action enablement
int resourceId = storageNodeRecord.getAttributeAsInt(FIELD_RESOURCE_ID.propertyName());
if (isStopStartOrRestart) {
// start, stop or restart the storage node
GWTServiceLookup.getOperationService().scheduleResourceOperation(resourceId, operationName,
null, "Run by Storage Node Administrations UI", 0, new AsyncCallback<Void>() {
public void onSuccess(Void result) {
latch.countDown();
}
public void onFailure(Throwable caught) {
String msg = failure.getMessage(operationName,
selectedAddresses + " " + caught.getMessage());
CoreGUI.getErrorHandler().handleError(msg, caught);
latch.countDown();
refreshTableInfo();
}
});
} else {
if (operationType != StorageNodeOperation.OTHER) { // (un)deploy
AsyncCallback<Void> callback = new AsyncCallback<Void>() {
public void onSuccess(Void result) {
latch.countDown();
}
public void onFailure(Throwable caught) {
String msg = failure.getMessage(
selectedAddresses.toString(),
Arrays.asList(getSelectedIds(selections)).toString() + " "
+ caught.getMessage());
CoreGUI.getErrorHandler().handleError(msg, caught);
latch.countDown();
refreshTableInfo();
}
};
int storageNodeId = storageNodeRecord.getAttributeAsInt("id");
StorageNode node = new StorageNode(storageNodeId);
if (operationType == StorageNodeOperation.DEPLOY) {
GWTServiceLookup.getStorageService().deployStorageNode(node, callback);
} else {
GWTServiceLookup.getStorageService().undeployStorageNode(node, callback);
}
} else {
// invoke the operation on the storage service resource
GWTServiceLookup.getStorageService().invokeOperationOnStorageService(resourceId,
operationName, new AsyncCallback<Void>() {
public void onSuccess(Void result) {
latch.countDown();
}
public void onFailure(Throwable caught) {
String msg = failure.getMessage(operationName, selectedAddresses + " "
+ caught.getMessage());
CoreGUI.getErrorHandler().handleError(msg, caught);
latch.countDown();
refreshTableInfo();
}
});
}
}