From 6088cbfe479ae54f04546c2f25d9988debc5391a Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Wed, 23 Jan 2013 17:18:34 -0800 Subject: [PATCH] nonoss compiled up til netscaler --- .../api/commands/netapp/AssociateLunCmd.java | 6 +- .../api/commands/netapp/CreateLunCmd.java | 5 +- .../netapp/CreateVolumeOnFilerCmd.java | 7 +- .../commands/netapp/CreateVolumePoolCmd.java | 5 +- .../commands/netapp/DeleteVolumePoolCmd.java | 7 +- .../api/commands/netapp/DestroyLunCmd.java | 5 +- .../netapp/DestroyVolumeOnFilerCmd.java | 7 +- .../api/commands/netapp/DissociateLunCmd.java | 5 +- .../api/commands/netapp/ListLunsCmd.java | 5 +- .../commands/netapp/ListVolumePoolsCmd.java | 5 +- .../netapp/ListVolumesOnFilerCmd.java | 7 +- .../commands/netapp/ModifyVolumePoolCmd.java | 8 +- .../com/cloud/hypervisor/guru/VMwareGuru.java | 354 +++++++++--------- .../hypervisor/vmware/VmwareCleanupMaid.java | 23 +- .../vmware/resource/VmwareContextFactory.java | 6 +- 15 files changed, 232 insertions(+), 223 deletions(-) diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java index 62c94cae9f3..5d9ad078ca2 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/AssociateLunCmd.java @@ -18,6 +18,8 @@ package com.cloud.api.commands.netapp; import java.rmi.ServerException; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -70,10 +72,10 @@ public class AssociateLunCmd extends BaseCmd { return s_name; } + @Inject NetappManager netappMgr; + @Override public void execute(){ - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { AssociateLunCmdResponse response = new AssociateLunCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java index d94b7c991ad..a0c19833a7e 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateLunCmd.java @@ -18,6 +18,8 @@ package com.cloud.api.commands.netapp; import java.rmi.ServerException; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -58,13 +60,12 @@ public class CreateLunCmd extends BaseCmd { public long getLunSize() { return size; } + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { CreateLunCmdResponse response = new CreateLunCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java index 9480c8500e5..56e9441638b 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumeOnFilerCmd.java @@ -19,6 +19,8 @@ package com.cloud.api.commands.netapp; import java.net.UnknownHostException; import java.rmi.ServerException; +import javax.inject.Inject; + import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -102,6 +104,8 @@ public class CreateVolumeOnFilerCmd extends BaseCmd { public String getPassword() { return password; } + + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, @@ -111,9 +115,6 @@ public class CreateVolumeOnFilerCmd extends BaseCmd { if(snapshotReservation != null && (snapshotReservation<0 || snapshotReservation>100)) throw new InvalidParameterValueException("Invalid snapshot reservation"); - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); - StringBuilder s = new StringBuilder(getVolSize().toString()); s.append("g"); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java index ae0e411de4f..a83b2c96501 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/CreateVolumePoolCmd.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.api.commands.netapp; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -51,13 +53,12 @@ public class CreateVolumePoolCmd extends BaseCmd { public String getAlgorithm() { return algorithm; } + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { CreateVolumePoolCmdResponse response = new CreateVolumePoolCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java index f5da74af940..f17c61ca94a 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DeleteVolumePoolCmd.java @@ -17,6 +17,8 @@ package com.cloud.api.commands.netapp; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +34,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.netapp.NetappManager; -import com.cloud.server.ManagementService; import com.cloud.server.api.response.netapp.DeleteVolumePoolCmdResponse; @@ -43,13 +44,13 @@ public class DeleteVolumePoolCmd extends BaseCmd { @Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; + + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { netappMgr.deletePool(poolName); DeleteVolumePoolCmdResponse response = new DeleteVolumePoolCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java index d6a857cad0d..f08defc0159 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyLunCmd.java @@ -18,6 +18,8 @@ package com.cloud.api.commands.netapp; import java.rmi.ServerException; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -45,12 +47,11 @@ public class DestroyLunCmd extends BaseCmd { @Parameter(name=ApiConstants.PATH, type=CommandType.STRING, required = true, description="LUN path.") private String path; + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { netappMgr.destroyLunOnFiler(path); DeleteLUNCmdResponse response = new DeleteLUNCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java index ab1e0df3de5..05413701cd9 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DestroyVolumeOnFilerCmd.java @@ -18,6 +18,8 @@ package com.cloud.api.commands.netapp; import java.rmi.ServerException; +import javax.inject.Inject; + import org.apache.cloudstack.api.*; import org.apache.log4j.Logger; @@ -29,7 +31,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.netapp.NetappManager; -import com.cloud.server.ManagementService; import com.cloud.server.api.response.netapp.DeleteVolumeOnFilerCmdResponse; @@ -47,13 +48,13 @@ public class DestroyVolumeOnFilerCmd extends BaseCmd { @Parameter(name=ApiConstants.VOLUME_NAME, type=CommandType.STRING, required = true, description="volume name.") private String volumeName; + @Inject NetappManager netappMgr; + @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { netappMgr.destroyVolumeOnFiler(ipAddr, aggrName, volumeName); DeleteVolumeOnFilerCmdResponse response = new DeleteVolumeOnFilerCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java index 1fc42ea91b8..ac6dbf0b561 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/DissociateLunCmd.java @@ -18,6 +18,8 @@ package com.cloud.api.commands.netapp; import java.rmi.ServerException; +import javax.inject.Inject; + import org.apache.cloudstack.api.*; import org.apache.log4j.Logger; @@ -43,12 +45,11 @@ public class DissociateLunCmd extends BaseCmd { @Parameter(name=ApiConstants.IQN, type=CommandType.STRING, required = true, description="Guest IQN.") private String guestIQN; + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { netappMgr.disassociateLun(guestIQN, path); DissociateLunCmdResponse response = new DissociateLunCmdResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java index d1bf7ea35c6..90bc5f3f425 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListLunsCmd.java @@ -19,6 +19,8 @@ package com.cloud.api.commands.netapp; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -48,12 +50,11 @@ public class ListLunsCmd extends BaseCmd @Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { List lunList = netappMgr.listLunsOnFiler(poolName); ListResponse listResponse = new ListResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java index 6ab551ed267..fd9b17d9ea1 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumePoolsCmd.java @@ -19,6 +19,8 @@ package com.cloud.api.commands.netapp; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiErrorCode; @@ -42,13 +44,12 @@ public class ListVolumePoolsCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(ListVolumePoolsCmd.class.getName()); private static final String s_name = "listpoolresponse"; + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); try { List poolList = netappMgr.listPools(); ListResponse listResponse = new ListResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java index 7d26365500f..ac839ba58c5 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ListVolumesOnFilerCmd.java @@ -19,6 +19,8 @@ package com.cloud.api.commands.netapp; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; + import org.apache.cloudstack.api.*; import org.apache.log4j.Logger; @@ -42,14 +44,13 @@ public class ListVolumesOnFilerCmd extends BaseCmd { @Parameter(name=ApiConstants.POOL_NAME, type=CommandType.STRING, required = true, description="pool name.") private String poolName; + + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); - try { List volumes = netappMgr.listVolumesOnFiler(poolName); ListResponse listResponse = new ListResponse(); diff --git a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ModifyVolumePoolCmd.java b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ModifyVolumePoolCmd.java index 6282a648a99..268345a46cf 100644 --- a/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ModifyVolumePoolCmd.java +++ b/plugins/file-systems/netapp/src/com/cloud/api/commands/netapp/ModifyVolumePoolCmd.java @@ -17,6 +17,8 @@ package com.cloud.api.commands.netapp; +import javax.inject.Inject; + import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; @@ -29,7 +31,6 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.netapp.NetappManager; -import com.cloud.server.ManagementService; import com.cloud.server.api.response.netapp.ModifyVolumePoolCmdResponse; @@ -43,14 +44,13 @@ public class ModifyVolumePoolCmd extends BaseCmd { @Parameter(name=ApiConstants.ALGORITHM, type=CommandType.STRING, required = true, description="algorithm.") private String algorithm; + + @Inject NetappManager netappMgr; @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name); - NetappManager netappMgr = locator.getManager(NetappManager.class); - netappMgr.modifyPool(poolName, algorithm); ModifyVolumePoolCmdResponse response = new ModifyVolumePoolCmdResponse(); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index 65fbf4adeb8..638b0e32ac3 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -38,7 +38,6 @@ import com.cloud.agent.api.storage.CopyVolumeCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.cluster.CheckPointManager; import com.cloud.cluster.ClusterManager; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.host.HostVO; @@ -47,7 +46,6 @@ import com.cloud.host.dao.HostDetailsDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; import com.cloud.hypervisor.HypervisorGuruBase; -import com.cloud.hypervisor.vmware.VmwareCleanupMaid; import com.cloud.hypervisor.vmware.manager.VmwareManager; import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType; import com.cloud.network.NetworkModel; @@ -75,23 +73,22 @@ import com.cloud.vm.VmDetailConstants; @Component @Local(value=HypervisorGuru.class) public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru { - private static final Logger s_logger = Logger.getLogger(VMwareGuru.class); + private static final Logger s_logger = Logger.getLogger(VMwareGuru.class); - @Inject NetworkDao _networkDao; - @Inject GuestOSDao _guestOsDao; + @Inject NetworkDao _networkDao; + @Inject GuestOSDao _guestOsDao; @Inject HostDao _hostDao; @Inject HostDetailsDao _hostDetailsDao; @Inject CommandExecLogDao _cmdExecLogDao; @Inject ClusterManager _clusterMgr; @Inject VmwareManager _vmwareMgr; @Inject SecondaryStorageVmManager _secStorageMgr; - @Inject CheckPointManager _checkPointMgr; @Inject NetworkModel _networkMgr; protected VMwareGuru() { - super(); + super(); } - + @Override public HypervisorType getHypervisorType() { return HypervisorType.VMware; @@ -102,117 +99,117 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru { VirtualMachineTO to = toVirtualMachineTO(vm); to.setBootloader(BootloaderType.HVM); - Map details = to.getDetails(); - if(details == null) - details = new HashMap(); - - String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER); + Map details = to.getDetails(); + if(details == null) + details = new HashMap(); + + String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER); if(vm.getVirtualMachine() instanceof DomainRouterVO || vm.getVirtualMachine() instanceof ConsoleProxyVO - || vm.getVirtualMachine() instanceof SecondaryStorageVmVO) { - - if(nicDeviceType == null) { - details.put(VmDetailConstants.NIC_ADAPTER, _vmwareMgr.getSystemVMDefaultNicAdapterType()); - } else { - try { - VirtualEthernetCardType.valueOf(nicDeviceType); - } catch (Exception e) { - s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000"); - details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString()); - } - } + || vm.getVirtualMachine() instanceof SecondaryStorageVmVO) { + + if(nicDeviceType == null) { + details.put(VmDetailConstants.NIC_ADAPTER, _vmwareMgr.getSystemVMDefaultNicAdapterType()); + } else { + try { + VirtualEthernetCardType.valueOf(nicDeviceType); + } catch (Exception e) { + s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000"); + details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString()); + } + } } else { - // for user-VM, use E1000 as default - if(nicDeviceType == null) { - details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString()); - } else { - try { - VirtualEthernetCardType.valueOf(nicDeviceType); - } catch (Exception e) { - s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000"); - details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString()); - } - } + // for user-VM, use E1000 as default + if(nicDeviceType == null) { + details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString()); + } else { + try { + VirtualEthernetCardType.valueOf(nicDeviceType); + } catch (Exception e) { + s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000"); + details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString()); + } + } } - to.setDetails(details); + to.setDetails(details); - if(vm.getVirtualMachine() instanceof DomainRouterVO) { - List nicProfiles = vm.getNics(); - NicProfile publicNicProfile = null; - - for(NicProfile nicProfile : nicProfiles) { - if(nicProfile.getTrafficType() == TrafficType.Public) { - publicNicProfile = nicProfile; - break; - } - } - - if(publicNicProfile != null) { - NicTO[] nics = to.getNics(); + if(vm.getVirtualMachine() instanceof DomainRouterVO) { + List nicProfiles = vm.getNics(); + NicProfile publicNicProfile = null; - // reserve extra NICs - NicTO[] expandedNics = new NicTO[nics.length + _vmwareMgr.getRouterExtraPublicNics()]; - int i = 0; - int deviceId = -1; - for(i = 0; i < nics.length; i++) { - expandedNics[i] = nics[i]; - if(nics[i].getDeviceId() > deviceId) - deviceId = nics[i].getDeviceId(); - } - deviceId++; - - long networkId = publicNicProfile.getNetworkId(); - NetworkVO network = _networkDao.findById(networkId); - - for(; i < nics.length + _vmwareMgr.getRouterExtraPublicNics(); i++) { - NicTO nicTo = new NicTO(); - - nicTo.setDeviceId(deviceId++); - nicTo.setBroadcastType(publicNicProfile.getBroadcastType()); - nicTo.setType(publicNicProfile.getTrafficType()); - nicTo.setIp("0.0.0.0"); - nicTo.setNetmask("255.255.255.255"); - - try { - String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId); - nicTo.setMac(mac); - } catch (InsufficientAddressCapacityException e) { - throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId); - } - nicTo.setDns1(publicNicProfile.getDns1()); - nicTo.setDns2(publicNicProfile.getDns2()); - if (publicNicProfile.getGateway() != null) { - nicTo.setGateway(publicNicProfile.getGateway()); - } else { - nicTo.setGateway(network.getGateway()); - } - nicTo.setDefaultNic(false); - nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri()); - nicTo.setIsolationuri(publicNicProfile.getIsolationUri()); + for(NicProfile nicProfile : nicProfiles) { + if(nicProfile.getTrafficType() == TrafficType.Public) { + publicNicProfile = nicProfile; + break; + } + } - Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null); - nicTo.setNetworkRateMbps(networkRate); - - expandedNics[i] = nicTo; - } - - to.setNics(expandedNics); - } - - StringBuffer sbMacSequence = new StringBuffer(); - for(NicTO nicTo : sortNicsByDeviceId(to.getNics())) { - sbMacSequence.append(nicTo.getMac()).append("|"); - } - sbMacSequence.deleteCharAt(sbMacSequence.length() - 1); - String bootArgs = to.getBootArgs(); - to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString()); - } + if(publicNicProfile != null) { + NicTO[] nics = to.getNics(); + + // reserve extra NICs + NicTO[] expandedNics = new NicTO[nics.length + _vmwareMgr.getRouterExtraPublicNics()]; + int i = 0; + int deviceId = -1; + for(i = 0; i < nics.length; i++) { + expandedNics[i] = nics[i]; + if(nics[i].getDeviceId() > deviceId) + deviceId = nics[i].getDeviceId(); + } + deviceId++; + + long networkId = publicNicProfile.getNetworkId(); + NetworkVO network = _networkDao.findById(networkId); + + for(; i < nics.length + _vmwareMgr.getRouterExtraPublicNics(); i++) { + NicTO nicTo = new NicTO(); + + nicTo.setDeviceId(deviceId++); + nicTo.setBroadcastType(publicNicProfile.getBroadcastType()); + nicTo.setType(publicNicProfile.getTrafficType()); + nicTo.setIp("0.0.0.0"); + nicTo.setNetmask("255.255.255.255"); + + try { + String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId); + nicTo.setMac(mac); + } catch (InsufficientAddressCapacityException e) { + throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId); + } + nicTo.setDns1(publicNicProfile.getDns1()); + nicTo.setDns2(publicNicProfile.getDns2()); + if (publicNicProfile.getGateway() != null) { + nicTo.setGateway(publicNicProfile.getGateway()); + } else { + nicTo.setGateway(network.getGateway()); + } + nicTo.setDefaultNic(false); + nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri()); + nicTo.setIsolationuri(publicNicProfile.getIsolationUri()); + + Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null); + nicTo.setNetworkRateMbps(networkRate); + + expandedNics[i] = nicTo; + } + + to.setNics(expandedNics); + } + + StringBuffer sbMacSequence = new StringBuffer(); + for(NicTO nicTo : sortNicsByDeviceId(to.getNics())) { + sbMacSequence.append(nicTo.getMac()).append("|"); + } + sbMacSequence.deleteCharAt(sbMacSequence.length() - 1); + String bootArgs = to.getBootArgs(); + to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString()); + } // Determine the VM's OS description GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId()); to.setOs(guestOS.getDisplayName()); return to; } - + private NicTO[] sortNicsByDeviceId(NicTO[] nics) { List listForSort = new ArrayList(); @@ -235,83 +232,86 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru { return listForSort.toArray(new NicTO[0]); } - + @Override @DB public long getCommandHostDelegation(long hostId, Command cmd) { - boolean needDelegation = false; - - if(cmd instanceof PrimaryStorageDownloadCommand || - cmd instanceof BackupSnapshotCommand || - cmd instanceof CreatePrivateTemplateFromVolumeCommand || - cmd instanceof CreatePrivateTemplateFromSnapshotCommand || - cmd instanceof CopyVolumeCommand || - cmd instanceof CreateVolumeFromSnapshotCommand) { - needDelegation = true; - } + boolean needDelegation = false; - if(needDelegation) { - HostVO host = _hostDao.findById(hostId); - assert(host != null); - assert(host.getHypervisorType() == HypervisorType.VMware); - long dcId = host.getDataCenterId(); - - Pair cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd); - if(cmdTarget != null) { - // TODO, we need to make sure agent is actually connected too - cmd.setContextParam("hypervisor", HypervisorType.VMware.toString()); - Map hostDetails = _hostDetailsDao.findDetails(hostId); - cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid"))); - cmd.setContextParam("username", hostDetails.get("username")); - cmd.setContextParam("password", hostDetails.get("password")); - cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName()); - cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName()); - - CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1); - _cmdExecLogDao.persist(execLog); - cmd.setContextParam("execid", String.valueOf(execLog.getId())); - - if(cmd instanceof BackupSnapshotCommand || - cmd instanceof CreatePrivateTemplateFromVolumeCommand || - cmd instanceof CreatePrivateTemplateFromSnapshotCommand || - cmd instanceof CopyVolumeCommand || - cmd instanceof CreateVolumeFromSnapshotCommand) { - - String workerName = _vmwareMgr.composeWorkerName(); - long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName)); - cmd.setContextParam("worker", workerName); - cmd.setContextParam("checkpoint", String.valueOf(checkPointId)); + if(cmd instanceof PrimaryStorageDownloadCommand || + cmd instanceof BackupSnapshotCommand || + cmd instanceof CreatePrivateTemplateFromVolumeCommand || + cmd instanceof CreatePrivateTemplateFromSnapshotCommand || + cmd instanceof CopyVolumeCommand || + cmd instanceof CreateVolumeFromSnapshotCommand) { + needDelegation = true; + } - // some commands use 2 workers + if(needDelegation) { + HostVO host = _hostDao.findById(hostId); + assert(host != null); + assert(host.getHypervisorType() == HypervisorType.VMware); + long dcId = host.getDataCenterId(); + + Pair cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd); + if(cmdTarget != null) { + // TODO, we need to make sure agent is actually connected too + cmd.setContextParam("hypervisor", HypervisorType.VMware.toString()); + Map hostDetails = _hostDetailsDao.findDetails(hostId); + cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid"))); + cmd.setContextParam("username", hostDetails.get("username")); + cmd.setContextParam("password", hostDetails.get("password")); + cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName()); + cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName()); + + CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1); + _cmdExecLogDao.persist(execLog); + cmd.setContextParam("execid", String.valueOf(execLog.getId())); + + if(cmd instanceof BackupSnapshotCommand || + cmd instanceof CreatePrivateTemplateFromVolumeCommand || + cmd instanceof CreatePrivateTemplateFromSnapshotCommand || + cmd instanceof CopyVolumeCommand || + cmd instanceof CreateVolumeFromSnapshotCommand) { + + String workerName = _vmwareMgr.composeWorkerName(); + long checkPointId = 1; +// FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName)); + cmd.setContextParam("worker", workerName); + cmd.setContextParam("checkpoint", String.valueOf(checkPointId)); + + // some commands use 2 workers String workerName2 = _vmwareMgr.composeWorkerName(); - long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2)); + long checkPointId2 = 1; +// FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2)); cmd.setContextParam("worker2", workerName2); cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2)); - } - - return cmdTarget.first().getId(); - } - } - - return hostId; - } - - public boolean trackVmHostChange() { - return true; - } - - private static String resolveNameInGuid(String guid) { - String tokens[] = guid.split("@"); - assert(tokens.length == 2); + } - String vCenterIp = NetUtils.resolveToIp(tokens[1]); - if(vCenterIp == null) { - s_logger.error("Fatal : unable to resolve vCenter address " + tokens[1] + ", please check your DNS configuration"); - return guid; - } - - if(vCenterIp.equals(tokens[1])) - return guid; - - return tokens[0] + "@" + vCenterIp; + return cmdTarget.first().getId(); + } + } + + return hostId; + } + + @Override + public boolean trackVmHostChange() { + return true; + } + + private static String resolveNameInGuid(String guid) { + String tokens[] = guid.split("@"); + assert(tokens.length == 2); + + String vCenterIp = NetUtils.resolveToIp(tokens[1]); + if(vCenterIp == null) { + s_logger.error("Fatal : unable to resolve vCenter address " + tokens[1] + ", please check your DNS configuration"); + return guid; + } + + if(vCenterIp.equals(tokens[1])) + return guid; + + return tokens[0] + "@" + vCenterIp; } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java index a3e2fca16bd..bae8857e1ef 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java @@ -23,8 +23,6 @@ import java.util.Map; import org.apache.log4j.Logger; -import com.cloud.cluster.CheckPointManager; -import com.cloud.cluster.CleanupMaid; import com.cloud.hypervisor.vmware.manager.VmwareManager; import com.cloud.hypervisor.vmware.mo.ClusterMO; import com.cloud.hypervisor.vmware.mo.DatacenterMO; @@ -32,7 +30,7 @@ import com.cloud.hypervisor.vmware.mo.HostMO; import com.cloud.hypervisor.vmware.mo.VirtualMachineMO; import com.cloud.hypervisor.vmware.util.VmwareContext; -public class VmwareCleanupMaid implements CleanupMaid { +public class VmwareCleanupMaid { private static final Logger s_logger = Logger.getLogger(VmwareCleanupMaid.class); private static Map> s_leftoverDummyVMs = new HashMap>(); @@ -67,16 +65,15 @@ public class VmwareCleanupMaid implements CleanupMaid { _vmName = vmName; } - @Override - public int cleanup(CheckPointManager checkPointMgr) { - - // save a check-point in case we crash at current run so that we won't lose it - _checkPoint = checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(_vCenterAddress, _dcMorValue, _vmName)); - addLeftOverVM(this); - return 0; - } +// @Override +// public int cleanup(CheckPointManager checkPointMgr) { +// +// // save a check-point in case we crash at current run so that we won't lose it +// _checkPoint = checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(_vCenterAddress, _dcMorValue, _vmName)); +// addLeftOverVM(this); +// return 0; +// } - @Override public String getCleanupProcedure() { return null; } @@ -137,7 +134,7 @@ public class VmwareCleanupMaid implements CleanupMaid { } catch(Throwable e) { s_logger.warn("Unable to destroy left over dummy VM " + cleanupMaid.getVmName()); } finally { - mgr.popCleanupCheckpoint(cleanupMaid.getCheckPoint()); +// FIXME mgr.popCleanupCheckpoint(cleanupMaid.getCheckPoint()); } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java index 7ec06575208..ab10e5e5ef1 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java @@ -19,8 +19,10 @@ package com.cloud.hypervisor.vmware.resource; import org.apache.log4j.Logger; import com.cloud.hypervisor.vmware.manager.VmwareManager; +import com.cloud.hypervisor.vmware.manager.VmwareManagerImpl; import com.cloud.hypervisor.vmware.util.VmwareContext; import com.cloud.utils.StringUtils; +import com.cloud.utils.component.ComponentContext; import com.vmware.apputils.version.ExtendedAppUtil; @@ -34,9 +36,7 @@ public class VmwareContextFactory { static { // skip certificate check System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory"); - - ComponentLocator locator = ComponentLocator.getLocator("management-server"); - s_vmwareMgr = locator.getManager(VmwareManager.class); + s_vmwareMgr = ComponentContext.inject(VmwareManagerImpl.class); } public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {