Moved VirtualMachineManager into engine

This commit is contained in:
Alex Huang 2013-08-14 16:12:21 -07:00
parent 9064acbb07
commit 4ba359c3fe
26 changed files with 250 additions and 202 deletions

View File

@ -27,6 +27,10 @@ import com.cloud.agent.api.LogLevel.Log4jLevel;
*/
public abstract class Command {
public static enum OnError {
Continue, Stop
}
public static final String HYPERVISOR_TYPE = "hypervisorType";
// allow command to carry over hypervisor or other environment related context info

View File

@ -16,7 +16,7 @@
// under the License.
package com.cloud.vm;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.Answer;
import com.cloud.agent.manager.Commands;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ResourceUnavailableException;
@ -49,7 +49,7 @@ public interface VirtualMachineGuru {
boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile);
void finalizeStop(VirtualMachineProfile profile, StopAnswer answer);
void finalizeStop(VirtualMachineProfile profile, Answer answer);
void finalizeExpunge(VirtualMachine vm);

View File

@ -17,7 +17,7 @@
package com.cloud.vm;
import java.net.URI;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Map;
import com.cloud.agent.api.to.NicTO;
@ -33,13 +33,11 @@ import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network;
import com.cloud.network.dao.NetworkVO;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.StoragePool;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
import com.cloud.utils.fsm.NoTransitionException;
@ -49,22 +47,39 @@ import com.cloud.utils.fsm.NoTransitionException;
*/
public interface VirtualMachineManager extends Manager {
/**
* Allocates a new virtual machine instance in the CloudStack DB. This
* orchestrates the creation of all virtual resources needed in CloudStack
* DB to bring up a VM.
*
* @param vmInstanceName Instance name of the VM. This name uniquely
* a VM in CloudStack's deploy environment. The caller gets to
* define this VM but it must be unqiue for all of CloudStack.
* @param template The template this VM is based on.
* @param serviceOffering The service offering that specifies the offering this VM should provide.
* @param defaultNetwork The default network for the VM.
* @param rootDiskOffering For created VMs not based on templates, root disk offering specifies the root disk.
* @param dataDiskOfferings Data disks to attach to the VM.
* @param auxiliaryNetworks additional networks to attach the VMs to.
* @param plan How to deploy the VM.
* @param hyperType Hypervisor type
* @throws InsufficientCapacityException If there are insufficient capacity to deploy this vm.
*/
void allocate(String vmInstanceName,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings,
List<Pair<NetworkVO, NicProfile>> networks,
Map<VirtualMachineProfile.Param, Object> params,
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException;
VirtualMachineTemplate template,
ServiceOffering serviceOffering,
Pair<? extends DiskOffering, Long> rootDiskOffering,
LinkedHashMap<? extends DiskOffering, Long> dataDiskOfferings,
LinkedHashMap<? extends Network, ? extends NicProfile> auxiliaryNetworks,
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException;
void allocate(String vmInstanceName,
VMTemplateVO template,
ServiceOfferingVO serviceOffering,
List<Pair<NetworkVO, NicProfile>> networkProfiles,
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException;
VirtualMachineTemplate template,
ServiceOffering serviceOffering,
LinkedHashMap<? extends Network, ? extends NicProfile> networkProfiles,
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException;
void start(String vmUuid, Map<VirtualMachineProfile.Param, Object> params);
@ -76,7 +91,7 @@ public interface VirtualMachineManager extends Manager {
void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru);
boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException;
boolean stateTransitTo(VirtualMachine vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException;
void advanceStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException,
ConcurrentOperationException, OperationTimedoutException;
@ -146,7 +161,7 @@ public interface VirtualMachineManager extends Manager {
* @throws ResourceUnavailableException
* @throws ConcurrentOperationException
*/
boolean removeNicFromVm(VirtualMachine vm, NicVO nic) throws ConcurrentOperationException, ResourceUnavailableException;
boolean removeNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* @param vm
@ -173,7 +188,7 @@ public interface VirtualMachineManager extends Manager {
VirtualMachineTO toVmTO(VirtualMachineProfile profile);
VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException;
VirtualMachine reConfigureVm(String vmUuid, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException;
void findHostAndMigrate(String vmUuid, Long newSvcOfferingId, DeploymentPlanner.ExcludeList excludeHostList) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException;

View File

@ -20,6 +20,7 @@ package org.apache.cloudstack.engine.orchestration;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -41,8 +42,10 @@ import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.offering.DiskOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
@ -165,11 +168,11 @@ public class CloudOrchestrator implements OrchestrationService {
// VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
List<Pair<NetworkVO, NicProfile>> networkIpMap = new ArrayList<Pair<NetworkVO, NicProfile>>();
LinkedHashMap<NetworkVO, NicProfile> networkIpMap = new LinkedHashMap<NetworkVO, NicProfile>();
for (String uuid : networkNicMap.keySet()) {
NetworkVO network = _networkDao.findByUuid(uuid);
if(network != null){
networkIpMap.add(new Pair<NetworkVO, NicProfile>(network, networkNicMap.get(uuid)));
networkIpMap.put(network, networkNicMap.get(uuid));
}
}
@ -186,7 +189,7 @@ public class CloudOrchestrator implements OrchestrationService {
// Else, a disk offering is optional, and if present will be used to create the data disk
Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null, null);
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>();
LinkedHashMap<DiskOfferingVO, Long> dataDiskOfferings = new LinkedHashMap<DiskOfferingVO, Long>();
ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
rootDiskOffering.first(offering);
@ -206,12 +209,19 @@ public class CloudOrchestrator implements OrchestrationService {
}
_volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
}
dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
dataDiskOfferings.put(diskOffering, size);
}
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null, plan, hypervisorType);
_itMgr.allocate(vm.getInstanceName(),
_templateDao.findById(new Long(templateId)),
offering,
rootDiskOffering,
dataDiskOfferings,
networkIpMap,
plan,
hypervisorType);
return vmEntity;
}
@ -228,11 +238,11 @@ public class CloudOrchestrator implements OrchestrationService {
VMInstanceVO vm = _vmDao.findByUuid(id);
Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null, null);
Pair<DiskOffering, Long> rootDiskOffering = new Pair<DiskOffering, Long>(null, null);
ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
rootDiskOffering.first(offering);
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>();
LinkedHashMap<DiskOffering, Long> dataDiskOfferings = new LinkedHashMap<DiskOffering, Long>();
Long diskOfferingId = vm.getDiskOfferingId();
if (diskOfferingId == null) {
throw new InvalidParameterValueException(
@ -254,17 +264,17 @@ public class CloudOrchestrator implements OrchestrationService {
rootDiskOffering.first(diskOffering);
rootDiskOffering.second(size);
List<Pair<NetworkVO, NicProfile>> networkIpMap = new ArrayList<Pair<NetworkVO, NicProfile>>();
LinkedHashMap<Network, NicProfile> networkIpMap = new LinkedHashMap<Network, NicProfile>();
for (String uuid : networkNicMap.keySet()) {
NetworkVO network = _networkDao.findByUuid(uuid);
if(network != null){
networkIpMap.add(new Pair<NetworkVO, NicProfile>(network, networkNicMap.get(uuid)));
networkIpMap.put(network, networkNicMap.get(uuid));
}
}
HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null, plan, hypervisorType);
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, plan, hypervisorType);
return vmEntity;
}

View File

@ -33,5 +33,10 @@
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -20,15 +20,15 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.Command.OnError;
import com.cloud.utils.exception.CloudRuntimeException;
public class Commands implements Iterable<Command> {
OnError _handler;
private ArrayList<String> _ids = new ArrayList<String>();
private ArrayList<Command> _cmds = new ArrayList<Command>();
private final ArrayList<String> _ids = new ArrayList<String>();
private final ArrayList<Command> _cmds = new ArrayList<Command>();
private Answer[] _answers;
public Commands(OnError handler) {
@ -126,7 +126,7 @@ public class Commands implements Iterable<Command> {
}
/**
* @return For Commands with handler OnError.Continue, one command succeeding is successful. If not, all commands must succeed to be successful.
* @return For Commands with handler OnError.Continue, one command succeeding is successful. If not, all commands must succeed to be successful.
*/
public boolean isSuccessful() {
if (_answers == null) {

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
@ -41,9 +42,8 @@ import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
@ -115,7 +115,6 @@ import com.cloud.user.AccountService;
import com.cloud.user.User;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
@ -327,7 +326,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
protected boolean applyLBRules(DomainRouterVO elbVm,
List<LoadBalancingRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createApplyLoadBalancingRulesCommands(rules, elbVm, cmds, guestNetworkId);
// Send commands to elbVm
return sendCommandsToRouter(elbVm, cmds);
@ -491,11 +490,11 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
NetworkOffering controlOffering = offerings.get(0);
NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(2);
LinkedHashMap<NetworkVO, NicProfile> networks = new LinkedHashMap<NetworkVO, NicProfile>(2);
NicProfile guestNic = new NicProfile();
guestNic.setDefaultNic(true);
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
networks.put(controlConfig, null);
networks.put((NetworkVO)guestNetwork, guestNic);
VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
@ -939,7 +938,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
if (answer != null) {
DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId());
processStopOrRebootAnswer(elbVm, answer);

View File

@ -18,6 +18,7 @@ package org.apache.cloudstack.network.lb;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -33,11 +34,10 @@ import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetDomRVersionAnswer;
import com.cloud.agent.api.GetDomRVersionCmd;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
@ -330,7 +330,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
}
@Override
@ -612,7 +612,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
return internalLbVms;
}
List<Pair<NetworkVO, NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
LinkedHashMap<Network, NicProfile> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(),
networks, false);
@ -648,11 +648,11 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
return internalLbProvider.getId();
}
protected List<Pair<NetworkVO, NicProfile>> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException,
protected LinkedHashMap<Network, NicProfile> createInternalLbVmNetworks(Network guestNetwork, DeploymentPlan plan, Ip guestIp) throws ConcurrentOperationException,
InsufficientAddressCapacityException {
//Form networks
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(3);
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(3);
//1) Guest network - default
if (guestNetwork != null) {
@ -671,7 +671,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
String gatewayCidr = guestNetwork.getCidr();
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
guestNic.setDefaultNic(true);
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
networks.put(guestNetwork, guestNic);
}
//2) Control network
@ -679,7 +679,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
List<? extends NetworkOffering> offerings = _ntwkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
NetworkOffering controlOffering = offerings.get(0);
NetworkVO controlConfig = _ntwkMgr.setupNetwork(_accountMgr.getSystemAccount(), controlOffering, plan, null, null, false).get(0);
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
networks.put(controlConfig, null);
return networks;
}
@ -713,7 +713,8 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
protected DomainRouterVO deployInternalLbVm(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
long internalLbProviderId, long svcOffId, Long vpcId,
List<Pair<NetworkVO, NicProfile>> networks, boolean startVm) throws ConcurrentOperationException,
LinkedHashMap<Network, NicProfile> networks,
boolean startVm) throws ConcurrentOperationException,
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
StorageUnavailableException, ResourceUnavailableException {
@ -876,7 +877,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
}
protected boolean sendLBRules(VirtualRouter internalLbVm, List<LoadBalancingRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createApplyLoadBalancingRulesCommands(rules, internalLbVm, cmds, guestNetworkId);
return sendCommandsToInternalLbVm(internalLbVm, cmds);
}

View File

@ -34,10 +34,6 @@ import com.cloud.utils.component.Manager;
* AgentManager manages hosts. It directly coordinates between the DAOs and the connections it manages.
*/
public interface AgentManager extends Manager {
public enum OnError {
Continue, Stop
}
public enum TapAgentsAction {
Add,
Del,

View File

@ -366,7 +366,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override
public Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException {
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand(cmd);
send(hostId, cmds, cmd.getWait());
Answer[] answers = cmds.getAnswers();

View File

@ -878,7 +878,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
private Answer[] sendRebalanceCommand(long peer, long agentId, long currentOwnerId, long futureOwnerId, Event event) {
TransferAgentCommand transfer = new TransferAgentCommand(agentId, currentOwnerId, futureOwnerId, event);
Commands commands = new Commands(OnError.Stop);
Commands commands = new Commands(Command.OnError.Stop);
commands.addCommand(transfer);
Command[] cmds = commands.toCommands();
@ -1233,7 +1233,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
public Answer[] sendToAgent(Long hostId, Command[] cmds, boolean stopOnError) throws AgentUnavailableException, OperationTimedoutException {
Commands commands = new Commands(stopOnError ? OnError.Stop : OnError.Continue);
Commands commands = new Commands(stopOnError ? Command.OnError.Stop : Command.OnError.Continue);
for (Command cmd : cmds) {
commands.addCommand(cmd);
}

View File

@ -17,10 +17,10 @@
package com.cloud.consoleproxy;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -46,7 +46,6 @@ import com.cloud.agent.api.ConsoleProxyLoadReportCommand;
import com.cloud.agent.api.RebootCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupProxyCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
@ -722,15 +721,15 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
}
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
LinkedHashMap<NetworkVO, NicProfile> networks = new LinkedHashMap<NetworkVO, NicProfile>(offerings.size() + 1);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(2);
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), defaultNic));
networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), defaultNic);
for (NetworkOffering offering : offerings) {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null));
networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null);
}
ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(),
@ -1503,7 +1502,7 @@ VirtualMachineGuru, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
//release elastic IP here if assigned
IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
if (ip != null && ip.getSystem()) {

View File

@ -16,6 +16,7 @@
// under the License.
package com.cloud.network;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -102,7 +103,7 @@ public interface NetworkManager {
List<NetworkVO> setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId,
ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException;
void allocate(VirtualMachineProfile vm, List<Pair<NetworkVO, NicProfile>> networks) throws InsufficientCapacityException, ConcurrentOperationException;
void allocate(VirtualMachineProfile vm, LinkedHashMap<? extends Network, ? extends NicProfile> networks) throws InsufficientCapacityException, ConcurrentOperationException;
void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException;

View File

@ -24,6 +24,7 @@ import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
@ -37,9 +38,9 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.vm.NicIpAlias;
import com.cloud.vm.dao.NicIpAliasDao;
import com.cloud.vm.dao.NicIpAliasVO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.context.CallContext;
@ -49,9 +50,6 @@ import org.apache.cloudstack.region.PortableIpDao;
import org.apache.cloudstack.region.PortableIpVO;
import org.apache.cloudstack.region.Region;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
@ -199,6 +197,7 @@ import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic;
import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicIpAlias;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
@ -209,6 +208,8 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.NicIpAliasDao;
import com.cloud.vm.dao.NicIpAliasVO;
import com.cloud.vm.dao.NicSecondaryIpDao;
import com.cloud.vm.dao.NicSecondaryIpVO;
import com.cloud.vm.dao.UserVmDao;
@ -723,7 +724,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
private IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId)
private IpAddress allocateIP(Account ipOwner, boolean isSystem, long zoneId)
throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
Account caller = CallContext.current().getCallingAccount();
long callerUserId = CallContext.current().getCallingUserId();
@ -1535,7 +1536,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
@Override
public List<NetworkVO> setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name,
public List<NetworkVO> setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name,
String displayText, boolean isDefault)
throws ConcurrentOperationException {
return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null, null, true);
@ -1543,7 +1544,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@Override
@DB
public List<NetworkVO> setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan
public List<NetworkVO> setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan
plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId,
ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException {
@ -1635,7 +1636,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@Override
@DB
public void allocate(VirtualMachineProfile vm, List<Pair<NetworkVO, NicProfile>> networks)
public void allocate(VirtualMachineProfile vm, LinkedHashMap<? extends Network, ? extends NicProfile> networks)
throws InsufficientCapacityException, ConcurrentOperationException {
Transaction txn = Transaction.currentTxn();
txn.start();
@ -1648,9 +1649,9 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
List<NicProfile> nics = new ArrayList<NicProfile>(networks.size());
NicProfile defaultNic = null;
for (Pair<NetworkVO, NicProfile> network : networks) {
NetworkVO config = network.first();
NicProfile requested = network.second();
for (Map.Entry<? extends Network, ? extends NicProfile> network : networks.entrySet()) {
Network config = network.getKey();
NicProfile requested = network.getValue();
Boolean isDefaultNic = false;
if (vm != null && (requested != null && requested.isDefaultNic())) {
@ -1742,7 +1743,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
vo = _nicDao.persist(vo);
Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate,
NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate,
_networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(),
network));
@ -2138,7 +2139,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
updateNic(nic, network.getId(), 1);
} else {
profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
guru.updateNicProfile(profile, network);
nic.setState(Nic.State.Reserved);
@ -2168,7 +2169,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
_networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
if(guru instanceof NetworkMigrationResponder){
if(!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)){
@ -2493,7 +2494,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
// if zone is basic, only Shared network offerings w/o source nat service are allowed
if (!(ntwkOff.getGuestType() == GuestType.Shared &&
if (!(ntwkOff.getGuestType() == GuestType.Shared &&
!_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) {
throw new InvalidParameterValueException("For zone of type " + NetworkType.Basic + " only offerings of " +
"guestType " + GuestType.Shared + " with disabled " + Service.SourceNat.getName()
@ -2651,7 +2652,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
// limitation, remove after we introduce support for multiple ip ranges
// with different Cidrs for the same Shared network
boolean cidrRequired = zone.getNetworkType() == NetworkType.Advanced && ntwkOff.getTrafficType() == TrafficType.Guest
&& (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated
&& (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated
&& !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)));
if (cidr == null && ip6Cidr == null && cidrRequired) {
throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of" +
@ -2824,7 +2825,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
s_logger.debug("Lock is released for network " + network + " as a part of network shutdown");
}
}
}
}
}
@Override
@ -2904,7 +2905,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
s_logger.debug("The network id=" + networkId + " has active Nics, but shouldn't.");
// at this point we have already determined that there are no active user vms in network
// if the op_networks table shows active nics, it's a bug in releasing nics updating op_networks
_networksDao.changeActiveNicsBy(networkId, (-1 * nicCount));
_networksDao.changeActiveNicsBy(networkId, (-1 * nicCount));
}
//In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network
@ -3813,16 +3814,15 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
if (dc.getNetworkType() == NetworkType.Basic) {
List<NicVO> nics = _nicDao.listByVmId(vmInstance.getId());
NetworkVO network = _networksDao.findById(nics.get(0).getNetworkId());
Pair<NetworkVO, NicProfile> profile = new Pair<NetworkVO, NicProfile>(network, null);
List<Pair<NetworkVO, NicProfile>> profiles = new ArrayList<Pair<NetworkVO, NicProfile>>();
profiles.add(profile);
LinkedHashMap<Network, NicProfile> profiles = new LinkedHashMap<Network, NicProfile>();
profiles.put(network, null);
Transaction txn = Transaction.currentTxn();
txn.start();
try {
this.cleanupNics(vm);
this.allocate(vm, profiles);
cleanupNics(vm);
allocate(vm, profiles);
} finally {
txn.commit();
}
@ -4252,7 +4252,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
@Override
public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp)
public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp)
throws InsufficientAddressCapacityException {
Network guestNetwork = _networksDao.findById(networkId);
NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
@ -4374,7 +4374,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@Override
public boolean setupDns(Network network, Provider provider) {
boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, provider );
boolean dhcpProvided =_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp,
boolean dhcpProvided =_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp,
provider);
boolean setupDns = dnsProvided || dhcpProvided;
@ -4409,7 +4409,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
VirtualMachine vm = vmProfile.getVirtualMachine();
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
NicProfile nic = getNicProfileForVm(network, requested, vm);
@ -4418,14 +4418,14 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
if (nic == null || (vmProfile.getType() == VirtualMachine.Type.User)) {
int deviceId = _nicDao.countNics(vm.getId());
nic = allocateNic(requested, network, false,
nic = allocateNic(requested, network, false,
deviceId, vmProfile).first();
if (nic == null) {
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
}
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
}
//2) prepare nic
@ -4450,7 +4450,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
guru.updateNicProfile(profile, network);
profiles.add(profile);
@ -4512,7 +4512,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
//support more than one LB providers only
s_logger.error("Found " + providers.size() + " " + service.getName() + " providers for network!" + network.getId());
return null;
}
}
for (Provider provider : providers) {
NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName());
@ -4554,8 +4554,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
}
assert lbElement != null;
assert lbElement instanceof LoadBalancingServiceProvider;
return (LoadBalancingServiceProvider)lbElement;
assert lbElement instanceof LoadBalancingServiceProvider;
return (LoadBalancingServiceProvider)lbElement;
}
@ -4612,7 +4612,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@Override
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
NicVO nic = new NicVO(null, null, network.getId(), null);
NicVO nic = new NicVO(null, null, network.getId(), null);
nic.setIp4Address(ip4Address);
nic.setIp6Address(ip6Address);
nic.setReservationStrategy(ReservationStrategy.PlaceHolder);

View File

@ -26,8 +26,9 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.Command.OnError;
import com.cloud.agent.api.routing.SavePasswordCommand;
import com.cloud.agent.api.routing.VmDataCommand;
import com.cloud.agent.manager.Commands;
@ -213,7 +214,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem
String userData = uservm.getUserData();
String sshPublicKey = uservm.getDetail("SSH.PublicKey");
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
if (password != null && nic.isDefaultNic()) {
final String encodedPassword = PasswordGenerator.rot13(password);
SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd());

View File

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -50,7 +51,6 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
@ -68,7 +68,6 @@ import com.cloud.agent.api.NetworkUsageAnswer;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.routing.CreateIpAliasCommand;
@ -492,7 +491,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
// for basic zone, send vm data/password information only to the router in the same pod
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
NicVO nicVo = _nicDao.findById(nic.getId());
createPasswordCommand(router, updatedProfile, nicVo, cmds);
return sendCommandsToRouter(router, cmds);
@ -511,7 +510,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
// for basic zone, send vm data/password information only to the router in the same pod
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
NicVO nicVo = _nicDao.findById(nic.getId());
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(updatedProfile.getTemplateId());
if(template != null && template.getEnablePassword()) {
@ -532,7 +531,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
// for basic zone, send vm data/password information only to the router in the same pod
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
NicVO nicVo = _nicDao.findById(nic.getId());
createVmDataCommand(router, vm, nicVo, null, cmds);
return sendCommandsToRouter(router, cmds);
@ -1538,7 +1537,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
int count = routerCount - routers.size();
DeploymentPlan plan = planAndRouters.first();
for (int i = 0; i < count; i++) {
List<Pair<NetworkVO, NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
LinkedHashMap<Network, NicProfile> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
//don't start the router as we are holding the network lock that needs to be released at the end of router allocation
DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId,
@ -1581,11 +1580,22 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId,
Long vpcId, List<Pair<NetworkVO, NicProfile>> networks, boolean startRouter, List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException,
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
StorageUnavailableException, ResourceUnavailableException {
protected DomainRouterVO deployRouter(Account owner,
DeployDestination dest,
DeploymentPlan plan,
Map<Param, Object> params,
boolean isRedundant,
VirtualRouterProvider vrProvider,
long svcOffId,
Long vpcId,
LinkedHashMap<Network, NicProfile> networks,
boolean startRouter,
List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException,
InsufficientAddressCapacityException,
InsufficientServerCapacityException,
InsufficientCapacityException,
StorageUnavailableException,
ResourceUnavailableException {
ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
@ -1726,7 +1736,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
return hypervisors;
}
protected List<Pair<NetworkVO, NicProfile>> createRouterNetworks(Account owner, boolean isRedundant,
protected LinkedHashMap<Network, NicProfile> createRouterNetworks(Account owner,
boolean isRedundant,
DeploymentPlan plan, Network guestNetwork, Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException,
InsufficientAddressCapacityException {
@ -1737,7 +1748,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
//Form networks
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(3);
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(3);
//1) Guest network
boolean hasGuestNetwork = false;
@ -1794,7 +1805,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
gatewayNic.setDefaultNic(true);
}
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, gatewayNic));
networks.put(guestNetwork, gatewayNic);
hasGuestNetwork = true;
}
@ -1803,7 +1814,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
NetworkOffering controlOffering = offerings.get(0);
NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
networks.put(controlConfig, null);
//3) Public network
@ -1832,7 +1843,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress());
defaultNic.setMacAddress(peerNic.getMacAddress());
}
networks.add(new Pair<NetworkVO, NicProfile>(publicNetworks.get(0), defaultNic));
networks.put(publicNetworks.get(0), defaultNic);
}
return networks;
@ -2621,7 +2632,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
if (answer != null) {
VirtualMachine vm = profile.getVirtualMachine();
DomainRouterVO domR = _routerDao.findById(vm.getId());
@ -2659,7 +2670,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
+ router.getState(), DataCenter.class, network.getDataCenterId());
}
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
createApplyVpnCommands(vpn, router, cmds);
try {
@ -2703,7 +2714,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
boolean result = true;
for (VirtualRouter router : routers) {
if (router.getState() == State.Running) {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
IpAddress ip = _networkModel.getIp(vpn.getServerAddressId());
RemoteAccessVpnCfgCommand removeVpnCmd = new RemoteAccessVpnCfgCommand(false, ip.getAddress().addr(),
@ -2826,7 +2837,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
_nicIpAliasDao.persist(alias);
List<IpAliasTO> ipaliasTo = new ArrayList<IpAliasTO>();
ipaliasTo.add(new IpAliasTO(routerAliasIp, alias.getNetmask(), alias.getAliasCount().toString()));
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
createIpAlias(router, ipaliasTo, alias.getNetworkId(), cmds);
//also add the required configuration to the dnsmasq for supporting dhcp and dns on the new ip.
configDnsMasq(router, network, cmds);
@ -2861,7 +2872,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
router.getState(), DataCenter.class, network.getDataCenterId());
}
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
List<NicIpAliasVO> revokedIpAliasVOs = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.state.revoked);
s_logger.debug("Found" + revokedIpAliasVOs.size() + "ip Aliases to revoke on the router as a part of dhcp configuration");
List<IpAliasTO> revokedIpAliasTOs = new ArrayList<IpAliasTO>();
@ -2916,7 +2927,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
//for basic zone, send dhcp/dns information to all routers in the basic network only when _dnsBasicZoneUpdates is set to "all" value
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
if (!(isZoneBasic && router.getPodIdToDeployIn().longValue() != podId.longValue() && _dnsBasicZoneUpdates.equalsIgnoreCase("pod"))) {
NicVO nicVo = _nicDao.findById(nic.getId());
createDhcpEntryCommand(router, vm, nicVo, cmds);
@ -2991,7 +3002,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
//for basic zone, send vm data/password information only to the router in the same pod
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
if (!(isZoneBasic && router.getPodIdToDeployIn().longValue() != podId.longValue())) {
NicVO nicVo = _nicDao.findById(nic.getId());
createPasswordCommand(router, updatedProfile, nicVo, cmds);
@ -3021,7 +3032,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
router.getState(), DataCenter.class, network.getDataCenterId());
}
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
List<VpnUser> addUsers = new ArrayList<VpnUser>();
List<VpnUser> removeUsers = new ArrayList<VpnUser>();
for (VpnUser user : users) {
@ -3581,7 +3592,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
return applyRules(network, routers, "ip association", false, null, false, new RuleApplier() {
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createAssociateIPCommands(router, ipAddress, cmds, 0);
return sendCommandsToRouter(router, cmds);
}
@ -3651,19 +3662,19 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
}
protected boolean sendLBRules(VirtualRouter router, List<LoadBalancingRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createApplyLoadBalancingRulesCommands(rules, router, cmds, guestNetworkId);
return sendCommandsToRouter(router, cmds);
}
protected boolean sendPortForwardingRules(VirtualRouter router, List<PortForwardingRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createApplyPortForwardingRulesCommands(rules, router, cmds, guestNetworkId);
return sendCommandsToRouter(router, cmds);
}
protected boolean sendStaticNatRules(VirtualRouter router, List<StaticNatRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createApplyStaticNatRulesCommands(rules, router, cmds, guestNetworkId);
return sendCommandsToRouter(router, cmds);
}
@ -3724,7 +3735,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
protected boolean sendFirewallRules(VirtualRouter router, List<FirewallRule> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createFirewallRulesCommands(rules, router, cmds, guestNetworkId);
return sendCommandsToRouter(router, cmds);
}
@ -3840,7 +3851,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
protected boolean applyStaticNat(VirtualRouter router, List<? extends StaticNat> rules, long guestNetworkId) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createApplyStaticNatCommands(rules, router, cmds, guestNetworkId);
return sendCommandsToRouter(router, cmds);
}

View File

@ -20,6 +20,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
@ -30,13 +31,12 @@ import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.NetworkUsageCommand;
import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.SetupGuestNetworkAnswer;
import com.cloud.agent.api.SetupGuestNetworkCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.routing.IpAssocVpcCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.routing.SetNetworkACLCommand;
@ -318,7 +318,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
StorageUnavailableException, ResourceUnavailableException {
List<Pair<NetworkVO, NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),
LinkedHashMap<Network, NicProfile> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),
vpcId);
DomainRouterVO router =
super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true,
@ -334,7 +334,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (router.getState() == State.Running) {
SetupGuestNetworkCommand setupCmd = createSetupGuestNetworkCommand(router, add, guestNic);
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand("setupguestnetwork", setupCmd);
sendCommandsToRouter(router, cmds);
@ -508,7 +508,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
}
Commands netUsagecmds = new Commands(OnError.Continue);
Commands netUsagecmds = new Commands(Command.OnError.Continue);
VpcVO vpc = _vpcDao.findById(router.getVpcId());
//2) Plug the nics
@ -561,7 +561,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
boolean result = applyRules(network, routers, "vpc ip association", false, null, false, new RuleApplier() {
@Override
public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
Map<String, String> vlanMacAddress = new HashMap<String, String>();
List<PublicIpAddress> ipsToSend = new ArrayList<PublicIpAddress>();
for (PublicIpAddress ipAddr : ipAddress) {
@ -655,7 +655,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
protected boolean sendNetworkACLs(VirtualRouter router, List<? extends NetworkACLItem> rules, long guestNetworkId, boolean isPrivateGateway)
throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createNetworkACLsCommands(rules, router, cmds, guestNetworkId, isPrivateGateway);
return sendCommandsToRouter(router, cmds);
}
@ -938,7 +938,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
privateIps.add(ip);
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add);
if (sendCommandsToRouter(router, cmds)) {
@ -1034,7 +1034,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
protected boolean sendStaticRoutes(List<StaticRouteProfile> staticRoutes, DomainRouterVO router)
throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createStaticRouteCommands(staticRoutes, router, cmds);
return sendCommandsToRouter(router, cmds);
}
@ -1076,7 +1076,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
protected boolean applySite2SiteVpn(boolean isCreate, VirtualRouter router, Site2SiteVpnConnection conn) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
Commands cmds = new Commands(Command.OnError.Continue);
createSite2SiteVpnCfgCommands(conn, isCreate, router, cmds);
return sendCommandsToRouter(router, cmds);
}
@ -1152,11 +1152,12 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
protected List<Pair<NetworkVO, NicProfile>> createVpcRouterNetworks(Account owner, boolean isRedundant,
protected LinkedHashMap<Network, NicProfile>
createVpcRouterNetworks(Account owner, boolean isRedundant,
DeploymentPlan plan, Pair<Boolean, PublicIp> sourceNatIp, long vpcId) throws ConcurrentOperationException,
InsufficientAddressCapacityException {
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(4);
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(4);
TreeSet<String> publicVlans = new TreeSet<String>();
publicVlans.add(sourceNatIp.second().getVlanTag());
@ -1170,7 +1171,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
for (PrivateGateway privateGateway : privateGateways) {
NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic));
networks.put(privateNetwork, privateNic);
}
}
@ -1179,7 +1180,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
for (Network guestNetwork : guestNetworks) {
if (guestNetwork.getState() == Network.State.Implemented) {
NicProfile guestNic = createGuestNicProfileForVpcRouter(guestNetwork);
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
networks.put(guestNetwork, guestNic);
}
}
@ -1201,7 +1202,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
publicNic.setIsolationUri(IsolationType.Vlan.toUri(publicIp.getVlanTag()));
NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
List<NetworkVO> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false);
networks.add(new Pair<NetworkVO, NicProfile>(publicNetworks.get(0), publicNic));
networks.put(publicNetworks.get(0), publicNic);
publicVlans.add(publicIp.getVlanTag());
}
}
@ -1321,7 +1322,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
super.finalizeStop(profile, answer);
//Mark VPN connections as Disconnected
DomainRouterVO router = _routerDao.findById(profile.getId());

View File

@ -48,8 +48,8 @@ import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command.OnError;
import com.cloud.agent.api.GetFileStatsCommand;
import com.cloud.agent.api.GetStorageStatsCommand;
import com.cloud.agent.api.HostStatsEntry;

View File

@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -52,7 +53,6 @@ import com.cloud.agent.api.SecStorageSetupCommand.Certificates;
import com.cloud.agent.api.SecStorageVMSetupCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupSecondaryStorageCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.to.NfsTO;
@ -554,14 +554,14 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
}
List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork, NetworkOfferingVO.SystemStorageNetwork);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
LinkedHashMap<NetworkVO, NicProfile> networks = new LinkedHashMap<NetworkVO, NicProfile>(offerings.size() + 1);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(2);
try {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), defaultNic));
networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), defaultNic);
for (NetworkOffering offering : offerings) {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null));
networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), null);
}
} catch (ConcurrentOperationException e) {
s_logger.info("Unable to setup due to concurrent operation. " + e);
@ -1178,7 +1178,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
//release elastic IP here
IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
if (ip != null && ip.getSystem()) {

View File

@ -81,7 +81,6 @@ import com.cloud.agent.api.GetVmStatsAnswer;
import com.cloud.agent.api.GetVmStatsCommand;
import com.cloud.agent.api.PvlanSetupCommand;
import com.cloud.agent.api.StartAnswer;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.VmDiskStatsEntry;
import com.cloud.agent.api.VmStatsEntry;
import com.cloud.agent.api.to.DiskTO;
@ -1302,7 +1301,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
// #3 scale the vm now
_itMgr.upgradeVmDb(vmId, newServiceOfferingId);
vmInstance = _vmInstanceDao.findById(vmId);
vmInstance = _itMgr.reConfigureVm(vmInstance, currentServiceOffering, existingHostHasCapacity);
_itMgr.reConfigureVm(vmInstance.getUuid(), currentServiceOffering, existingHostHasCapacity);
success = true;
return success;
}catch(InsufficientCapacityException e ){
@ -3210,7 +3209,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
@Override
public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
VirtualMachine vm = profile.getVirtualMachine();
// release elastic IP here
IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId());
@ -4549,11 +4548,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
}
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>();
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>();
NicProfile profile = new NicProfile();
profile.setDefaultNic(true);
networks.add(new Pair<NetworkVO, NicProfile>(networkList.get(0),
profile));
networks.put(networkList.get(0), profile);
VirtualMachine vmi = _itMgr.findById(vm.getId());
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmi);
@ -4677,7 +4675,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
// add the new nics
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>();
LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>();
int toggle = 0;
for (NetworkVO appNet : applicableNetworks) {
NicProfile defaultNic = new NicProfile();
@ -4685,8 +4683,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
defaultNic.setDefaultNic(true);
toggle++;
}
networks.add(new Pair<NetworkVO, NicProfile>(appNet,
defaultNic));
networks.put(appNet, defaultNic);
}
VirtualMachine vmi = _itMgr.findById(vm.getId());
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmi);

View File

@ -18,11 +18,11 @@
package com.cloud.vm;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -35,7 +35,6 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.exception.StorageUnavailableException;
import org.apache.log4j.Logger;
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
@ -49,7 +48,6 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
@ -113,6 +111,7 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.ha.HighAvailabilityManager;
import com.cloud.ha.HighAvailabilityManager.WorkType;
import com.cloud.host.Host;
@ -125,13 +124,11 @@ import com.cloud.hypervisor.HypervisorGuruManager;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.element.DhcpServiceProvider;
import com.cloud.network.rules.RulesManager;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Cluster;
import com.cloud.resource.ResourceManager;
@ -153,6 +150,7 @@ import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.ResourceLimitService;
@ -177,7 +175,6 @@ import com.cloud.vm.VirtualMachine.Event;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.NicIpAliasDao;
import com.cloud.vm.dao.NicIpAliasVO;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
import com.cloud.vm.dao.VMInstanceDao;
@ -325,9 +322,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
@Override
@DB
public void allocate(String vmInstanceName, VMTemplateVO template, ServiceOfferingVO serviceOffering, Pair<? extends DiskOfferingVO, Long> rootDiskOffering,
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings, List<Pair<NetworkVO, NicProfile>> networks, Map<VirtualMachineProfile.Param, Object> params, DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException {
public void allocate(String vmInstanceName,
VirtualMachineTemplate template,
ServiceOffering serviceOffering,
Pair<? extends DiskOffering, Long> rootDiskOffering,
LinkedHashMap<? extends DiskOffering, Long> dataDiskOfferings,
LinkedHashMap<? extends Network, ? extends NicProfile> auxiliaryNetworks,
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException {
VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName);
Account owner = _entityMgr.findById(Account.class, vm.getAccountId());
@ -343,7 +345,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
assert (plan.getClusterId() == null && plan.getPoolId() == null) : "We currently don't support cluster and pool preset yet";
vm = _vmDao.persist(vm);
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, serviceOffering, null, params);
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, serviceOffering, null, null);
Transaction txn = Transaction.currentTxn();
txn.start();
@ -353,13 +355,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
try {
_networkMgr.allocate(vmProfile, networks);
_networkMgr.allocate(vmProfile, auxiliaryNetworks);
} catch (ConcurrentOperationException e) {
throw new CloudRuntimeException("Concurrent operation while trying to allocate resources for the VM", e);
}
if (dataDiskOfferings == null) {
dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>(0);
dataDiskOfferings = new LinkedHashMap<DiskOffering, Long>(0);
}
if (s_logger.isDebugEnabled()) {
@ -374,8 +376,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
volumeMgr.allocateTemplatedVolume(Type.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), template, vm, owner);
}
for (Pair<DiskOfferingVO, Long> offering : dataDiskOfferings) {
volumeMgr.allocateRawVolume(Type.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), vm, template, owner);
for (Map.Entry<? extends DiskOffering, Long> offering : dataDiskOfferings.entrySet()) {
volumeMgr.allocateRawVolume(Type.DATADISK, "DATA-" + vm.getId(), offering.getKey(), offering.getValue(), vm, template, owner);
}
txn.commit();
@ -385,9 +387,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
@Override
public void allocate(String vmInstanceName, VMTemplateVO template, ServiceOfferingVO serviceOffering, List<Pair<NetworkVO, NicProfile>> networks, DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException {
allocate(vmInstanceName, template, serviceOffering, new Pair<DiskOfferingVO, Long>(serviceOffering, null), null, networks, null, plan, hyperType);
public void allocate(String vmInstanceName,
VirtualMachineTemplate template,
ServiceOffering serviceOffering,
LinkedHashMap<? extends Network, ? extends NicProfile> networks,
DeploymentPlan plan,
HypervisorType hyperType) throws InsufficientCapacityException {
allocate(vmInstanceName, template, serviceOffering, new Pair<DiskOffering, Long>(serviceOffering, null), null, networks, plan, hyperType);
}
private VirtualMachineGuru getVmGuru(VirtualMachine vm) {
@ -457,7 +463,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (finalizeExpungeCommands != null && finalizeExpungeCommands.size() > 0) {
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
if (hostId != null) {
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
for (Command command : finalizeExpungeCommands) {
cmds.addCommand(command);
}
@ -867,7 +873,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
cmds = new Commands(OnError.Stop);
cmds = new Commands(Command.OnError.Stop);
cmds.addCommand(new StartCommand(vmTO, dest.getHost(), _mgmtServer.getExecuteInSequence()));
vmGuru.finalizeDeployment(cmds, vmProfile, dest, ctx);
@ -1005,7 +1011,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
return false;
}
guru.finalizeStop(profile, (StopAnswer)answer);
guru.finalizeStop(profile, answer);
} catch (AgentUnavailableException e) {
if (!force) {
return false;
@ -1282,7 +1288,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
@Override
public boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException {
public boolean stateTransitTo(VirtualMachine vm1, VirtualMachine.Event e, Long hostId) throws NoTransitionException {
VMInstanceVO vm = (VMInstanceVO)vm1;
// if there are active vm snapshots task, state change is not allowed
if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
s_logger.error("State transit with event: " + e + " failed due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
@ -1906,7 +1913,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
try {
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand(new RebootCommand(vm.getInstanceName()));
_agentMgr.send(host.getId(), cmds);
@ -1930,7 +1937,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
public Commands fullHostSync(final long hostId, StartupRoutingCommand startup) {
Commands commands = new Commands(OnError.Continue);
Commands commands = new Commands(Command.OnError.Continue);
Map<Long, AgentVmInfo> infos = convertToInfos(startup);
@ -1990,7 +1997,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
public Commands deltaHostSync(long hostId, Map<String, State> newStates) {
Map<Long, AgentVmInfo> states = convertDeltaToInfos(newStates);
Commands commands = new Commands(OnError.Continue);
Commands commands = new Commands(Command.OnError.Continue);
for (Map.Entry<Long, AgentVmInfo> entry : states.entrySet()) {
AgentVmInfo info = entry.getValue();
@ -2462,7 +2469,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
profile.addNic(nicProfile);
}
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
s_logger.debug("Finalizing commands that need to be send to complete Start process for the vm " + vm);
if (vmGuru.finalizeCommandsOnStart(cmds, profile)) {
@ -2824,7 +2831,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
@Override
public boolean removeNicFromVm(VirtualMachine vm, NicVO nic) throws ConcurrentOperationException, ResourceUnavailableException {
public boolean removeNicFromVm(VirtualMachine vm, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
NetworkVO network = _networkDao.findById(nic.getNetworkId());
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
@ -3196,7 +3203,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
try {
PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName(), vm.getType());
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand("plugnic", plugNicCmd);
_agentMgr.send(dest.getHost().getId(), cmds);
PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
@ -3226,7 +3233,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (router.getState() == State.Running) {
try {
Commands cmds = new Commands(OnError.Stop);
Commands cmds = new Commands(Command.OnError.Stop);
UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName());
cmds.addCommand("unplugnic", unplugNicCmd);
_agentMgr.send(dest.getHost().getId(), cmds);
@ -3254,8 +3261,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
}
@Override
public VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering oldServiceOffering, boolean reconfiguringOnExistingHost) throws ResourceUnavailableException,
public VMInstanceVO reConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, boolean reconfiguringOnExistingHost) throws ResourceUnavailableException,
ConcurrentOperationException {
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
long newServiceofferingId = vm.getServiceOfferingId();
ServiceOffering newServiceOffering = _configMgr.getServiceOffering(newServiceofferingId);

View File

@ -25,7 +25,6 @@ import com.cloud.agent.api.to.DiskTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.user.Account;
@ -52,7 +51,7 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile {
VirtualMachine.Type _type;
public VirtualMachineProfileImpl(VirtualMachine vm, VMTemplateVO template, ServiceOfferingVO offering, Account owner, Map<Param, Object> params) {
public VirtualMachineProfileImpl(VirtualMachine vm, VirtualMachineTemplate template, ServiceOffering offering, Account owner, Map<Param, Object> params) {
_vm = vm;
_template = template;
_offering = offering;

View File

@ -449,7 +449,7 @@ public class UserVmManagerTest {
//when(ApiDBUtils.getCpuOverprovisioningFactor()).thenReturn(3f);
when(_capacityMgr.checkIfHostHasCapacity(anyLong(), anyInt(), anyLong(), anyBoolean(), anyFloat(), anyFloat(), anyBoolean())).thenReturn(false);
when(_itMgr.reConfigureVm(_vmInstance, so1, false)).thenReturn(_vmInstance);
when(_itMgr.reConfigureVm(_vmInstance.getUuid(), so1, false)).thenReturn(_vmInstance);
doReturn(true).when(_itMgr).upgradeVmDb(anyLong(), anyLong());

View File

@ -279,7 +279,7 @@ public class VirtualMachineManagerImplTest {
newServiceOffering.getLimitCpuUse());
Answer answer = new ScaleVmAnswer(reconfigureCmd, true, "details");
when(_agentMgr.send(2l, reconfigureCmd)).thenReturn(null);
_vmMgr.reConfigureVm(_vmInstance, getSvcoffering(256), false);
_vmMgr.reConfigureVm(_vmInstance.getUuid(), getSvcoffering(256), false);
}

View File

@ -17,6 +17,7 @@
package com.cloud.vpc;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -738,7 +739,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
* @see com.cloud.network.NetworkManager#allocate(com.cloud.vm.VirtualMachineProfile, java.util.List)
*/
@Override
public void allocate(VirtualMachineProfile vm, List<Pair<NetworkVO, NicProfile>> networks)
public void allocate(VirtualMachineProfile vm, LinkedHashMap<? extends Network, ? extends NicProfile> networks)
throws InsufficientCapacityException, ConcurrentOperationException {
// TODO Auto-generated method stub