http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8be5bde8/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index a3c894d..4d663b2 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -47,6 +47,9 @@ import javax.naming.ConfigurationException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.apache.cloudstack.storage.command.StorageSubSystemCommand; +import org.apache.cloudstack.storage.to.TemplateObjectTO; +import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import org.w3c.dom.Document; @@ -55,36 +58,6 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import com.trilead.ssh2.SCPClient; -import com.xensource.xenapi.Bond; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Console; -import com.xensource.xenapi.Host; -import com.xensource.xenapi.HostCpu; -import com.xensource.xenapi.HostMetrics; -import com.xensource.xenapi.Network; -import com.xensource.xenapi.PBD; -import com.xensource.xenapi.PIF; -import com.xensource.xenapi.Pool; -import com.xensource.xenapi.SR; -import com.xensource.xenapi.Session; -import com.xensource.xenapi.Task; -import com.xensource.xenapi.Types; -import com.xensource.xenapi.Types.BadServerResponse; -import com.xensource.xenapi.Types.VmPowerState; -import com.xensource.xenapi.Types.XenAPIException; -import com.xensource.xenapi.VBD; -import com.xensource.xenapi.VDI; -import com.xensource.xenapi.VGPU; -import com.xensource.xenapi.VIF; -import com.xensource.xenapi.VLAN; -import com.xensource.xenapi.VM; -import com.xensource.xenapi.XenAPIObject; - -import org.apache.cloudstack.storage.command.StorageSubSystemCommand; -import org.apache.cloudstack.storage.to.TemplateObjectTO; -import org.apache.cloudstack.storage.to.VolumeObjectTO; - import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; @@ -244,6 +217,31 @@ import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.snapshot.VMSnapshot; +import com.trilead.ssh2.SCPClient; +import com.xensource.xenapi.Bond; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Console; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.HostCpu; +import com.xensource.xenapi.HostMetrics; +import com.xensource.xenapi.Network; +import com.xensource.xenapi.PBD; +import com.xensource.xenapi.PIF; +import com.xensource.xenapi.Pool; +import com.xensource.xenapi.SR; +import com.xensource.xenapi.Session; +import com.xensource.xenapi.Task; +import com.xensource.xenapi.Types; +import com.xensource.xenapi.Types.BadServerResponse; +import com.xensource.xenapi.Types.VmPowerState; +import com.xensource.xenapi.Types.XenAPIException; +import com.xensource.xenapi.VBD; +import com.xensource.xenapi.VDI; +import com.xensource.xenapi.VGPU; +import com.xensource.xenapi.VIF; +import com.xensource.xenapi.VLAN; +import com.xensource.xenapi.VM; +import com.xensource.xenapi.XenAPIObject; /** * CitrixResourceBase encapsulates the calls to the XenServer Xapi process @@ -321,7 +319,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return _str; } - public boolean equals(String type) { + public boolean equals(final String type) { return _str.equalsIgnoreCase(type); } } @@ -340,23 +338,24 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return _host; } - private static boolean isAlienVm(VM vm, Connection conn) throws XenAPIException, XmlRpcException { + private static boolean isAlienVm(final VM vm, final Connection conn) throws XenAPIException, XmlRpcException { // TODO : we need a better way to tell whether or not the VM belongs to CloudStack - String vmName = vm.getNameLabel(conn); - if (vmName.matches("^[ivs]-\\d+-.+")) + final String vmName = vm.getNameLabel(conn); + if (vmName.matches("^[ivs]-\\d+-.+")) { return false; + } return true; } - protected boolean cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException { - Host host = Host.getByUuid(conn, _host.uuid); - Map<VM, VM.Record> vms = VM.getAllRecords(conn); + protected boolean cleanupHaltedVms(final Connection conn) throws XenAPIException, XmlRpcException { + final Host host = Host.getByUuid(conn, _host.uuid); + final Map<VM, VM.Record> vms = VM.getAllRecords(conn); boolean success = true; if(vms != null && !vms.isEmpty()) { - for (Map.Entry<VM, VM.Record> entry : vms.entrySet()) { - VM vm = entry.getKey(); - VM.Record vmRec = entry.getValue(); + for (final Map.Entry<VM, VM.Record> entry : vms.entrySet()) { + final VM vm = entry.getKey(); + final VM.Record vmRec = entry.getValue(); if (vmRec.isATemplate || vmRec.isControlDomain) { continue; } @@ -364,7 +363,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (VmPowerState.HALTED.equals(vmRec.powerState) && vmRec.affinity.equals(host) && !isAlienVm(vm, conn)) { try { vm.destroy(conn); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Catch Exception " + e.getClass().getName() + ": unable to destroy VM " + vmRec.nameLabel + " due to ", e); success = false; } @@ -374,15 +373,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return success; } - protected boolean isRefNull(XenAPIObject object) { - return (object == null || object.toWireString().equals("OpaqueRef:NULL") || object.toWireString().equals("<not in database>")); + protected boolean isRefNull(final XenAPIObject object) { + return object == null || object.toWireString().equals("OpaqueRef:NULL") || object.toWireString().equals("<not in database>"); } @Override public void disconnected() { } - protected boolean pingdomr(Connection conn, String host, String port) { + protected boolean pingdomr(final Connection conn, final String host, final String port) { String status; status = callHostPlugin(conn, "vmops", "pingdomr", "host", host, "port", port); @@ -395,20 +394,20 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } protected boolean pingXAPI() { - Connection conn = getConnection(); + final Connection conn = getConnection(); try { - Host host = Host.getByUuid(conn, _host.uuid); + final Host host = Host.getByUuid(conn, _host.uuid); if( !host.getEnabled(conn) ) { s_logger.debug("Host " + _host.ip + " is not enabled!"); return false; } - } catch (Exception e) { + } catch (final Exception e) { s_logger.debug("cannot get host enabled status, host " + _host.ip + " due to " + e.toString(), e); return false; } try { callHostPlugin(conn, "echo", "main"); - } catch (Exception e) { + } catch (final Exception e) { s_logger.debug("cannot ping host " + _host.ip + " due to " + e.toString(), e); return false; } @@ -416,13 +415,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } - protected String logX(XenAPIObject obj, String msg) { + protected String logX(final XenAPIObject obj, final String msg) { return new StringBuilder("Host ").append(_host.ip).append(" ").append(obj.toWireString()).append(": ").append(msg).toString(); } @Override - public Answer executeRequest(Command cmd) { - Class<? extends Command> clazz = cmd.getClass(); + public Answer executeRequest(final Command cmd) { + final Class<? extends Command> clazz = cmd.getClass(); if (clazz == CreateCommand.class) { return execute((CreateCommand)cmd); } else if (cmd instanceof NetworkElementCommand) { @@ -547,7 +546,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } @Override - public ExecutionResult executeInVR(String routerIP, String script, String args, int timeout) { + public ExecutionResult executeInVR(final String routerIP, final String script, final String args, final int timeout) { Pair<Boolean, String> result; String cmdline = "/opt/cloud/bin/router_proxy.sh " + script + " " + routerIP + " " + args; // semicolon need to be escape for bash @@ -556,29 +555,29 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.debug("Executing command in VR: " + cmdline); result = SshHelper.sshExecute(_host.ip, 22, _username, null, _password.peek(), cmdline, 60000, 60000, timeout * 1000); - } catch (Exception e) { + } catch (final Exception e) { return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(result.first(), result.second()); } @Override - public ExecutionResult executeInVR(String routerIP, String script, String args) { + public ExecutionResult executeInVR(final String routerIP, final String script, final String args) { // Timeout is 120 seconds by default return executeInVR(routerIP, script, args, 120); } @Override - public ExecutionResult createFileInVR(String routerIp, String path, String filename, String content) { - Connection conn = getConnection(); - String rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "filepath", path + filename, "filecontents", content); + public ExecutionResult createFileInVR(final String routerIp, final String path, final String filename, final String content) { + final Connection conn = getConnection(); + final String rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "filepath", path + filename, "filecontents", content); s_logger.debug ("VR Config file " + filename + " got created in VR with ip " + routerIp + " with content \n" + content); // Fail case would be start with "fail#" return new ExecutionResult(rc.startsWith("succ#"), rc.substring(5)); } @Override - public ExecutionResult prepareCommand(NetworkElementCommand cmd) { + public ExecutionResult prepareCommand(final NetworkElementCommand cmd) { //Update IP used to access router cmd.setRouterAccessIp(cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP)); assert cmd.getRouterAccessIp() != null; @@ -598,66 +597,68 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } @Override - public ExecutionResult cleanupCommand(NetworkElementCommand cmd) { + public ExecutionResult cleanupCommand(final NetworkElementCommand cmd) { if (cmd instanceof IpAssocCommand && !(cmd instanceof IpAssocVpcCommand)) { return cleanupNetworkElementCommand((IpAssocCommand)cmd); } return new ExecutionResult(true, null); } - private Answer execute(PerformanceMonitorCommand cmd) { - Connection conn = getConnection(); - String perfMon = getPerfMon(conn, cmd.getParams(), cmd.getWait()); + private Answer execute(final PerformanceMonitorCommand cmd) { + final Connection conn = getConnection(); + final String perfMon = getPerfMon(conn, cmd.getParams(), cmd.getWait()); if (perfMon == null) { return new PerformanceMonitorAnswer(cmd, false, perfMon); - } else + } else { return new PerformanceMonitorAnswer(cmd, true, perfMon); + } } - private String getPerfMon(Connection conn, Map<String, String> params, - int wait) { + private String getPerfMon(final Connection conn, final Map<String, String> params, + final int wait) { String result = null; try { result = callHostPluginAsync(conn, "vmopspremium", "asmonitor", 60, params); - if (result != null) + if (result != null) { return result; - } catch (Exception e) { + } + } catch (final Exception e) { s_logger.error("Can not get performance monitor for AS due to ", e); } return null; } - protected String callHostPluginAsync(Connection conn, String plugin, - String cmd, int wait, Map<String, String> params) { - int timeout = wait * 1000; - Map<String, String> args = new HashMap<String, String>(); + protected String callHostPluginAsync(final Connection conn, final String plugin, + final String cmd, final int wait, final Map<String, String> params) { + final int timeout = wait * 1000; + final Map<String, String> args = new HashMap<String, String>(); Task task = null; try { - for (Map.Entry< String, String > entry : params.entrySet()) { + for (final Map.Entry< String, String > entry : params.entrySet()) { args.put(entry.getKey(), entry.getValue()); } if (s_logger.isTraceEnabled()) { s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); } - Host host = Host.getByUuid(conn, _host.uuid); + final Host host = Host.getByUuid(conn, _host.uuid); task = host.callPluginAsync(conn, plugin, cmd, args); // poll every 1 seconds waitForTask(conn, task, 1000, timeout); checkForSuccess(conn, task); - String result = task.getResult(conn); + final String result = task.getResult(conn); if (s_logger.isTraceEnabled()) { s_logger.trace("callHostPlugin Result: " + result); } return result.replace("<value>", "").replace("</value>", "") .replace("\n", ""); - } catch (Types.HandleInvalid e) { + } catch (final Types.HandleInvalid e) { s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn( "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), @@ -666,7 +667,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (task != null) { try { task.destroy(conn); - } catch (Exception e1) { + } catch (final Exception e1) { s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.uuid + ") due to " + e1.toString()); } } @@ -674,12 +675,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return null; } - protected void scaleVM(Connection conn, VM vm, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { + protected void scaleVM(final Connection conn, final VM vm, final VirtualMachineTO vmSpec, final Host host) throws XenAPIException, XmlRpcException { - Long staticMemoryMax = vm.getMemoryStaticMax(conn); - Long staticMemoryMin = vm.getMemoryStaticMin(conn); - Long newDynamicMemoryMin = vmSpec.getMinRam(); - Long newDynamicMemoryMax = vmSpec.getMaxRam(); + final Long staticMemoryMax = vm.getMemoryStaticMax(conn); + final Long staticMemoryMin = vm.getMemoryStaticMin(conn); + final Long newDynamicMemoryMin = vmSpec.getMinRam(); + final Long newDynamicMemoryMax = vmSpec.getMaxRam(); if (staticMemoryMin > newDynamicMemoryMin || newDynamicMemoryMax > staticMemoryMax) { throw new CloudRuntimeException("Cannot scale up the vm because of memory constraint violation: " + "0 <= memory-static-min(" + staticMemoryMin + ") <= memory-dynamic-min(" + newDynamicMemoryMin + ") <= memory-dynamic-max(" + newDynamicMemoryMax + ") <= memory-static-max(" + staticMemoryMax + ")"); @@ -688,21 +689,21 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vm.setMemoryDynamicRange(conn, newDynamicMemoryMin, newDynamicMemoryMax); vm.setVCPUsNumberLive(conn, (long)vmSpec.getCpus()); - Integer speed = vmSpec.getMinSpeed(); + final Integer speed = vmSpec.getMinSpeed(); if (speed != null) { int cpuWeight = _maxWeight; //cpu_weight // weight based allocation - cpuWeight = (int)((speed * 0.99) / _host.speed * _maxWeight); + cpuWeight = (int)(speed * 0.99 / _host.speed * _maxWeight); if (cpuWeight > _maxWeight) { cpuWeight = _maxWeight; } if (vmSpec.getLimitCpuUse()) { long utilization = 0; // max CPU cap, default is unlimited - utilization = (int)((vmSpec.getMaxSpeed() * 0.99 * vmSpec.getCpus()) / _host.speed * 100); + utilization = (int)(vmSpec.getMaxSpeed() * 0.99 * vmSpec.getCpus() / _host.speed * 100); //vm.addToVCPUsParamsLive(conn, "cap", Long.toString(utilization)); currently xenserver doesnot support Xapi to add VCPUs params live. callHostPlugin(conn, "vmops", "add_to_VCPUs_params_live", "key", "cap", "value", Long.toString(utilization), "vmname", vmSpec.getName()); } @@ -711,13 +712,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - public ScaleVmAnswer execute(ScaleVmCommand cmd) { - VirtualMachineTO vmSpec = cmd.getVirtualMachine(); - String vmName = vmSpec.getName(); + public ScaleVmAnswer execute(final ScaleVmCommand cmd) { + final VirtualMachineTO vmSpec = cmd.getVirtualMachine(); + final String vmName = vmSpec.getName(); try { - Connection conn = getConnection(); - Set<VM> vms = VM.getByNameLabel(conn, vmName); - Host host = Host.getByUuid(conn, _host.uuid); + final Connection conn = getConnection(); + final Set<VM> vms = VM.getByNameLabel(conn, vmName); + final Host host = Host.getByUuid(conn, _host.uuid); // If DMC is not enable then don't execute this command. if (!isDmcEnabled(conn, host)) { @@ -726,13 +727,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } // stop vm which is running on this host or is in halted state - Iterator<VM> iter = vms.iterator(); + final Iterator<VM> iter = vms.iterator(); while (iter.hasNext()) { - VM vm = iter.next(); - VM.Record vmr = vm.getRecord(conn); + final VM vm = iter.next(); + final VM.Record vmr = vm.getRecord(conn); - if ((vmr.powerState == VmPowerState.HALTED) || - (vmr.powerState == VmPowerState.RUNNING && !isRefNull(vmr.residentOn) && !vmr.residentOn.getUuid(conn).equals(_host.uuid))) { + if (vmr.powerState == VmPowerState.HALTED || + vmr.powerState == VmPowerState.RUNNING && !isRefNull(vmr.residentOn) && !vmr.residentOn.getUuid(conn).equals(_host.uuid)) { iter.remove(); } } @@ -742,56 +743,57 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new ScaleVmAnswer(cmd, false, "VM does not exist"); } - for (VM vm : vms) { + for (final VM vm : vms) { vm.getRecord(conn); try { scaleVM(conn, vm, vmSpec, host); - } catch (Exception e) { - String msg = "Catch exception " + e.getClass().getName() + " when scaling VM:" + vmName + " due to " + e.toString(); + } catch (final Exception e) { + final String msg = "Catch exception " + e.getClass().getName() + " when scaling VM:" + vmName + " due to " + e.toString(); s_logger.debug(msg); return new ScaleVmAnswer(cmd, false, msg); } } - String msg = "scaling VM " + vmName + " is successful on host " + host; + final String msg = "scaling VM " + vmName + " is successful on host " + host; s_logger.debug(msg); return new ScaleVmAnswer(cmd, true, msg); - } catch (XenAPIException e) { - String msg = "Upgrade Vm " + vmName + " fail due to " + e.toString(); + } catch (final XenAPIException e) { + final String msg = "Upgrade Vm " + vmName + " fail due to " + e.toString(); s_logger.warn(msg, e); return new ScaleVmAnswer(cmd, false, msg); - } catch (XmlRpcException e) { - String msg = "Upgrade Vm " + vmName + " fail due to " + e.getMessage(); + } catch (final XmlRpcException e) { + final String msg = "Upgrade Vm " + vmName + " fail due to " + e.getMessage(); s_logger.warn(msg, e); return new ScaleVmAnswer(cmd, false, msg); - } catch (Exception e) { - String msg = "Unable to upgrade " + vmName + " due to " + e.getMessage(); + } catch (final Exception e) { + final String msg = "Unable to upgrade " + vmName + " due to " + e.getMessage(); s_logger.warn(msg, e); return new ScaleVmAnswer(cmd, false, msg); } } - private Answer execute(RevertToVMSnapshotCommand cmd) { - String vmName = cmd.getVmName(); - List<VolumeObjectTO> listVolumeTo = cmd.getVolumeTOs(); - VMSnapshot.Type vmSnapshotType = cmd.getTarget().getType(); - Boolean snapshotMemory = vmSnapshotType == VMSnapshot.Type.DiskAndMemory; - Connection conn = getConnection(); + private Answer execute(final RevertToVMSnapshotCommand cmd) { + final String vmName = cmd.getVmName(); + final List<VolumeObjectTO> listVolumeTo = cmd.getVolumeTOs(); + final VMSnapshot.Type vmSnapshotType = cmd.getTarget().getType(); + final Boolean snapshotMemory = vmSnapshotType == VMSnapshot.Type.DiskAndMemory; + final Connection conn = getConnection(); PowerState vmState = null; VM vm = null; try { - Set<VM> vmSnapshots = VM.getByNameLabel(conn, cmd.getTarget().getSnapshotName()); - if (vmSnapshots.size() == 0) + final Set<VM> vmSnapshots = VM.getByNameLabel(conn, cmd.getTarget().getSnapshotName()); + if (vmSnapshots.size() == 0) { return new RevertToVMSnapshotAnswer(cmd, false, "Cannot find vmSnapshot with name: " + cmd.getTarget().getSnapshotName()); + } - VM vmSnapshot = vmSnapshots.iterator().next(); + final VM vmSnapshot = vmSnapshots.iterator().next(); // find target VM or creating a work VM try { vm = getVM(conn, vmName); - } catch (Exception e) { + } catch (final Exception e) { vm = createWorkingVM(conn, vmName, cmd.getGuestOSType(), cmd.getPlatformEmulator(), listVolumeTo); } @@ -802,13 +804,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe // call plugin to execute revert revertToSnapshot(conn, vmSnapshot, vmName, vm.getUuid(conn), snapshotMemory, _host.uuid); vm = getVM(conn, vmName); - Set<VBD> vbds = vm.getVBDs(conn); - Map<String, VDI> vdiMap = new HashMap<String, VDI>(); + final Set<VBD> vbds = vm.getVBDs(conn); + final Map<String, VDI> vdiMap = new HashMap<String, VDI>(); // get vdi:vbdr to a map - for (VBD vbd : vbds) { - VBD.Record vbdr = vbd.getRecord(conn); + for (final VBD vbd : vbds) { + final VBD.Record vbdr = vbd.getRecord(conn); if (vbdr.type == Types.VbdType.DISK) { - VDI vdi = vbdr.VDI; + final VDI vdi = vbdr.VDI; vdiMap.put(vbdr.userdevice, vdi); } } @@ -821,23 +823,23 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } // after revert, VM's volumes path have been changed, need to report to manager - for (VolumeObjectTO volumeTo : listVolumeTo) { - Long deviceId = volumeTo.getDeviceId(); - VDI vdi = vdiMap.get(deviceId.toString()); + for (final VolumeObjectTO volumeTo : listVolumeTo) { + final Long deviceId = volumeTo.getDeviceId(); + final VDI vdi = vdiMap.get(deviceId.toString()); volumeTo.setPath(vdi.getUuid(conn)); } return new RevertToVMSnapshotAnswer(cmd, listVolumeTo, vmState); - } catch (Exception e) { + } catch (final Exception e) { s_logger.error("revert vm " + vmName + " to snapshot " + cmd.getTarget().getSnapshotName() + " failed due to " + e.getMessage()); return new RevertToVMSnapshotAnswer(cmd, false, e.getMessage()); } } - protected String revertToSnapshot(Connection conn, VM vmSnapshot, String vmName, String oldVmUuid, Boolean snapshotMemory, String hostUUID) throws XenAPIException, + protected String revertToSnapshot(final Connection conn, final VM vmSnapshot, final String vmName, final String oldVmUuid, final Boolean snapshotMemory, final String hostUUID) throws XenAPIException, XmlRpcException { - String results = + final String results = callHostPluginAsync(conn, "vmopsSnapshot", "revert_memory_snapshot", 10 * 60 * 1000, "snapshotUUID", vmSnapshot.getUuid(conn), "vmName", vmName, "oldVmUuid", oldVmUuid, "snapshotMemory", snapshotMemory.toString(), "hostUUID", hostUUID); String errMsg = null; @@ -854,7 +856,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new CloudRuntimeException(errMsg); } - protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType type, String name) throws XenAPIException, XmlRpcException { + protected XsLocalNetwork getNativeNetworkForTraffic(final Connection conn, final TrafficType type, final String name) throws XenAPIException, XmlRpcException { if (name != null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Looking for network named " + name); @@ -879,13 +881,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new CloudRuntimeException("Unsupported network type: " + type); } - private synchronized Network setupvSwitchNetwork(Connection conn) { + private synchronized Network setupvSwitchNetwork(final Connection conn) { try { if (_host.vswitchNetwork == null) { Network vswitchNw = null; - Network.Record rec = new Network.Record(); - String nwName = Networks.BroadcastScheme.VSwitch.toString(); - Set<Network> networks = Network.getByNameLabel(conn, nwName); + final Network.Record rec = new Network.Record(); + final String nwName = Networks.BroadcastScheme.VSwitch.toString(); + final Set<Network> networks = Network.getByNameLabel(conn, nwName); if (networks.size() == 0) { rec.nameDescription = "vswitch network for " + nwName; @@ -897,11 +899,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe _host.vswitchNetwork = vswitchNw; } return _host.vswitchNetwork; - } catch (BadServerResponse e) { + } catch (final BadServerResponse e) { s_logger.error("Failed to setup vswitch network", e); - } catch (XenAPIException e) { + } catch (final XenAPIException e) { s_logger.error("Failed to setup vswitch network", e); - } catch (XmlRpcException e) { + } catch (final XmlRpcException e) { s_logger.error("Failed to setup vswitch network", e); } @@ -911,17 +913,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe /** * This method just creates a XenServer network following the tunnel network naming convention */ - private synchronized Network findOrCreateTunnelNetwork(Connection conn, String nwName) { + private synchronized Network findOrCreateTunnelNetwork(final Connection conn, final String nwName) { try { Network nw = null; - Network.Record rec = new Network.Record(); - Set<Network> networks = Network.getByNameLabel(conn, nwName); + final Network.Record rec = new Network.Record(); + final Set<Network> networks = Network.getByNameLabel(conn, nwName); if (networks.size() == 0) { rec.nameDescription = "tunnel network id# " + nwName; rec.nameLabel = nwName; //Initialize the ovs-host-setup to avoid error when doing get-param in plugin - Map<String, String> otherConfig = new HashMap<String, String>(); + final Map<String, String> otherConfig = new HashMap<String, String>(); otherConfig.put("ovs-host-setup", ""); // Mark 'internal network' as shared so bridge gets automatically created on each host in the cluster // when VM with vif connected to this internal network is started @@ -934,7 +936,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.debug("XenServer network for tunnels found:" + nwName); } return nw; - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("createTunnelNetwork failed", e); return null; } @@ -943,18 +945,18 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe /** * This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network */ - private synchronized Network configureTunnelNetwork(Connection conn, Long networkId, long hostId, String bridgeName) { + private synchronized Network configureTunnelNetwork(final Connection conn, final Long networkId, final long hostId, final String bridgeName) { try { - Network nw = findOrCreateTunnelNetwork(conn, bridgeName); - String nwName = bridgeName; + final Network nw = findOrCreateTunnelNetwork(conn, bridgeName); + final String nwName = bridgeName; //Invoke plugin to setup the bridge which will be used by this network - String bridge = nw.getBridge(conn); - Map<String, String> nwOtherConfig = nw.getOtherConfig(conn); - String configuredHosts = nwOtherConfig.get("ovs-host-setup"); + final String bridge = nw.getBridge(conn); + final Map<String, String> nwOtherConfig = nw.getOtherConfig(conn); + final String configuredHosts = nwOtherConfig.get("ovs-host-setup"); boolean configured = false; if (configuredHosts != null) { - String hostIdsStr[] = configuredHosts.split(","); - for (String hostIdStr : hostIdsStr) { + final String hostIdsStr[] = configuredHosts.split(","); + for (final String hostIdStr : hostIdsStr) { if (hostIdStr.equals(((Long)hostId).toString())) { configured = true; break; @@ -977,25 +979,25 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } //Note down the fact that the ovs bridge has been setup - String[] res = result.split(":"); + final String[] res = result.split(":"); if (res.length != 2 || !res[0].equalsIgnoreCase("SUCCESS")) { //TODO: Should make this error not fatal? throw new CloudRuntimeException("Unable to pre-configure OVS bridge " + bridge ); } } return nw; - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("createandConfigureTunnelNetwork failed", e); return null; } } - private synchronized void destroyTunnelNetwork(Connection conn, Network nw, long hostId) { + private synchronized void destroyTunnelNetwork(final Connection conn, final Network nw, final long hostId) { try { - String bridge = nw.getBridge(conn); - String result = callHostPlugin(conn, "ovstunnel", "destroy_ovs_bridge", "bridge", bridge, + final String bridge = nw.getBridge(conn); + final String result = callHostPlugin(conn, "ovstunnel", "destroy_ovs_bridge", "bridge", bridge, "cs_host_id", ((Long)hostId).toString()); - String[] res = result.split(":"); + final String[] res = result.split(":"); if (res.length != 2 || !res[0].equalsIgnoreCase("SUCCESS")) { //TODO: Should make this error not fatal? //Can Concurrent VM shutdown/migration/reboot events can cause this method @@ -1003,32 +1005,32 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe throw new CloudRuntimeException("Unable to remove OVS bridge " + bridge + ":" + result); } return; - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("destroyTunnelNetwork failed:", e); return; } } - protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException, XmlRpcException { - String name = nic.getName(); - XsLocalNetwork network = getNativeNetworkForTraffic(conn, nic.getType(), name); + protected Network getNetwork(final Connection conn, final NicTO nic) throws XenAPIException, XmlRpcException { + final String name = nic.getName(); + final XsLocalNetwork network = getNativeNetworkForTraffic(conn, nic.getType(), name); if (network == null) { s_logger.error("Network is not configured on the backend for nic " + nic.toString()); throw new CloudRuntimeException("Network for the backend is not configured correctly for network broadcast domain: " + nic.getBroadcastUri()); } - URI uri = nic.getBroadcastUri(); - BroadcastDomainType type = nic.getBroadcastType(); + final URI uri = nic.getBroadcastUri(); + final BroadcastDomainType type = nic.getBroadcastType(); if (uri != null && uri.toString().contains("untagged")) { return network.getNetwork(); } else if (uri != null && type == BroadcastDomainType.Vlan) { - assert (BroadcastDomainType.getSchemeValue(uri) == BroadcastDomainType.Vlan); - long vlan = Long.parseLong(BroadcastDomainType.getValue(uri)); + assert BroadcastDomainType.getSchemeValue(uri) == BroadcastDomainType.Vlan; + final long vlan = Long.parseLong(BroadcastDomainType.getValue(uri)); return enableVlanNetwork(conn, vlan, network); } else if (type == BroadcastDomainType.Native || type == BroadcastDomainType.LinkLocal || - type == BroadcastDomainType.Vsp) { + type == BroadcastDomainType.Vsp) { return network.getNetwork(); } else if (uri != null && type == BroadcastDomainType.Vswitch) { - String header = uri.toString().substring(Networks.BroadcastDomainType.Vswitch.scheme().length() + "://".length()); + final String header = uri.toString().substring(Networks.BroadcastDomainType.Vswitch.scheme().length() + "://".length()); if (header.startsWith("vlan")) { _isOvs = true; return setupvSwitchNetwork(conn); @@ -1039,7 +1041,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (uri == null) { return network.getNetwork(); } else { - long vlan = Long.parseLong(BroadcastDomainType.getValue(uri)); + final long vlan = Long.parseLong(BroadcastDomainType.getValue(uri)); return enableVlanNetwork(conn, vlan, network); } } else if (type == BroadcastDomainType.Lswitch) { @@ -1048,28 +1050,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } else if (uri != null && type == BroadcastDomainType.Pvlan) { assert BroadcastDomainType.getSchemeValue(uri) == BroadcastDomainType.Pvlan; // should we consider moving this NetUtils method to BroadcastDomainType? - long vlan = Long.parseLong(NetUtils.getPrimaryPvlanFromUri(uri)); + final long vlan = Long.parseLong(NetUtils.getPrimaryPvlanFromUri(uri)); return enableVlanNetwork(conn, vlan, network); } throw new CloudRuntimeException("Unable to support this type of network broadcast domain: " + nic.getBroadcastUri()); } - private String getOvsTunnelNetworkName(String broadcastUri) { + private String getOvsTunnelNetworkName(final String broadcastUri) { if (broadcastUri.contains(".")) { - String[] parts = broadcastUri.split("\\."); + final String[] parts = broadcastUri.split("\\."); return "OVS-DR-VPC-Bridge"+parts[0]; } else { try { return "OVSTunnel" + broadcastUri; - } catch (Exception e) { + } catch (final Exception e) { return null; } } } - protected VIF createVif(Connection conn, String vmName, VM vm, VirtualMachineTO vmSpec, NicTO nic) throws XmlRpcException, XenAPIException { - assert (nic.getUuid() != null) : "Nic should have a uuid value"; + protected VIF createVif(final Connection conn, final String vmName, final VM vm, final VirtualMachineTO vmSpec, final NicTO nic) throws XmlRpcException, XenAPIException { + assert nic.getUuid() != null : "Nic should have a uuid value"; if (s_logger.isDebugEnabled()) { s_logger.debug("Creating VIF for " + vmName + " on nic " + nic); @@ -1095,9 +1097,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe // Nuage Vsp needs Virtual Router IP to be passed in the otherconfig // get the virtual router IP information from broadcast uri - URI broadcastUri = nic.getBroadcastUri(); + final URI broadcastUri = nic.getBroadcastUri(); if (broadcastUri != null && broadcastUri.getScheme().equalsIgnoreCase(Networks.BroadcastDomainType.Vsp.scheme())) { - String path = broadcastUri.getPath(); + final String path = broadcastUri.getPath(); vifr.otherConfig.put("vsp-vr-ip", path.substring(1)); } vifr.network = getNetwork(conn, nic); @@ -1110,7 +1112,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT; - VIF vif = VIF.create(conn, vifr); + final VIF vif = VIF.create(conn, vifr); if (s_logger.isDebugEnabled()) { vifr = vif.getRecord(conn); if(vifr != null) { @@ -1121,47 +1123,47 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return vif; } - protected void prepareISO(Connection conn, String vmName) throws XmlRpcException, XenAPIException { + protected void prepareISO(final Connection conn, final String vmName) throws XmlRpcException, XenAPIException { - Set<VM> vms = VM.getByNameLabel(conn, vmName); + final Set<VM> vms = VM.getByNameLabel(conn, vmName); if (vms == null || vms.size() != 1) { - throw new CloudRuntimeException("There are " + ((vms == null) ? "0" : vms.size()) + " VMs named " + vmName); + throw new CloudRuntimeException("There are " + (vms == null ? "0" : vms.size()) + " VMs named " + vmName); } - VM vm = vms.iterator().next(); - Set<VBD> vbds = vm.getVBDs(conn); - for (VBD vbd : vbds) { - VBD.Record vbdr = vbd.getRecord(conn); + final VM vm = vms.iterator().next(); + final Set<VBD> vbds = vm.getVBDs(conn); + for (final VBD vbd : vbds) { + final VBD.Record vbdr = vbd.getRecord(conn); if (vbdr.type == Types.VbdType.CD && vbdr.empty == false) { - VDI vdi = vbdr.VDI; - SR sr = vdi.getSR(conn); - Set<PBD> pbds = sr.getPBDs(conn); + final VDI vdi = vbdr.VDI; + final SR sr = vdi.getSR(conn); + final Set<PBD> pbds = sr.getPBDs(conn); if (pbds == null) { throw new CloudRuntimeException("There is no pbd for sr " + sr); } - for (PBD pbd : pbds) { - PBD.Record pbdr = pbd.getRecord(conn); + for (final PBD pbd : pbds) { + final PBD.Record pbdr = pbd.getRecord(conn); if (pbdr.host.getUuid(conn).equals(_host.uuid)) { return; } } sr.setShared(conn, true); - Host host = Host.getByUuid(conn, _host.uuid); - PBD.Record pbdr = pbds.iterator().next().getRecord(conn); + final Host host = Host.getByUuid(conn, _host.uuid); + final PBD.Record pbdr = pbds.iterator().next().getRecord(conn); pbdr.host = host; pbdr.uuid = ""; - PBD pbd = PBD.create(conn, pbdr); + final PBD pbd = PBD.create(conn, pbdr); pbdPlug(conn, pbd, pbd.getUuid(conn)); break; } } } - protected VDI mount(Connection conn, String vmName, DiskTO volume) throws XmlRpcException, XenAPIException { - DataTO data = volume.getData(); - Volume.Type type = volume.getType(); + protected VDI mount(final Connection conn, final String vmName, final DiskTO volume) throws XmlRpcException, XenAPIException { + final DataTO data = volume.getData(); + final Volume.Type type = volume.getType(); if (type == Volume.Type.ISO) { - TemplateObjectTO iso = (TemplateObjectTO)data; - DataStoreTO store = iso.getDataStore(); + final TemplateObjectTO iso = (TemplateObjectTO)data; + final DataStoreTO store = iso.getDataStore(); if (store == null) { //It's a fake iso @@ -1169,17 +1171,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } //corer case, xenserver pv driver iso - String templateName = iso.getName(); + final String templateName = iso.getName(); if (templateName.startsWith("xs-tools")) { try { - Set<VDI> vdis = VDI.getByNameLabel(conn, templateName); + final Set<VDI> vdis = VDI.getByNameLabel(conn, templateName); if (vdis.isEmpty()) { throw new CloudRuntimeException("Could not find ISO with URL: " + templateName); } return vdis.iterator().next(); - } catch (XenAPIException e) { + } catch (final XenAPIException e) { throw new CloudRuntimeException("Unable to get pv iso: " + templateName + " due to " + e.toString()); - } catch (Exception e) { + } catch (final Exception e) { throw new CloudRuntimeException("Unable to get pv iso: " + templateName + " due to " + e.toString()); } } @@ -1187,35 +1189,35 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (!(store instanceof NfsTO)) { throw new CloudRuntimeException("only support mount iso on nfs"); } - NfsTO nfsStore = (NfsTO)store; - String isoPath = nfsStore.getUrl() + File.separator + iso.getPath(); - int index = isoPath.lastIndexOf("/"); + final NfsTO nfsStore = (NfsTO)store; + final String isoPath = nfsStore.getUrl() + File.separator + iso.getPath(); + final int index = isoPath.lastIndexOf("/"); - String mountpoint = isoPath.substring(0, index); + final String mountpoint = isoPath.substring(0, index); URI uri; try { uri = new URI(mountpoint); - } catch (URISyntaxException e) { + } catch (final URISyntaxException e) { throw new CloudRuntimeException("Incorrect uri " + mountpoint, e); } - SR isoSr = createIsoSRbyURI(conn, uri, vmName, false); + final SR isoSr = createIsoSRbyURI(conn, uri, vmName, false); - String isoname = isoPath.substring(index + 1); + final String isoname = isoPath.substring(index + 1); - VDI isoVdi = getVDIbyLocationandSR(conn, isoname, isoSr); + final VDI isoVdi = getVDIbyLocationandSR(conn, isoname, isoSr); if (isoVdi == null) { throw new CloudRuntimeException("Unable to find ISO " + isoPath); } return isoVdi; } else { - VolumeObjectTO vol = (VolumeObjectTO)data; + final VolumeObjectTO vol = (VolumeObjectTO)data; return VDI.getByUuid(conn, vol.getPath()); } } - protected VBD createVbd(Connection conn, DiskTO volume, String vmName, VM vm, BootloaderType bootLoaderType, VDI vdi) throws XmlRpcException, XenAPIException { - Volume.Type type = volume.getType(); + protected VBD createVbd(final Connection conn, final DiskTO volume, final String vmName, final VM vm, final BootloaderType bootLoaderType, VDI vdi) throws XmlRpcException, XenAPIException { + final Volume.Type type = volume.getType(); if (vdi == null) { vdi = mount(conn, vmName, volume); @@ -1226,15 +1228,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vdi.setNameLabel(conn, vmName + "-DATA"); } - Map<String, String> smConfig = vdi.getSmConfig(conn); - for (String key : smConfig.keySet()) { + final Map<String, String> smConfig = vdi.getSmConfig(conn); + for (final String key : smConfig.keySet()) { if (key.startsWith("host_")) { vdi.removeFromSmConfig(conn, key); break; } } } - VBD.Record vbdr = new VBD.Record(); + final VBD.Record vbdr = new VBD.Record(); vbdr.VM = vm; if (vdi != null) { vbdr.VDI = vdi; @@ -1260,7 +1262,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vbdr.type = Types.VbdType.DISK; vbdr.unpluggable = true; } - VBD vbd = VBD.create(conn, vbdr); + final VBD vbd = VBD.create(conn, vbdr); if (s_logger.isDebugEnabled()) { s_logger.debug("VBD " + vbd.getUuid(conn) + " created for " + volume); @@ -1270,13 +1272,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } - private long getStaticMax(String os, boolean b, long dynamicMinRam, long dynamicMaxRam){ - long recommendedValue = CitrixHelper.getXenServerStaticMax(os, b); + private long getStaticMax(final String os, final boolean b, final long dynamicMinRam, final long dynamicMaxRam){ + final long recommendedValue = CitrixHelper.getXenServerStaticMax(os, b); if(recommendedValue == 0){ s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal"); return dynamicMaxRam; } - long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability + final long staticMax = Math.min(recommendedValue, 4l * dynamicMinRam); // XS constraint for stability if (dynamicMaxRam > staticMax){ // XS contraint that dynamic max <= static max s_logger.warn("dynamixMax " + dynamicMaxRam + " cant be greater than static max " + staticMax + ", can lead to stability issues. Setting static max as much as dynamic max "); return dynamicMaxRam; @@ -1285,8 +1287,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } - private long getStaticMin(String os, boolean b, long dynamicMinRam, long dynamicMaxRam) { - long recommendedValue = CitrixHelper.getXenServerStaticMin(os, b); + private long getStaticMin(final String os, final boolean b, final long dynamicMinRam, final long dynamicMaxRam) { + final long recommendedValue = CitrixHelper.getXenServerStaticMin(os, b); if (recommendedValue == 0) { s_logger.warn("No recommended value found for dynamic min"); return dynamicMinRam; @@ -1299,23 +1301,23 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } - protected HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(Connection conn) throws XenAPIException, XmlRpcException { + protected HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final Connection conn) throws XenAPIException, XmlRpcException { return null; } - protected void createVGPU(Connection conn, StartCommand cmd, VM vm, GPUDeviceTO gpuDevice) throws XenAPIException, XmlRpcException { + protected void createVGPU(final Connection conn, final StartCommand cmd, final VM vm, final GPUDeviceTO gpuDevice) throws XenAPIException, XmlRpcException { } - protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host host) throws XenAPIException, XmlRpcException { - String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD); - Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName); + protected VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmSpec, final Host host) throws XenAPIException, XmlRpcException { + final String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD); + final Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName); if ( templates == null || templates.isEmpty()) { throw new CloudRuntimeException("Cannot find template " + guestOsTypeName + " on XenServer host"); } assert templates.size() == 1 : "Should only have 1 template but found " + templates.size(); - VM template = templates.iterator().next(); + final VM template = templates.iterator().next(); - VM.Record vmr = template.getRecord(conn); + final VM.Record vmr = template.getRecord(conn); vmr.affinity = host; vmr.otherConfig.remove("disks"); vmr.otherConfig.remove("default_template"); @@ -1326,7 +1328,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vmr.actionsAfterShutdown = Types.OnNormalExit.DESTROY; vmr.otherConfig.put("vm_uuid", vmSpec.getUuid()); vmr.VCPUsMax = (long) vmSpec.getCpus(); // FIX ME: In case of dynamic scaling this VCPU max should be the minumum of - // recommended value for that template and capacity remaining on host + // recommended value for that template and capacity remaining on host if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) { //scaling is allowed @@ -1357,28 +1359,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vmr.VCPUsAtStartup = (long) vmSpec.getCpus(); vmr.consoles.clear(); - VM vm = VM.create(conn, vmr); + final VM vm = VM.create(conn, vmr); if (s_logger.isDebugEnabled()) { s_logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName()); } - Map<String, String> vcpuParams = new HashMap<String, String>(); + final Map<String, String> vcpuParams = new HashMap<String, String>(); - Integer speed = vmSpec.getMinSpeed(); + final Integer speed = vmSpec.getMinSpeed(); if (speed != null) { int cpuWeight = _maxWeight; // cpu_weight int utilization = 0; // max CPU cap, default is unlimited // weight based allocation, CPU weight is calculated per VCPU - cpuWeight = (int)((speed * 0.99) / _host.speed * _maxWeight); + cpuWeight = (int)(speed * 0.99 / _host.speed * _maxWeight); if (cpuWeight > _maxWeight) { cpuWeight = _maxWeight; } if (vmSpec.getLimitCpuUse()) { // CPU cap is per VM, so need to assign cap based on the number of vcpus - utilization = (int)((vmSpec.getMaxSpeed() * 0.99 * vmSpec.getCpus()) / _host.speed * 100); + utilization = (int)(vmSpec.getMaxSpeed() * 0.99 * vmSpec.getCpus() / _host.speed * 100); } vcpuParams.put("weight", Integer.toString(cpuWeight)); @@ -1390,7 +1392,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe vm.setVCPUsParams(conn, vcpuParams); } - String bootArgs = vmSpec.getBootArgs(); + final String bootArgs = vmSpec.getBootArgs(); if (bootArgs != null && bootArgs.length() > 0) { String pvargs = vm.getPVArgs(conn); pvargs = pvargs + vmSpec.getBootArgs().replaceAll(" ", "%"); @@ -1402,13 +1404,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) { if (vmSpec.getBootloader() == BootloaderType.CD) { - DiskTO[] disks = vmSpec.getDisks(); - for (DiskTO disk : disks) { + final DiskTO[] disks = vmSpec.getDisks(); + for (final DiskTO disk : disks) { if (disk.getType() == Volume.Type.ISO) { - TemplateObjectTO iso = (TemplateObjectTO)disk.getData(); - String osType = iso.getGuestOsType(); + final TemplateObjectTO iso = (TemplateObjectTO)disk.getData(); + final String osType = iso.getGuestOsType(); if (osType != null) { - String isoGuestOsName = getGuestOsType(osType, vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD); + final String isoGuestOsName = getGuestOsType(osType, vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD); if (!isoGuestOsName.equals(guestOsTypeName)) { vmSpec.setBootloader(BootloaderType.PyGrub); } @@ -1430,39 +1432,39 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } try { finalizeVmMetaData(vm, conn, vmSpec); - } catch (Exception e) { + } catch (final Exception e) { throw new CloudRuntimeException("Unable to finalize VM MetaData: " + vmSpec); } return vm; } - protected void finalizeVmMetaData(VM vm, Connection conn, VirtualMachineTO vmSpec) throws Exception { + protected void finalizeVmMetaData(final VM vm, final Connection conn, final VirtualMachineTO vmSpec) throws Exception { - Map<String, String> details = vmSpec.getDetails(); + final Map<String, String> details = vmSpec.getDetails(); if (details != null) { - String platformstring = details.get("platform"); + final String platformstring = details.get("platform"); if (platformstring != null && !platformstring.isEmpty()) { - Map<String, String> platform = StringUtils.stringToMap(platformstring); + final Map<String, String> platform = StringUtils.stringToMap(platformstring); vm.setPlatform(conn, platform); } else { - String timeoffset = details.get("timeoffset"); + final String timeoffset = details.get("timeoffset"); if (timeoffset != null) { - Map<String, String> platform = vm.getPlatform(conn); + final Map<String, String> platform = vm.getPlatform(conn); platform.put("timeoffset", timeoffset); vm.setPlatform(conn, platform); } - String coresPerSocket = details.get("cpu.corespersocket"); + final String coresPerSocket = details.get("cpu.corespersocket"); if (coresPerSocket != null) { - Map<String, String> platform = vm.getPlatform(conn); + final Map<String, String> platform = vm.getPlatform(conn); platform.put("cores-per-socket", coresPerSocket); vm.setPlatform(conn, platform); } } if ( !BootloaderType.CD.equals(vmSpec.getBootloader())) { - String xenservertoolsversion = details.get("hypervisortoolsversion"); + final String xenservertoolsversion = details.get("hypervisortoolsversion"); if ((xenservertoolsversion == null || !xenservertoolsversion.equalsIgnoreCase("xenserver61")) && vmSpec.getGpuDevice() == null) { - Map<String, String> platform = vm.getPlatform(conn); + final Map<String, String> platform = vm.getPlatform(conn); platform.remove("device_id"); vm.setPlatform(conn, platform); } @@ -1470,8 +1472,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - protected String handleVmStartFailure(Connection conn, String vmName, VM vm, String message, Throwable th) { - String msg = "Unable to start " + vmName + " due to " + message; + protected String handleVmStartFailure(final Connection conn, final String vmName, final VM vm, final String message, final Throwable th) { + final String msg = "Unable to start " + vmName + " due to " + message; s_logger.warn(msg, th); if (vm == null) { @@ -1479,77 +1481,77 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } try { - VM.Record vmr = vm.getRecord(conn); - List<Network> networks = new ArrayList<Network>(); - for (VIF vif : vmr.VIFs) { + final VM.Record vmr = vm.getRecord(conn); + final List<Network> networks = new ArrayList<Network>(); + for (final VIF vif : vmr.VIFs) { try { - VIF.Record rec = vif.getRecord(conn); + final VIF.Record rec = vif.getRecord(conn); if(rec != null) { networks.add(rec.network); } else { s_logger.warn("Unable to cleanup VIF: " + vif.toWireString() + " As vif record is null"); } - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Unable to cleanup VIF", e); } } if (vmr.powerState == VmPowerState.RUNNING) { try { vm.hardShutdown(conn); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("VM hardshutdown failed due to ", e); } } if (vm.getPowerState(conn) == VmPowerState.HALTED) { try { vm.destroy(conn); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("VM destroy failed due to ", e); } } - for (VBD vbd : vmr.VBDs) { + for (final VBD vbd : vmr.VBDs) { try { vbd.unplug(conn); vbd.destroy(conn); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Unable to clean up VBD due to ", e); } } - for (VIF vif : vmr.VIFs) { + for (final VIF vif : vmr.VIFs) { try { vif.unplug(conn); vif.destroy(conn); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Unable to cleanup VIF", e); } } - for (Network network : networks) { + for (final Network network : networks) { if (network.getNameLabel(conn).startsWith("VLAN")) { disableVlanNetwork(conn, network); } } - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("VM getRecord failed due to ", e); } return msg; } - protected VBD createPatchVbd(Connection conn, String vmName, VM vm) throws XmlRpcException, XenAPIException { + protected VBD createPatchVbd(final Connection conn, final String vmName, final VM vm) throws XmlRpcException, XenAPIException { if (_host.systemvmisouuid == null) { - Set<SR> srs = SR.getByNameLabel(conn, "XenServer Tools"); + final Set<SR> srs = SR.getByNameLabel(conn, "XenServer Tools"); if (srs.size() != 1) { throw new CloudRuntimeException("There are " + srs.size() + " SRs with name XenServer Tools"); } - SR sr = srs.iterator().next(); + final SR sr = srs.iterator().next(); sr.scan(conn); - SR.Record srr = sr.getRecord(conn); + final SR.Record srr = sr.getRecord(conn); if (_host.systemvmisouuid == null) { - for (VDI vdi : srr.VDIs) { - VDI.Record vdir = vdi.getRecord(conn); + for (final VDI vdi : srr.VDIs) { + final VDI.Record vdir = vdi.getRecord(conn); if (vdir.nameLabel.contains("systemvm.iso")) { _host.systemvmisouuid = vdir.uuid; break; @@ -1561,28 +1563,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - VBD.Record cdromVBDR = new VBD.Record(); + final VBD.Record cdromVBDR = new VBD.Record(); cdromVBDR.VM = vm; cdromVBDR.empty = true; cdromVBDR.bootable = false; cdromVBDR.userdevice = "3"; cdromVBDR.mode = Types.VbdMode.RO; cdromVBDR.type = Types.VbdType.CD; - VBD cdromVBD = VBD.create(conn, cdromVBDR); + final VBD cdromVBD = VBD.create(conn, cdromVBDR); cdromVBD.insert(conn, VDI.getByUuid(conn, _host.systemvmisouuid)); return cdromVBD; } - protected void destroyPatchVbd(Connection conn, String vmName) throws XmlRpcException, XenAPIException { + protected void destroyPatchVbd(final Connection conn, final String vmName) throws XmlRpcException, XenAPIException { try { if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) { return; } - Set<VM> vms = VM.getByNameLabel(conn, vmName); - for (VM vm : vms) { - Set<VBD> vbds = vm.getVBDs(conn); - for (VBD vbd : vbds) { + final Set<VM> vms = VM.getByNameLabel(conn, vmName); + for (final VM vm : vms) { + final Set<VBD> vbds = vm.getVBDs(conn); + for (final VBD vbd : vbds) { if (vbd.getType(conn) == Types.VbdType.CD) { vbd.eject(conn); vbd.destroy(conn); @@ -1590,28 +1592,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } } - } catch (Exception e) { + } catch (final Exception e) { s_logger.debug("Cannot destory CD-ROM device for VM " + vmName + " due to " + e.toString(), e); } } - protected CheckSshAnswer execute(CheckSshCommand cmd) { - Connection conn = getConnection(); - String vmName = cmd.getName(); - String privateIp = cmd.getIp(); - int cmdPort = cmd.getPort(); + protected CheckSshAnswer execute(final CheckSshCommand cmd) { + final Connection conn = getConnection(); + final String vmName = cmd.getName(); + final String privateIp = cmd.getIp(); + final int cmdPort = cmd.getPort(); if (s_logger.isDebugEnabled()) { s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); } try { - String result = connect(conn, cmd.getName(), privateIp, cmdPort); + final String result = connect(conn, cmd.getName(), privateIp, cmdPort); if (result != null) { return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result); } destroyPatchVbd(conn, vmName); - } catch (Exception e) { + } catch (final Exception e) { return new CheckSshAnswer(cmd, e); } @@ -1622,14 +1624,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new CheckSshAnswer(cmd); } - private HashMap<String, String> parseDefaultOvsRuleComamnd(String str) { - HashMap<String, String> cmd = new HashMap<String, String>(); - String[] sarr = str.split("/"); + private HashMap<String, String> parseDefaultOvsRuleComamnd(final String str) { + final HashMap<String, String> cmd = new HashMap<String, String>(); + final String[] sarr = str.split("/"); for (int i = 0; i < sarr.length; i++) { String c = sarr[i]; c = c.startsWith("/") ? c.substring(1) : c; c = c.endsWith("/") ? c.substring(0, c.length() - 1) : c; - String[] p = c.split(";"); + final String[] p = c.split(";"); if (p.length != 2) { continue; } @@ -1642,55 +1644,55 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return cmd; } - private void cleanUpTmpDomVif(Connection conn, Network nw) throws XenAPIException, XmlRpcException { + private void cleanUpTmpDomVif(final Connection conn, final Network nw) throws XenAPIException, XmlRpcException { - Pair<VM, VM.Record> vm = getControlDomain(conn); - VM dom0 = vm.first(); - Set<VIF> dom0Vifs = dom0.getVIFs(conn); - for (VIF v : dom0Vifs) { + final Pair<VM, VM.Record> vm = getControlDomain(conn); + final VM dom0 = vm.first(); + final Set<VIF> dom0Vifs = dom0.getVIFs(conn); + for (final VIF v : dom0Vifs) { String vifName = "unknown"; try { - VIF.Record vifr = v.getRecord(conn); + final VIF.Record vifr = v.getRecord(conn); if (v.getNetwork(conn).getUuid(conn).equals(nw.getUuid(conn))) { if(vifr != null) { - Map<String, String> config = vifr.otherConfig; + final Map<String, String> config = vifr.otherConfig; vifName = config.get("nameLabel"); } s_logger.debug("A VIF in dom0 for the network is found - so destroy the vif"); v.destroy(conn); s_logger.debug("Destroy temp dom0 vif" + vifName + " success"); } - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Destroy temp dom0 vif " + vifName + "failed", e); } } } - private Answer execute(PvlanSetupCommand cmd) { - Connection conn = getConnection(); + private Answer execute(final PvlanSetupCommand cmd) { + final Connection conn = getConnection(); - String primaryPvlan = cmd.getPrimary(); - String isolatedPvlan = cmd.getIsolated(); - String op = cmd.getOp(); - String dhcpName = cmd.getDhcpName(); - String dhcpMac = cmd.getDhcpMac(); - String dhcpIp = cmd.getDhcpIp(); - String vmMac = cmd.getVmMac(); - String networkTag = cmd.getNetworkTag(); + final String primaryPvlan = cmd.getPrimary(); + final String isolatedPvlan = cmd.getIsolated(); + final String op = cmd.getOp(); + final String dhcpName = cmd.getDhcpName(); + final String dhcpMac = cmd.getDhcpMac(); + final String dhcpIp = cmd.getDhcpIp(); + final String vmMac = cmd.getVmMac(); + final String networkTag = cmd.getNetworkTag(); XsLocalNetwork nw = null; String nwNameLabel = null; try { nw = getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag); if (nw == null) { - s_logger.error("Network is not configured on the backend for pvlan " + primaryPvlan); - throw new CloudRuntimeException("Network for the backend is not configured correctly for pvlan primary: " + primaryPvlan); + s_logger.error("Network is not configured on the backend for pvlan " + primaryPvlan); + throw new CloudRuntimeException("Network for the backend is not configured correctly for pvlan primary: " + primaryPvlan); } nwNameLabel = nw.getNetwork().getNameLabel(conn); - } catch (XenAPIException e) { + } catch (final XenAPIException e) { s_logger.warn("Fail to get network", e); return new Answer(cmd, false, e.toString()); - } catch (XmlRpcException e) { + } catch (final XmlRpcException e) { s_logger.warn("Fail to get network", e); return new Answer(cmd, false, e.toString()); } @@ -1721,28 +1723,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } @Override - public StartAnswer execute(StartCommand cmd) { - Connection conn = getConnection(); - VirtualMachineTO vmSpec = cmd.getVirtualMachine(); - String vmName = vmSpec.getName(); + public StartAnswer execute(final StartCommand cmd) { + final Connection conn = getConnection(); + final VirtualMachineTO vmSpec = cmd.getVirtualMachine(); + final String vmName = vmSpec.getName(); VmPowerState state = VmPowerState.HALTED; VM vm = null; // if a VDI is created, record its UUID to send back to the CS MS - Map<String, String> iqnToPath = new HashMap<String, String>(); + final Map<String, String> iqnToPath = new HashMap<String, String>(); try { - Set<VM> vms = VM.getByNameLabel(conn, vmName); + final Set<VM> vms = VM.getByNameLabel(conn, vmName); if (vms != null) { - for (VM v : vms) { - VM.Record vRec = v.getRecord(conn); + for (final VM v : vms) { + final VM.Record vRec = v.getRecord(conn); if (vRec.powerState == VmPowerState.HALTED) { v.destroy(conn); } else if (vRec.powerState == VmPowerState.RUNNING) { - String host = vRec.residentOn.getUuid(conn); - String msg = "VM " + vmName + " is runing on host " + host; + final String host = vRec.residentOn.getUuid(conn); + final String msg = "VM " + vmName + " is runing on host " + host; s_logger.debug(msg); return new StartAnswer(cmd, msg, host); } else { - String msg = "There is already a VM having the same name " + vmName + " vm record " + vRec.toString(); + final String msg = "There is already a VM having the same name " + vmName + " vm record " + vRec.toString(); s_logger.warn(msg); return new StartAnswer(cmd, msg); } @@ -1750,21 +1752,21 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } s_logger.debug("1. The VM " + vmName + " is in Starting state."); - Host host = Host.getByUuid(conn, _host.uuid); + final Host host = Host.getByUuid(conn, _host.uuid); vm = createVmFromTemplate(conn, vmSpec, host); - GPUDeviceTO gpuDevice = vmSpec.getGpuDevice(); + final GPUDeviceTO gpuDevice = vmSpec.getGpuDevice(); if (gpuDevice != null) { s_logger.debug("Creating VGPU for of VGPU type: " + gpuDevice.getVgpuType() + " in GPU group " + gpuDevice.getGpuGroup() + " for VM " + vmName ); createVGPU(conn, cmd, vm, gpuDevice); } - for (DiskTO disk : vmSpec.getDisks()) { - VDI newVdi = prepareManagedDisk(conn, disk, vmName); + for (final DiskTO disk : vmSpec.getDisks()) { + final VDI newVdi = prepareManagedDisk(conn, disk, vmName); if (newVdi != null) { - String path = newVdi.getUuid(conn); + final String path = newVdi.getUuid(conn); iqnToPath.put(disk.getDetails().get(DiskTO.IQN), path); } @@ -1776,7 +1778,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe createPatchVbd(conn, vmName, vm); } - for (NicTO nic : vmSpec.getNics()) { + for (final NicTO nic : vmSpec.getNics()) { createVif(conn, vmName, vm, vmSpec, nic); } @@ -1784,12 +1786,12 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (_isOvs) { // TODO(Salvatore-orlando): This code should go - for (NicTO nic : vmSpec.getNics()) { + for (final NicTO nic : vmSpec.getNics()) { if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vswitch) { - HashMap<String, String> args = parseDefaultOvsRuleComamnd(BroadcastDomainType.getValue(nic.getBroadcastUri())); - OvsSetTagAndFlowCommand flowCmd = + final HashMap<String, String> args = parseDefaultOvsRuleComamnd(BroadcastDomainType.getValue(nic.getBroadcastUri())); + final OvsSetTagAndFlowCommand flowCmd = new OvsSetTagAndFlowCommand(args.get("vmName"), args.get("tag"), args.get("vlans"), args.get("seqno"), Long.parseLong(args.get("vmId"))); - OvsSetTagAndFlowAnswer r = execute(flowCmd); + final OvsSetTagAndFlowAnswer r = execute(flowCmd); if (!r.getResult()) { s_logger.warn("Failed to set flow for VM " + r.getVmId()); } else { @@ -1802,11 +1804,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe if (_canBridgeFirewall) { String result = null; if (vmSpec.getType() != VirtualMachine.Type.User) { - NicTO[] nics = vmSpec.getNics(); + final NicTO[] nics = vmSpec.getNics(); boolean secGrpEnabled = false; - for (NicTO nic : nics) { + for (final NicTO nic : nics) { if (nic.isSecurityGroupEnabled() || - (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString()))) { + nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) { secGrpEnabled = true; break; } @@ -1822,15 +1824,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } else { //For user vm, program the rules for each nic if the isolation uri scheme is ec2 - NicTO[] nics = vmSpec.getNics(); - for (NicTO nic : nics) { + final NicTO[] nics = vmSpec.getNics(); + for (final NicTO nic : nics) { if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) { - List<String> nicSecIps = nic.getNicSecIps(); + final List<String> nicSecIps = nic.getNicSecIps(); String secIpsStr; - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); if (nicSecIps != null) { - for (String ip : nicSecIps) { + for (final String ip : nicSecIps) { sb.append(ip).append(":"); } secIpsStr = sb.toString(); @@ -1853,16 +1855,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe state = VmPowerState.RUNNING; - StartAnswer startAnswer = new StartAnswer(cmd); + final StartAnswer startAnswer = new StartAnswer(cmd); startAnswer.setIqnToPath(iqnToPath); return startAnswer; - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); - String msg = handleVmStartFailure(conn, vmName, vm, "", e); + final String msg = handleVmStartFailure(conn, vmName, vm, "", e); - StartAnswer startAnswer = new StartAnswer(cmd, msg); + final StartAnswer startAnswer = new StartAnswer(cmd, msg); startAnswer.setIqnToPath(iqnToPath); @@ -1879,44 +1881,44 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe // the idea here is to see if the DiskTO in question is from managed storage and // does not yet have an SR // if no SR, create it and create a VDI in it - private VDI prepareManagedDisk(Connection conn, DiskTO disk, String vmName) throws Exception { - Map<String, String> details = disk.getDetails(); + private VDI prepareManagedDisk(final Connection conn, final DiskTO disk, final String vmName) throws Exception { + final Map<String, String> details = disk.getDetails(); if (details == null) { return null; } - boolean isManaged = new Boolean(details.get(DiskTO.MANAGED)).booleanValue(); + final boolean isManaged = new Boolean(details.get(DiskTO.MANAGED)).booleanValue(); if (!isManaged) { return null; } - String iqn = details.get(DiskTO.IQN); + final String iqn = details.get(DiskTO.IQN); - Set<SR> srNameLabels = SR.getByNameLabel(conn, iqn); + final Set<SR> srNameLabels = SR.getByNameLabel(conn, iqn); if (srNameLabels.size() != 0) { return null; } - String vdiNameLabel = vmName + "-DATA"; + final String vdiNameLabel = vmName + "-DATA"; return prepareManagedStorage(conn, details, null, vdiNameLabel); } - protected SR prepareManagedSr(Connection conn, Map<String, String> details) { - String iScsiName = details.get(DiskTO.IQN); - String storageHost = details.get(DiskTO.STORAGE_HOST); - String chapInitiatorUsername = details.get(DiskTO.CHAP_INITIATOR_USERNAME); - String chapInitiatorSecret = details.get(DiskTO.CHAP_INITIATOR_SECRET); - String mountpoint = details.get(DiskTO.MOUNT_POINT); - String protocoltype = details.get(DiskTO.PROTOCOL_TYPE); + protected SR prepareManagedSr(final Connection conn, final Map<String, String> details) { + final String iScsiName = details.get(DiskTO.IQN); + final String storageHost = details.get(DiskTO.STORAGE_HOST); + final String chapInitiatorUsername = details.get(DiskTO.CHAP_INITIATOR_USERNAME); + final String chapInitiatorSecret = details.get(DiskTO.CHAP_INITIATOR_SECRET); + final String mountpoint = details.get(DiskTO.MOUNT_POINT); + final String protocoltype = details.get(DiskTO.PROTOCOL_TYPE); if (StoragePoolType.NetworkFilesystem.toString().equalsIgnoreCase(protocoltype)) { - String poolid = storageHost + ":" + mountpoint; - String namelable = mountpoint; - String volumedesc = storageHost + ":" + mountpoint; + final String poolid = storageHost + ":" + mountpoint; + final String namelable = mountpoint; + final String volumedesc = storageHost + ":" + mountpoint; return getNfsSR(conn, poolid, namelable, storageHost, mountpoint, volumedesc); } else { @@ -1924,11 +1926,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - protected VDI prepareManagedStorage(Connection conn, Map<String, String> details, String path, String vdiNameLabel) throws Exception { - SR sr = prepareManagedSr(conn, details); + protected VDI prepareManagedStorage(final Connection conn, final Map<String, String> details, final String path, final String vdiNameLabel) throws Exception { + final SR sr = prepareManagedSr(conn, details); VDI vdi = getVDIbyUuid(conn, path, false); - Long volumeSize = Long.parseLong(details.get(DiskTO.VOLUME_SIZE)); + final Long volumeSize = Long.parseLong(details.get(DiskTO.VOLUME_SIZE)); if (vdi == null) { vdi = createVdi(sr, vdiNameLabel, volumeSize); @@ -1938,40 +1940,40 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.info("checking for the resize of the datadisk"); - long vdiVirtualSize = vdi.getVirtualSize(conn); + final long vdiVirtualSize = vdi.getVirtualSize(conn); if (vdiVirtualSize != volumeSize) { s_logger.info("resizing the data disk (vdi) from vdiVirtualsize: "+ vdiVirtualSize + " to volumeSize: " + volumeSize); try { vdi.resize(conn, volumeSize); - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Unable to resize volume", e); } } - } + } return vdi; } - protected Answer execute(ModifySshKeysCommand cmd) { + protected Answer execute(final ModifySshKeysCommand cmd) { return new Answer(cmd); } - private boolean doPingTest(Connection conn, final String computingHostIp) { - com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.ip, 22); + private boolean doPingTest(final Connection conn, final String computingHostIp) { + final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.ip, 22); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password.peek())) { throw new CloudRuntimeException("Unable to authenticate"); } - String cmd = "ping -c 2 " + computingHostIp; + final String cmd = "ping -c 2 " + computingHostIp; if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) { throw new CloudRuntimeException("Cannot ping host " + computingHostIp + " from host " + _host.ip); } return true; - } catch (Exception e) { + } catch (final Exception e) { s_logger.warn("Catch exception " + e.toString(), e); return false; } finally { @@ -1979,21 +1981,21 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - protected CheckOnHostAnswer execute(CheckOnHostCommand cmd) { + protected CheckOnHostAnswer execute(final CheckOnHostCommand cmd) { return new CheckOnHostAnswer(cmd, null, "Not Implmeneted"); } - private boolean doPingTest(Connection conn, final String domRIp, final String vmIp) { - String args = "-i " + domRIp + " -p " + vmIp; - String result = callHostPlugin(conn, "vmops", "pingtest", "args", args); + private boolean doPingTest(final Connection conn, final String domRIp, final String vmIp) { + final String args = "-i " + domRIp + " -p " + vmIp; + final String result = callHostPlugin(conn, "vmops", "pingtest", "args", args); if (result == null || result.isEmpty()) { return false; } return true; } - private Answer execute(PingTestCommand cmd) { - Connection conn = getConnection(); + private Answer execute(final PingTestCommand cmd) { + final Connection conn = getConnection(); boolean result = false; final String computingHostIp = cmd.getComputingHostIp(); @@ -2009,56 +2011,56 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new Answer(cmd); } - protected MaintainAnswer execute(MaintainCommand cmd) { - Connection conn = getConnection(); + protected MaintainAnswer execute(final MaintainCommand cmd) { + final Connection conn = getConnection(); try { - Host host = Host.getByUuid(conn, _host.uuid); + final Host host = Host.
<TRUNCATED>
