Removed getzone

This commit is contained in:
Alex Huang 2013-08-26 15:04:40 -07:00
parent 89b54596f8
commit ff6b3fd11a
21 changed files with 194 additions and 180 deletions

View File

@ -20,12 +20,6 @@ import java.util.List;
import javax.naming.NamingException; import javax.naming.NamingException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.ResourceAllocationException;
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd; import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd; import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
@ -52,19 +46,23 @@ import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd; import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
import org.apache.cloudstack.config.Configuration; import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpRange;
import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter;
import com.cloud.dc.Pod; import com.cloud.dc.Pod;
import com.cloud.dc.Vlan; import com.cloud.dc.Vlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Networks.TrafficType; import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.DiskOffering; import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering; import com.cloud.offering.ServiceOffering;
import com.cloud.user.Account; import com.cloud.user.Account;
import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpRange;
public interface ConfigurationService { public interface ConfigurationService {
/** /**
@ -265,8 +263,6 @@ public interface ConfigurationService {
List<? extends NetworkOffering> listNetworkOfferings(TrafficType trafficType, boolean systemOnly); List<? extends NetworkOffering> listNetworkOfferings(TrafficType trafficType, boolean systemOnly);
DataCenter getZone(long id);
ServiceOffering getServiceOffering(long serviceOfferingId); ServiceOffering getServiceOffering(long serviceOfferingId);
Long getDefaultPageSize(); Long getDefaultPageSize();

View File

@ -164,7 +164,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
return null; return null;
} }
DataCenter zone = _configService.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) { if (zone.getNetworkType() == NetworkType.Advanced) {
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(),
_accountService.getAccount(getEntityOwnerId())); _accountService.getAccount(getEntityOwnerId()));
@ -218,7 +218,7 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd {
NetworkOffering offering = _configService.getNetworkOffering(network.getNetworkOfferingId()); NetworkOffering offering = _configService.getNetworkOffering(network.getNetworkOfferingId());
DataCenter zone = _configService.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) { if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
// Since the basic zone network is owned by 'Root' domain, domain access checkers will fail for the // Since the basic zone network is owned by 'Root' domain, domain access checkers will fail for the
// accounts in non-root domains while acquiring public IP. So add an exception for the 'Basic' zone // accounts in non-root domains while acquiring public IP. So add an exception for the 'Basic' zone

View File

@ -164,7 +164,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements
} }
if (zoneId != null) { if (zoneId != null) {
DataCenter zone = _configService.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) { if (zone.getNetworkType() == NetworkType.Advanced) {
List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId())); List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
if (networks.size() == 0) { if (networks.size() == 0) {

View File

@ -455,7 +455,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
//Verify that all objects exist before passing them to the service //Verify that all objects exist before passing them to the service
Account owner = _accountService.getActiveAccountById(getEntityOwnerId()); Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
DataCenter zone = _configService.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) { if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId); throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
} }

View File

@ -1902,7 +1902,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
ResourceUnavailableException { ResourceUnavailableException {
VMInstanceVO vm = _vmDao.findByUuid(vmUuid); VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
DataCenter dc = _configMgr.getZone(vm.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId()); Host host = _hostDao.findById(vm.getHostId());
Cluster cluster = null; Cluster cluster = null;
if (host != null) { if (host != null) {
@ -2771,7 +2771,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
DataCenter dc = _configMgr.getZone(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);
@ -2840,7 +2840,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
null, null, null); null, null, null);
DataCenter dc = _configMgr.getZone(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);
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
@ -2904,7 +2904,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null,
null, null, null); null, null, null);
DataCenter dc = _configMgr.getZone(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);
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());

View File

@ -121,6 +121,7 @@ import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException; import com.cloud.resource.UnableDeleteHostException;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
@ -136,6 +137,8 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
private static final Logger s_logger = Logger.getLogger(CiscoVnmcElement.class); private static final Logger s_logger = Logger.getLogger(CiscoVnmcElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities(); private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@Inject
EntityManager _entityMgr;
@Inject @Inject
AgentManager _agentMgr; AgentManager _agentMgr;
@Inject @Inject
@ -275,7 +278,7 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
DeployDestination dest, ReservationContext context) DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException, throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException { InsufficientCapacityException {
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic) { if (zone.getNetworkType() == NetworkType.Basic) {
s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic); s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic);

View File

@ -83,6 +83,7 @@ import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceManager;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.net.Ip; import com.cloud.utils.net.Ip;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
@ -102,6 +103,7 @@ public class CiscoVnmcElementTest {
CiscoNexusVSMDeviceDao _vsmDeviceDao = mock(CiscoNexusVSMDeviceDao.class); CiscoNexusVSMDeviceDao _vsmDeviceDao = mock(CiscoNexusVSMDeviceDao.class);
VlanDao _vlanDao = mock(VlanDao.class); VlanDao _vlanDao = mock(VlanDao.class);
IpAddressManager _ipAddrMgr = mock(IpAddressManager.class); IpAddressManager _ipAddrMgr = mock(IpAddressManager.class);
EntityManager _entityMgr = mock(EntityManager.class);
@Before @Before
public void setUp() throws ConfigurationException { public void setUp() throws ConfigurationException {
@ -117,6 +119,7 @@ public class CiscoVnmcElementTest {
_element._clusterVsmMapDao = _clusterVsmMapDao; _element._clusterVsmMapDao = _clusterVsmMapDao;
_element._vsmDeviceDao = _vsmDeviceDao; _element._vsmDeviceDao = _vsmDeviceDao;
_element._vlanDao = _vlanDao; _element._vlanDao = _vlanDao;
_element._entityMgr = _entityMgr;
// Standard responses // Standard responses
when(_networkModel.isProviderForNetwork(Provider.CiscoVnmc, 1L)).thenReturn(true); when(_networkModel.isProviderForNetwork(Provider.CiscoVnmc, 1L)).thenReturn(true);
@ -164,7 +167,7 @@ public class CiscoVnmcElementTest {
DataCenter dc = mock(DataCenter.class); DataCenter dc = mock(DataCenter.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced); when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_configMgr.getZone(network.getDataCenterId())).thenReturn(dc); when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>(); List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
devices.add(mock(CiscoVnmcControllerVO.class)); devices.add(mock(CiscoVnmcControllerVO.class));

View File

@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an // software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
@ -27,12 +27,13 @@ import java.util.Set;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd; import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd;
import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd; import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd;
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd; import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd;
import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao; import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager; import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO; import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;
@ -71,6 +72,7 @@ import com.cloud.user.Account;
import com.cloud.user.AccountManager; import com.cloud.user.AccountManager;
import com.cloud.user.User; import com.cloud.user.User;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.SearchCriteria2; import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.db.SearchCriteriaService; import com.cloud.utils.db.SearchCriteriaService;
@ -98,7 +100,9 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
@Inject ConfigurationManager _configMgr; @Inject ConfigurationManager _configMgr;
@Inject AccountManager _accountMgr; @Inject AccountManager _accountMgr;
@Inject ApplicationLoadBalancerRuleDao _appLbDao; @Inject ApplicationLoadBalancerRuleDao _appLbDao;
@Inject
EntityManager _entityMgr;
protected InternalLoadBalancerElement() { protected InternalLoadBalancerElement() {
} }
@ -113,7 +117,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
private boolean canHandle(Network config, Scheme lbScheme) { private boolean canHandle(Network config, Scheme lbScheme) {
//works in Advance zone only //works in Advance zone only
DataCenter dc = _configMgr.getZone(config.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, config.getDataCenterId());
if (dc.getNetworkType() != NetworkType.Advanced) { if (dc.getNetworkType() != NetworkType.Advanced) {
s_logger.trace("Not hanling zone of network type " + dc.getNetworkType()); s_logger.trace("Not hanling zone of network type " + dc.getNetworkType());
return false; return false;
@ -123,12 +127,12 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
return false; return false;
} }
Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb); Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb);
if (!lbCaps.isEmpty()) { if (!lbCaps.isEmpty()) {
String schemeCaps = lbCaps.get(Capability.LbSchemes); String schemeCaps = lbCaps.get(Capability.LbSchemes);
if (schemeCaps != null && lbScheme != null) { if (schemeCaps != null && lbScheme != null) {
if (!schemeCaps.contains(lbScheme.toString())) { if (!schemeCaps.contains(lbScheme.toString())) {
s_logger.debug("Scheme " + lbScheme.toString() + " is not supported by the provider " + this.getName()); s_logger.debug("Scheme " + lbScheme.toString() + " is not supported by the provider " + getName());
return false; return false;
} }
} }
@ -161,7 +165,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
InsufficientCapacityException { InsufficientCapacityException {
if (!canHandle(network, null)) { if (!canHandle(network, null)) {
s_logger.trace("No need to implement " + this.getName()); s_logger.trace("No need to implement " + getName());
return true; return true;
} }
@ -174,7 +178,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
ResourceUnavailableException, InsufficientCapacityException { ResourceUnavailableException, InsufficientCapacityException {
if (!canHandle(network, null)) { if (!canHandle(network, null)) {
s_logger.trace("No need to prepare " + this.getName()); s_logger.trace("No need to prepare " + getName());
return true; return true;
} }
@ -200,18 +204,18 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
try { try {
internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null); internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
} catch (InsufficientCapacityException e) { } catch (InsufficientCapacityException e) {
s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e); s_logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e);
return false; return false;
} catch (ConcurrentOperationException e) { } catch (ConcurrentOperationException e) {
s_logger.warn("Failed to deploy element " + this.getName() + " for ip " + sourceIp + " due to:", e); s_logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e);
return false; return false;
} }
if (internalLbVms == null || internalLbVms.isEmpty()) { if (internalLbVms == null || internalLbVms.isEmpty()) {
throw new ResourceUnavailableException("Can't deploy " + this.getName() + " to handle LB rules", throw new ResourceUnavailableException("Can't deploy " + getName() + " to handle LB rules",
DataCenter.class, network.getDataCenterId()); DataCenter.class, network.getDataCenterId());
} }
} }
} }
return true; return true;
@ -265,7 +269,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
@Override @Override
public boolean isReady(PhysicalNetworkServiceProvider provider) { public boolean isReady(PhysicalNetworkServiceProvider provider) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
VirtualRouterProviderType.InternalLbVm); VirtualRouterProviderType.InternalLbVm);
if (element == null) { if (element == null) {
return false; return false;
@ -277,7 +281,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
@Override @Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException { throws ConcurrentOperationException, ResourceUnavailableException {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(),
VirtualRouterProviderType.InternalLbVm); VirtualRouterProviderType.InternalLbVm);
if (element == null) { if (element == null) {
return true; return true;
@ -320,7 +324,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
//2) Get rules to apply //2) Get rules to apply
Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules); Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules);
s_logger.debug("Applying " + rulesToApply.size() + " on element " + this.getName()); s_logger.debug("Applying " + rulesToApply.size() + " on element " + getName());
for (Ip sourceIp : rulesToApply.keySet()) { for (Ip sourceIp : rulesToApply.keySet()) {
@ -334,7 +338,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM),
_accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId()); _accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId());
} catch (ConcurrentOperationException e) { } catch (ConcurrentOperationException e) {
s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + " on the element " + this.getName() + " due to:", e); s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + " on the element " + getName() + " due to:", e);
return false; return false;
} }
} }
@ -342,13 +346,13 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
//2.2 Start Internal LB vm per IP address //2.2 Start Internal LB vm per IP address
List<? extends VirtualRouter> internalLbVms; List<? extends VirtualRouter> internalLbVms;
try { try {
DeployDestination dest = new DeployDestination(_configMgr.getZone(network.getDataCenterId()), null, null, null); DeployDestination dest = new DeployDestination(_entityMgr.findById(DataCenter.class, network.getDataCenterId()), null, null, null);
internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null); internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null);
} catch (InsufficientCapacityException e) { } catch (InsufficientCapacityException e) {
s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + "on the element " + this.getName() + " due to:", e); s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + "on the element " + getName() + " due to:", e);
return false; return false;
} catch (ConcurrentOperationException e) { } catch (ConcurrentOperationException e) {
s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + "on the element " + this.getName() + " due to:", e); s_logger.warn("Failed to apply lb rule(s) for ip " + sourceIp.addr() + "on the element " + getName() + " due to:", e);
return false; return false;
} }
@ -359,13 +363,13 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
//2.3 Apply Internal LB rules on the VM //2.3 Apply Internal LB rules on the VM
if (!_internalLbMgr.applyLoadBalancingRules(network, rulesToApply.get(sourceIp), internalLbVms)) { if (!_internalLbMgr.applyLoadBalancingRules(network, rulesToApply.get(sourceIp), internalLbVms)) {
throw new CloudRuntimeException("Failed to apply load balancing rules for ip " + sourceIp.addr() + throw new CloudRuntimeException("Failed to apply load balancing rules for ip " + sourceIp.addr() +
" in network " + network.getId() + " on element " + this.getName()); " in network " + network.getId() + " on element " + getName());
} }
} }
} }
return true; return true;
} }
@ -464,8 +468,8 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
public VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable) { public VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable) {
VirtualRouterProviderVO element = _vrProviderDao.findById(id); VirtualRouterProviderVO element = _vrProviderDao.findById(id);
if (element == null || element.getType() != VirtualRouterProviderType.InternalLbVm) { if (element == null || element.getType() != VirtualRouterProviderType.InternalLbVm) {
throw new InvalidParameterValueException("Can't find " + this.getName() + " element with network service provider id " + id + throw new InvalidParameterValueException("Can't find " + getName() + " element with network service provider id " + id +
" to be used as a provider for " + this.getName()); " to be used as a provider for " + getName());
} }
element.setEnabled(enable); element.setEnabled(enable);
@ -478,12 +482,12 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) { public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) {
VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm); VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, VirtualRouterProviderType.InternalLbVm);
if (element != null) { if (element != null) {
s_logger.debug("There is already an " + this.getName() + " with service provider id " + ntwkSvcProviderId); s_logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId);
return null; return null;
} }
PhysicalNetworkServiceProvider provider = _pNtwkSvcProviderDao.findById(ntwkSvcProviderId); PhysicalNetworkServiceProvider provider = _pNtwkSvcProviderDao.findById(ntwkSvcProviderId);
if (provider == null || !provider.getProviderName().equalsIgnoreCase(this.getName())) { if (provider == null || !provider.getProviderName().equalsIgnoreCase(getName())) {
throw new InvalidParameterValueException("Invalid network service provider is specified"); throw new InvalidParameterValueException("Invalid network service provider is specified");
} }
@ -497,7 +501,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
public VirtualRouterProvider getInternalLoadBalancerElement(long id) { public VirtualRouterProvider getInternalLoadBalancerElement(long id) {
VirtualRouterProvider provider = _vrProviderDao.findById(id); VirtualRouterProvider provider = _vrProviderDao.findById(id);
if (provider == null || provider.getType() != VirtualRouterProviderType.InternalLbVm) { if (provider == null || provider.getType() != VirtualRouterProviderType.InternalLbVm) {
throw new InvalidParameterValueException("Unable to find " + this.getName() + " by id"); throw new InvalidParameterValueException("Unable to find " + getName() + " by id");
} }
return provider; return provider;
} }

View File

@ -41,6 +41,7 @@ import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VirtualRouterProviderDao; import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.user.AccountManager; import com.cloud.user.AccountManager;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.DomainRouterDao;
@ -107,6 +108,10 @@ public class ElementChildTestConfiguration {
return Mockito.mock(ConfigurationManager.class); return Mockito.mock(ConfigurationManager.class);
} }
@Bean
public EntityManager entityManager() {
return Mockito.mock(EntityManager.class);
}
@Bean @Bean
public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() { public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() {

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the // to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance // "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at // with the License. You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
@ -28,9 +28,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.network.element.InternalLoadBalancerElement;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -38,8 +35,13 @@ import org.mockito.Mockito;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
import org.apache.cloudstack.network.element.InternalLoadBalancerElement;
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
import com.cloud.agent.api.to.LoadBalancerTO; import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.ResourceUnavailableException;
@ -57,6 +59,7 @@ import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LoadBalancerContainer.Scheme; import com.cloud.network.rules.LoadBalancerContainer.Scheme;
import com.cloud.user.AccountManager; import com.cloud.user.AccountManager;
import com.cloud.utils.component.ComponentContext; import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.net.Ip; import com.cloud.utils.net.Ip;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ -71,6 +74,8 @@ public class InternalLbElementTest {
@Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao; @Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao;
@Inject InternalLoadBalancerVMManager _internalLbMgr; @Inject InternalLoadBalancerVMManager _internalLbMgr;
@Inject ConfigurationManager _configMgr; @Inject ConfigurationManager _configMgr;
@Inject
EntityManager _entityMgr;
long validElId = 1L; long validElId = 1L;
long nonExistingElId = 2L; long nonExistingElId = 2L;
@ -109,20 +114,20 @@ public class InternalLbElementTest {
DataCenterVO dc = new DataCenterVO DataCenterVO dc = new DataCenterVO
(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null); (1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
Mockito.when(_configMgr.getZone(Mockito.anyLong())).thenReturn(dc); Mockito.when(_entityMgr.findById(Mockito.eq(DataCenter.class), Mockito.anyLong())).thenReturn(dc);
} }
//TEST FOR getProvider() method //TEST FOR getProvider() method
@Test @Test
public void verifyProviderName() { public void verifyProviderName() {
Provider pr = _lbEl.getProvider(); Provider pr = _lbEl.getProvider();
assertEquals("Wrong provider is returned", pr.getName(), Provider.InternalLbVm.getName()); assertEquals("Wrong provider is returned", pr.getName(), Provider.InternalLbVm.getName());
} }
//TEST FOR isReady() METHOD //TEST FOR isReady() METHOD
@Test @Test
public void verifyValidProviderState() { public void verifyValidProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO(); PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, validElId); provider = setId(provider, validElId);
@ -131,7 +136,7 @@ public class InternalLbElementTest {
} }
@Test @Test
public void verifyNonExistingProviderState() { public void verifyNonExistingProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO(); PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, nonExistingElId); provider = setId(provider, nonExistingElId);
@ -140,7 +145,7 @@ public class InternalLbElementTest {
} }
@Test @Test
public void verifyInvalidProviderState() { public void verifyInvalidProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO(); PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, invalidElId); provider = setId(provider, invalidElId);
@ -148,7 +153,7 @@ public class InternalLbElementTest {
assertFalse("Not valid provider is returned as ready", isReady); assertFalse("Not valid provider is returned as ready", isReady);
} }
@Test @Test
public void verifyNotEnabledProviderState() { public void verifyNotEnabledProviderState() {
PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO(); PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
provider = setId(provider, notEnabledElId); provider = setId(provider, notEnabledElId);
@ -157,22 +162,22 @@ public class InternalLbElementTest {
} }
//TEST FOR canEnableIndividualServices METHOD //TEST FOR canEnableIndividualServices METHOD
@Test @Test
public void verifyCanEnableIndividualSvc() { public void verifyCanEnableIndividualSvc() {
boolean result = _lbEl.canEnableIndividualServices(); boolean result = _lbEl.canEnableIndividualServices();
assertTrue("Wrong value is returned by canEnableIndividualSvc", result); assertTrue("Wrong value is returned by canEnableIndividualSvc", result);
} }
//TEST FOR verifyServicesCombination METHOD //TEST FOR verifyServicesCombination METHOD
@Test @Test
public void verifyServicesCombination() { public void verifyServicesCombination() {
boolean result = _lbEl.verifyServicesCombination(new HashSet<Service>()); boolean result = _lbEl.verifyServicesCombination(new HashSet<Service>());
assertTrue("Wrong value is returned by verifyServicesCombination", result); assertTrue("Wrong value is returned by verifyServicesCombination", result);
} }
//TEST FOR applyIps METHOD //TEST FOR applyIps METHOD
@Test @Test
public void verifyApplyIps() throws ResourceUnavailableException { public void verifyApplyIps() throws ResourceUnavailableException {
List<PublicIp> ips = new ArrayList<PublicIp>(); List<PublicIp> ips = new ArrayList<PublicIp>();
boolean result = _lbEl.applyIps(new NetworkVO(), ips, new HashSet<Service>()); boolean result = _lbEl.applyIps(new NetworkVO(), ips, new HashSet<Service>());
@ -181,14 +186,14 @@ public class InternalLbElementTest {
//TEST FOR updateHealthChecks METHOD //TEST FOR updateHealthChecks METHOD
@Test @Test
public void verifyUpdateHealthChecks() throws ResourceUnavailableException { public void verifyUpdateHealthChecks() throws ResourceUnavailableException {
List<LoadBalancerTO> check = _lbEl.updateHealthChecks(new NetworkVO(), new ArrayList<LoadBalancingRule>()); List<LoadBalancerTO> check = _lbEl.updateHealthChecks(new NetworkVO(), new ArrayList<LoadBalancingRule>());
assertNull("Wrong value is returned by updateHealthChecks method", check); assertNull("Wrong value is returned by updateHealthChecks method", check);
} }
//TEST FOR validateLBRule METHOD //TEST FOR validateLBRule METHOD
@Test @Test
public void verifyValidateLBRule() throws ResourceUnavailableException { public void verifyValidateLBRule() throws ResourceUnavailableException {
ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin", ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin",
1L, 1L, 1L, new Ip("10.10.10.1"), 1L, Scheme.Internal); 1L, 1L, 1L, new Ip("10.10.10.1"), 1L, Scheme.Internal);

View File

@ -11,13 +11,35 @@
// Unless required by applicable law or agreed to in writing, // Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an // software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.network.element; package com.cloud.network.element;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.response.ExternalFirewallResponse;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import com.cloud.api.ApiDBUtils; import com.cloud.api.ApiDBUtils;
import com.cloud.api.commands.*; import com.cloud.api.commands.AddExternalFirewallCmd;
import com.cloud.api.commands.AddSrxFirewallCmd;
import com.cloud.api.commands.ConfigureSrxFirewallCmd;
import com.cloud.api.commands.DeleteExternalFirewallCmd;
import com.cloud.api.commands.DeleteSrxFirewallCmd;
import com.cloud.api.commands.ListExternalFirewallsCmd;
import com.cloud.api.commands.ListSrxFirewallNetworksCmd;
import com.cloud.api.commands.ListSrxFirewallsCmd;
import com.cloud.api.response.SrxFirewallResponse; import com.cloud.api.response.SrxFirewallResponse;
import com.cloud.configuration.Config; import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;
@ -26,17 +48,36 @@ import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeployDestination;
import com.cloud.exception.*; import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientNetworkCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.Host; import com.cloud.host.Host;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao; import com.cloud.host.dao.HostDetailsDao;
import com.cloud.network.*; import com.cloud.network.ExternalFirewallDeviceManagerImpl;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability; import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider; import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service; import com.cloud.network.Network.Service;
import com.cloud.network.dao.*; import com.cloud.network.NetworkModel;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.RemoteAccessVpn;
import com.cloud.network.VpnUser;
import com.cloud.network.dao.ExternalFirewallDeviceDao;
import com.cloud.network.dao.ExternalFirewallDeviceVO;
import com.cloud.network.dao.ExternalFirewallDeviceVO.FirewallDeviceState; import com.cloud.network.dao.ExternalFirewallDeviceVO.FirewallDeviceState;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkExternalFirewallDao;
import com.cloud.network.dao.NetworkExternalFirewallVO;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.resource.JuniperSrxResource; import com.cloud.network.resource.JuniperSrxResource;
import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.PortForwardingRule; import com.cloud.network.rules.PortForwardingRule;
@ -44,25 +85,14 @@ import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
import org.apache.cloudstack.api.response.ExternalFirewallResponse; @Local(value = {NetworkElement.class, FirewallServiceProvider.class,
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; PortForwardingServiceProvider.class, IpDeployer.class,
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.inject.Inject;
import java.util.*;
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
PortForwardingServiceProvider.class, IpDeployer.class,
SourceNatServiceProvider.class, RemoteAccessVPNServiceProvider.class}) SourceNatServiceProvider.class, RemoteAccessVPNServiceProvider.class})
public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceManagerImpl implements SourceNatServiceProvider, FirewallServiceProvider, public class JuniperSRXExternalFirewallElement extends ExternalFirewallDeviceManagerImpl implements SourceNatServiceProvider, FirewallServiceProvider,
PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, JuniperSRXFirewallElementService, StaticNatServiceProvider { PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, JuniperSRXFirewallElementService, StaticNatServiceProvider {
@ -97,9 +127,11 @@ PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, Junip
HostDetailsDao _hostDetailDao; HostDetailsDao _hostDetailDao;
@Inject @Inject
ConfigurationDao _configDao; ConfigurationDao _configDao;
@Inject
EntityManager _entityMgr;
private boolean canHandle(Network network, Service service) { private boolean canHandle(Network network, Service service) {
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if ((zone.getNetworkType() == NetworkType.Advanced && !(network.getGuestType() == Network.GuestType.Isolated || if ((zone.getNetworkType() == NetworkType.Advanced && !(network.getGuestType() == Network.GuestType.Isolated ||
network.getGuestType() == Network.GuestType.Shared )) || network.getGuestType() == Network.GuestType.Shared )) ||
(zone.getNetworkType() == NetworkType.Basic && network.getGuestType() != Network.GuestType.Shared)) { (zone.getNetworkType() == NetworkType.Basic && network.getGuestType() != Network.GuestType.Shared)) {
@ -125,7 +157,7 @@ PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, Junip
@Override @Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientNetworkCapacityException { InsufficientNetworkCapacityException {
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
// don't have to implement network is Basic zone // don't have to implement network is Basic zone
if (zone.getNetworkType() == NetworkType.Basic) { if (zone.getNetworkType() == NetworkType.Basic) {
@ -160,7 +192,7 @@ PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, Junip
@Override @Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ResourceUnavailableException, ConcurrentOperationException { public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ResourceUnavailableException, ConcurrentOperationException {
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
// don't have to implement network is Basic zone // don't have to implement network is Basic zone
if (zone.getNetworkType() == NetworkType.Basic) { if (zone.getNetworkType() == NetworkType.Basic) {

View File

@ -4379,7 +4379,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
Boolean forVpc = cmd.getForVpc(); Boolean forVpc = cmd.getForVpc();
if (zoneId != null) { if (zoneId != null) {
zone = getZone(zoneId); zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) { if (zone == null) {
throw new InvalidParameterValueException("Unable to find the zone by id=" + zoneId); throw new InvalidParameterValueException("Unable to find the zone by id=" + zoneId);
} }
@ -4767,11 +4767,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
} }
} }
@Override
public DataCenterVO getZone(long id) {
return _zoneDao.findById(id);
}
@Override @Override
public NetworkOffering getNetworkOffering(long id) { public NetworkOffering getNetworkOffering(long id) {
return _networkOfferingDao.findById(id); return _networkOfferingDao.findById(id);

View File

@ -409,7 +409,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
// check permissions // check permissions
_accountMgr.checkAccess(caller, null, false, ipOwner); _accountMgr.checkAccess(caller, null, false, ipOwner);
DataCenter zone = _configMgr.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
return allocateIp(ipOwner, isSystem, caller, callerUserId, zone); return allocateIp(ipOwner, isSystem, caller, callerUserId, zone);
} }
@ -702,7 +702,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
sc.setParameters("dc", dcId); sc.setParameters("dc", dcId);
DataCenter zone = _configMgr.getZone(dcId); DataCenter zone = _entityMgr.findById(DataCenter.class, dcId);
// for direct network take ip addresses only from the vlans belonging to the network // for direct network take ip addresses only from the vlans belonging to the network
if (vlanUse == VlanType.DirectAttached) { if (vlanUse == VlanType.DirectAttached) {
@ -1153,7 +1153,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
throw new InvalidParameterValueException("Invalid network id is given"); throw new InvalidParameterValueException("Invalid network id is given");
} }
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Advanced) { if (zone.getNetworkType() == NetworkType.Advanced) {
if (network.getGuestType() == Network.GuestType.Shared) { if (network.getGuestType() == Network.GuestType.Shared) {
if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) { if (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())) {
@ -1185,7 +1185,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
return null; return null;
} }
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
// allow associating IP addresses to guest network only // allow associating IP addresses to guest network only
if (network.getTrafficType() != TrafficType.Guest) { if (network.getTrafficType() != TrafficType.Guest) {
@ -1300,7 +1300,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
throw new InvalidParameterValueException("IP " + ipToAssoc + " is not associated with network id" + networkId); throw new InvalidParameterValueException("IP " + ipToAssoc + " is not associated with network id" + networkId);
} }
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Advanced) { if (zone.getNetworkType() == NetworkType.Advanced) {
if (network.getGuestType() == Network.GuestType.Shared) { if (network.getGuestType() == Network.GuestType.Shared) {
assert (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId())); assert (isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()));
@ -1315,7 +1315,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
return null; return null;
} }
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
// Check that network belongs to IP owner - skip this check // Check that network belongs to IP owner - skip this check
// - if zone is basic zone as there is just one guest network, // - if zone is basic zone as there is just one guest network,

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.springframework.stereotype.Component;
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;
@ -162,6 +161,7 @@ import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.db.JoinBuilder.JoinType; import com.cloud.utils.db.JoinBuilder.JoinType;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
@ -194,10 +194,11 @@ import com.cloud.vm.dao.VMInstanceDao;
/** /**
* NetworkManagerImpl implements NetworkManager. * NetworkManagerImpl implements NetworkManager.
*/ */
@Component
@Local(value = { NetworkManager.class}) @Local(value = { NetworkManager.class})
public class NetworkManagerImpl extends ManagerBase implements NetworkManager, Listener { public class NetworkManagerImpl extends ManagerBase implements NetworkManager, Listener {
static final Logger s_logger = Logger.getLogger(NetworkManagerImpl.class); static final Logger s_logger = Logger.getLogger(NetworkManagerImpl.class);
@Inject
EntityManager _entityMgr;
@Inject @Inject
DataCenterDao _dcDao = null; DataCenterDao _dcDao = null;
@ -2124,7 +2125,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
} }
//In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network //In Basic zone, make sure that there are no non-removed console proxies and SSVMs using the network
DataCenter zone = _configMgr.getZone(network.getDataCenterId()); DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (zone.getNetworkType() == NetworkType.Basic) { if (zone.getNetworkType() == NetworkType.Basic) {
List<VMInstanceVO> systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), List<VMInstanceVO> systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(),
Type.ConsoleProxy, Type.SecondaryStorageVm); Type.ConsoleProxy, Type.SecondaryStorageVm);
@ -2454,7 +2455,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
protected boolean isSharedNetworkWithServices(Network network) { protected boolean isSharedNetworkWithServices(Network network) {
assert(network != null); assert(network != null);
DataCenter zone = _configMgr.getZone(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())) {
@ -2973,7 +2974,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
VirtualMachine vm = vmProfile.getVirtualMachine(); VirtualMachine vm = vmProfile.getVirtualMachine();
DataCenter dc = _configMgr.getZone(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);

View File

@ -152,6 +152,7 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
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;
@ -188,6 +189,8 @@ 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;
@ -507,7 +510,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
long callerUserId = CallContext.current().getCallingUserId(); long callerUserId = CallContext.current().getCallingUserId();
DataCenter zone = _configMgr.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (networkId != null) { if (networkId != null) {
Network network = _networksDao.findById(networkId); Network network = _networksDao.findById(networkId);
@ -546,7 +549,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException { throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
long callerUserId = CallContext.current().getCallingUserId(); long callerUserId = CallContext.current().getCallingUserId();
DataCenter zone = _configMgr.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if ((networkId == null && vpcId == null) || (networkId != null && vpcId != null)) { if ((networkId == null && vpcId == null) || (networkId != null && vpcId != null)) {
throw new InvalidParameterValueException("One of Network id or VPC is should be passed"); throw new InvalidParameterValueException("One of Network id or VPC is should be passed");
@ -672,7 +675,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
DataCenter dc = _dcDao.findById(network.getDataCenterId()); DataCenter dc = _dcDao.findById(network.getDataCenterId());
DataCenter zone = _configMgr.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) { if (zone == null) {
throw new InvalidParameterValueException("Invalid zone Id is given"); throw new InvalidParameterValueException("Invalid zone Id is given");
} }
@ -3860,7 +3863,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
//Do not allow multiple private gateways with same Vlan within a VPC //Do not allow multiple private gateways with same Vlan within a VPC
if(vpcId.equals(privateNetwork.getVpcId())){ if(vpcId.equals(privateNetwork.getVpcId())){
throw new InvalidParameterValueException("Private network for the vlan: " + vlan + " and cidr "+ cidr +" already exists " + throw new InvalidParameterValueException("Private network for the vlan: " + vlan + " and cidr "+ cidr +" already exists " +
"for Vpc "+vpcId+" in zone " + _configMgr.getZone(pNtwk.getDataCenterId()).getName()); "for Vpc "+vpcId+" in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
} }
} }
@ -3868,7 +3871,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(), startIp, vpcId); PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(), startIp, vpcId);
if (privateIp != null) { if (privateIp != null) {
throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" + throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" +
" in zone " + _configMgr.getZone(pNtwk.getDataCenterId()).getName()); " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
} }
Long mac = dc.getMacAddress(); Long mac = dc.getMacAddress();

View File

@ -24,7 +24,11 @@ import java.util.Map;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
@ -46,9 +50,6 @@ import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.api.ApiDBUtils; import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiDispatcher; import com.cloud.api.ApiDispatcher;
import com.cloud.configuration.Config; import com.cloud.configuration.Config;
@ -86,9 +87,9 @@ import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao; import com.cloud.user.dao.UserDao;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.Ternary; import com.cloud.utils.Ternary;
import com.cloud.utils.component.Manager;
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.GenericDao; import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.JoinBuilder;
@ -98,14 +99,12 @@ import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.Transaction; import com.cloud.utils.db.Transaction;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@Component
@Local(value = { AutoScaleService.class, AutoScaleManager.class }) @Local(value = { AutoScaleService.class, AutoScaleManager.class })
public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScaleManager, AutoScaleService { public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScaleManager, AutoScaleService {
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class); private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
@Inject
EntityManager _entityMgr;
@Inject @Inject
AccountDao _accountDao; AccountDao _accountDao;
@Inject @Inject
@ -315,7 +314,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
long serviceOfferingId = cmd.getServiceOfferingId(); long serviceOfferingId = cmd.getServiceOfferingId();
long autoscaleUserId = cmd.getAutoscaleUserId(); long autoscaleUserId = cmd.getAutoscaleUserId();
DataCenter zone = _configMgr.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) { if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id"); throw new InvalidParameterValueException("Unable to find zone by id");

View File

@ -46,12 +46,12 @@ import com.cloud.network.vpc.dao.PrivateIpDao;
import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import com.cloud.vm.Nic.ReservationStrategy; import com.cloud.vm.Nic.ReservationStrategy;
import com.cloud.vm.NicProfile; import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
@Local(value = NetworkGuru.class) @Local(value = NetworkGuru.class)
@ -63,6 +63,8 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
protected PrivateIpDao _privateIpDao; protected PrivateIpDao _privateIpDao;
@Inject @Inject
protected NetworkModel _networkMgr; protected NetworkModel _networkMgr;
@Inject
EntityManager _entityMgr;
private static final TrafficType[] _trafficTypes = {TrafficType.Guest}; private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
@ -87,7 +89,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
protected boolean canHandle(NetworkOffering offering, DataCenter dc) { protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// This guru handles only system Guest network // This guru handles only system Guest network
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType())
&& offering.getGuestType() == Network.GuestType.Isolated && offering.isSystemOnly()) { && offering.getGuestType() == Network.GuestType.Isolated && offering.isSystemOnly()) {
return true; return true;
} else { } else {
@ -99,7 +101,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
DataCenter dc = _configMgr.getZone(plan.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, plan.getDataCenterId());
if (!canHandle(offering, dc)) { if (!canHandle(offering, dc)) {
return null; return null;
} }
@ -107,7 +109,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Vlan, offering.getId(), NetworkVO network = new NetworkVO(offering.getTrafficType(), Mode.Static, BroadcastDomainType.Vlan, offering.getId(),
State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId()); State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId());
if (userSpecified != null) { if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) { (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
throw new InvalidParameterValueException("cidr and gateway must be specified together."); throw new InvalidParameterValueException("cidr and gateway must be specified together.");
} }
@ -146,7 +148,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, public Network implement(Network network, NetworkOffering offering, DeployDestination dest,
ReservationContext context) throws InsufficientVirtualNetworkCapcityException { ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
return network; return network;
@ -155,7 +157,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
DataCenter dc = _configMgr.getZone(network.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
if (!canHandle(offering, dc)) { if (!canHandle(offering, dc)) {
return null; return null;
@ -183,7 +185,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), null); PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), null);
String vlanTag = network.getBroadcastUri().getHost(); String vlanTag = network.getBroadcastUri().getHost();
String netmask = NetUtils.getCidrNetmask(network.getCidr()); String netmask = NetUtils.getCidrNetmask(network.getCidr());
PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask, PrivateIpAddress ip = new PrivateIpAddress(ipVO, vlanTag, network.getGateway(), netmask,
NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()))); NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
nic.setIp4Address(ip.getIpAddress()); nic.setIp4Address(ip.getIpAddress());
@ -204,7 +206,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public void updateNicProfile(NicProfile profile, Network network) { public void updateNicProfile(NicProfile profile, Network network) {
DataCenter dc = _configMgr.getZone(network.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
if (profile != null) { if (profile != null) {
profile.setDns1(dc.getDns1()); profile.setDns1(dc.getDns1());
profile.setDns2(dc.getDns2()); profile.setDns2(dc.getDns2());
@ -216,7 +218,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
DeployDestination dest, ReservationContext context) DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
if (nic.getIp4Address() == null) { if (nic.getIp4Address() == null) {
getIp(nic, _configMgr.getZone(network.getDataCenterId()), network); getIp(nic, _entityMgr.findById(DataCenter.class, network.getDataCenterId()), network);
nic.setStrategy(ReservationStrategy.Create); nic.setStrategy(ReservationStrategy.Create);
} }
} }
@ -238,7 +240,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru {
@Override @Override
public void updateNetworkProfile(NetworkProfile networkProfile) { public void updateNetworkProfile(NetworkProfile networkProfile) {
DataCenter dc = _configMgr.getZone(networkProfile.getDataCenterId()); DataCenter dc = _entityMgr.findById(DataCenter.class, networkProfile.getDataCenterId());
networkProfile.setDns1(dc.getDns1()); networkProfile.setDns1(dc.getDns1());
networkProfile.setDns2(dc.getDns2()); networkProfile.setDns2(dc.getDns2());
} }

View File

@ -147,6 +147,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;
@ -249,6 +250,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
@Inject ApplicationLoadBalancerRuleDao _appLbRuleDao; @Inject ApplicationLoadBalancerRuleDao _appLbRuleDao;
@Inject @Inject
IpAddressManager _ipAddrMgr; IpAddressManager _ipAddrMgr;
@Inject
EntityManager _entityMgr;
// Will return a string. For LB Stickiness this will be a json, for // Will return a string. For LB Stickiness this will be a json, for
// autoscale this will be "," separated values // autoscale this will be "," separated values
@ -305,7 +308,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
String vmName = "AutoScale-LB-" + lbName; String vmName = "AutoScale-LB-" + lbName;
String lbNetworkUuid = null; String lbNetworkUuid = null;
DataCenter zone = _configMgr.getZone(vmGroup.getZoneId()); DataCenter zone = _entityMgr.findById(DataCenter.class, vmGroup.getZoneId());
if (zone == null) { if (zone == null) {
// This should never happen, but still a cautious check // This should never happen, but still a cautious check
s_logger.warn("Unable to find zone while packaging AutoScale Vm Group, zoneid: " + vmGroup.getZoneId()); s_logger.warn("Unable to find zone while packaging AutoScale Vm Group, zoneid: " + vmGroup.getZoneId());

View File

@ -107,6 +107,7 @@ import com.cloud.user.Account;
import com.cloud.user.UserStatisticsVO; import com.cloud.user.UserStatisticsVO;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO; import com.cloud.vm.DomainRouterVO;
@ -124,6 +125,8 @@ 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
@ -374,7 +377,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
Nic nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId()); Nic nic = _nicDao.findByNtwkIdAndInstanceId(network.getId(), router.getId());
String networkDomain = network.getNetworkDomain(); String networkDomain = network.getNetworkDomain();
String dhcpRange = getGuestDhcpRange(guestNic, network, _configMgr.getZone(network.getDataCenterId())); String dhcpRange = getGuestDhcpRange(guestNic, network, _entityMgr.findById(DataCenter.class, network.getDataCenterId()));
NicProfile nicProfile = _networkModel.getNicProfile(router, nic.getNetworkId(), null); NicProfile nicProfile = _networkModel.getNicProfile(router, nic.getNetworkId(), null);

View File

@ -111,6 +111,7 @@ import com.cloud.utils.Ternary;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;
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.GlobalLock; import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.db.JoinBuilder; import com.cloud.utils.db.JoinBuilder;
@ -130,6 +131,8 @@ import com.cloud.vm.dao.DomainRouterDao;
public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService{ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService{
private static final Logger s_logger = Logger.getLogger(VpcManagerImpl.class); private static final Logger s_logger = Logger.getLogger(VpcManagerImpl.class);
@Inject @Inject
EntityManager _entityMgr;
@Inject
VpcOfferingDao _vpcOffDao; VpcOfferingDao _vpcOffDao;
@Inject @Inject
VpcOfferingServiceMapDao _vpcOffSvcMapDao; VpcOfferingServiceMapDao _vpcOffSvcMapDao;
@ -599,7 +602,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
} }
//Validate zone //Validate zone
DataCenter zone = _configMgr.getZone(zoneId); DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) { if (zone == null) {
throw new InvalidParameterValueException("Can't find zone by id specified"); throw new InvalidParameterValueException("Can't find zone by id specified");
} }
@ -961,7 +964,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
//permission check //permission check
_accountMgr.checkAccess(caller, null, false, vpc); _accountMgr.checkAccess(caller, null, false, vpc);
DataCenter dc = _configMgr.getZone(vpc.getZoneId()); DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId());
DeployDestination dest = new DeployDestination(dc, null, null, null); DeployDestination dest = new DeployDestination(dc, null, null, null);
ReservationContext context = new ReservationContextImpl(null, null, callerUser, ReservationContext context = new ReservationContextImpl(null, null, callerUser,

View File

@ -25,6 +25,8 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import javax.naming.NamingException; import javax.naming.NamingException;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd; import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd; import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
@ -50,11 +52,10 @@ import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd; import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd; import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.region.PortableIp; import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpRange; import org.apache.cloudstack.region.PortableIpRange;
import org.springframework.stereotype.Component;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.ConfigurationService; import com.cloud.configuration.ConfigurationService;
import com.cloud.dc.ClusterVO; import com.cloud.dc.ClusterVO;
@ -87,41 +88,6 @@ import com.cloud.user.Account;
import com.cloud.utils.component.ManagerBase; import com.cloud.utils.component.ManagerBase;
import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachine.Type;
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
import org.apache.cloudstack.api.command.admin.ldap.LDAPConfigCmd;
import org.apache.cloudstack.api.command.admin.ldap.LDAPRemoveCmd;
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.CreateDiskOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.CreateServiceOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.DeleteDiskOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd;
import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd;
import org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd;
import org.apache.cloudstack.api.command.admin.vlan.DedicatePublicIpRangeCmd;
import org.apache.cloudstack.api.command.admin.vlan.DeleteVlanIpRangeCmd;
import org.apache.cloudstack.api.command.admin.vlan.ReleasePublicIpRangeCmd;
import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
import org.apache.cloudstack.config.Configuration;
import org.springframework.stereotype.Component;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import javax.naming.NamingException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Component @Component
@Local(value = { ConfigurationManager.class, ConfigurationService.class }) @Local(value = { ConfigurationManager.class, ConfigurationService.class })
public class MockConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService { public class MockConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService {
@ -343,15 +309,6 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu
return null; return null;
} }
/* (non-Javadoc)
* @see com.cloud.configuration.ConfigurationService#getZone(long)
*/
@Override
public DataCenter getZone(long id) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see com.cloud.configuration.ConfigurationService#getServiceOffering(long) * @see com.cloud.configuration.ConfigurationService#getServiceOffering(long)
*/ */