Search in sources :

Example 71 with HostVO

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);
}
Also used : DetailVO(com.cloud.host.DetailVO) HostVO(com.cloud.host.HostVO)

Example 72 with HostVO

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;
}
Also used : UpdateBuilder(com.cloud.utils.db.UpdateBuilder) HostVO(com.cloud.host.HostVO)

Example 73 with HostVO

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);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HostVO(com.cloud.host.HostVO) DB(com.cloud.utils.db.DB)

Example 74 with HostVO

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);
}
Also used : Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) HostVO(com.cloud.host.HostVO)

Example 75 with HostVO

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;
}
Also used : Scope(org.apache.cloudstack.engine.subsystem.api.storage.Scope) ArrayList(java.util.ArrayList) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46