use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method getDeploymentPlanAndInternalLbVms.
protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndInternalLbVms(final DeployDestination dest, final long guestNetworkId, final Ip requestedGuestIp) {
final long dcId = dest.getDataCenter().getId();
final DeploymentPlan plan = new DataCenterDeployment(dcId);
final List<DomainRouterVO> internalLbVms = findInternalLbVms(guestNetworkId, requestedGuestIp);
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, internalLbVms);
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method deployInternalLbVm.
protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDestination dest, final DeploymentPlan plan, final Map<Param, Object> params, final long internalLbProviderId, final long svcOffId, final Long vpcId, final LinkedHashMap<Network, List<? extends NicProfile>> networks, final boolean startVm) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
// Internal lb is the network element, we don't know the hypervisor type yet.
// Try to allocate the internal lb twice using diff hypervisors, and when failed both times, throw the exception up
final List<HypervisorType> hypervisors = getHypervisors(dest, plan, null);
int allocateRetry = 0;
int startRetry = 0;
DomainRouterVO internalLbVm = null;
for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext(); ) {
final HypervisorType hType = iter.next();
try {
final long id = _internalLbVmDao.getNextInSequence(Long.class, "id");
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating the internal lb vm " + id + " in datacenter " + dest.getDataCenter() + " with hypervisor type " + hType);
}
String templateName = null;
switch(hType) {
case XenServer:
templateName = VirtualNetworkApplianceManager.RouterTemplateXen.valueIn(dest.getDataCenter().getId());
break;
case KVM:
templateName = VirtualNetworkApplianceManager.RouterTemplateKvm.valueIn(dest.getDataCenter().getId());
break;
case VMware:
templateName = VirtualNetworkApplianceManager.RouterTemplateVmware.valueIn(dest.getDataCenter().getId());
break;
case Hyperv:
templateName = VirtualNetworkApplianceManager.RouterTemplateHyperV.valueIn(dest.getDataCenter().getId());
break;
case LXC:
templateName = VirtualNetworkApplianceManager.RouterTemplateLxc.valueIn(dest.getDataCenter().getId());
break;
default:
break;
}
final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
if (template == null) {
s_logger.debug(hType + " won't support system vm, skip it");
continue;
}
long userId = CallContext.current().getCallingUserId();
if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
if (!userVOs.isEmpty()) {
userId = userVOs.get(0).getId();
}
}
internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProviderId, VirtualMachineName.getSystemVmName(id, _instance, InternalLbVmNamePrefix), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
internalLbVm.setRole(Role.INTERNAL_LB_VM);
internalLbVm = _internalLbVmDao.persist(internalLbVm);
_itMgr.allocate(internalLbVm.getInstanceName(), template, routerOffering, networks, plan, null);
internalLbVm = _internalLbVmDao.findById(internalLbVm.getId());
} catch (final InsufficientCapacityException ex) {
if (allocateRetry < 2 && iter.hasNext()) {
s_logger.debug("Failed to allocate the Internal lb vm with hypervisor type " + hType + ", retrying one more time");
continue;
} else {
throw ex;
}
} finally {
allocateRetry++;
}
if (startVm) {
try {
internalLbVm = startInternalLbVm(internalLbVm, _accountMgr.getSystemAccount(), User.UID_SYSTEM, params);
break;
} catch (final InsufficientCapacityException ex) {
if (startRetry < 2 && iter.hasNext()) {
s_logger.debug("Failed to start the Internal lb vm " + internalLbVm + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time");
// destroy the internal lb vm
destroyInternalLbVm(internalLbVm.getId(), _accountMgr.getSystemAccount(), User.UID_SYSTEM);
continue;
} else {
throw ex;
}
} finally {
startRetry++;
}
} else {
// return stopped internal lb vm
return internalLbVm;
}
}
return internalLbVm;
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method destroyInternalLbVm.
@Override
public boolean destroyInternalLbVm(final long vmId, final Account caller, final Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Attempting to destroy Internal LB vm " + vmId);
}
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
if (internalLbVm == null) {
return true;
}
_accountMgr.checkAccess(caller, null, true, internalLbVm);
_itMgr.expunge(internalLbVm.getUuid());
_internalLbVmDao.remove(internalLbVm.getId());
return true;
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method getInternalLbControlIp.
protected String getInternalLbControlIp(final long internalLbVmId) {
String controlIpAddress = null;
final List<NicVO> nics = _nicDao.listByVmId(internalLbVmId);
for (final NicVO nic : nics) {
final Network ntwk = _ntwkModel.getNetwork(nic.getNetworkId());
if (ntwk.getTrafficType() == TrafficType.Control) {
controlIpAddress = nic.getIPv4Address();
}
}
if (controlIpAddress == null) {
s_logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId);
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId);
return internalLbVm.getPrivateIpAddress();
}
return controlIpAddress;
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLBVMManagerTest method setUp.
@Override
@Before
public void setUp() {
// mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
list.add(off);
list.add(off);
Mockito.when(_svcOffDao.createSystemServiceOfferings(nullable(String.class), nullable(String.class), nullable(Integer.class), nullable(Integer.class), nullable(Integer.class), nullable(Integer.class), nullable(Integer.class), nullable(Boolean.class), nullable(String.class), nullable(ProvisioningType.class), nullable(Boolean.class), nullable(String.class), nullable(Boolean.class), nullable(VirtualMachine.Type.class), nullable(Boolean.class))).thenReturn(list);
ComponentContext.initComponentsLifeCycle();
vm = new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
vm.setRole(Role.INTERNAL_LB_VM);
vm = setId(vm, 1);
vm.setPrivateIpAddress("10.2.2.2");
final NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
nic.setIPv4Address(requestedIp);
final List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
final List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
nonEmptyList.add(vm);
Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
final Answer answer = new Answer(null, true, null);
final Answer[] answers = new Answer[1];
answers[0] = answer;
try {
Mockito.when(_agentMgr.send(nullable(Long.class), nullable(Commands.class))).thenReturn(answers);
} catch (final AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
createNetwork();
Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk);
Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null);
Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm);
final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
networkOfferingVO.setConcurrentConnections(500);
Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO);
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
}
Aggregations