2727import org .apache .log4j .Logger ;
2828import org .apache .xmlrpc .XmlRpcException ;
2929
30- import com .xensource .xenapi .Connection ;
31- import com .xensource .xenapi .Host ;
32- import com .xensource .xenapi .SR ;
33- import com .xensource .xenapi .Types ;
34- import com .xensource .xenapi .Types .XenAPIException ;
35- import com .xensource .xenapi .VBD ;
36- import com .xensource .xenapi .VDI ;
37- import com .xensource .xenapi .VM ;
38-
3930import com .cloud .agent .api .Answer ;
4031import com .cloud .agent .api .Command ;
4132import com .cloud .agent .api .NetworkUsageAnswer ;
4940import com .cloud .storage .Storage ;
5041import com .cloud .utils .exception .CloudRuntimeException ;
5142import com .cloud .utils .script .Script ;
43+ import com .xensource .xenapi .Connection ;
44+ import com .xensource .xenapi .Host ;
45+ import com .xensource .xenapi .SR ;
46+ import com .xensource .xenapi .Types ;
47+ import com .xensource .xenapi .Types .XenAPIException ;
48+ import com .xensource .xenapi .VBD ;
49+ import com .xensource .xenapi .VDI ;
50+ import com .xensource .xenapi .VM ;
5251
5352@ Local (value = ServerResource .class )
5453public class XcpOssResource extends CitrixResourceBase {
@@ -57,63 +56,63 @@ public class XcpOssResource extends CitrixResourceBase {
5756
5857 @ Override
5958 protected List <File > getPatchFiles () {
60- List <File > files = new ArrayList <File >();
61- String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch" ;
62- String patchfilePath = Script .findScript ("" , patch );
59+ final List <File > files = new ArrayList <File >();
60+ final String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch" ;
61+ final String patchfilePath = Script .findScript ("" , patch );
6362 if (patchfilePath == null ) {
6463 throw new CloudRuntimeException ("Unable to find patch file " + patch );
6564 }
66- File file = new File (patchfilePath );
65+ final File file = new File (patchfilePath );
6766 files .add (file );
6867 return files ;
6968 }
7069
7170 @ Override
72- protected void fillHostInfo (Connection conn , StartupRoutingCommand cmd ) {
71+ protected void fillHostInfo (final Connection conn , final StartupRoutingCommand cmd ) {
7372 super .fillHostInfo (conn , cmd );
7473 cmd .setCaps (cmd .getCapabilities () + " , hvm" );
7574 }
7675
7776 @ Override
78- protected boolean launchHeartBeat (Connection conn ) {
77+ protected boolean launchHeartBeat (final Connection conn ) {
7978 return true ;
8079 }
8180
8281 @ Override
83- protected StartupStorageCommand initializeLocalSR (Connection conn ) {
84- SR extsr = getLocalEXTSR (conn );
82+ protected StartupStorageCommand initializeLocalSR (final Connection conn ) {
83+ final SR extsr = getLocalEXTSR (conn );
8584 if (extsr != null ) {
8685 try {
87- String extuuid = extsr .getUuid (conn );
88- _host .localSRuuid = extuuid ;
89- long cap = extsr .getPhysicalSize (conn );
86+ final String extuuid = extsr .getUuid (conn );
87+ _host .setLocalSRuuid ( extuuid ) ;
88+ final long cap = extsr .getPhysicalSize (conn );
9089 if (cap > 0 ) {
91- long avail = cap - extsr .getPhysicalUtilisation (conn );
92- String name = "Cloud Stack Local EXT Storage Pool for " + _host .uuid ;
90+ final long avail = cap - extsr .getPhysicalUtilisation (conn );
91+ final String name = "Cloud Stack Local EXT Storage Pool for " + _host .getUuid () ;
9392 extsr .setNameDescription (conn , name );
94- Host host = Host .getByUuid (conn , _host .uuid );
95- String address = host .getAddress (conn );
96- StoragePoolInfo pInfo = new StoragePoolInfo (extsr .getNameLabel (conn ), address , SRType .EXT .toString (), SRType .EXT .toString (), Storage .StoragePoolType .EXT , cap , avail );
97- StartupStorageCommand cmd = new StartupStorageCommand ();
93+ final Host host = Host .getByUuid (conn , _host .getUuid () );
94+ final String address = host .getAddress (conn );
95+ final StoragePoolInfo pInfo = new StoragePoolInfo (extsr .getNameLabel (conn ), address , SRType .EXT .toString (), SRType .EXT .toString (), Storage .StoragePoolType .EXT , cap , avail );
96+ final StartupStorageCommand cmd = new StartupStorageCommand ();
9897 cmd .setPoolInfo (pInfo );
99- cmd .setGuid (_host .uuid );
98+ cmd .setGuid (_host .getUuid () );
10099 cmd .setDataCenter (Long .toString (_dcId ));
101100 cmd .setResourceType (Storage .StorageResourceType .STORAGE_POOL );
102101 return cmd ;
103102 }
104- } catch (XenAPIException e ) {
105- String msg = "build local EXT info err in host:" + _host .uuid + e .toString ();
103+ } catch (final XenAPIException e ) {
104+ final String msg = "build local EXT info err in host:" + _host .getUuid () + e .toString ();
106105 s_logger .warn (msg );
107- } catch (XmlRpcException e ) {
108- String msg = "build local EXT info err in host:" + _host .uuid + e .getMessage ();
106+ } catch (final XmlRpcException e ) {
107+ final String msg = "build local EXT info err in host:" + _host .getUuid () + e .getMessage ();
109108 s_logger .warn (msg );
110109 }
111110 }
112111 return null ;
113112 }
114113
115114 @ Override
116- protected String getGuestOsType (String stdType , String platformEmulator , boolean bootFromCD ) {
115+ protected String getGuestOsType (final String stdType , final String platformEmulator , final boolean bootFromCD ) {
117116 if (stdType .equalsIgnoreCase ("Debian GNU/Linux 6(64-bit)" )) {
118117 return "Debian Squeeze 6.0 (64-bit)" ;
119118 } else if (stdType .equalsIgnoreCase ("CentOS 5.6 (64-bit)" )) {
@@ -124,54 +123,54 @@ protected String getGuestOsType(String stdType, String platformEmulator, boolean
124123 }
125124
126125 @ Override
127- protected synchronized VBD createPatchVbd (Connection conn , String vmName , VM vm ) throws XmlRpcException , XenAPIException {
128- if (_host .localSRuuid != null ) {
126+ protected synchronized VBD createPatchVbd (final Connection conn , final String vmName , final VM vm ) throws XmlRpcException , XenAPIException {
127+ if (_host .getLocalSRuuid () != null ) {
129128 //create an iso vdi on it
130- String result = callHostPlugin (conn , "vmops" , "createISOVHD" , "uuid" , _host .localSRuuid );
129+ final String result = callHostPlugin (conn , "vmops" , "createISOVHD" , "uuid" , _host .getLocalSRuuid () );
131130 if (result == null || result .equalsIgnoreCase ("Failed" )) {
132131 throw new CloudRuntimeException ("can not create systemvm vdi" );
133132 }
134133
135- Set <VDI > vdis = VDI .getByNameLabel (conn , "systemvm-vdi" );
134+ final Set <VDI > vdis = VDI .getByNameLabel (conn , "systemvm-vdi" );
136135 if (vdis .size () != 1 ) {
137136 throw new CloudRuntimeException ("can not find systemvmiso" );
138137 }
139- VDI systemvmVDI = vdis .iterator ().next ();
138+ final VDI systemvmVDI = vdis .iterator ().next ();
140139
141- VBD .Record cdromVBDR = new VBD .Record ();
140+ final VBD .Record cdromVBDR = new VBD .Record ();
142141 cdromVBDR .VM = vm ;
143142 cdromVBDR .empty = false ;
144143 cdromVBDR .bootable = false ;
145144 cdromVBDR .userdevice = "3" ;
146145 cdromVBDR .mode = Types .VbdMode .RO ;
147146 cdromVBDR .type = Types .VbdType .DISK ;
148147 cdromVBDR .VDI = systemvmVDI ;
149- VBD cdromVBD = VBD .create (conn , cdromVBDR );
148+ final VBD cdromVBD = VBD .create (conn , cdromVBDR );
150149 return cdromVBD ;
151150 } else {
152151 throw new CloudRuntimeException ("can not find local sr" );
153152 }
154153 }
155154
156- protected NetworkUsageAnswer execute (NetworkUsageCommand cmd ) {
155+ protected NetworkUsageAnswer execute (final NetworkUsageCommand cmd ) {
157156 try {
158- Connection conn = getConnection ();
157+ final Connection conn = getConnection ();
159158 if (cmd .getOption () != null && cmd .getOption ().equals ("create" )) {
160- String result = networkUsage (conn , cmd .getPrivateIP (), "create" , null );
161- NetworkUsageAnswer answer = new NetworkUsageAnswer (cmd , result , 0L , 0L );
159+ final String result = networkUsage (conn , cmd .getPrivateIP (), "create" , null );
160+ final NetworkUsageAnswer answer = new NetworkUsageAnswer (cmd , result , 0L , 0L );
162161 return answer ;
163162 }
164- long [] stats = getNetworkStats (conn , cmd .getPrivateIP ());
165- NetworkUsageAnswer answer = new NetworkUsageAnswer (cmd , "" , stats [0 ], stats [1 ]);
163+ final long [] stats = getNetworkStats (conn , cmd .getPrivateIP ());
164+ final NetworkUsageAnswer answer = new NetworkUsageAnswer (cmd , "" , stats [0 ], stats [1 ]);
166165 return answer ;
167- } catch (Exception ex ) {
166+ } catch (final Exception ex ) {
168167 s_logger .warn ("Failed to get network usage stats due to " , ex );
169168 return new NetworkUsageAnswer (cmd , ex );
170169 }
171170 }
172171
173172 @ Override
174- public Answer executeRequest (Command cmd ) {
173+ public Answer executeRequest (final Command cmd ) {
175174 if (cmd instanceof NetworkUsageCommand ) {
176175 return execute ((NetworkUsageCommand ) cmd );
177176 } else {
@@ -180,18 +179,18 @@ public Answer executeRequest(Command cmd) {
180179 }
181180
182181 @ Override
183- public StopAnswer execute (StopCommand cmd ) {
184- StopAnswer answer = super .execute (cmd );
185- String vmName = cmd .getVmName ();
182+ public StopAnswer execute (final StopCommand cmd ) {
183+ final StopAnswer answer = super .execute (cmd );
184+ final String vmName = cmd .getVmName ();
186185 if (vmName .startsWith ("v-" )) {
187- Connection conn = getConnection ();
186+ final Connection conn = getConnection ();
188187 callHostPlugin (conn , "vmops" , "setDNATRule" , "add" , "false" );
189188 }
190189 return answer ;
191190 }
192191
193192 @ Override
194- protected void setMemory (Connection conn , VM vm , long minMemsize , long maxMemsize ) throws XmlRpcException , XenAPIException {
193+ protected void setMemory (final Connection conn , final VM vm , final long minMemsize , final long maxMemsize ) throws XmlRpcException , XenAPIException {
195194 vm .setMemoryLimits (conn , mem_32m , maxMemsize , minMemsize , maxMemsize );
196195 }
197196}
0 commit comments