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;
}
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;
}
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);
}
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;
}
Aggregations