use of com.cloud.host.HostVO in project cloudstack by apache.
the class HostDaoImpl method listByHostCapability.
@Override
public List<HostVO> listByHostCapability(Type type, Long clusterId, Long podId, long dcId, String hostCapabilty) {
SearchBuilder<DetailVO> hostCapabilitySearch = _detailsDao.createSearchBuilder();
DetailVO tagEntity = hostCapabilitySearch.entity();
hostCapabilitySearch.and("capability", tagEntity.getName(), SearchCriteria.Op.EQ);
hostCapabilitySearch.and("value", tagEntity.getValue(), 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("hostCapabilitySearch", hostCapabilitySearch, entity.getId(), tagEntity.getHostId(), JoinBuilder.JoinType.INNER);
SearchCriteria<HostVO> sc = hostSearch.create();
sc.setJoinParameters("hostCapabilitySearch", "value", Boolean.toString(true));
sc.setJoinParameters("hostCapabilitySearch", "capability", hostCapabilty);
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);
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class HostDaoImpl method updateResourceState.
@Override
public boolean updateResourceState(ResourceState oldState, ResourceState.Event event, ResourceState newState, Host vo) {
HostVO host = (HostVO) vo;
SearchBuilder<HostVO> sb = createSearchBuilder();
sb.and("resource_state", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.done();
SearchCriteria<HostVO> sc = sb.create();
sc.setParameters("resource_state", oldState);
sc.setParameters("id", host.getId());
UpdateBuilder ub = getUpdateBuilder(host);
ub.set(host, _resourceStateAttr, newState);
int result = update(ub, sc, null);
assert result <= 1 : "How can this update " + result + " rows? ";
if (state_logger.isDebugEnabled() && result == 0) {
HostVO ho = findById(host.getId());
assert ho != null : "How how how? : " + host.getId();
StringBuilder str = new StringBuilder("Unable to update resource state: [");
str.append("m = " + host.getId());
str.append("; name = " + host.getName());
str.append("; old state = " + oldState);
str.append("; event = " + event);
str.append("; new state = " + newState + "]");
state_logger.debug(str.toString());
} else {
StringBuilder msg = new StringBuilder("Resource state update: [");
msg.append("id = " + host.getId());
msg.append("; name = " + host.getName());
msg.append("; old state = " + oldState);
msg.append("; event = " + event);
msg.append("; new state = " + newState + "]");
state_logger.debug(msg.toString());
}
return result > 0;
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class DefaultEndPointSelector method findEndPointInScope.
@DB
protected EndPoint findEndPointInScope(Scope scope, String sqlBase, Long poolId) {
StringBuilder sbuilder = new StringBuilder();
sbuilder.append(sqlBase);
List<Long> dedicatedHosts = new ArrayList<Long>();
if (scope != null) {
if (scope.getScopeType() == ScopeType.HOST) {
sbuilder.append(" and h.id = ");
sbuilder.append(scope.getScopeId());
} else if (scope.getScopeType() == ScopeType.CLUSTER) {
sbuilder.append(" and h.cluster_id = ");
sbuilder.append(scope.getScopeId());
dedicatedHosts = dedicatedResourceDao.findHostsByCluster(scope.getScopeId());
} else if (scope.getScopeType() == ScopeType.ZONE) {
sbuilder.append(" and h.data_center_id = ");
sbuilder.append(scope.getScopeId());
dedicatedHosts = dedicatedResourceDao.findHostsByZone(scope.getScopeId());
}
} else {
dedicatedHosts = dedicatedResourceDao.listAllHosts();
}
// TODO: order by rand() is slow if there are lot of hosts
// Added for exclude cluster's subquery
sbuilder.append(") t where t.value<>'true' or t.value is null");
sbuilder.append(" ORDER by ");
if (dedicatedHosts.size() > 0) {
moveDedicatedHostsToLowerPriority(sbuilder, dedicatedHosts);
}
sbuilder.append(" rand() limit 1");
String sql = sbuilder.toString();
HostVO host = null;
TransactionLegacy txn = TransactionLegacy.currentTxn();
try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
pstmt.setLong(1, poolId);
try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
long id = rs.getLong(1);
host = hostDao.findById(id);
}
} catch (SQLException e) {
s_logger.warn("can't find endpoint", e);
}
} catch (SQLException e) {
s_logger.warn("can't find endpoint", e);
}
if (host == null) {
return null;
}
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class DefaultEndPointSelector method findEndpointForImageStorage.
protected EndPoint findEndpointForImageStorage(DataStore store) {
Long dcId = null;
Scope storeScope = store.getScope();
if (storeScope.getScopeType() == ScopeType.ZONE) {
dcId = storeScope.getScopeId();
}
// find ssvm that can be used to download data to store. For zone-wide
// image store, use SSVM for that zone. For region-wide store,
// we can arbitrarily pick one ssvm to do that task
List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
if (ssAHosts == null || ssAHosts.isEmpty()) {
return null;
}
Collections.shuffle(ssAHosts);
HostVO host = ssAHosts.get(0);
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class DefaultEndPointSelector method findAllEndpointsForScope.
@Override
public List<EndPoint> findAllEndpointsForScope(DataStore store) {
Long dcId = null;
Scope storeScope = store.getScope();
if (storeScope.getScopeType() == ScopeType.ZONE) {
dcId = storeScope.getScopeId();
}
// find ssvm that can be used to download data to store. For zone-wide
// image store, use SSVM for that zone. For region-wide store,
// we can arbitrarily pick one ssvm to do that task
List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
if (ssAHosts == null || ssAHosts.isEmpty()) {
return null;
}
List<EndPoint> endPoints = new ArrayList<EndPoint>();
for (HostVO host : ssAHosts) {
endPoints.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host));
}
return endPoints;
}
Aggregations