use of com.cloud.dc.PodVlanMapVO in project cloudstack by apache.
the class LoadBalanceRuleHandlerTest method testFindElbVmWithCapacityWhenThereAreUnusedElbVmsAndOneMatchesThePodId.
@Test
public void testFindElbVmWithCapacityWhenThereAreUnusedElbVmsAndOneMatchesThePodId() throws Exception {
Long podId = 1L;
IPAddressVO ipAddrMock = mock(IPAddressVO.class);
when(ipAddrMock.getVlanId()).thenReturn(podId);
PodVlanMapVO podVlanMapVoMock = mock(PodVlanMapVO.class);
when(podVlanMapVoMock.getPodId()).thenReturn(podId);
when(podVlanMapDao.listPodVlanMapsByVlan(podId)).thenReturn(podVlanMapVoMock);
DomainRouterVO unusedElbVmThatMatchesPodId = mock(DomainRouterVO.class);
when(unusedElbVmThatMatchesPodId.getPodIdToDeployIn()).thenReturn(podId);
List<DomainRouterVO> unusedElbVms = Arrays.asList(new DomainRouterVO[] { unusedElbVmThatMatchesPodId, mock(DomainRouterVO.class) });
when(this.elasticLbVmMapDao.listUnusedElbVms()).thenReturn(unusedElbVms);
DomainRouterVO expected = unusedElbVmThatMatchesPodId;
DomainRouterVO actual = loadBalanceRuleHandler.findElbVmWithCapacity(ipAddrMock);
assertNotNull(actual);
assertEquals(expected, actual);
}
use of com.cloud.dc.PodVlanMapVO in project cloudstack by apache.
the class ConfigurationManagerImpl method commitVlanAndIpRange.
private VlanVO commitVlanAndIpRange(final long zoneId, final long networkId, final long physicalNetworkId, final Long podId, final String startIP, final String endIP, final String vlanGateway, final String vlanNetmask, final String vlanId, final Domain domain, final Account vlanOwner, final String vlanIp6Gateway, final String vlanIp6Cidr, final boolean ipv4, final DataCenterVO zone, final VlanType vlanType, final String ipv6Range, final String ipRange) {
return Transaction.execute(new TransactionCallback<VlanVO>() {
@Override
public VlanVO doInTransaction(final TransactionStatus status) {
VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId, physicalNetworkId, vlanIp6Gateway, vlanIp6Cidr, ipv6Range);
s_logger.debug("Saving vlan range " + vlan);
vlan = _vlanDao.persist(vlan);
// public ip range
if (ipv4) {
if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId(), networkId, physicalNetworkId)) {
throw new CloudRuntimeException("Failed to save IPv4 range. Please contact Cloud Support.");
}
}
if (vlanOwner != null) {
// This VLAN is account-specific, so create an AccountVlanMapVO
// entry
final AccountVlanMapVO accountVlanMapVO = new AccountVlanMapVO(vlanOwner.getId(), vlan.getId());
_accountVlanMapDao.persist(accountVlanMapVO);
// generate usage event for dedication of every ip address in the
// range
final List<IPAddressVO> ips = _publicIpAddressDao.listByVlanId(vlan.getId());
for (final IPAddressVO ip : ips) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_ASSIGN, vlanOwner.getId(), ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(), vlan.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), ip.getUuid());
}
// increment resource count for dedicated public ip's
_resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip, new Long(ips.size()));
} else if (domain != null) {
// This VLAN is domain-wide, so create a DomainVlanMapVO entry
final DomainVlanMapVO domainVlanMapVO = new DomainVlanMapVO(domain.getId(), vlan.getId());
_domainVlanMapDao.persist(domainVlanMapVO);
} else if (podId != null) {
// This VLAN is pod-wide, so create a PodVlanMapVO entry
final PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId());
_podVlanMapDao.persist(podVlanMapVO);
}
return vlan;
}
});
}
use of com.cloud.dc.PodVlanMapVO in project cloudstack by apache.
the class DirectPodBasedNetworkGuru method reserve.
@Override
@DB
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
String oldIp = nic.getIPv4Address();
boolean getNewIp = false;
if (oldIp == null) {
getNewIp = true;
} else {
// we need to get a new ip address if we try to deploy a vm in a different pod
final IPAddressVO ipVO = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), oldIp);
if (ipVO != null) {
PodVlanMapVO mapVO = _podVlanDao.listPodVlanMapsByVlan(ipVO.getVlanId());
if (mapVO.getPodId() != dest.getPod().getId()) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
//release the old ip here
_ipAddrMgr.markIpAsUnavailable(ipVO.getId());
_ipAddressDao.unassignIpAddress(ipVO.getId());
}
});
nic.setIPv4Address(null);
getNewIp = true;
}
}
}
if (getNewIp) {
//we don't set reservationStrategy to Create because we need this method to be called again for the case when vm fails to deploy in Pod1, and we try to redeploy it in Pod2
getIp(nic, dest.getPod(), vm, network);
}
DataCenter dc = _dcDao.findById(network.getDataCenterId());
nic.setIPv4Dns1(dc.getDns1());
nic.setIPv4Dns2(dc.getDns2());
}
use of com.cloud.dc.PodVlanMapVO in project cloudstack by apache.
the class VlanDaoImpl method addToPod.
@Override
public void addToPod(long podId, long vlanDbId) {
PodVlanMapVO pvmvo = new PodVlanMapVO(podId, vlanDbId);
_podVlanMapDao.persist(pvmvo);
}
use of com.cloud.dc.PodVlanMapVO in project cloudstack by apache.
the class ManagementServerImpl method searchForVlans.
@Override
public Pair<List<? extends Vlan>, Integer> searchForVlans(final ListVlanIpRangesCmd cmd) {
// If an account name and domain ID are specified, look up the account
final String accountName = cmd.getAccountName();
final Long domainId = cmd.getDomainId();
Long accountId = null;
final Long networkId = cmd.getNetworkId();
final Boolean forVirtual = cmd.getForVirtualNetwork();
String vlanType = null;
final Long projectId = cmd.getProjectId();
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
if (accountName != null && domainId != null) {
if (projectId != null) {
throw new InvalidParameterValueException("Account and projectId can't be specified together");
}
final Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
// Since we don't have a DomainVO object here, we directly set
// tablename to "domain".
final DomainVO domain = ApiDBUtils.findDomainById(domainId);
String domainUuid = domainId.toString();
if (domain != null) {
domainUuid = domain.getUuid();
}
ex.addProxyObject(domainUuid, "domainId");
throw ex;
} else {
accountId = account.getId();
}
}
if (forVirtual != null) {
if (forVirtual) {
vlanType = VlanType.VirtualNetwork.toString();
} else {
vlanType = VlanType.DirectAttached.toString();
}
}
// set project information
if (projectId != null) {
final Project project = _projectMgr.getProject(projectId);
if (project == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project by id " + projectId);
ex.addProxyObject(projectId.toString(), "projectId");
throw ex;
}
accountId = project.getProjectAccountId();
}
final Filter searchFilter = new Filter(VlanVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
final Object id = cmd.getId();
final Object vlan = cmd.getVlan();
final Object dataCenterId = cmd.getZoneId();
final Object podId = cmd.getPodId();
final Object keyword = cmd.getKeyword();
final SearchBuilder<VlanVO> sb = _vlanDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("vlan", sb.entity().getVlanTag(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("vlan", sb.entity().getVlanTag(), SearchCriteria.Op.EQ);
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
sb.and("vlanType", sb.entity().getVlanType(), SearchCriteria.Op.EQ);
sb.and("physicalNetworkId", sb.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
if (accountId != null) {
final SearchBuilder<AccountVlanMapVO> accountVlanMapSearch = _accountVlanMapDao.createSearchBuilder();
accountVlanMapSearch.and("accountId", accountVlanMapSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
sb.join("accountVlanMapSearch", accountVlanMapSearch, sb.entity().getId(), accountVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.INNER);
}
if (podId != null) {
final SearchBuilder<PodVlanMapVO> podVlanMapSearch = _podVlanMapDao.createSearchBuilder();
podVlanMapSearch.and("podId", podVlanMapSearch.entity().getPodId(), SearchCriteria.Op.EQ);
sb.join("podVlanMapSearch", podVlanMapSearch, sb.entity().getId(), podVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.INNER);
}
final SearchCriteria<VlanVO> sc = sb.create();
if (keyword != null) {
final SearchCriteria<VlanVO> ssc = _vlanDao.createSearchCriteria();
ssc.addOr("vlanTag", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("ipRange", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("vlanTag", SearchCriteria.Op.SC, ssc);
} else {
if (id != null) {
sc.setParameters("id", id);
}
if (vlan != null) {
sc.setParameters("vlan", vlan);
}
if (dataCenterId != null) {
sc.setParameters("dataCenterId", dataCenterId);
}
if (networkId != null) {
sc.setParameters("networkId", networkId);
}
if (accountId != null) {
sc.setJoinParameters("accountVlanMapSearch", "accountId", accountId);
}
if (podId != null) {
sc.setJoinParameters("podVlanMapSearch", "podId", podId);
}
if (vlanType != null) {
sc.setParameters("vlanType", vlanType);
}
if (physicalNetworkId != null) {
sc.setParameters("physicalNetworkId", physicalNetworkId);
}
}
final Pair<List<VlanVO>, Integer> result = _vlanDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends Vlan>, Integer>(result.first(), result.second());
}
Aggregations