Search in sources :

Example 6 with DomainRouterJoinVO

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

the class QueryManagerImpl method searchForRouters.

@Override
public ListResponse<DomainRouterResponse> searchForRouters(ListRoutersCmd cmd) {
    Pair<List<DomainRouterJoinVO>, Integer> result = searchForRoutersInternal(cmd, cmd.getId(), cmd.getRouterName(), cmd.getState(), cmd.getZoneId(), cmd.getPodId(), cmd.getClusterId(), cmd.getHostId(), cmd.getKeyword(), cmd.getNetworkId(), cmd.getVpcId(), cmd.getForVpc(), cmd.getRole(), cmd.getVersion(), cmd.isHealthCheckFailed());
    ListResponse<DomainRouterResponse> response = new ListResponse<DomainRouterResponse>();
    List<DomainRouterResponse> routerResponses = ViewResponseHelper.createDomainRouterResponse(result.first().toArray(new DomainRouterJoinVO[result.first().size()]));
    if (VirtualNetworkApplianceManager.RouterHealthChecksEnabled.value()) {
        for (DomainRouterResponse res : routerResponses) {
            DomainRouterVO resRouter = _routerDao.findByUuid(res.getId());
            res.setHealthChecksFailed(routerHealthCheckResultDao.hasFailingChecks(resRouter.getId()));
            if (cmd.shouldFetchHealthCheckResults()) {
                res.setHealthCheckResults(responseGenerator.createHealthCheckResponse(resRouter, new ArrayList<>(routerHealthCheckResultDao.getHealthCheckResults(resRouter.getId()))));
            }
        }
    }
    response.setResponses(routerResponses, result.second());
    return response;
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) DomainRouterVO(com.cloud.vm.DomainRouterVO) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Example 7 with DomainRouterJoinVO

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

the class QueryManagerImpl method searchForInternalLbVms.

@Override
public ListResponse<DomainRouterResponse> searchForInternalLbVms(ListInternalLBVMsCmd cmd) {
    Pair<List<DomainRouterJoinVO>, Integer> result = searchForRoutersInternal(cmd, cmd.getId(), cmd.getRouterName(), cmd.getState(), cmd.getZoneId(), cmd.getPodId(), null, cmd.getHostId(), cmd.getKeyword(), cmd.getNetworkId(), cmd.getVpcId(), cmd.getForVpc(), cmd.getRole(), null, null);
    ListResponse<DomainRouterResponse> response = new ListResponse<DomainRouterResponse>();
    List<DomainRouterResponse> routerResponses = ViewResponseHelper.createDomainRouterResponse(result.first().toArray(new DomainRouterJoinVO[result.first().size()]));
    if (VirtualNetworkApplianceManager.RouterHealthChecksEnabled.value()) {
        for (DomainRouterResponse res : routerResponses) {
            DomainRouterVO resRouter = _routerDao.findByUuid(res.getId());
            res.setHealthChecksFailed(routerHealthCheckResultDao.hasFailingChecks(resRouter.getId()));
            if (cmd.shouldFetchHealthCheckResults()) {
                res.setHealthCheckResults(responseGenerator.createHealthCheckResponse(resRouter, new ArrayList<>(routerHealthCheckResultDao.getHealthCheckResults(resRouter.getId()))));
            }
        }
    }
    response.setResponses(routerResponses, result.second());
    return response;
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) DomainRouterVO(com.cloud.vm.DomainRouterVO) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO)

Example 8 with DomainRouterJoinVO

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

the class QueryManagerImpl method searchForRoutersInternal.

private Pair<List<DomainRouterJoinVO>, Integer> searchForRoutersInternal(BaseListProjectAndAccountResourcesCmd cmd, Long id, String name, String state, Long zoneId, Long podId, Long clusterId, Long hostId, String keyword, Long networkId, Long vpcId, Boolean forVpc, String role, String version, Boolean isHealthCheckFailed) {
    Account caller = CallContext.current().getCallingAccount();
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
    _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
    Long domainId = domainIdRecursiveListProject.first();
    Boolean isRecursive = domainIdRecursiveListProject.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    Filter searchFilter = new Filter(DomainRouterJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    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);
    }
    List<Long> routersWithFailures = null;
    if (isHealthCheckFailed != null) {
        GenericSearchBuilder<RouterHealthCheckResultVO, Long> routerHealthCheckResultSearch = routerHealthCheckResultDao.createSearchBuilder(Long.class);
        routerHealthCheckResultSearch.and("checkResult", routerHealthCheckResultSearch.entity().getCheckResult(), SearchCriteria.Op.EQ);
        routerHealthCheckResultSearch.selectFields(routerHealthCheckResultSearch.entity().getRouterId());
        routerHealthCheckResultSearch.done();
        SearchCriteria<Long> ssc = routerHealthCheckResultSearch.create();
        ssc.setParameters("checkResult", false);
        routersWithFailures = routerHealthCheckResultDao.customSearch(ssc, null);
        if (routersWithFailures != null && !routersWithFailures.isEmpty()) {
            if (isHealthCheckFailed) {
                sb.and("routerId", sb.entity().getId(), SearchCriteria.Op.IN);
            } else {
                sb.and("routerId", sb.entity().getId(), SearchCriteria.Op.NIN);
            }
        } else if (isHealthCheckFailed) {
            return new Pair<List<DomainRouterJoinVO>, Integer>(Collections.emptyList(), 0);
        }
    }
    SearchCriteria<DomainRouterJoinVO> sc = sb.create();
    _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (keyword != null) {
        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 + "%");
        ssc.addOr("redundantState", 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 + "%");
    }
    if (routersWithFailures != null && !routersWithFailures.isEmpty()) {
        sc.setParameters("routerId", routersWithFailures.toArray(new Object[routersWithFailures.size()]));
    }
    // search VR details by ids
    Pair<List<DomainRouterJoinVO>, Integer> uniqueVrPair = _routerJoinDao.searchAndCount(sc, searchFilter);
    Integer count = uniqueVrPair.second();
    if (count.intValue() == 0) {
        // empty result
        return uniqueVrPair;
    }
    List<DomainRouterJoinVO> uniqueVrs = uniqueVrPair.first();
    Long[] vrIds = new Long[uniqueVrs.size()];
    int i = 0;
    for (DomainRouterJoinVO v : uniqueVrs) {
        vrIds[i++] = v.getId();
    }
    List<DomainRouterJoinVO> vrs = _routerJoinDao.searchByIds(vrIds);
    return new Pair<List<DomainRouterJoinVO>, Integer>(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) RouterHealthCheckResultVO(com.cloud.network.dao.RouterHealthCheckResultVO) Pair(com.cloud.utils.Pair)

Example 9 with DomainRouterJoinVO

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

the class VirtualNetworkApplianceManagerImpl method recreateRouter.

/**
 * Attempts recreation of router by restarting with cleanup a VPC if any or a guest network associated in case no VPC.
 * @param routerId - the id of the router to be recreated.
 * @return true if successfully restart is attempted else false.
 */
private boolean recreateRouter(long routerId) {
    User systemUser = _userDao.getUser(User.UID_SYSTEM);
    // Find any VPC containing router join VO, restart it and return
    DomainRouterJoinVO routerJoinToRestart = getAnyRouterJoinWithVpc(routerId);
    if (routerJoinToRestart != null) {
        return restartVpcInDomainRouter(routerJoinToRestart, systemUser);
    }
    // If no VPC containing router join VO was found we look for a guest network traffic containing join VO and restart that.
    routerJoinToRestart = getAnyRouterJoinWithGuestTraffic(routerId);
    if (routerJoinToRestart != null) {
        return restartGuestNetworkInDomainRouter(routerJoinToRestart, systemUser);
    }
    s_logger.warn("Unable to find a valid guest network or VPC to restart for recreating router id " + routerId);
    return false;
}
Also used : User(com.cloud.user.User) 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