Removed useless code

This commit is contained in:
Alex Huang 2011-01-19 18:14:50 -08:00
parent 94ec7bf27a
commit 3a9d6884ce
4 changed files with 10 additions and 368 deletions

View File

@ -68,16 +68,18 @@ public class Command {
public Argument getReqArgByName(String name){
for (Argument a : this.getRequest()) {
if (a.getName().equals(name))
return a;
if (a.getName().equals(name)) {
return a;
}
}
return null;
}
public Argument getResArgByName(String name){
for (Argument a : this.getResponse()) {
if (a.getName().equals(name))
return a;
if (a.getName().equals(name)) {
return a;
}
}
return null;
}

View File

@ -1,81 +0,0 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.ha;
import java.util.Map;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.host.HostVO;
import com.cloud.storage.StorageManager;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.vm.VMInstanceVO;
@Local(value=FenceBuilder.class)
public class StorageFence implements FenceBuilder {
private final static Logger s_logger = Logger.getLogger(StorageFence.class);
String _name;
StorageManager _storageMgr;
public StorageFence() {
}
@Override
public Boolean fenceOff(VMInstanceVO vm, HostVO host) {
s_logger.debug("Asking storage server to unshare " + vm.toString());
return _storageMgr.unshare(vm, host) != null;
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
_name = name;
ComponentLocator locator = ComponentLocator.getCurrentLocator();
if (locator == null) {
throw new ConfigurationException("Unable to locate the locator!");
}
_storageMgr = locator.getManager(StorageManager.class);
if (_storageMgr == null) {
throw new ConfigurationException("Unable to get " + StorageManager.class);
}
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
}

View File

@ -36,75 +36,12 @@ import com.cloud.storage.Volume.VolumeType;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
public interface StorageManager extends Manager {
VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, Account account);
/**
* Calls the storage agent and makes the volumes sharable with this host.
*
* @param vm vm that owns the volumes
* @param vols volumes to share
* @param host host to share the volumes to.
* @param cancelPrevious cancel the previous shares?
* @return true if works.
*
* @throws StorageUnavailableException if the storage server is unavailable.
*/
boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, boolean cancelPrevious) throws StorageUnavailableException;
List<VolumeVO> prepare(VMInstanceVO vm, HostVO host);
/**
* Calls the storage server to unshare volumes to the host.
*
* @param vm vm that owns the volumes.
* @param vols volumes to remove from share.
* @param host host to unshare the volumes to.
* @return true if it worked; false if not.
*/
boolean unshare(VMInstanceVO vm, List<VolumeVO> vols, HostVO host);
/**
* unshares the storage volumes of a certain vm to the host.
*
* @param vm vm to unshare.
* @param host host.
* @return List<VolumeVO> if succeeded. null if not.
*/
List<VolumeVO> unshare(VMInstanceVO vm, HostVO host);
/**
* Creates volumes for a particular VM.
* @param account account to create volumes for.
* @param vm vm to create the volumes for.
* @param template template the root volume is based on.
* @param dc datacenter to put this.
* @param pod pod to put this.
* @param offering service offering of the vm.
* @param diskOffering disk offering of the vm.
* @param avoids storage pools to avoid.
* @param size : size of the volume if defined
* @return List of VolumeVO
*/
List<VolumeVO> create(Account account, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, ServiceOfferingVO offering, DiskOfferingVO diskOffering, long size) throws StorageUnavailableException, ExecutionException;
/**
* Get the storage ip address to connect to.
* @param vm vm to run.
* @param host host to run it on.
* @param storage storage that contains the vm.
* @return ip address if it can be determined. null if not.
*/
String chooseStorageIp(VMInstanceVO vm, Host host, Host storage);
boolean canVmRestartOnAnotherServer(long vmId);
/** Returns the absolute path of the specified ISO
@ -135,16 +72,6 @@ public interface StorageManager extends Manager {
*/
public HostVO getSecondaryStorageHost(long zoneId);
/**
* Create the volumes for a user VM based on service offering in a particular data center
*
* @return true if successful
*/
public long createUserVM(Account account, VMInstanceVO vm,
VMTemplateVO template, DataCenterVO dc, HostPodVO pod,
ServiceOfferingVO offering, DiskOfferingVO diskOffering,
List<StoragePoolVO> avoids, long size);
/**
* This method sends the given command on all the hosts in the primary storage pool given until is succeeds on any one.
* If the command doesn't succeed on any, it return null. All exceptions are swallowed. Any errors are expected be be in
@ -240,14 +167,6 @@ public interface StorageManager extends Manager {
*/
void cleanupStorage(boolean recurring);
/**
* Find all of the storage pools needed for this vm.
*
* @param vmId id of the vm.
* @return List of StoragePoolVO
*/
StoragePoolVO getStoragePoolForVm(long vmId);
String getPrimaryStorageNameLabel(VolumeVO volume);
/**
@ -270,7 +189,6 @@ public interface StorageManager extends Manager {
void prepare(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException;
//void release(VirtualMachineProfile<? extends VirtualMachine> vm);
void release(VirtualMachineProfile<? extends VMInstanceVO> profile);

View File

@ -73,7 +73,6 @@ import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
import com.cloud.api.commands.UpdateStoragePoolCmd;
import com.cloud.async.AsyncInstanceCreateStatus;
import com.cloud.async.AsyncJobManager;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
@ -91,10 +90,7 @@ import com.cloud.deploy.DeployDestination;
import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.ActionEvent;
import com.cloud.event.Event;
import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils;
import com.cloud.event.EventVO;
import com.cloud.event.UsageEventVO;
import com.cloud.event.dao.EventDao;
import com.cloud.event.dao.UsageEventDao;
@ -164,7 +160,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
@ -242,7 +237,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
private int _pauseInterval;
private final boolean _shouldBeSnapshotCapable = true;
@Override
public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, boolean cancelPreviousShare) throws StorageUnavailableException {
//if pool is in maintenance and it is the ONLY pool available; reject
@ -299,16 +293,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return vols;
}
@Override
public VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, Account account) {
assert (template.getFormat() == ImageFormat.ISO) : "The template has to be ISO";
long rootId = _volsDao.getNextInSequence(Long.class, "volume_seq");
DiskProfile rootDisk = new DiskProfile(rootId, VolumeType.ROOT, "ROOT-" + vm.getId() + "-" + rootId, rootOffering.getId(), size != null ? size : rootOffering.getDiskSizeInBytes(), rootOffering.getTagsArray(), rootOffering.getUseLocalStorage(), rootOffering.isRecreatable(), null);
List<VolumeVO> vols = allocate(rootDisk, null, vm, dc, account);
return vols.get(0);
}
VolumeVO allocateDuplicateVolume(VolumeVO oldVol) {
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize());
newVol.setTemplateId(oldVol.getTemplateId());
@ -329,89 +313,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
}
@Override
public List<VolumeVO> prepare(VMInstanceVO vm, HostVO host) {
List<VolumeVO> vols = _volsDao.findCreatedByInstance(vm.getId());
List<VolumeVO> recreateVols = new ArrayList<VolumeVO>(vols.size());
for (VolumeVO vol : vols) {
if (!vol.isRecreatable()) {
return vols;
}
//if pool is in maintenance and it is the ONLY pool available; reject
List<VolumeVO> rootVolForGivenVm = _volsDao.findByInstanceAndType(vm.getId(), VolumeType.ROOT);
if(rootVolForGivenVm != null && rootVolForGivenVm.size() > 0){
boolean isPoolAvailable = isPoolAvailable(rootVolForGivenVm.get(0).getPoolId());
if(!isPoolAvailable){
return new ArrayList<VolumeVO>();
}
}
//if we have a system vm
//get the storage pool
//if pool is in prepareformaintenance
//add to recreate vols, and continue
if(vm.getType().equals(VirtualMachine.Type.ConsoleProxy) || vm.getType().equals(VirtualMachine.Type.DomainRouter) || vm.getType().equals(VirtualMachine.Type.SecondaryStorageVm))
{
StoragePoolVO sp = _storagePoolDao.findById(vol.getPoolId());
if(sp!=null && sp.getStatus().equals(Status.PrepareForMaintenance))
{
recreateVols.add(vol);
continue;
}
}
StoragePoolHostVO ph = _storagePoolHostDao.findByPoolHost(vol.getPoolId(), host.getId());
if (ph == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Must recreate " + vol + " since " + vol.getPoolId() + " has is not hooked up with host " + host.getId());
}
recreateVols.add(vol);
}
}
if (recreateVols.size() == 0) {
s_logger.debug("No need to recreate the volumes");
return vols;
}
List<VolumeVO> createds = new ArrayList<VolumeVO>();
for (VolumeVO vol : recreateVols) {
VolumeVO create = new VolumeVO(vol.getVolumeType(), vol.getInstanceId(), vol.getTemplateId(), vol.getName(), vol.getDataCenterId(), host.getPodId(), vol.getAccountId(), vol.getDomainId(), vol.isRecreatable());
create.setDiskOfferingId(vol.getDiskOfferingId());
create.setDeviceId(vol.getDeviceId());
create = _volsDao.persist(create);
VMTemplateVO template = _templateDao.findById(create.getTemplateId());
DataCenterVO dc = _dcDao.findById(create.getDataCenterId());
HostPodVO pod = _podDao.findById(host.getPodId());
DiskOfferingVO diskOffering = null;
diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
ServiceOfferingVO offering;
if (vm instanceof UserVmVO) {
offering = _offeringDao.findById(((UserVmVO)vm).getServiceOfferingId());
} else {
offering = _offeringDao.findById(vol.getDiskOfferingId());
}
VolumeVO created = createVolume(create, vm, template, dc, pod, host.getClusterId(), offering, diskOffering, new ArrayList<StoragePoolVO>(),0, template.getHypervisorType());
if (created == null) {
break;
}
createds.add(created);
}
if (createds.size() != recreateVols.size()) {
return null;
}
for (VolumeVO vol : recreateVols) {
_volsDao.remove(vol.getId());
}
return createds;
}
@Override
public List<Pair<VolumeVO, StoragePoolVO>> isStoredOn(VMInstanceVO vm) {
List<Pair<VolumeVO, StoragePoolVO>> lst = new ArrayList<Pair<VolumeVO, StoragePoolVO>>();
@ -453,16 +354,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return false;
}
@Override
public List<VolumeVO> unshare(VMInstanceVO vm, HostVO host) {
final List<VolumeVO> vols = _volsDao.findCreatedByInstance(vm.getId());
if (vols.size() == 0) {
return vols;
}
return unshare(vm, vols, host) ? vols : null;
}
protected StoragePoolVO findStoragePool(DiskProfile dskCh, final DataCenterVO dc, HostPodVO pod, Long clusterId, final ServiceOffering offering, final VMInstanceVO vm, final VMTemplateVO template, final Set<StoragePool> avoid) {
Enumeration<StoragePoolAllocator> en = _storagePoolAllocators.enumeration();
while (en.hasMoreElements()) {
@ -656,10 +547,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
SnapshotVO snapshot = _snapshotDao.findById(snapshotId); // Precondition: snapshot is not null and not removed.
Long origVolumeId = snapshot.getVolumeId();
VolumeVO originalVolume = _volsDao.findById(origVolumeId); // NOTE: Original volume could be destroyed and removed.
VMTemplateVO template = null;
if (originalVolume != null) {
template = _templateDao.findById(originalVolume.getTemplateId());
}
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot, originalVolume.getSize());
createdVolume = volumeDetails.first();
@ -818,12 +705,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return volume;
}
@Override
public List<VolumeVO> create(Account account, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, ServiceOfferingVO offering, DiskOfferingVO diskOffering, long size) throws StorageUnavailableException, ExecutionException {
List<StoragePoolVO> avoids = new ArrayList<StoragePoolVO>();
return create(account, vm, template, dc, pod, offering, diskOffering, avoids, size);
}
@DB
protected List<VolumeVO> create(Account account, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod,
ServiceOfferingVO offering, DiskOfferingVO diskOffering, List<StoragePoolVO> avoids, long size) {
@ -894,30 +775,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
}
@Override
public long createUserVM(Account account, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, ServiceOfferingVO offering, DiskOfferingVO diskOffering,
List<StoragePoolVO> avoids, long size) {
List<VolumeVO> volumes = create(account, vm, template, dc, pod, offering, diskOffering, avoids, size);
if( volumes == null || volumes.size() == 0) {
throw new CloudRuntimeException("Unable to create volume for " + vm.getName());
}
for (VolumeVO v : volumes) {
//when the user vm is created, the volume is attached upon creation
//set the attached datetime
try{
v.setAttached(new Date());
_volsDao.update(v.getId(), v);
}catch(Exception e)
{
s_logger.warn("Error updating the attached value for volume "+v.getId()+":"+e);
}
}
return volumes.get(0).getPoolId();
}
public Long chooseHostForStoragePool(StoragePoolVO poolVO, List<Long> avoidHosts, boolean sendToVmResidesOn, Long vmId) {
if (sendToVmResidesOn) {
if (vmId != null) {
@ -943,30 +800,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return null;
}
@Override
public String chooseStorageIp(VMInstanceVO vm, Host host, Host storage) {
Enumeration<StoragePoolAllocator> en = _storagePoolAllocators.enumeration();
while (en.hasMoreElements()) {
StoragePoolAllocator allocator = en.nextElement();
String ip = allocator.chooseStorageIp(vm, host, storage);
if (ip != null) {
return ip;
}
}
assert false : "Hmm....fell thru the loop";
return null;
}
@Override
public boolean unshare(VMInstanceVO vm, List<VolumeVO> vols, HostVO host) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking for volumes of " + vm.toString() + " to be unshared to " + (host != null ? host.toString() : "all"));
}
return true;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
@ -1225,15 +1058,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
}
List<HostVO> hosts = null;
if (clusterId != null) {
hosts = _hostDao.listByCluster(clusterId);
} else if (podId != null) {
hosts = _hostDao.listByHostPod(podId);
} else {
hosts = _hostDao.listByDataCenter(zoneId);
}
String scheme = uri.getScheme();
String storageHost = uri.getHost();
String hostPath = uri.getPath();
@ -2058,27 +1882,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
}
@Override
public StoragePoolVO getStoragePoolForVm(long vmId) {
SearchCriteria<StoragePoolVO> sc = PoolsUsedByVmSearch.create();
sc.setJoinParameters("volumes", "vm", vmId);
sc.setJoinParameters("volumes", "status", AsyncInstanceCreateStatus.Created.toString());
List<StoragePoolVO> sps= _storagePoolDao.search(sc, null);
if( sps.size() == 0 ) {
throw new RuntimeException("Volume is not created for VM " + vmId);
}
StoragePoolVO sp = sps.get(0);
for (StoragePoolVO tsp: sps ) {
// use the local storage pool to choose host,
// shared storage pool should be in the same cluster as local storage pool
if( tsp.isLocal()) {
sp = tsp;
break;
}
}
return sp;
}
@Override
public String getPrimaryStorageNameLabel(VolumeVO volume) {
Long poolId = volume.getPoolId();
@ -2540,8 +2343,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
if(type.equals(VolumeType.ROOT)) {
vol.setDeviceId(0l);
if(!vm.getType().equals(Type.User))
vol.setRecreatable(true);
if(!vm.getType().equals(Type.User)) {
vol.setRecreatable(true);
}
} else {
vol.setDeviceId(1l);
}
@ -2575,7 +2379,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
return createDiskCharacteristics(volume, offering);
}
protected StoragePool findStorage(DiskProfile dskCh, DeployDestination dest, VirtualMachineProfile vm, List<? extends Volume> alreadyAllocated, Set<? extends StoragePool> avoid) {
protected StoragePool findStorage(DiskProfile dskCh, DeployDestination dest, VirtualMachineProfile<? extends VirtualMachine> vm, List<? extends Volume> alreadyAllocated, Set<? extends StoragePool> avoid) {
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
StoragePool pool = allocator.allocateTo(dskCh, vm, dest, alreadyAllocated, avoid);
if (pool != null) {
@ -2607,7 +2411,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
List<VolumeVO> recreateVols = new ArrayList<VolumeVO>(vols.size());
int i = 0;
for (VolumeVO vol : vols) {
Volume.State state = vol.getState();
if (state == Volume.State.Ready) {