use of com.cloud.vm.DomainRouterVO 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.vm.DomainRouterVO in project cloudstack by apache.
the class LoadBalanceRuleHandlerTest method testStartWhenParamsIsEmpty.
@Test
public void testStartWhenParamsIsEmpty() throws Exception {
DomainRouterVO elbVmMock = mock(DomainRouterVO.class);
String uuid = "uuid";
when(elbVmMock.getUuid()).thenReturn(uuid);
long id = 1L;
when(elbVmMock.getId()).thenReturn(id);
Map<Param, Object> params = new HashMap<Param, Object>();
loadBalanceRuleHandler.start(elbVmMock, params);
verify(virtualMachineManagerMock, times(1)).start(uuid, params);
verify(domainRouterDaoMock, times(1)).findById(id);
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class LoadBalanceRuleHandler method deployLoadBalancerVM.
private DomainRouterVO deployLoadBalancerVM(final Long networkId, final IPAddressVO ipAddr) {
final NetworkVO network = _networkDao.findById(networkId);
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
final Long podId = getPodIdForDirectIp(ipAddr);
final Pod pod = podId == null ? null : _podDao.findById(podId);
final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
final Account owner = _accountService.getActiveAccountByName("system", new Long(1));
final DeployDestination dest = new DeployDestination(dc, pod, null, null);
s_logger.debug("About to deploy ELB vm ");
try {
final DomainRouterVO elbVm = deployELBVm(network, dest, owner, params);
if (elbVm == null) {
throw new InvalidParameterValueException("Could not deploy or find existing ELB VM");
}
s_logger.debug("Deployed ELB vm = " + elbVm);
return elbVm;
} catch (final Throwable t) {
s_logger.warn("Error while deploying ELB VM: ", t);
return null;
}
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class ElasticLoadBalancerManagerImpl method findElbVmForLb.
protected DomainRouterVO findElbVmForLb(LoadBalancingRule lb) {
//TODO: use a table to lookup
Network ntwk = _networkModel.getNetwork(lb.getNetworkId());
long sourceIpId = _networkModel.getPublicIpAddress(lb.getSourceIp().addr(), ntwk.getDataCenterId()).getId();
ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(sourceIpId);
if (map == null) {
return null;
}
DomainRouterVO elbVm = _routerDao.findById(map.getElbVmId());
return elbVm;
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class ElasticLoadBalancerManagerImpl method finalizeDeployment.
@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId());
List<NicProfile> nics = profile.getNics();
for (NicProfile nic : nics) {
if (nic.getTrafficType() == TrafficType.Public) {
elbVm.setPublicIpAddress(nic.getIPv4Address());
elbVm.setPublicNetmask(nic.getIPv4Netmask());
elbVm.setPublicMacAddress(nic.getMacAddress());
} else if (nic.getTrafficType() == TrafficType.Control) {
elbVm.setPrivateIpAddress(nic.getIPv4Address());
elbVm.setPrivateMacAddress(nic.getMacAddress());
}
}
_routerDao.update(elbVm.getId(), elbVm);
finalizeCommandsOnStart(cmds, profile);
return true;
}
Aggregations