1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.redhat.vmtruckloader.vmware.action;
23
24 import java.rmi.RemoteException;
25
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import com.vmware.vim25.DuplicateName;
30 import com.vmware.vim25.FileFault;
31 import com.vmware.vim25.InsufficientResourcesFault;
32 import com.vmware.vim25.InvalidDatastore;
33 import com.vmware.vim25.InvalidName;
34 import com.vmware.vim25.OutOfBounds;
35 import com.vmware.vim25.RuntimeFault;
36 import com.vmware.vim25.TaskInfo;
37 import com.vmware.vim25.VmConfigFault;
38 import com.vmware.vim25.mo.Task;
39
40
41
42
43
44
45 public abstract class AbstractVMWareActionCallback<T> implements VMWareActionCallback<T> {
46
47 private static final Logger LOGGER = LoggerFactory.getLogger(AbstractVMWareActionCallback.class);
48
49 protected void runTask(String errorMssg) {
50 Task task;
51 try {
52 task = runTask();
53 String status = task.waitForTask();
54 if ( status != Task.SUCCESS ) {
55 TaskInfo info = task.getTaskInfo();
56 LOGGER.warn(info.getError().localizedMessage);
57 throw new IllegalStateException(errorMssg);
58 }
59 } catch (InvalidName e) {
60 throw new IllegalArgumentException(e);
61 } catch (VmConfigFault e) {
62 throw new IllegalArgumentException(e);
63 } catch (DuplicateName e) {
64 throw new IllegalArgumentException(e);
65 } catch (FileFault e) {
66 throw new IllegalStateException(e);
67 } catch (OutOfBounds e) {
68 throw new IllegalStateException(e);
69 } catch (InsufficientResourcesFault e) {
70 throw new IllegalStateException(e);
71 } catch (InvalidDatastore e) {
72 throw new IllegalArgumentException(e);
73 } catch (RuntimeFault e) {
74 throw new IllegalStateException(e);
75 } catch (RemoteException e) {
76 throw new IllegalStateException(e);
77 } catch (InterruptedException e) {
78 LOGGER.warn("Wait for task timed out - task may not have finished successfully:" + e.getLocalizedMessage());
79 } catch (Exception e ) {
80 LOGGER.warn("Unknown Exception:" + e.getMessage());
81 throw new IllegalStateException(e);
82 }
83 }
84
85 protected Task runTask() throws InvalidName, VmConfigFault, DuplicateName, FileFault, OutOfBounds, InsufficientResourcesFault, InvalidDatastore, RuntimeFault, RemoteException {
86 throw new UnsupportedOperationException("Callback " + this.getClass() + " has invoked runTaks but not override it!");
87 }
88
89 }