Search in sources :

Example 1 with DomainRouterJoinVO

use of com.cloud.api.query.vo.DomainRouterJoinVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method getRouterHealthChecksConfig.

private Map<String, String> getRouterHealthChecksConfig(final DomainRouterVO router) {
    Map<String, String> data = new HashMap<>();
    List<DomainRouterJoinVO> routerJoinVOs = domainRouterJoinDao.searchByIds(router.getId());
    StringBuilder vmsData = new StringBuilder();
    StringBuilder portData = new StringBuilder();
    StringBuilder loadBalancingData = new StringBuilder();
    StringBuilder gateways = new StringBuilder();
    gateways.append("gatewaysIps=");
    for (DomainRouterJoinVO routerJoinVO : routerJoinVOs) {
        if (StringUtils.isNotBlank(routerJoinVO.getGateway())) {
            gateways.append(routerJoinVO.getGateway() + " ");
        }
        SearchBuilder<UserVmJoinVO> sbvm = userVmJoinDao.createSearchBuilder();
        sbvm.and("networkId", sbvm.entity().getNetworkId(), SearchCriteria.Op.EQ);
        SearchCriteria<UserVmJoinVO> scvm = sbvm.create();
        scvm.setParameters("networkId", routerJoinVO.getNetworkId());
        List<UserVmJoinVO> vms = userVmJoinDao.search(scvm, null);
        boolean isDhcpSupported = _ntwkSrvcDao.areServicesSupportedInNetwork(routerJoinVO.getNetworkId(), Service.Dhcp);
        boolean isDnsSupported = _ntwkSrvcDao.areServicesSupportedInNetwork(routerJoinVO.getNetworkId(), Service.Dns);
        for (UserVmJoinVO vm : vms) {
            if (vm.getState() != VirtualMachine.State.Running) {
                continue;
            }
            vmsData.append("vmName=").append(vm.getName()).append(",macAddress=").append(vm.getMacAddress()).append(",ip=").append(vm.getIpAddress()).append(",dhcp=").append(isDhcpSupported).append(",dns=").append(isDnsSupported).append(";");
            updateWithPortForwardingRules(routerJoinVO, vm, portData);
        }
        updateWithLbRules(routerJoinVO, loadBalancingData);
    }
    String routerVersion = getRouterVersionHealthChecksData(router);
    data.put("virtualMachines", vmsData.toString());
    data.put("gateways", gateways.toString());
    data.put("portForwarding", portData.toString());
    data.put("haproxyData", loadBalancingData.toString());
    data.put("systemThresholds", getSystemThresholdsHealthChecksData(router));
    if (routerVersion != null) {
        data.put("routerVersion", routerVersion);
    }
    return data;
}
Also used : HashMap(java.util.HashMap) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Example 2 with DomainRouterJoinVO

use of com.cloud.api.query.vo.DomainRouterJoinVO in project cloudstack by apache.

the class ViewResponseHelper method createDomainRouterResponse.

public static List<DomainRouterResponse> createDomainRouterResponse(DomainRouterJoinVO... routers) {
    Account caller = CallContext.current().getCallingAccount();
    Hashtable<Long, DomainRouterResponse> vrDataList = new Hashtable<Long, DomainRouterResponse>();
    // Initialise the vrdatalist with the input data
    for (DomainRouterJoinVO vr : routers) {
        DomainRouterResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newDomainRouterResponse(vr, caller);
        } else {
            // update nics for 1 to many mapping fields
            vrData = ApiDBUtils.fillRouterDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<DomainRouterResponse>(vrDataList.values());
}
Also used : Account(com.cloud.user.Account) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Example 3 with DomainRouterJoinVO

use of com.cloud.api.query.vo.DomainRouterJoinVO in project cosmic by MissionCriticalCloud.

the class QueryManagerImpl method searchForRoutersInternal.

private Pair<List<DomainRouterJoinVO>, Integer> searchForRoutersInternal(final BaseListProjectAndAccountResourcesCmd cmd, final Long id, final String name, final String state, final Long zoneId, final Long podId, final Long clusterId, final Long hostId, final String keyword, final Long networkId, final Long vpcId, final Boolean forVpc, final String role, final String version) {
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
    _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
    final Long domainId = domainIdRecursiveListProject.first();
    final Boolean isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter searchFilter = new Filter(DomainRouterJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchBuilder<DomainRouterJoinVO> sb = _routerJoinDao.createSearchBuilder();
    // select distinct
    sb.select(null, Func.DISTINCT, sb.entity().getId());
    // ids to get
    // number of
    // records with
    // pagination
    _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("name", sb.entity().getInstanceName(), SearchCriteria.Op.LIKE);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.IN);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
    sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
    sb.and("hostId", sb.entity().getHostId(), SearchCriteria.Op.EQ);
    sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
    sb.and("role", sb.entity().getRole(), SearchCriteria.Op.EQ);
    sb.and("version", sb.entity().getTemplateVersion(), SearchCriteria.Op.LIKE);
    if (forVpc != null) {
        if (forVpc) {
            sb.and("forVpc", sb.entity().getVpcId(), SearchCriteria.Op.NNULL);
        } else {
            sb.and("forVpc", sb.entity().getVpcId(), SearchCriteria.Op.NULL);
        }
    }
    if (networkId != null) {
        sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
    }
    final SearchCriteria<DomainRouterJoinVO> sc = sb.create();
    _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (keyword != null) {
        final SearchCriteria<DomainRouterJoinVO> ssc = _routerJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("instanceName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("networkName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("vpcName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("instanceName", SearchCriteria.Op.SC, ssc);
    }
    if (name != null) {
        sc.setParameters("name", "%" + name + "%");
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (state != null) {
        sc.setParameters("state", state);
    }
    if (zoneId != null) {
        sc.setParameters("dataCenterId", zoneId);
    }
    if (podId != null) {
        sc.setParameters("podId", podId);
    }
    if (clusterId != null) {
        sc.setParameters("clusterId", clusterId);
    }
    if (hostId != null) {
        sc.setParameters("hostId", hostId);
    }
    if (networkId != null) {
        sc.setParameters("networkId", networkId);
    }
    if (vpcId != null) {
        sc.setParameters("vpcId", vpcId);
    }
    if (role != null) {
        sc.setParameters("role", role);
    }
    if (version != null) {
        sc.setParameters("version", "Cloudstack Release " + version + "%");
    }
    // search VR details by ids
    final Pair<List<DomainRouterJoinVO>, Integer> uniqueVrPair = _routerJoinDao.searchAndCount(sc, searchFilter);
    final Integer count = uniqueVrPair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniqueVrPair;
    }
    final List<DomainRouterJoinVO> uniqueVrs = uniqueVrPair.first();
    final Long[] vrIds = new Long[uniqueVrs.size()];
    int i = 0;
    for (final DomainRouterJoinVO v : uniqueVrs) {
        vrIds[i++] = v.getId();
    }
    final List<DomainRouterJoinVO> vrs = _routerJoinDao.searchByIds(vrIds);
    return new Pair<>(vrs, count);
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 4 with DomainRouterJoinVO

use of com.cloud.api.query.vo.DomainRouterJoinVO in project cosmic by MissionCriticalCloud.

the class ViewResponseHelper method createDomainRouterResponse.

public static List<DomainRouterResponse> createDomainRouterResponse(final DomainRouterJoinVO... routers) {
    final Account caller = CallContext.current().getCallingAccount();
    final Hashtable<Long, DomainRouterResponse> vrDataList = new Hashtable<>();
    // Initialise the vrdatalist with the input data
    for (final DomainRouterJoinVO vr : routers) {
        DomainRouterResponse vrData = vrDataList.get(vr.getId());
        if (vrData == null) {
            // first time encountering this vm
            vrData = ApiDBUtils.newDomainRouterResponse(vr, caller);
        } else {
            // update nics for 1 to many mapping fields
            vrData = ApiDBUtils.fillRouterDetails(vrData, vr);
        }
        vrDataList.put(vr.getId(), vrData);
    }
    return new ArrayList<>(vrDataList.values());
}
Also used : Account(com.cloud.user.Account) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DomainRouterResponse(com.cloud.api.response.DomainRouterResponse) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Example 5 with DomainRouterJoinVO

use of com.cloud.api.query.vo.DomainRouterJoinVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method getVlanToPersistenceMapForVM.

private Map<String, Boolean> getVlanToPersistenceMapForVM(long vmId) {
    List<UserVmJoinVO> userVmJoinVOs = userVmJoinDao.searchByIds(vmId);
    Map<String, Boolean> vlanToPersistenceMap = new HashMap<>();
    if (userVmJoinVOs != null && !userVmJoinVOs.isEmpty()) {
        for (UserVmJoinVO userVmJoinVO : userVmJoinVOs) {
            NetworkVO networkVO = _networkDao.findById(userVmJoinVO.getNetworkId());
            updatePersistenceMap(vlanToPersistenceMap, networkVO);
        }
    } else {
        VMInstanceVO vmInstanceVO = _vmDao.findById(vmId);
        if (vmInstanceVO != null && vmInstanceVO.getType() == VirtualMachine.Type.DomainRouter) {
            DomainRouterJoinVO routerVO = domainRouterJoinDao.findById(vmId);
            NetworkVO networkVO = _networkDao.findById(routerVO.getNetworkId());
            updatePersistenceMap(vlanToPersistenceMap, networkVO);
        }
    }
    return vlanToPersistenceMap;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Aggregations

DomainRouterJoinVO (com.cloud.api.query.vo.DomainRouterJoinVO)9 ArrayList (java.util.ArrayList)6 Account (com.cloud.user.Account)4 List (java.util.List)4 DomainRouterResponse (org.apache.cloudstack.api.response.DomainRouterResponse)3 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 Pair (com.cloud.utils.Pair)2 Ternary (com.cloud.utils.Ternary)2 Filter (com.cloud.utils.db.Filter)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 RouterHealthCheckResultVO (com.cloud.network.dao.RouterHealthCheckResultVO)1 User (com.cloud.user.User)1 LinkedHashMap (java.util.LinkedHashMap)1