mirror of https://github.com/apache/cloudstack.git
Changed network tags to network name as we no longer need to send the entire network tags down to the resource.
This commit is contained in:
parent
1d268dc23a
commit
84d5f0514e
|
|
@ -18,14 +18,12 @@
|
|||
|
||||
package com.cloud.agent.api.to;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
||||
|
||||
public class IpAddressTO {
|
||||
|
||||
private long accountId;
|
||||
|
||||
private long accountId;
|
||||
private String publicIp;
|
||||
private boolean sourceNat;
|
||||
private boolean add;
|
||||
|
|
@ -38,8 +36,8 @@ public class IpAddressTO {
|
|||
private String guestIp;
|
||||
private Integer networkRate;
|
||||
private TrafficType trafficType;
|
||||
private String[] networkTags;
|
||||
|
||||
private String networkName;
|
||||
|
||||
public IpAddressTO(long accountId, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, String guestIp, Integer networkRate, boolean isOneToOneNat) {
|
||||
this.accountId = accountId;
|
||||
this.publicIp = ipAddress;
|
||||
|
|
@ -54,12 +52,12 @@ public class IpAddressTO {
|
|||
this.networkRate = networkRate;
|
||||
this.oneToOneNat = isOneToOneNat;
|
||||
}
|
||||
|
||||
|
||||
protected IpAddressTO() {
|
||||
}
|
||||
|
||||
|
||||
public long getAccountId() {
|
||||
return accountId;
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public String getGuestIp(){
|
||||
|
|
@ -69,24 +67,20 @@ public class IpAddressTO {
|
|||
public String getPublicIp() {
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
|
||||
public TrafficType getTrafficType() {
|
||||
return trafficType;
|
||||
}
|
||||
|
||||
public void setNetworkTags(List<String> tagsList) {
|
||||
if (tagsList == null || tagsList.size() == 0) {
|
||||
networkTags = null;
|
||||
} else {
|
||||
networkTags = tagsList.toArray(new String[tagsList.size()]);
|
||||
}
|
||||
|
||||
public void setNetworkName(String name) {
|
||||
this.networkName = name;
|
||||
}
|
||||
|
||||
public String[] getNetworkTags() {
|
||||
return networkTags;
|
||||
|
||||
public String getNetworkName() {
|
||||
return networkName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setTrafficType(TrafficType trafficType) {
|
||||
this.trafficType = trafficType;
|
||||
}
|
||||
|
|
@ -94,11 +88,11 @@ public class IpAddressTO {
|
|||
public boolean isAdd() {
|
||||
return add;
|
||||
}
|
||||
|
||||
|
||||
public boolean isOneToOneNat(){
|
||||
return this.oneToOneNat;
|
||||
}
|
||||
|
||||
|
||||
public boolean isFirstIP() {
|
||||
return firstIP;
|
||||
}
|
||||
|
|
@ -110,23 +104,23 @@ public class IpAddressTO {
|
|||
public boolean isSourceNat() {
|
||||
return sourceNat;
|
||||
}
|
||||
|
||||
|
||||
public String getVlanId() {
|
||||
return vlanId;
|
||||
}
|
||||
|
||||
|
||||
public String getVlanGateway() {
|
||||
return vlanGateway;
|
||||
}
|
||||
|
||||
|
||||
public String getVlanNetmask() {
|
||||
return vlanNetmask;
|
||||
}
|
||||
|
||||
|
||||
public String getVifMacAddress() {
|
||||
return vifMacAddress;
|
||||
}
|
||||
|
||||
|
||||
public Integer getNetworkRate() {
|
||||
return networkRate;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
package com.cloud.agent.api.to;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
|
@ -39,7 +38,7 @@ public class NetworkTO {
|
|||
protected URI broadcastUri;
|
||||
protected URI isolationUri;
|
||||
protected boolean isSecurityGroupEnabled;
|
||||
protected String[] tags;
|
||||
protected String name;
|
||||
|
||||
public NetworkTO() {
|
||||
}
|
||||
|
|
@ -88,12 +87,12 @@ public class NetworkTO {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags.toArray(new String[tags.size()]);
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return tags;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setSecurityGroupEnabled(boolean enabled) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
package com.cloud.vm;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
|
|
@ -54,15 +53,15 @@ public class NicProfile {
|
|||
String dns2;
|
||||
Integer networkRate;
|
||||
boolean isSecurityGroupEnabled;
|
||||
List<String> tags;
|
||||
String name;
|
||||
String requestedIp;
|
||||
|
||||
public String getDns1() {
|
||||
return dns1;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDns2() {
|
||||
|
|
@ -213,7 +212,7 @@ public class NicProfile {
|
|||
return strategy;
|
||||
}
|
||||
|
||||
public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, List<String> tags) {
|
||||
public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name) {
|
||||
this.id = nic.getId();
|
||||
this.networkId = network.getId();
|
||||
this.gateway = nic.getGateway();
|
||||
|
|
@ -233,7 +232,7 @@ public class NicProfile {
|
|||
this.netmask = nic.getNetmask();
|
||||
this.isSecurityGroupEnabled = isSecurityGroupEnabled;
|
||||
this.vmId = nic.getInstanceId();
|
||||
this.tags = tags;
|
||||
this.name = name;
|
||||
|
||||
if (networkRate != null) {
|
||||
this.networkRate = networkRate;
|
||||
|
|
@ -255,7 +254,7 @@ public class NicProfile {
|
|||
this.netmask = netmask;
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
|
||||
public NicProfile(String requestedIp) {
|
||||
this.requestedIp = requestedIp;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -49,7 +49,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
|||
to.setBroadcastUri(profile.getBroadCastUri());
|
||||
to.setIsolationuri(profile.getIsolationUri());
|
||||
to.setNetworkRateMbps(profile.getNetworkRate());
|
||||
to.setTags(profile.getTags());
|
||||
to.setName(profile.getName());
|
||||
return to;
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
|||
} else {
|
||||
to.setArch("x86_64");
|
||||
}
|
||||
|
||||
|
||||
to.setDetails(vm.getDetails());
|
||||
|
||||
return to;
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public interface NetworkManager extends NetworkService {
|
|||
void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkVO, NicProfile>> networks) throws InsufficientCapacityException, ConcurrentOperationException;
|
||||
|
||||
void prepare(VirtualMachineProfile<? extends VMInstanceVO> profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException,
|
||||
ResourceUnavailableException;
|
||||
ResourceUnavailableException;
|
||||
|
||||
void release(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, boolean forced);
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ public interface NetworkManager extends NetworkService {
|
|||
List<? extends Vlan> listPodVlans(long podId);
|
||||
|
||||
Pair<NetworkGuru, NetworkVO> implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
|
||||
InsufficientCapacityException;
|
||||
InsufficientCapacityException;
|
||||
|
||||
List<NetworkVO> listNetworksUsedByVm(long vmId, boolean isSystem);
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ public interface NetworkManager extends NetworkService {
|
|||
* @throws
|
||||
*/
|
||||
boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network networkToAssociateWith) throws InsufficientCapacityException, ConcurrentOperationException,
|
||||
ResourceUnavailableException;
|
||||
ResourceUnavailableException;
|
||||
|
||||
Nic getNicInNetwork(long vmId, long networkId);
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ public interface NetworkManager extends NetworkService {
|
|||
Nic getDefaultNic(long vmId);
|
||||
|
||||
List<? extends UserDataServiceProvider> getPasswordResetElements();
|
||||
|
||||
|
||||
boolean networkIsConfiguredForExternalNetworking(long zoneId, long networkId);
|
||||
|
||||
Map<Capability, String> getNetworkServiceCapabilities(long networkId, Service service);
|
||||
|
|
@ -200,51 +200,51 @@ public interface NetworkManager extends NetworkService {
|
|||
List<NetworkVO> listNetworksForAccount(long accountId, long zoneId, Network.GuestType type, Boolean isDefault);
|
||||
|
||||
IPAddressVO markIpAsUnavailable(long addrId);
|
||||
|
||||
|
||||
public String acquireGuestIpAddress(Network network, String requestedIp);
|
||||
|
||||
String getGlobalGuestDomainSuffix();
|
||||
|
||||
|
||||
String getStartIpAddress(long networkId);
|
||||
|
||||
boolean applyStaticNats(List<? extends StaticNat> staticNats, boolean continueOnError) throws ResourceUnavailableException;
|
||||
|
||||
|
||||
String getIpInNetwork(long vmId, long networkId);
|
||||
|
||||
String getIpInNetworkIncludingRemoved(long vmId, long networkId);
|
||||
|
||||
|
||||
Long getPodIdForVlan(long vlanDbId);
|
||||
|
||||
|
||||
List<Long> listNetworkOfferingsForUpgrade(long networkId);
|
||||
|
||||
PhysicalNetwork translateZoneIdToPhysicalNetwork(long zoneId);
|
||||
|
||||
boolean isSecurityGroupSupportedInNetwork(Network network);
|
||||
|
||||
|
||||
boolean isProviderSupportServiceInNetwork(long networkId, Service service, Provider provider);
|
||||
|
||||
|
||||
boolean isProviderEnabledInPhysicalNetwork(long physicalNetowrkId, String providerName);
|
||||
|
||||
List<String> getNetworkTags(HypervisorType hType, Network network);
|
||||
String getNetworkTag(HypervisorType hType, Network network);
|
||||
|
||||
List<Service> getElementServices(Provider provider);
|
||||
|
||||
boolean canElementEnableIndividualServices(Provider provider);
|
||||
|
||||
|
||||
PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId);
|
||||
|
||||
|
||||
boolean areServicesSupportedInNetwork(long networkId, Service... services);
|
||||
|
||||
boolean isNetworkSystem(Network network);
|
||||
|
||||
boolean reallocate(VirtualMachineProfile<? extends VMInstanceVO> vm,
|
||||
DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException;
|
||||
boolean reallocate(VirtualMachineProfile<? extends VMInstanceVO> vm,
|
||||
DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException;
|
||||
|
||||
Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service);
|
||||
|
||||
Long getPhysicalNetworkId(Network network);
|
||||
|
||||
boolean getAllowSubdomainAccessGlobal();
|
||||
|
||||
boolean isProviderForNetwork(Provider provider, long networkId);
|
||||
boolean getAllowSubdomainAccessGlobal();
|
||||
|
||||
boolean isProviderForNetwork(Provider provider, long networkId);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -25,6 +25,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
|||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
|
@ -32,33 +33,33 @@ import com.cloud.utils.db.SearchCriteria.Op;
|
|||
@Local(value=PhysicalNetworkTrafficTypeDao.class) @DB(txn=false)
|
||||
public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNetworkTrafficTypeVO, Long> implements PhysicalNetworkTrafficTypeDao {
|
||||
final SearchBuilder<PhysicalNetworkTrafficTypeVO> physicalNetworkSearch;
|
||||
final SearchBuilder<PhysicalNetworkTrafficTypeVO> kvmAllFieldsSearch;
|
||||
final SearchBuilder<PhysicalNetworkTrafficTypeVO> xenAllFieldsSearch;
|
||||
final SearchBuilder<PhysicalNetworkTrafficTypeVO> vmWareAllFieldsSearch;
|
||||
|
||||
final GenericSearchBuilder<PhysicalNetworkTrafficTypeVO, String> kvmAllFieldsSearch;
|
||||
final GenericSearchBuilder<PhysicalNetworkTrafficTypeVO, String> xenAllFieldsSearch;
|
||||
final GenericSearchBuilder<PhysicalNetworkTrafficTypeVO, String> vmWareAllFieldsSearch;
|
||||
|
||||
protected PhysicalNetworkTrafficTypeDaoImpl() {
|
||||
super();
|
||||
physicalNetworkSearch = createSearchBuilder();
|
||||
physicalNetworkSearch.and("physicalNetworkId", physicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
physicalNetworkSearch.and("trafficType", physicalNetworkSearch.entity().getTrafficType(), Op.EQ);
|
||||
physicalNetworkSearch.done();
|
||||
|
||||
kvmAllFieldsSearch = createSearchBuilder();
|
||||
|
||||
kvmAllFieldsSearch = createSearchBuilder(String.class);
|
||||
kvmAllFieldsSearch.and("physicalNetworkId", kvmAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
kvmAllFieldsSearch.and("trafficType", kvmAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
kvmAllFieldsSearch.and("kvm_network_label", kvmAllFieldsSearch.entity().getKvmNetworkLabel(), Op.NNULL);
|
||||
kvmAllFieldsSearch.selectField(kvmAllFieldsSearch.entity().getKvmNetworkLabel());
|
||||
kvmAllFieldsSearch.done();
|
||||
|
||||
xenAllFieldsSearch = createSearchBuilder();
|
||||
|
||||
xenAllFieldsSearch = createSearchBuilder(String.class);
|
||||
xenAllFieldsSearch.and("physicalNetworkId", xenAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
xenAllFieldsSearch.and("trafficType", xenAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
xenAllFieldsSearch.and("xen_network_label", xenAllFieldsSearch.entity().getKvmNetworkLabel(), Op.NNULL);
|
||||
xenAllFieldsSearch.selectField(xenAllFieldsSearch.entity().getXenNetworkLabel());
|
||||
xenAllFieldsSearch.done();
|
||||
|
||||
vmWareAllFieldsSearch = createSearchBuilder();
|
||||
|
||||
vmWareAllFieldsSearch = createSearchBuilder(String.class);
|
||||
vmWareAllFieldsSearch.and("physicalNetworkId", vmWareAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
|
||||
vmWareAllFieldsSearch.and("trafficType", vmWareAllFieldsSearch.entity().getTrafficType(), Op.EQ);
|
||||
vmWareAllFieldsSearch.and("vmware_network_label", vmWareAllFieldsSearch.entity().getKvmNetworkLabel(), Op.NNULL);
|
||||
vmWareAllFieldsSearch.selectField(vmWareAllFieldsSearch.entity().getKvmNetworkLabel());
|
||||
vmWareAllFieldsSearch.done();
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
|
|||
sc.setParameters("physicalNetworkId", physicalNetworkId);
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isTrafficTypeSupported(long physicalNetworkId, TrafficType trafficType){
|
||||
SearchCriteria<PhysicalNetworkTrafficTypeVO> sc = physicalNetworkSearch.create();
|
||||
|
|
@ -80,10 +81,10 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getNetworkTag(long physicalNetworkId, TrafficType trafficType, HypervisorType hType) {
|
||||
SearchCriteria<PhysicalNetworkTrafficTypeVO> sc = null;
|
||||
SearchCriteria<String> sc = null;
|
||||
if (hType == HypervisorType.XenServer) {
|
||||
sc = xenAllFieldsSearch.create();
|
||||
} else if (hType == HypervisorType.KVM) {
|
||||
|
|
@ -91,25 +92,17 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
|
|||
} else if (hType == HypervisorType.VMware) {
|
||||
sc = vmWareAllFieldsSearch.create();
|
||||
} else {
|
||||
assert(false) : "We don't handle this hypervisor type";
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
sc.setParameters("physicalNetworkId", physicalNetworkId);
|
||||
sc.setParameters("trafficType", trafficType);
|
||||
PhysicalNetworkTrafficTypeVO record = findOneBy(sc);
|
||||
|
||||
if (record != null) {
|
||||
if (hType == HypervisorType.XenServer) {
|
||||
return record.getXenNetworkLabel();
|
||||
} else if (hType == HypervisorType.KVM) {
|
||||
return record.getKvmNetworkLabel();
|
||||
} else if (hType == HypervisorType.VMware) {
|
||||
return record.getVmwareNetworkLabel();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
List<String> tag = customSearch(sc, null);
|
||||
|
||||
return tag.size() == 0 ? null : tag.get(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PhysicalNetworkTrafficTypeVO findBy(long physicalNetworkId, TrafficType trafficType){
|
||||
SearchCriteria<PhysicalNetworkTrafficTypeVO> sc = physicalNetworkSearch.create();
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -86,7 +86,6 @@ import com.cloud.dc.DataCenter;
|
|||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.dao.AccountVlanMapDao;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
|
|
@ -393,7 +392,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (userVm == null) {
|
||||
throw new InvalidParameterValueException("unable to find a virtual machine with id " + cmd.getId());
|
||||
}
|
||||
|
||||
|
||||
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm.getTemplateId());
|
||||
if (template == null || !template.getEnablePassword()) {
|
||||
throw new InvalidParameterValueException("Fail to reset password for the virtual machine, the template is not password enabled");
|
||||
|
|
@ -445,7 +444,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
|
||||
NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTags(template.getHypervisorType(), defaultNetwork));
|
||||
NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTag(template.getHypervisorType(), defaultNetwork));
|
||||
VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmInstance);
|
||||
vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password);
|
||||
|
||||
|
|
@ -676,10 +675,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (moveVolumeNeeded) {
|
||||
// Move the volume to a storage pool in the VM's zone, pod, or cluster
|
||||
try {
|
||||
volume = _storageMgr.moveVolume(volume, vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), dataDiskHyperType);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
throw new CloudRuntimeException(e.toString());
|
||||
}
|
||||
volume = _storageMgr.moveVolume(volume, vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), dataDiskHyperType);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
throw new CloudRuntimeException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor.getCurrentExecutor();
|
||||
|
|
@ -1037,7 +1036,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
|
||||
}
|
||||
|
||||
|
||||
//check permissions
|
||||
_accountMgr.checkAccess(caller, null, vm);
|
||||
|
||||
|
|
@ -1129,10 +1128,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (_instance == null) {
|
||||
_instance = "DEFAULT";
|
||||
}
|
||||
|
||||
|
||||
String value = _configDao.getValue(Config.CreatePrivateTemplateFromVolumeWait.toString());
|
||||
_createprivatetemplatefromvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreatePrivateTemplateFromVolumeWait.getDefaultValue()));
|
||||
|
||||
|
||||
value = _configDao.getValue(Config.CreatePrivateTemplateFromSnapshotWait.toString());
|
||||
_createprivatetemplatefromsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreatePrivateTemplateFromSnapshotWait.getDefaultValue()));
|
||||
|
||||
|
|
@ -1234,7 +1233,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
|
||||
//Remove vm from instance group
|
||||
removeInstanceFromInstanceGroup(vmId);
|
||||
|
||||
|
||||
//cleanup firewall rules
|
||||
if (_firewallMgr.revokeFirewallRulesForVm(vmId)) {
|
||||
s_logger.debug("Firewall rules are removed successfully as a part of vm id=" + vmId + " expunge");
|
||||
|
|
@ -1305,7 +1304,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if ((name == null) || (name.length() > 32)) {
|
||||
throw new InvalidParameterValueException("Template name cannot be null and should be less than 32 characters");
|
||||
}
|
||||
|
||||
|
||||
if(cmd.getTemplateTag() != null){
|
||||
if(!_accountService.isRootAdmin(caller.getType())){
|
||||
throw new PermissionDeniedException("Parameter templatetag can only be specified by a Root Admin, permission denied");
|
||||
|
|
@ -1349,7 +1348,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
//check permissions
|
||||
_accountMgr.checkAccess(caller, null, volume);
|
||||
|
||||
|
||||
// If private template is created from Volume, check that the volume will not be active when the private template is
|
||||
// created
|
||||
if (!_storageMgr.volumeInactive(volume)) {
|
||||
|
|
@ -1366,21 +1365,21 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
|
||||
volume = _volsDao.findById(snapshot.getVolumeId());
|
||||
VolumeVO snapshotVolume = _volsDao.findByIdIncludingRemoved(snapshot.getVolumeId());
|
||||
|
||||
|
||||
if (snapshot == null) {
|
||||
throw new InvalidParameterValueException("Failed to create private template record, unable to find snapshot " + snapshotId);
|
||||
}
|
||||
|
||||
|
||||
//check permissions
|
||||
_accountMgr.checkAccess(caller, null, snapshot);
|
||||
|
||||
if (snapshot.getStatus() != Snapshot.Status.BackedUp) {
|
||||
throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.Status.BackedUp + " state yet and can't be used for template creation");
|
||||
}
|
||||
|
||||
|
||||
// bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT
|
||||
if(snapshot.getHypervisorType() == HypervisorType.VMware && snapshotVolume.getVolumeType() == Type.DATADISK){
|
||||
throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from Data Disk");
|
||||
throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from Data Disk");
|
||||
}
|
||||
|
||||
domainId = snapshot.getDomainId();
|
||||
|
|
@ -1606,7 +1605,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
String checkSum = getChecksum(secondaryStorageHost.getId(), answer.getPath());
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
|
||||
txn.start();
|
||||
|
||||
privateTemplate.setChecksum(checkSum);
|
||||
|
|
@ -1855,7 +1854,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
String accountName = cmd.getAccountName();
|
||||
String groupName = cmd.getGroupName();
|
||||
Long projectId = cmd.getProjectId();
|
||||
|
||||
|
||||
Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
|
||||
long accountId = owner.getId();
|
||||
|
||||
|
|
@ -1904,7 +1903,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if ((group == null) || (group.getRemoved() != null)) {
|
||||
throw new InvalidParameterValueException("unable to find a vm group with id " + groupId);
|
||||
}
|
||||
|
||||
|
||||
_accountMgr.checkAccess(caller, null, group);
|
||||
|
||||
return deleteVmGroup(groupId);
|
||||
|
|
@ -2025,7 +2024,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
@Override
|
||||
public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner,
|
||||
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp, String keyboard)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
List<NetworkVO> networkList = new ArrayList<NetworkVO>();
|
||||
|
|
@ -2195,7 +2194,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
@Override
|
||||
public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp, String keyboard)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
List<NetworkVO> networkList = new ArrayList<NetworkVO>();
|
||||
|
|
@ -2219,7 +2218,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (defaultVirtualOffering.get(0).getAvailability() == Availability.Required) {
|
||||
// get Virtual netowrks
|
||||
List<NetworkVO> virtualNetworks = _networkMgr.listNetworksForAccount(owner.getId(), zone.getId(), Network.GuestType.Isolated, true);
|
||||
|
||||
|
||||
|
||||
if (virtualNetworks.isEmpty()) {
|
||||
s_logger.debug("Creating default Virtual network for account " + owner + " as a part of deployVM process");
|
||||
|
|
@ -2280,7 +2279,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
throw new PermissionDeniedException("Shared network id=" + networkId + " is not available in domain id=" + owner.getDomainId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//don't allow to use system networks
|
||||
NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
|
||||
if (networkOffering.isSystemOnly()) {
|
||||
|
|
@ -2445,12 +2444,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
networks.add(new Pair<NetworkVO, NicProfile>(network, profile));
|
||||
|
||||
|
||||
if (_networkMgr.isSecurityGroupSupportedInNetwork(network)) {
|
||||
securityGroupEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (securityGroupIdList != null && !securityGroupIdList.isEmpty() && !securityGroupEnabled) {
|
||||
throw new InvalidParameterValueException("Unable to deploy vm with security groups as SecurityGroup service is not enabled for the vm's network");
|
||||
}
|
||||
|
|
@ -2647,12 +2646,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
if (vm.getIsoId() != null) {
|
||||
String isoPath = null;
|
||||
|
||||
VirtualMachineTemplate template = _templateDao.findById(vm.getIsoId());
|
||||
if (template == null || template.getFormat() != ImageFormat.ISO) {
|
||||
throw new CloudRuntimeException("Can not find ISO in vm_template table for id " + vm.getIsoId());
|
||||
}
|
||||
String isoPath = null;
|
||||
|
||||
VirtualMachineTemplate template = _templateDao.findById(vm.getIsoId());
|
||||
if (template == null || template.getFormat() != ImageFormat.ISO) {
|
||||
throw new CloudRuntimeException("Can not find ISO in vm_template table for id " + vm.getIsoId());
|
||||
}
|
||||
|
||||
Pair<String, String> isoPathPair = _storageMgr.getAbsoluteIsoPath(template.getId(), vm.getDataCenterIdToDeployIn());
|
||||
|
||||
|
|
@ -2709,7 +2708,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
@Override
|
||||
public boolean finalizeStart(VirtualMachineProfile<UserVmVO> profile, long hostId, Commands cmds, ReservationContext context) {
|
||||
UserVmVO vm = profile.getVirtualMachine();
|
||||
|
||||
|
||||
Answer[] answersToCmds = cmds.getAnswers();
|
||||
if(answersToCmds == null){
|
||||
if(s_logger.isDebugEnabled()){
|
||||
|
|
@ -2886,7 +2885,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
s_logger.trace("Vm id=" + vmId + " is already destroyed");
|
||||
return vm;
|
||||
}
|
||||
|
||||
|
||||
_accountMgr.checkAccess(caller, null, vm);
|
||||
User userCaller = _userDao.findById(userId);
|
||||
|
||||
|
|
@ -2976,7 +2975,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
domainId = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//set project information
|
||||
if (projectId != null) {
|
||||
permittedAccounts.clear();
|
||||
|
|
@ -3229,10 +3228,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
public UserVm getUserVm(long vmId) {
|
||||
return _vmDao.findById(vmId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool) {
|
||||
// access check - only root admin can migrate VM
|
||||
// access check - only root admin can migrate VM
|
||||
Account caller = UserContext.current().getCaller();
|
||||
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -3240,27 +3239,27 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
throw new PermissionDeniedException("No permission to migrate VM, Only Root Admin can migrate a VM!");
|
||||
}
|
||||
|
||||
|
||||
VMInstanceVO vm = _vmInstanceDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Unable to find the VM by id=" + vmId);
|
||||
}
|
||||
|
||||
|
||||
if (vm.getState() != State.Stopped) {
|
||||
throw new InvalidParameterValueException("VM is not Stopped, unable to migrate the vm " + vm);
|
||||
throw new InvalidParameterValueException("VM is not Stopped, unable to migrate the vm " + vm);
|
||||
}
|
||||
|
||||
|
||||
if (vm.getType() != VirtualMachine.Type.User) {
|
||||
throw new InvalidParameterValueException("can only do storage migration on user vm");
|
||||
throw new InvalidParameterValueException("can only do storage migration on user vm");
|
||||
}
|
||||
|
||||
|
||||
HypervisorType destHypervisorType = _clusterDao.findById(destPool.getClusterId()).getHypervisorType();
|
||||
if (vm.getHypervisorType() != destHypervisorType) {
|
||||
throw new InvalidParameterValueException("hypervisor is not compatible: dest: " + destHypervisorType.toString() + ", vm: " + vm.getHypervisorType().toString());
|
||||
throw new InvalidParameterValueException("hypervisor is not compatible: dest: " + destHypervisorType.toString() + ", vm: " + vm.getHypervisorType().toString());
|
||||
}
|
||||
VMInstanceVO migratedVm = _itMgr.storageMigration(vm, destPool);
|
||||
return migratedVm;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -3274,7 +3273,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
throw new PermissionDeniedException("No permission to migrate VM, Only Root Admin can migrate a VM!");
|
||||
}
|
||||
|
||||
|
||||
VMInstanceVO vm = _vmInstanceDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Unable to find the VM by id=" + vmId);
|
||||
|
|
@ -3307,7 +3306,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
long srcHostId = vm.getHostId();
|
||||
Cluster cluster = _clusterDao.findById(destinationHost.getClusterId());
|
||||
DeployDestination dest = new DeployDestination(dcVO, pod, cluster, destinationHost);
|
||||
|
||||
|
||||
//check max guest vm limit for the destinationHost
|
||||
HypervisorType hypervisorType = destinationHost.getHypervisorType();
|
||||
String hypervisorVersion = destinationHost.getHypervisorVersion();
|
||||
|
|
@ -3336,7 +3335,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
if (newAccount == null || newAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Invalid accountid=" + cmd.getAccountId() + " in domain " + oldAccount.getDomainId());
|
||||
}
|
||||
|
||||
|
||||
//don't allow to move the vm from the project
|
||||
if (oldAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Vm id=" + cmd.getVmId() + " belongs to the project and can't be moved");
|
||||
|
|
@ -3369,12 +3368,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
_accountMgr.checkAccess(newAccount, domain);
|
||||
|
||||
DataCenterVO zone = _dcDao.findById(vm.getDataCenterIdToDeployIn());
|
||||
|
||||
|
||||
//check is zone networking is advanced
|
||||
if (zone.getNetworkType() != NetworkType.Advanced) {
|
||||
throw new InvalidParameterValueException("Assing virtual machine to another account is only available for advanced networking " + vm);
|
||||
}
|
||||
|
||||
|
||||
VMInstanceVO vmoi = _itMgr.findByIdAndType(vm.getType(), vm.getId());
|
||||
VirtualMachineProfileImpl<VMInstanceVO> vmOldProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmoi);
|
||||
|
||||
|
|
@ -3385,7 +3384,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString()));
|
||||
// update resource counts
|
||||
_resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
|
||||
|
||||
|
||||
// OWNERSHIP STEP 1: update the vm owner
|
||||
vm.setAccountId(newAccount.getAccountId());
|
||||
_vmDao.persist(vm);
|
||||
|
|
@ -3397,13 +3396,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
_volsDao.persist(volume);
|
||||
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, new Long(volumes.size()));
|
||||
}
|
||||
|
||||
|
||||
_resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
|
||||
//generate usage evenst to account for this change
|
||||
_usageEventDao.persist(new UsageEventVO(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterIdToDeployIn(), vm.getId(),
|
||||
vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString()));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// OS 3: update the network
|
||||
if (zone.getNetworkType() == NetworkType.Advanced) {
|
||||
|
|
@ -3461,80 +3460,80 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
|
||||
txn.commit();
|
||||
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public UserVm restoreVM(RestoreVMCmd cmd) {
|
||||
// Input validation
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Long userId = UserContext.current().getCallerUserId();
|
||||
UserVO user = _userDao.findById(userId);
|
||||
boolean needRestart = false;
|
||||
|
||||
|
||||
// if account is removed, return error
|
||||
if (caller != null && caller.getRemoved() != null) {
|
||||
throw new PermissionDeniedException("The account " + caller.getId() + " is removed");
|
||||
}
|
||||
|
||||
long vmId = cmd.getVmId();
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Cann not find VM with ID " + vmId);
|
||||
}
|
||||
|
||||
if (vm.getState() != VirtualMachine.State.Running && vm.getState() != VirtualMachine.State.Stopped) {
|
||||
throw new CloudRuntimeException("Vm " + vmId + " currently in " + vm.getState() + " state, restore vm can only execute when VM in Running or Stopped");
|
||||
}
|
||||
|
||||
if (vm.getState() == VirtualMachine.State.Running) {
|
||||
needRestart = true;
|
||||
}
|
||||
|
||||
List<VolumeVO> rootVols = _volsDao.findByInstance(vmId);
|
||||
if (rootVols.isEmpty()) {
|
||||
throw new InvalidParameterValueException("Can not find root volume for VM " + vmId);
|
||||
}
|
||||
|
||||
VolumeVO root = rootVols.get(0);
|
||||
long templateId = root.getTemplateId();
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("Cannot find template for volume " + root.getId() + " vm " + vmId);
|
||||
}
|
||||
|
||||
if (needRestart) {
|
||||
try {
|
||||
_itMgr.stop(vm, user, caller);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.debug("Stop vm " + vmId + " failed", e);
|
||||
throw new CloudRuntimeException("Stop vm " + vmId + " failed");
|
||||
}
|
||||
}
|
||||
|
||||
/* allocate a new volume from original template*/
|
||||
VolumeVO newVol = _storageMgr.allocateDuplicateVolume(root, null);
|
||||
_volsDao.attachVolume(newVol.getId(), vmId, newVol.getDeviceId());
|
||||
|
||||
/* Detach and destory the old root volume */
|
||||
try {
|
||||
_volsDao.detachVolume(root.getId());
|
||||
_storageMgr.destroyVolume(root);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.debug("Unable to delete old root volume " + root.getId() + ", user may manually delete it", e);
|
||||
long vmId = cmd.getVmId();
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Cann not find VM with ID " + vmId);
|
||||
}
|
||||
|
||||
if (needRestart) {
|
||||
try {
|
||||
_itMgr.start(vm, null, user, caller);
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Unable to start VM " + vmId, e);
|
||||
throw new CloudRuntimeException("Unable to start VM " + vmId + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Restore VM " + vmId + " with template " + root.getTemplateId() + " successfully");
|
||||
return vm;
|
||||
|
||||
if (vm.getState() != VirtualMachine.State.Running && vm.getState() != VirtualMachine.State.Stopped) {
|
||||
throw new CloudRuntimeException("Vm " + vmId + " currently in " + vm.getState() + " state, restore vm can only execute when VM in Running or Stopped");
|
||||
}
|
||||
|
||||
if (vm.getState() == VirtualMachine.State.Running) {
|
||||
needRestart = true;
|
||||
}
|
||||
|
||||
List<VolumeVO> rootVols = _volsDao.findByInstance(vmId);
|
||||
if (rootVols.isEmpty()) {
|
||||
throw new InvalidParameterValueException("Can not find root volume for VM " + vmId);
|
||||
}
|
||||
|
||||
VolumeVO root = rootVols.get(0);
|
||||
long templateId = root.getTemplateId();
|
||||
VMTemplateVO template = _templateDao.findById(templateId);
|
||||
if (template == null) {
|
||||
throw new InvalidParameterValueException("Cannot find template for volume " + root.getId() + " vm " + vmId);
|
||||
}
|
||||
|
||||
if (needRestart) {
|
||||
try {
|
||||
_itMgr.stop(vm, user, caller);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.debug("Stop vm " + vmId + " failed", e);
|
||||
throw new CloudRuntimeException("Stop vm " + vmId + " failed");
|
||||
}
|
||||
}
|
||||
|
||||
/* allocate a new volume from original template*/
|
||||
VolumeVO newVol = _storageMgr.allocateDuplicateVolume(root, null);
|
||||
_volsDao.attachVolume(newVol.getId(), vmId, newVol.getDeviceId());
|
||||
|
||||
/* Detach and destory the old root volume */
|
||||
try {
|
||||
_volsDao.detachVolume(root.getId());
|
||||
_storageMgr.destroyVolume(root);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.debug("Unable to delete old root volume " + root.getId() + ", user may manually delete it", e);
|
||||
}
|
||||
|
||||
if (needRestart) {
|
||||
try {
|
||||
_itMgr.start(vm, null, user, caller);
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("Unable to start VM " + vmId, e);
|
||||
throw new CloudRuntimeException("Unable to start VM " + vmId + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("Restore VM " + vmId + " with template " + root.getTemplateId() + " successfully");
|
||||
return vm;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
@Inject(adapter = HostAllocator.class)
|
||||
protected Adapters<HostAllocator> _hostAllocators;
|
||||
|
||||
|
||||
@Inject
|
||||
protected ResourceManager _resourceMgr;
|
||||
|
||||
|
|
@ -434,7 +434,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
_lockStateRetry = NumbersUtil.parseInt(params.get(Config.VmOpLockStateRetry.key()), 5);
|
||||
_operationTimeout = NumbersUtil.parseInt(params.get(Config.Wait.key()), 1800) * 2;
|
||||
_forceStop = Boolean.parseBoolean(params.get(Config.VmDestroyForcestop.key()));
|
||||
|
||||
|
||||
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vm-Operations-Cleanup"));
|
||||
_nodeId = _clusterMgr.getManagementNodeId();
|
||||
|
||||
|
|
@ -459,7 +459,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> T start(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException,
|
||||
ResourceUnavailableException {
|
||||
ResourceUnavailableException {
|
||||
try {
|
||||
return advanceStart(vm, params, caller, account, planToDeploy);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
|
|
@ -585,7 +585,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> T advanceStart(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
return advanceStart(vm, params, caller, account, null);
|
||||
}
|
||||
|
||||
|
|
@ -1179,68 +1179,68 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> T storageMigration(T vm, StoragePool destPool) {
|
||||
VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
|
||||
VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
|
||||
|
||||
long vmId = vm.getId();
|
||||
vm = vmGuru.findById(vmId);
|
||||
long vmId = vm.getId();
|
||||
vm = vmGuru.findById(vmId);
|
||||
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Unable to migrate vm: " + e.toString());
|
||||
throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
|
||||
}
|
||||
|
||||
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
|
||||
boolean migrationResult = false;
|
||||
try {
|
||||
migrationResult = _storageMgr.StorageMigration(profile, destPool);
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Unable to migrate vm: " + e.toString());
|
||||
throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
|
||||
}
|
||||
|
||||
if (migrationResult) {
|
||||
//if the vm is migrated to different pod in basic mode, need to reallocate ip
|
||||
|
||||
if (vm.getPodIdToDeployIn() != destPool.getPodId()) {
|
||||
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
|
||||
boolean migrationResult = false;
|
||||
try {
|
||||
migrationResult = _storageMgr.StorageMigration(profile, destPool);
|
||||
|
||||
if (migrationResult) {
|
||||
//if the vm is migrated to different pod in basic mode, need to reallocate ip
|
||||
|
||||
if (vm.getPodIdToDeployIn() != destPool.getPodId()) {
|
||||
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), destPool.getPodId(), null, null, null, null);
|
||||
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, null, null, null, null);
|
||||
_networkMgr.reallocate(vmProfile, plan);
|
||||
}
|
||||
|
||||
//when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
|
||||
vm.setLastHostId(null);
|
||||
vm.setPodId(destPool.getPodId());
|
||||
} else {
|
||||
s_logger.debug("Storage migration failed");
|
||||
}
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} catch (InsufficientVirtualNetworkCapcityException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} catch (InsufficientAddressCapacityException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} catch (InsufficientCapacityException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} finally {
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to change vm state: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return vm;
|
||||
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, null, null, null, null);
|
||||
_networkMgr.reallocate(vmProfile, plan);
|
||||
}
|
||||
|
||||
//when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
|
||||
vm.setLastHostId(null);
|
||||
vm.setPodId(destPool.getPodId());
|
||||
} else {
|
||||
s_logger.debug("Storage migration failed");
|
||||
}
|
||||
} catch (ConcurrentOperationException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} catch (InsufficientVirtualNetworkCapcityException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} catch (InsufficientAddressCapacityException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} catch (InsufficientCapacityException e) {
|
||||
s_logger.debug("Failed to migration: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to migration: " + e.toString());
|
||||
} finally {
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to change vm state: " + e.toString());
|
||||
throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return vm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException,
|
||||
VirtualMachineMigrationException {
|
||||
VirtualMachineMigrationException {
|
||||
s_logger.info("Migrating " + vm + " to " + dest);
|
||||
|
||||
long dstHostId = dest.getHost().getId();
|
||||
|
|
@ -1547,7 +1547,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> T advanceReboot(T vm, Map<VirtualMachineProfile.Param, Object> params, User caller, Account account) throws InsufficientCapacityException,
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
ConcurrentOperationException, ResourceUnavailableException {
|
||||
T rebootedVm = null;
|
||||
|
||||
DataCenter dc = _configMgr.getZone(vm.getDataCenterIdToDeployIn());
|
||||
|
|
@ -1588,59 +1588,59 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
public Command cleanup(String vmName) {
|
||||
return new StopCommand(vmName);
|
||||
}
|
||||
|
||||
|
||||
public Commands fullHostSync(final long hostId, StartupRoutingCommand startup) {
|
||||
Commands commands = new Commands(OnError.Continue);
|
||||
|
||||
Map<Long, AgentVmInfo> infos = convertToInfos(startup);
|
||||
|
||||
final List<? extends VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
||||
s_logger.debug("Found " + vms.size() + " VMs for host " + hostId);
|
||||
for (VMInstanceVO vm : vms) {
|
||||
AgentVmInfo info = infos.remove(vm.getId());
|
||||
VMInstanceVO castedVm = null;
|
||||
if (info == null) {
|
||||
info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
|
||||
castedVm = info.guru.findById(vm.getId());
|
||||
} else {
|
||||
castedVm = info.vm;
|
||||
}
|
||||
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(castedVm.getHypervisorType());
|
||||
|
||||
Command command = compareState(hostId, castedVm, info, true, hvGuru.trackVmHostChange());
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
for (final AgentVmInfo left : infos.values()) {
|
||||
boolean found = false;
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
|
||||
VMInstanceVO vm = vmGuru.findByName(left.name);
|
||||
if (vm != null) {
|
||||
found = true;
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
|
||||
if(hvGuru.trackVmHostChange()) {
|
||||
Command command = compareState(hostId, vm, left, true, true);
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Stopping a VM, VM " + left.name + " migrate from Host " + vm.getHostId() + " to Host " + hostId );
|
||||
commands.addCommand(cleanup(left.name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! found ) {
|
||||
s_logger.warn("Stopping a VM that we have no record of: " + left.name);
|
||||
commands.addCommand(cleanup(left.name));
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
Commands commands = new Commands(OnError.Continue);
|
||||
|
||||
Map<Long, AgentVmInfo> infos = convertToInfos(startup);
|
||||
|
||||
final List<? extends VMInstanceVO> vms = _vmDao.listByHostId(hostId);
|
||||
s_logger.debug("Found " + vms.size() + " VMs for host " + hostId);
|
||||
for (VMInstanceVO vm : vms) {
|
||||
AgentVmInfo info = infos.remove(vm.getId());
|
||||
VMInstanceVO castedVm = null;
|
||||
if (info == null) {
|
||||
info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
|
||||
castedVm = info.guru.findById(vm.getId());
|
||||
} else {
|
||||
castedVm = info.vm;
|
||||
}
|
||||
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(castedVm.getHypervisorType());
|
||||
|
||||
Command command = compareState(hostId, castedVm, info, true, hvGuru.trackVmHostChange());
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
for (final AgentVmInfo left : infos.values()) {
|
||||
boolean found = false;
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
|
||||
VMInstanceVO vm = vmGuru.findByName(left.name);
|
||||
if (vm != null) {
|
||||
found = true;
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
|
||||
if(hvGuru.trackVmHostChange()) {
|
||||
Command command = compareState(hostId, vm, left, true, true);
|
||||
if (command != null) {
|
||||
commands.addCommand(command);
|
||||
}
|
||||
} else {
|
||||
s_logger.warn("Stopping a VM, VM " + left.name + " migrate from Host " + vm.getHostId() + " to Host " + hostId );
|
||||
commands.addCommand(cleanup(left.name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( ! found ) {
|
||||
s_logger.warn("Stopping a VM that we have no record of: " + left.name);
|
||||
commands.addCommand(cleanup(left.name));
|
||||
}
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
public Commands deltaHostSync(long hostId, Map<String, State> newStates) {
|
||||
Map<Long, AgentVmInfo> states = convertDeltaToInfos(newStates);
|
||||
|
|
@ -1670,8 +1670,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
return commands;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Commands deltaSync(Map<String, Pair<String, State>> newStates) {
|
||||
Map<Long, AgentVmInfo> states = convertToInfos(newStates);
|
||||
Commands commands = new Commands(OnError.Continue);
|
||||
|
|
@ -1684,7 +1684,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
String hostGuid = info.getHostUuid();
|
||||
Host host = _resourceMgr.findHostByGuid(hostGuid);
|
||||
long hId = host.getId();
|
||||
|
||||
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
|
||||
command = compareState(hId, vm, info, false, hvGuru.trackVmHostChange());
|
||||
} else {
|
||||
|
|
@ -1701,7 +1701,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Commands fullSync(final long clusterId, Map<String, Pair<String, State>> newStates) {
|
||||
|
|
@ -1769,7 +1769,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
protected Map<Long, AgentVmInfo> convertToInfos(StartupRoutingCommand cmd) {
|
||||
final Map<String, VmState> states = cmd.getVmStates();
|
||||
final HashMap<Long, AgentVmInfo> map = new HashMap<Long, AgentVmInfo>();
|
||||
|
|
@ -1777,7 +1777,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
return map;
|
||||
}
|
||||
Collection<VirtualMachineGuru<? extends VMInstanceVO>> vmGurus = _vmGurus.values();
|
||||
|
||||
|
||||
for (Map.Entry<String, VmState> entry : states.entrySet()) {
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : vmGurus) {
|
||||
String name = entry.getKey();
|
||||
|
|
@ -1793,10 +1793,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
protected Map<Long, AgentVmInfo> convertDeltaToInfos(final Map<String, State> states) {
|
||||
final HashMap<Long, AgentVmInfo> map = new HashMap<Long, AgentVmInfo>();
|
||||
|
||||
|
|
@ -1847,7 +1847,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM " + serverName + ": cs state = " + serverState + " and realState = " + agentState);
|
||||
}
|
||||
|
||||
|
||||
if (agentState == State.Error) {
|
||||
agentState = State.Stopped;
|
||||
|
||||
|
|
@ -2024,13 +2024,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
s_logger.debug("VM's " + vm + " state is starting on full sync so updating it to Running");
|
||||
vm = vmGuru.findById(vm.getId()); // this should ensure vm has the most
|
||||
// up to date info
|
||||
// up to date info
|
||||
|
||||
VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
|
||||
List<NicVO> nics = _nicsDao.listByVmId(profile.getId());
|
||||
for (NicVO nic : nics) {
|
||||
Network network = _networkMgr.getNetwork(nic.getNetworkId());
|
||||
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTags(profile.getHypervisorType(), network));
|
||||
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(profile.getHypervisorType(), network));
|
||||
profile.addNic(nicProfile);
|
||||
}
|
||||
|
||||
|
|
@ -2101,24 +2101,24 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] cmds) {
|
||||
boolean processed = false;
|
||||
for (Command cmd : cmds) {
|
||||
if (cmd instanceof PingRoutingCommand) {
|
||||
PingRoutingCommand ping = (PingRoutingCommand) cmd;
|
||||
if (ping.getNewStates() != null && ping.getNewStates().size() > 0) {
|
||||
Commands commands = deltaHostSync(agentId, ping.getNewStates());
|
||||
if (commands.size() > 0) {
|
||||
try {
|
||||
_agentMgr.send(agentId, commands, this);
|
||||
} catch (final AgentUnavailableException e) {
|
||||
s_logger.warn("Agent is now unavailable", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
return processed;
|
||||
boolean processed = false;
|
||||
for (Command cmd : cmds) {
|
||||
if (cmd instanceof PingRoutingCommand) {
|
||||
PingRoutingCommand ping = (PingRoutingCommand) cmd;
|
||||
if (ping.getNewStates() != null && ping.getNewStates().size() > 0) {
|
||||
Commands commands = deltaHostSync(agentId, ping.getNewStates());
|
||||
if (commands.size() > 0) {
|
||||
try {
|
||||
_agentMgr.send(agentId, commands, this);
|
||||
} catch (final AgentUnavailableException e) {
|
||||
s_logger.warn("Agent is now unavailable", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2146,7 +2146,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Long clusterId = agent.getClusterId();
|
||||
long agentId = agent.getId();
|
||||
if (agent.getHypervisorType() == HypervisorType.XenServer) { // only fro Xen
|
||||
|
|
|
|||
Loading…
Reference in New Issue