Search in sources :

Example 36 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class NetScalerVMManagerImpl method deployNsVpx.

@Override
public Map<String, Object> deployNsVpx(Account owner, DeployDestination dest, DeploymentPlan plan, long svcOffId, long templateId) throws InsufficientCapacityException {
    VMTemplateVO template = _templateDao.findById(templateId);
    long id = _vmDao.getNextInSequence(Long.class, "id");
    Account systemAcct = _accountMgr.getSystemAccount();
    if (template == null) {
        s_logger.error(" Unable to find the NS VPX template");
        throw new CloudRuntimeException("Unable to find the Template" + templateId);
    }
    long dataCenterId = dest.getDataCenter().getId();
    DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId());
    String nxVpxName = VirtualMachineName.getSystemVmName(id, "Vpx", NetScalerLbVmNamePrefix);
    // using 2GB and 2CPU  offering
    ServiceOfferingVO vpxOffering = _serviceOfferingDao.findById(svcOffId);
    if (vpxOffering.getRamSize() < 2048 && vpxOffering.getCpu() < 2) {
        throw new InvalidParameterValueException("Specified Service Offering :" + vpxOffering.getUuid() + " NS Vpx cannot be deployed. Min 2GB Ram and 2 CPU are required");
    }
    long userId = CallContext.current().getCallingUserId();
    // TODO change the os bits from 142  103 to the actual guest of bits
    if (template.getGuestOSId() != 103) {
        throw new InvalidParameterValueException("Specified Template " + template.getUuid() + " not suitable for NS VPX Deployment. Please register the template with guest os type as unknow(64-bit)");
    }
    NetworkVO defaultNetwork = null;
    NetworkVO defaultPublicNetwork = null;
    if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
        List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
        if (networks == null || networks.size() == 0) {
            throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
        }
        defaultNetwork = networks.get(0);
    } else {
        TrafficType defaultTrafficType = TrafficType.Management;
        List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
        TrafficType publicTrafficType = TrafficType.Public;
        List<NetworkVO> publicNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, publicTrafficType);
        // api should never allow this situation to happen
        if (defaultNetworks.size() != 1) {
            throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
        }
        if (publicNetworks.size() != 1) {
            throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
        }
        defaultPublicNetwork = publicNetworks.get(0);
        defaultNetwork = defaultNetworks.get(0);
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(4);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(0);
    networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<NicProfile>());
    NicProfile defaultNic1 = new NicProfile();
    defaultNic1.setDefaultNic(false);
    defaultNic1.setDeviceId(1);
    NicProfile defaultNic2 = new NicProfile();
    defaultNic2.setDefaultNic(false);
    defaultNic2.setDeviceId(2);
    defaultNic2.setIPv4Address("");
    defaultNic2.setIPv4Gateway("");
    defaultNic2.setIPv4Netmask("");
    String macAddress = _networkDao.getNextAvailableMacAddress(defaultPublicNetwork.getId(), null);
    defaultNic2.setMacAddress(macAddress);
    networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findByUniqueName(NetworkOffering.SystemPublicNetwork), plan, null, null, false).get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic2)));
    networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findByUniqueName(NetworkOffering.SystemControlNetwork), plan, null, null, false).get(0), new ArrayList<NicProfile>());
    long physicalNetworkId = _networkModel.findPhysicalNetworkId(dataCenterId, _networkOfferingDao.findById(defaultPublicNetwork.getNetworkOfferingId()).getTags(), TrafficType.Public);
    // Validate physical network
    PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Unable to find physical network with id: " + physicalNetworkId + " and tag: " + _networkOfferingDao.findById(defaultPublicNetwork.getNetworkOfferingId()).getTags());
    }
    String guestvnet = physicalNetwork.getVnetString();
    final List<VlanVO> vlans = _vlanDao.listByZone(dataCenterId);
    List<String> pvlan = new ArrayList<String>();
    for (final VlanVO vlan : vlans) {
        pvlan.add(vlan.getVlanTag());
    }
    long netScalerProvider = getNetScalerLbProviderId(physicalNetworkId);
    DomainRouterVO nsVpx = new DomainRouterVO(id, vpxOffering.getId(), netScalerProvider, nxVpxName, template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, false, false, VirtualMachine.Type.NetScalerVm, null);
    nsVpx.setRole(Role.NETSCALER_VM);
    nsVpx = _routerDao.persist(nsVpx);
    VMInstanceVO vmVO = _vmDao.findVMByHostName(nxVpxName);
    _itMgr.allocate(nxVpxName, template, vpxOffering, networks, plan, template.getHypervisorType());
    Map<Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
    try {
        if (vmVO != null) {
            startNsVpx(vmVO, params);
        } else {
            throw new NullPointerException();
        }
    } catch (StorageUnavailableException e) {
        e.printStackTrace();
    } catch (ConcurrentOperationException e) {
        e.printStackTrace();
    } catch (ResourceUnavailableException e) {
        e.printStackTrace();
    }
    vmVO = _vmDao.findByUuid(nsVpx.getUuid());
    Map<String, Object> deployResponse = new HashMap<String, Object>();
    deployResponse.put("vm", vmVO);
    deployResponse.put("guestvlan", guestvnet);
    deployResponse.put("publicvlan", pvlan);
    return deployResponse;
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) List(java.util.List) ArrayList(java.util.ArrayList) VlanVO(com.cloud.dc.VlanVO) TrafficType(com.cloud.network.Networks.TrafficType) DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) Param(com.cloud.vm.VirtualMachineProfile.Param) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 37 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class QueryManagerImpl method listDataCentersInternal.

private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(ListZonesCmd cmd) {
    Account account = CallContext.current().getCallingAccount();
    Long domainId = cmd.getDomainId();
    Long id = cmd.getId();
    String keyword = cmd.getKeyword();
    String name = cmd.getName();
    String networkType = cmd.getNetworkType();
    Map<String, String> resourceTags = cmd.getTags();
    SearchBuilder<DataCenterJoinVO> sb = _dcJoinDao.createSearchBuilder();
    if (resourceTags != null && !resourceTags.isEmpty()) {
        SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < resourceTags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    Filter searchFilter = new Filter(DataCenterJoinVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
    searchFilter.addOrderBy(DataCenterJoinVO.class, "id", true);
    SearchCriteria<DataCenterJoinVO> sc = sb.create();
    if (networkType != null) {
        sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    } else if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    } else {
        if (keyword != null) {
            SearchCriteria<DataCenterJoinVO> ssc = _dcJoinDao.createSearchCriteria();
            ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
            ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
            sc.addAnd("name", SearchCriteria.Op.SC, ssc);
        }
        /*
             * List all resources due to Explicit Dedication except the
             * dedicated resources of other account
             */
        if (domainId != null) {
            // 
            // for domainId != null // right now, we made the decision to
            // only list zones associated // with this domain, private zone
            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
            if (_accountMgr.isNormalUser(account.getId())) {
                // accountId == null (zones dedicated to a domain) or
                // accountId = caller
                SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
                sdc.addOr("accountId", SearchCriteria.Op.EQ, account.getId());
                sdc.addOr("accountId", SearchCriteria.Op.NULL);
                sc.addAnd("accountId", SearchCriteria.Op.SC, sdc);
            }
        } else if (_accountMgr.isNormalUser(account.getId())) {
            // it was decided to return all zones for the user's domain, and
            // everything above till root
            // list all zones belonging to this domain, and all of its
            // parents
            // check the parent, if not null, add zones for that parent to
            // list
            // find all domain Id up to root domain for this account
            List<Long> domainIds = new ArrayList<Long>();
            DomainVO domainRecord = _domainDao.findById(account.getDomainId());
            if (domainRecord == null) {
                s_logger.error("Could not find the domainId for account:" + account.getAccountName());
                throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
            }
            domainIds.add(domainRecord.getId());
            while (domainRecord.getParent() != null) {
                domainRecord = _domainDao.findById(domainRecord.getParent());
                domainIds.add(domainRecord.getId());
            }
            // domainId == null (public zones) or domainId IN [all domain id
            // up to root domain]
            SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
            sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray());
            sdc.addOr("domainId", SearchCriteria.Op.NULL);
            sc.addAnd("domainId", SearchCriteria.Op.SC, sdc);
            // remove disabled zones
            sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled);
            // accountId == null (zones dedicated to a domain) or
            // accountId = caller
            SearchCriteria<DataCenterJoinVO> sdc2 = _dcJoinDao.createSearchCriteria();
            sdc2.addOr("accountId", SearchCriteria.Op.EQ, account.getId());
            sdc2.addOr("accountId", SearchCriteria.Op.NULL);
            sc.addAnd("accountId", SearchCriteria.Op.SC, sdc2);
            // remove Dedicated zones not dedicated to this domainId or
            // subdomainId
            List<Long> dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds);
            if (!dedicatedZoneIds.isEmpty()) {
                sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()]));
            }
        } else if (_accountMgr.isDomainAdmin(account.getId()) || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
            // it was decided to return all zones for the domain admin, and
            // everything above till root, as well as zones till the domain
            // leaf
            List<Long> domainIds = new ArrayList<Long>();
            DomainVO domainRecord = _domainDao.findById(account.getDomainId());
            if (domainRecord == null) {
                s_logger.error("Could not find the domainId for account:" + account.getAccountName());
                throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName());
            }
            domainIds.add(domainRecord.getId());
            // find all domain Ids till leaf
            List<DomainVO> allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId());
            for (DomainVO domain : allChildDomains) {
                domainIds.add(domain.getId());
            }
            // then find all domain Id up to root domain for this account
            while (domainRecord.getParent() != null) {
                domainRecord = _domainDao.findById(domainRecord.getParent());
                domainIds.add(domainRecord.getId());
            }
            // domainId == null (public zones) or domainId IN [all domain id
            // up to root domain]
            SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
            sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray());
            sdc.addOr("domainId", SearchCriteria.Op.NULL);
            sc.addAnd("domainId", SearchCriteria.Op.SC, sdc);
            // remove disabled zones
            sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled);
            // remove Dedicated zones not dedicated to this domainId or
            // subdomainId
            List<Long> dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds);
            if (!dedicatedZoneIds.isEmpty()) {
                sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()]));
            }
        }
        // handle available=FALSE option, only return zones with at least
        // one VM running there
        Boolean available = cmd.isAvailable();
        if (account != null) {
            if ((available != null) && Boolean.FALSE.equals(available)) {
                // data centers with
                Set<Long> dcIds = new HashSet<Long>();
                // at least one VM
                // running
                List<DomainRouterVO> routers = _routerDao.listBy(account.getId());
                for (DomainRouterVO router : routers) {
                    dcIds.add(router.getDataCenterId());
                }
                if (dcIds.size() == 0) {
                    return new Pair<List<DataCenterJoinVO>, Integer>(new ArrayList<DataCenterJoinVO>(), 0);
                } else {
                    sc.addAnd("id", SearchCriteria.Op.IN, dcIds.toArray());
                }
            }
        }
    }
    if (resourceTags != null && !resourceTags.isEmpty()) {
        int count = 0;
        sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.Zone.toString());
        for (Map.Entry<String, String> entry : resourceTags.entrySet()) {
            sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), entry.getKey());
            sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), entry.getValue());
            count++;
        }
    }
    return _dcJoinDao.searchAndCount(sc, searchFilter);
}
Also used : DataCenterJoinVO(com.cloud.api.query.vo.DataCenterJoinVO) Account(com.cloud.user.Account) HashSet(java.util.HashSet) Set(java.util.Set) CloudAuthenticationException(com.cloud.exception.CloudAuthenticationException) ArrayList(java.util.ArrayList) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) SearchCriteria(com.cloud.utils.db.SearchCriteria) DomainVO(com.cloud.domain.DomainVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) Map(java.util.Map) HashMap(java.util.HashMap) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 38 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class BaremetalKickStartServiceImpl method getVirtualRouter.

private DomainRouterVO getVirtualRouter(Network network) {
    List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), VirtualRouter.Role.VIRTUAL_ROUTER);
    if (routers.isEmpty()) {
        throw new CloudRuntimeException(String.format("cannot find any running virtual router on network[id:%s, uuid:%s]", network.getId(), network.getUuid()));
    }
    if (routers.size() > 1) {
        throw new CloudRuntimeException(String.format("baremetal hasn't supported redundant router yet"));
    }
    DomainRouterVO vr = routers.get(0);
    if (!Hypervisor.HypervisorType.VMware.equals(vr.getHypervisorType())) {
        throw new CloudRuntimeException(String.format("baremetal only support vmware virtual router, but get %s", vr.getHypervisorType()));
    }
    return vr;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 39 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId());
    boolean result = true;
    Answer answer = cmds.getAnswer("checkSsh");
    if (answer != null && answer instanceof CheckSshAnswer) {
        final CheckSshAnswer sshAnswer = (CheckSshAnswer) answer;
        if (sshAnswer == null || !sshAnswer.getResult()) {
            s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails());
            result = false;
        }
    } else {
        result = false;
    }
    if (result == false) {
        return result;
    }
    // Get guest network info
    final List<Network> guestNetworks = new ArrayList<Network>();
    final List<? extends Nic> internalLbVmNics = _nicDao.listByVmId(profile.getId());
    for (final Nic internalLbVmNic : internalLbVmNics) {
        final Network network = _ntwkModel.getNetwork(internalLbVmNic.getNetworkId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
        }
    }
    answer = cmds.getAnswer("getDomRVersion");
    if (answer != null && answer instanceof GetDomRVersionAnswer) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) answer;
        if (answer == null || !answer.getResult()) {
            s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() + " due to: " + versionAnswer.getDetails());
            result = false;
        } else {
            internalLbVm.setTemplateVersion(versionAnswer.getTemplateVersion());
            internalLbVm.setScriptsVersion(versionAnswer.getScriptsVersion());
            internalLbVm = _internalLbVmDao.persist(internalLbVm, guestNetworks);
        }
    } else {
        result = false;
    }
    return result;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 40 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method stopInternalLbVm.

@Override
public VirtualRouter stopInternalLbVm(final long vmId, final boolean forced, final Account caller, final long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException {
    final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId);
    if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
        throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
    }
    // check permissions
    _accountMgr.checkAccess(caller, null, true, internalLbVm);
    return stopInternalLbVm(internalLbVm, forced, caller, callerUserId);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)253 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)64 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 DataCenterVO (com.cloud.dc.DataCenterVO)36 Network (com.cloud.network.Network)34 Test (org.junit.Test)32 NicProfile (com.cloud.vm.NicProfile)29 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)28 Zone (com.cloud.db.model.Zone)27 Account (com.cloud.user.Account)27 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 Vpc (com.cloud.network.vpc.Vpc)22 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)17 HashMap (java.util.HashMap)17 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)16 NetworkVO (com.cloud.network.dao.NetworkVO)16 UserVmVO (com.cloud.vm.UserVmVO)15 Answer (com.cloud.agent.api.Answer)14