Merged conflicts resolved

This commit is contained in:
Alex Huang 2013-08-27 14:34:29 -07:00
parent 5b439f0748
commit 47afae8112
7 changed files with 91 additions and 141 deletions

View File

@ -37,7 +37,6 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.lf5.viewer.configure.ConfigurationManager;
import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
@ -48,10 +47,21 @@ import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigValue; import org.apache.cloudstack.framework.config.ConfigValue;
import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.region.PortableIpDao;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckNetworkAnswer;
import com.cloud.agent.api.CheckNetworkCommand;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.NicTO;
import com.cloud.alert.AlertManager;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.Resource.ResourceType;
import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenter.NetworkType;
@ -127,13 +137,18 @@ import com.cloud.network.element.StaticNatServiceProvider;
import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.element.UserDataServiceProvider;
import com.cloud.network.guru.NetworkGuru; import com.cloud.network.guru.NetworkGuru;
import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.rules.FirewallManager;
import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.Purpose; import com.cloud.network.rules.FirewallRule.Purpose;
import com.cloud.network.rules.FirewallRuleVO; import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.LoadBalancerContainer.Scheme; import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.network.rules.PortForwardingRuleVO; import com.cloud.network.rules.PortForwardingRuleVO;
import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.StaticNatRule; import com.cloud.network.rules.StaticNatRule;
import com.cloud.network.rules.StaticNatRuleImpl;
import com.cloud.network.rules.dao.PortForwardingRulesDao; import com.cloud.network.rules.dao.PortForwardingRulesDao;
import com.cloud.network.vpc.NetworkACLManager;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.dao.PrivateIpDao; import com.cloud.network.vpc.dao.PrivateIpDao;
import com.cloud.network.vpn.RemoteAccessVpnService; import com.cloud.network.vpn.RemoteAccessVpnService;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
@ -190,7 +205,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
static final Logger s_logger = Logger.getLogger(NetworkOrchestrator.class); static final Logger s_logger = Logger.getLogger(NetworkOrchestrator.class);
@Inject @Inject
EntityManager _entityMgr = null; EntityManager _entityMgr;
@Inject @Inject
DataCenterDao _dcDao = null; DataCenterDao _dcDao = null;
@Inject @Inject
@ -279,7 +294,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
this._dhcpProviders = _dhcpProviders; this._dhcpProviders = _dhcpProviders;
} }
@Inject @Inject
VMInstanceDao _vmDao; VMInstanceDao _vmDao;
@Inject @Inject
@ -605,7 +619,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
} }
if (errorIfAlreadySetup) { if (errorIfAlreadySetup) {
InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)"); InvalidParameterValueException ex = new InvalidParameterValueException(
"Found existing network configuration (with specified id) for offering (with specified id)");
ex.addProxyObject(offering.getUuid(), "offeringId"); ex.addProxyObject(offering.getUuid(), "offeringId");
ex.addProxyObject(configs.get(0).getUuid(), "networkConfigId"); ex.addProxyObject(configs.get(0).getUuid(), "networkConfigId");
throw ex; throw ex;
@ -642,22 +657,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
NetworkVO vo = new NetworkVO(id, NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText,
network, predefined.getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId);
offering.getId(),
guru.getName(),
owner.getDomainId(),
owner.getId(),
related,
name,
displayText,
predefined.getNetworkDomain(),
offering.getGuestType(),
plan.getDataCenterId(),
plan.getPhysicalNetworkId(),
aclType,
offering.getSpecifyIpRanges(),
vpcId);
vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled); vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()))); finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
@ -791,12 +792,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
vo = _nicDao.persist(vo); vo = _nicDao.persist(vo);
Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
NicProfile vmNic = new NicProfile(vo, NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
network,
vo.getBroadcastUri(),
vo.getIsolationUri(),
networkRate,
_networkModel.isSecurityGroupSupportedInNetwork(network),
_networkModel.getNetworkTag(vm.getHypervisorType(), network)); _networkModel.getNetworkTag(vm.getHypervisorType(), network));
return new Pair<NicProfile, Integer>(vmNic, Integer.valueOf(deviceId)); return new Pair<NicProfile, Integer>(vmNic, Integer.valueOf(deviceId));
@ -1071,8 +1067,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) { if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
s_logger.warn("Failed to re-program the network as a part of network " + network + " implement"); s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
// see DataCenterVO.java // see DataCenterVO.java
ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class,
DataCenter.class,
network.getDataCenterId()); network.getDataCenterId());
ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid()); ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
throw ex; throw ex;
@ -1281,12 +1276,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
updateNic(nic, network.getId(), 1); updateNic(nic, network.getId(), 1);
} else { } else {
profile = new NicProfile(nic, profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
network,
nic.getBroadcastUri(),
nic.getIsolationUri(),
networkRate,
_networkModel.isSecurityGroupSupportedInNetwork(network),
_networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
guru.updateNicProfile(profile, network); guru.updateNicProfile(profile, network);
nic.setState(Nic.State.Reserved); nic.setState(Nic.State.Reserved);
@ -1297,13 +1287,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (NetworkElement element : _networkElements) { for (NetworkElement element : _networkElements) {
if (providersToImplement.contains(element.getProvider())) { if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " +
network.getPhysicalNetworkId());
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
} }
if(!prepareElement(element, network, profile, vmProfile, dest, context)) { if (!prepareElement(element, network, profile, vmProfile, dest, context)) {
throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity",Network.class, network.getId()); throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity", Network.class, network.getId());
} }
} }
} }
@ -1322,12 +1313,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
network,
nic.getBroadcastUri(),
nic.getIsolationUri(),
networkRate,
_networkModel.isSecurityGroupSupportedInNetwork(network),
_networkModel.getNetworkTag(vm.getHypervisorType(), network)); _networkModel.getNetworkTag(vm.getHypervisorType(), network));
if (guru instanceof NetworkMigrationResponder) { if (guru instanceof NetworkMigrationResponder) {
if (!((NetworkMigrationResponder)guru).prepareMigration(profile, network, vm, dest, context)) { if (!((NetworkMigrationResponder)guru).prepareMigration(profile, network, vm, dest, context)) {
@ -1338,11 +1324,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (NetworkElement element : _networkElements) { for (NetworkElement element : _networkElements) {
if (providersToImplement.contains(element.getProvider())) { if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " +
network.getPhysicalNetworkId());
} }
if(element instanceof NetworkMigrationResponder){ if (element instanceof NetworkMigrationResponder) {
if(!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)){ if (!((NetworkMigrationResponder)element).prepareMigration(profile, network, vm, dest, context)) {
s_logger.error("NetworkElement "+element+" prepareForMigration failed."); // XXX: Transaction error s_logger.error("NetworkElement " + element + " prepareForMigration failed."); // XXX: Transaction error
} }
} }
} }
@ -1377,10 +1364,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (NetworkElement element : _networkElements) { for (NetworkElement element : _networkElements) {
if (providersToImplement.contains(element.getProvider())) { if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " +
network.getPhysicalNetworkId());
} }
if(element instanceof NetworkMigrationResponder){ if (element instanceof NetworkMigrationResponder) {
((NetworkMigrationResponder) element).commitMigration(nicSrc, network, src, src_context, dst_context); ((NetworkMigrationResponder)element).commitMigration(nicSrc, network, src, src_context, dst_context);
} }
} }
} }
@ -1407,10 +1395,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (NetworkElement element : _networkElements) { for (NetworkElement element : _networkElements) {
if (providersToImplement.contains(element.getProvider())) { if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " +
network.getPhysicalNetworkId());
} }
if(element instanceof NetworkMigrationResponder){ if (element instanceof NetworkMigrationResponder) {
((NetworkMigrationResponder) element).rollbackMigration(nicDst, network, dst, src_context, dst_context); ((NetworkMigrationResponder)element).rollbackMigration(nicDst, network, dst, src_context, dst_context);
} }
} }
} }
@ -1451,12 +1440,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
nic.setState(Nic.State.Releasing); nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic); _nicDao.update(nic.getId(), nic);
NicProfile profile = new NicProfile(nic, NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network),
network,
nic.getBroadcastUri(),
nic.getIsolationUri(),
null,
_networkModel.isSecurityGroupSupportedInNetwork(network),
_networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
if (guru.release(profile, vmProfile, nic.getReservationId())) { if (guru.release(profile, vmProfile, nic.getReservationId())) {
applyProfileToNicForRelease(nic, profile); applyProfileToNicForRelease(nic, profile);
@ -1475,7 +1459,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (NetworkElement element : _networkElements) { for (NetworkElement element : _networkElements) {
if (providersToImplement.contains(element.getProvider())) { if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); throw new CloudRuntimeException("Service provider " + element.getProvider().getName() +
" either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to release " + nic); s_logger.debug("Asking " + element.getName() + " to release " + nic);
@ -1527,7 +1512,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
for (NetworkElement element : _networkElements) { for (NetworkElement element : _networkElements) {
if (providersToImplement.contains(element.getProvider())) { if (providersToImplement.contains(element.getProvider())) {
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) { if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " +
network.getPhysicalNetworkId());
} }
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to release " + nic); s_logger.debug("Asking " + element.getName() + " to release " + nic);
@ -1535,9 +1521,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
try { try {
element.release(network, profile, vm, null); element.release(network, profile, vm, null);
} catch (ConcurrentOperationException ex) { } catch (ConcurrentOperationException ex) {
s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex); s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex);
} catch (ResourceUnavailableException ex) { } catch (ResourceUnavailableException ex) {
s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex); s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex);
} }
} }
} }
@ -1778,7 +1764,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
// If networkDomain is not specified, take it from the global configuration // If networkDomain is not specified, take it from the global configuration
if (_networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) { if (_networkModel.areServicesSupportedByNetworkOffering(networkOfferingId, Service.Dns)) {
Map<Network.Capability, String> dnsCapabilities = _networkModel.getNetworkOfferingServiceCapabilities(_entityMgr.findById(NetworkOffering.class, networkOfferingId), Service.Dns); Map<Network.Capability, String> dnsCapabilities = _networkModel.getNetworkOfferingServiceCapabilities(_entityMgr.findById(NetworkOffering.class, networkOfferingId),
Service.Dns);
String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification); String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification);
if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) { if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) {
if (networkDomain != null) { if (networkDomain != null) {
@ -1802,9 +1789,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
} else { } else {
// validate network domain // validate network domain
if (!NetUtils.verifyDomainName(networkDomain)) { if (!NetUtils.verifyDomainName(networkDomain)) {
throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain " throw new InvalidParameterValueException(
+ "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', " "Invalid network domain. Total length shouldn't exceed 190 chars. Each domain "
+ "and the hyphen ('-'); can't start or end with \"-\""); + "label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
+ "and the hyphen ('-'); can't start or end with \"-\"");
} }
} }
} }
@ -2408,11 +2396,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
} }
protected boolean isSharedNetworkWithServices(Network network) { protected boolean isSharedNetworkWithServices(Network network) {
assert(network != null); assert (network != null);
DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (network.getGuestType() == Network.GuestType.Shared && if (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced &&
zone.getNetworkType() == NetworkType.Advanced && isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
return true; return true;
} }
return false; return false;
@ -2915,38 +2902,24 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
@Override @Override
public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException,
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { ResourceUnavailableException {
VirtualMachine vm = vmProfile.getVirtualMachine(); VirtualMachine vm = vmProfile.getVirtualMachine();
DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId()); Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host); DeployDestination dest = new DeployDestination(dc, null, null, host);
NicProfile nic = getNicProfileForVm(network, requested, vm); NicProfile nic = getNicProfileForVm(network, requested, vm);
//1) allocate nic (if needed) Always allocate if it is a user vm //1) allocate nic (if needed) Always allocate if it is a user vm
if (nic == null || (vmProfile.getType() == VirtualMachine.Type.User)) { if (nic == null || (vmProfile.getType() == VirtualMachine.Type.User)) {
int deviceId = _nicDao.countNics(vm.getId()); int deviceId = _nicDao.countNics(vm.getId());
nic = allocateNic(requested, network, false, nic = allocateNic(requested, network, false, deviceId, vmProfile).first();
deviceId, vmProfile).first();
if (nic == null) { if (nic == null) {
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network); 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);
}
//2) prepare nic
if (prepare) {
Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context);
nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second());
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
}
return nic;
} }
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);
@ -2973,13 +2946,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName());
NicProfile profile = new NicProfile(nic, NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
network, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
nic.getBroadcastUri(),
nic.getIsolationUri(),
networkRate,
_networkModel.isSecurityGroupSupportedInNetwork(network),
_networkModel.getNetworkTag(vm.getHypervisorType(), network));
guru.updateNicProfile(profile, network); guru.updateNicProfile(profile, network);
profiles.add(profile); profiles.add(profile);
} }
@ -3117,18 +3085,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
return NetworkOrchestrationService.class.getSimpleName(); return NetworkOrchestrationService.class.getSimpleName();
} }
public static final ConfigKey<Integer> NetworkGcWait = new ConfigKey<Integer>(Integer.class, public static final ConfigKey<Integer> NetworkGcWait = new ConfigKey<Integer>(Integer.class, "network.gc.wait", "Advanced", "600",
"network.gc.wait", "Time (in seconds) to wait before shutting down a network that's not in used", false);
"Advanced", public static final ConfigKey<Integer> NetworkGcInterval = new ConfigKey<Integer>(Integer.class, "network.gc.interval", "Advanced", "600",
"600", "Seconds to wait before checking for networks to shutdown", true);
"Time (in seconds) to wait before shutting down a network that's not in used",
false);
public static final ConfigKey<Integer> NetworkGcInterval = new ConfigKey<Integer>(Integer.class,
"network.gc.interval",
"Advanced",
"600",
"Seconds to wait before checking for networks to shutdown",
true);
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, GuestDomainSuffix, NetworkThrottlingRate}; return new ConfigKey<?>[] {NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, GuestDomainSuffix, NetworkThrottlingRate};

View File

@ -190,6 +190,7 @@ import com.cloud.user.dao.AccountDao;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils; import com.cloud.utils.StringUtils;
import com.cloud.utils.component.InjectConfig;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;

View File

@ -190,9 +190,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
private static final long MIN_GRE_KEY = 0L; private static final long MIN_GRE_KEY = 0L;
private static final long MAX_GRE_KEY = 4294967295L; // 2^32 -1 private static final long MAX_GRE_KEY = 4294967295L; // 2^32 -1
@Inject
EntityManager _entityMgr;
@Inject @Inject
DataCenterDao _dcDao = null; DataCenterDao _dcDao = null;
@Inject @Inject

View File

@ -125,9 +125,6 @@ import com.cloud.vm.dao.VMInstanceDao;
@Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class}) @Local(value = {VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class})
public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{
private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class); private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class);
@Inject
EntityManager _entityMgr;
String _name; String _name;
@Inject @Inject
VpcDao _vpcDao; VpcDao _vpcDao;

View File

@ -68,6 +68,7 @@ import com.cloud.utils.Pair;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.Filter; import com.cloud.utils.db.Filter;
import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
@ -93,6 +94,8 @@ public class RulesApiServiceImpl extends ManagerBase implements RulesService {
@Inject @Inject
IpAddressManager _ipAddrMgr; IpAddressManager _ipAddrMgr;
@Inject
EntityManager _entityMgr;
@Inject @Inject
PortForwardingRulesDao _portForwardingDao; PortForwardingRulesDao _portForwardingDao;
@ -379,7 +382,7 @@ public class RulesApiServiceImpl extends ManagerBase implements RulesService {
_networkModel.checkIpForService(ipAddress, Service.StaticNat, null); _networkModel.checkIpForService(ipAddress, Service.StaticNat, null);
Network network = _networkModel.getNetwork(networkId); Network network = _networkModel.getNetwork(networkId);
NetworkOffering off = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
if (off.getElasticIp()) { if (off.getElasticIp()) {
throw new InvalidParameterValueException("Can't create ip forwarding rules for the network where elasticIP service is enabled"); throw new InvalidParameterValueException("Can't create ip forwarding rules for the network where elasticIP service is enabled");
} }
@ -631,7 +634,7 @@ public class RulesApiServiceImpl extends ManagerBase implements RulesService {
boolean reassignStaticNat = false; boolean reassignStaticNat = false;
if (networkId != null) { if (networkId != null) {
Network guestNetwork = _networkModel.getNetwork(networkId); Network guestNetwork = _networkModel.getNetwork(networkId);
NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
if (offering.getElasticIp()) { if (offering.getElasticIp()) {
reassignStaticNat = true; reassignStaticNat = true;
} }
@ -939,7 +942,7 @@ public class RulesApiServiceImpl extends ManagerBase implements RulesService {
// if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to // if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to
// re-enable it on the new one enable static nat takes care of that // re-enable it on the new one enable static nat takes care of that
Network guestNetwork = _networkModel.getNetwork(ipAddress.getAssociatedWithNetworkId()); Network guestNetwork = _networkModel.getNetwork(ipAddress.getAssociatedWithNetworkId());
NetworkOffering offering = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId()); NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, guestNetwork.getNetworkOfferingId());
if (offering.getElasticIp()) { if (offering.getElasticIp()) {
if (offering.getAssociatePublicIP()) { if (offering.getAssociatePublicIP()) {
getSystemIpAndEnableStaticNatForVm(_vmDao.findById(vmId), true); getSystemIpAndEnableStaticNatForVm(_vmDao.findById(vmId), true);

View File

@ -1283,16 +1283,6 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager, Rules
} }
} }
@Override
public PortForwardingRule getPortForwardigRule(long ruleId) {
return _portForwardingDao.findById(ruleId);
}
@Override
public FirewallRule getFirewallRule(long ruleId) {
return _firewallDao.findById(ruleId);
}
@Override @Override
public StaticNatRule buildStaticNatRule(FirewallRule rule, boolean forRevoke) { public StaticNatRule buildStaticNatRule(FirewallRule rule, boolean forRevoke) {
IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId()); IpAddress ip = _ipAddressDao.findById(rule.getSourceIpAddressId());

View File

@ -66,6 +66,7 @@ import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao; import com.cloud.user.dao.UserDao;
import com.cloud.utils.EnumUtils; import com.cloud.utils.EnumUtils;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.InjectConfig;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.UserVmVO; import com.cloud.vm.UserVmVO;
import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDao;