Skip to content

Commit 5594ea9

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-5519. [VMWARE] Cancel vCenter tasks if the task invoked by CloudStack failes with timeout error
Conflicts: vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java
1 parent f919441 commit 5594ea9

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareClient.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import javax.net.ssl.SSLSession;
2929
import javax.xml.ws.BindingProvider;
3030
import javax.xml.ws.handler.MessageContext;
31+
import javax.xml.ws.WebServiceException;
32+
33+
import org.apache.log4j.Logger;
3134

3235
import com.vmware.vim25.DynamicProperty;
3336
import com.vmware.vim25.InvalidCollectorVersionFaultMsg;
@@ -59,6 +62,7 @@
5962
*
6063
*/
6164
public class VmwareClient {
65+
private static final Logger s_logger = Logger.getLogger(VmwareClient.class);
6266

6367
private static class TrustAllTrustManager implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
6468

@@ -313,20 +317,25 @@ private List<ObjectContent> retrieveMoRefProperties(ManagedObjectReference mObj,
313317
* @throws RuntimeFaultFaultMsg
314318
* @throws InvalidPropertyFaultMsg
315319
*/
316-
public boolean waitForTask(ManagedObjectReference task) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
320+
public boolean waitForTask(ManagedObjectReference task) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg, Exception {
317321

318322
boolean retVal = false;
319323

320-
// info has a property - state for state of the task
321-
Object[] result =
322-
waitForValues(task, new String[] {"info.state", "info.error"}, new String[] {"state"}, new Object[][] {new Object[] {TaskInfoState.SUCCESS,
323-
TaskInfoState.ERROR}});
324-
325-
if (result[0].equals(TaskInfoState.SUCCESS)) {
326-
retVal = true;
327-
}
328-
if (result[1] instanceof LocalizedMethodFault) {
329-
throw new RuntimeException(((LocalizedMethodFault)result[1]).getLocalizedMessage());
324+
try {
325+
// info has a property - state for state of the task
326+
Object[] result = waitForValues(task, new String[] { "info.state", "info.error" }, new String[] { "state" }, new Object[][] { new Object[] {
327+
TaskInfoState.SUCCESS, TaskInfoState.ERROR } });
328+
329+
if (result[0].equals(TaskInfoState.SUCCESS)) {
330+
retVal = true;
331+
}
332+
if (result[1] instanceof LocalizedMethodFault) {
333+
throw new RuntimeException(((LocalizedMethodFault) result[1]).getLocalizedMessage());
334+
}
335+
} catch(WebServiceException we) {
336+
s_logger.debug("Cancelling vCenter task because task failed with " + we.getLocalizedMessage());
337+
getService().cancelTask(task);
338+
throw new RuntimeException("vCenter task failed due to " + we.getLocalizedMessage());
330339
}
331340
return retVal;
332341
}

0 commit comments

Comments
 (0)