Search in sources :

Example 1 with QueryBuilder

use of com.cloud.utils.db.QueryBuilder in project cloudstack by apache.

the class DefaultEndPointSelector method selectAll.

@Override
public List<EndPoint> selectAll(DataStore store) {
    List<EndPoint> endPoints = new ArrayList<EndPoint>();
    if (store.getScope().getScopeType() == ScopeType.HOST) {
        HostVO host = hostDao.findById(store.getScope().getScopeId());
        endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
    } else if (store.getScope().getScopeType() == ScopeType.CLUSTER) {
        QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
        sc.and(sc.entity().getClusterId(), Op.EQ, store.getScope().getScopeId());
        sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
        List<HostVO> hosts = sc.list();
        for (HostVO host : hosts) {
            endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
        }
    } else {
        throw new CloudRuntimeException("shouldn't use it for other scope");
    }
    return endPoints;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) QueryBuilder(com.cloud.utils.db.QueryBuilder) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)1 QueryBuilder (com.cloud.utils.db.QueryBuilder)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)1 RemoteHostEndPoint (org.apache.cloudstack.storage.RemoteHostEndPoint)1