Search in sources :

Example 1 with HostTagVO

use of com.cloud.host.HostTagVO in project cloudstack by apache.

the class EngineHostDaoImpl method listByHostTag.

@Override
public List<EngineHostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) {
    SearchBuilder<HostTagVO> hostTagSearch = _hostTagsDao.createSearchBuilder();
    HostTagVO tagEntity = hostTagSearch.entity();
    hostTagSearch.and("tag", tagEntity.getTag(), SearchCriteria.Op.EQ);
    SearchBuilder<EngineHostVO> hostSearch = createSearchBuilder();
    EngineHostVO entity = hostSearch.entity();
    hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
    hostSearch.and("pod", entity.getPodId(), SearchCriteria.Op.EQ);
    hostSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
    hostSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
    hostSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
    hostSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
    hostSearch.join("hostTagSearch", hostTagSearch, entity.getId(), tagEntity.getHostId(), JoinBuilder.JoinType.INNER);
    SearchCriteria<EngineHostVO> sc = hostSearch.create();
    sc.setJoinParameters("hostTagSearch", "tag", hostTag);
    sc.setParameters("type", type.toString());
    if (podId != null) {
        sc.setParameters("pod", podId);
    }
    if (clusterId != null) {
        sc.setParameters("cluster", clusterId);
    }
    sc.setParameters("dc", dcId);
    sc.setParameters("status", Status.Up.toString());
    sc.setParameters("resourceState", ResourceState.Enabled.toString());
    return listBy(sc);
}
Also used : HostTagVO(com.cloud.host.HostTagVO) EngineHostVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO)

Example 2 with HostTagVO

use of com.cloud.host.HostTagVO in project cloudstack by apache.

the class HostTagsDaoImpl method deleteTags.

@Override
public void deleteTags(long hostId) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    SearchCriteria<HostTagVO> sc = HostSearch.create();
    sc.setParameters("hostId", hostId);
    expunge(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) HostTagVO(com.cloud.host.HostTagVO)

Example 3 with HostTagVO

use of com.cloud.host.HostTagVO in project cloudstack by apache.

the class HostTagsDaoImpl method gethostTags.

@Override
public List<String> gethostTags(long hostId) {
    SearchCriteria<HostTagVO> sc = HostSearch.create();
    sc.setParameters("hostId", hostId);
    List<HostTagVO> results = search(sc, null);
    List<String> hostTags = new ArrayList<String>(results.size());
    for (HostTagVO result : results) {
        hostTags.add(result.getTag());
    }
    return hostTags;
}
Also used : HostTagVO(com.cloud.host.HostTagVO) ArrayList(java.util.ArrayList)

Example 4 with HostTagVO

use of com.cloud.host.HostTagVO in project cloudstack by apache.

the class ManagementServerImpl method searchForServers.

private Pair<List<HostVO>, Integer> searchForServers(final Long startIndex, final Long pageSize, final Object name, final Object type, final Object state, final Object zone, final Object pod, final Object cluster, final Object id, final Object keyword, final Object resourceState, final Object haHosts, final Object hypervisorType, final Object hypervisorVersion) {
    final Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);
    final SearchBuilder<HostVO> sb = _hostDao.createSearchBuilder();
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
    sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
    sb.and("status", sb.entity().getStatus(), 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("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
    sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
    sb.and("hypervisorVersion", sb.entity().getHypervisorVersion(), SearchCriteria.Op.EQ);
    final String haTag = _haMgr.getHaTag();
    SearchBuilder<HostTagVO> hostTagSearch = null;
    if (haHosts != null && haTag != null && !haTag.isEmpty()) {
        hostTagSearch = _hostTagsDao.createSearchBuilder();
        if ((Boolean) haHosts) {
            hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.EQ);
        } else {
            hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.NEQ);
            hostTagSearch.or("tagNull", hostTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
        }
        hostTagSearch.cp();
        sb.join("hostTagSearch", hostTagSearch, sb.entity().getId(), hostTagSearch.entity().getHostId(), JoinBuilder.JoinType.LEFTOUTER);
    }
    final SearchCriteria<HostVO> sc = sb.create();
    if (keyword != null) {
        final SearchCriteria<HostVO> ssc = _hostDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("status", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (name != null) {
        sc.setParameters("name", "%" + name + "%");
    }
    if (type != null) {
        sc.setParameters("type", "%" + type);
    }
    if (state != null) {
        sc.setParameters("status", state);
    }
    if (zone != null) {
        sc.setParameters("dataCenterId", zone);
    }
    if (pod != null) {
        sc.setParameters("podId", pod);
    }
    if (cluster != null) {
        sc.setParameters("clusterId", cluster);
    }
    if (hypervisorType != null) {
        sc.setParameters("hypervisorType", hypervisorType);
    }
    if (hypervisorVersion != null) {
        sc.setParameters("hypervisorVersion", hypervisorVersion);
    }
    if (resourceState != null) {
        sc.setParameters("resourceState", resourceState);
    }
    if (haHosts != null && haTag != null && !haTag.isEmpty()) {
        sc.setJoinParameters("hostTagSearch", "tag", haTag);
    }
    return _hostDao.searchAndCount(sc, searchFilter);
}
Also used : Filter(com.cloud.utils.db.Filter) HostTagVO(com.cloud.host.HostTagVO) HostVO(com.cloud.host.HostVO)

Example 5 with HostTagVO

use of com.cloud.host.HostTagVO in project cloudstack by apache.

the class HostDaoImpl method listByHostTag.

@Override
public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) {
    SearchBuilder<HostTagVO> hostTagSearch = _hostTagsDao.createSearchBuilder();
    HostTagVO tagEntity = hostTagSearch.entity();
    hostTagSearch.and("tag", tagEntity.getTag(), SearchCriteria.Op.EQ);
    SearchBuilder<HostVO> hostSearch = createSearchBuilder();
    HostVO entity = hostSearch.entity();
    hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
    hostSearch.and("pod", entity.getPodId(), SearchCriteria.Op.EQ);
    hostSearch.and("dc", entity.getDataCenterId(), SearchCriteria.Op.EQ);
    hostSearch.and("cluster", entity.getClusterId(), SearchCriteria.Op.EQ);
    hostSearch.and("status", entity.getStatus(), SearchCriteria.Op.EQ);
    hostSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
    hostSearch.join("hostTagSearch", hostTagSearch, entity.getId(), tagEntity.getHostId(), JoinBuilder.JoinType.INNER);
    SearchCriteria<HostVO> sc = hostSearch.create();
    sc.setJoinParameters("hostTagSearch", "tag", hostTag);
    sc.setParameters("type", type.toString());
    if (podId != null) {
        sc.setParameters("pod", podId);
    }
    if (clusterId != null) {
        sc.setParameters("cluster", clusterId);
    }
    sc.setParameters("dc", dcId);
    sc.setParameters("status", Status.Up.toString());
    sc.setParameters("resourceState", ResourceState.Enabled.toString());
    return listBy(sc);
}
Also used : HostTagVO(com.cloud.host.HostTagVO) HostVO(com.cloud.host.HostVO)

Aggregations

HostTagVO (com.cloud.host.HostTagVO)8 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 HostVO (com.cloud.host.HostVO)2 ArrayList (java.util.ArrayList)2 Filter (com.cloud.utils.db.Filter)1 EngineHostVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO)1