nonoss compiled up til netscaler

This commit is contained in:
Alex Huang 2013-01-23 17:18:34 -08:00
parent 8e2a96923c
commit 6088cbfe47
15 changed files with 232 additions and 223 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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");

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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<LunVO> lunList = netappMgr.listLunsOnFiler(poolName);
ListResponse<ListLunsCmdResponse> listResponse = new ListResponse<ListLunsCmdResponse>();

View File

@ -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<PoolVO> poolList = netappMgr.listPools();
ListResponse<ListVolumePoolsCmdResponse> listResponse = new ListResponse<ListVolumePoolsCmdResponse>();

View File

@ -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<NetappVolumeVO> volumes = netappMgr.listVolumesOnFiler(poolName);
ListResponse<ListVolumesOnFilerCmdResponse> listResponse = new ListResponse<ListVolumesOnFilerCmdResponse>();

View File

@ -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();

View File

@ -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<String, String> details = to.getDetails();
if(details == null)
details = new HashMap<String, String>();
String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER);
Map<String, String> details = to.getDetails();
if(details == null)
details = new HashMap<String, String>();
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<NicProfile> 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<NicProfile> 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<NicTO> listForSort = new ArrayList<NicTO>();
@ -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<HostVO, SecondaryStorageVmVO> 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<String, String> 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<HostVO, SecondaryStorageVmVO> 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<String, String> 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;
}
}

View File

@ -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<String, List<VmwareCleanupMaid>> s_leftoverDummyVMs = new HashMap<String, List<VmwareCleanupMaid>>();
@ -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());
}
}

View File

@ -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 {