Search in sources :

Example 1 with EngineHostVO

use of org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO in project cloudstack by apache.

the class EngineHostDaoImpl method updateState.

@Override
public boolean updateState(State currentState, DataCenterResourceEntity.State.Event event, State nextState, DataCenterResourceEntity hostEntity, Object data) {
    EngineHostVO vo = findById(hostEntity.getId());
    Date oldUpdatedTime = vo.getLastUpdated();
    SearchCriteria<EngineHostVO> sc = StateChangeSearch.create();
    sc.setParameters("id", hostEntity.getId());
    sc.setParameters("state", currentState);
    UpdateBuilder builder = getUpdateBuilder(vo);
    builder.set(vo, "state", nextState);
    builder.set(vo, "lastUpdated", new Date());
    int rows = update(vo, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        EngineHostVO dbHost = findByIdIncludingRemoved(vo.getId());
        if (dbHost != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
            str.append(": DB Data={id=").append(dbHost.getId()).append("; state=").append(dbHost.getState()).append(";updatedTime=").append(dbHost.getLastUpdated());
            str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatedTime=").append(vo.getLastUpdated());
            str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : EngineHostVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 2 with EngineHostVO

use of org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO 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 3 with EngineHostVO

use of org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO in project cloudstack by apache.

the class EngineHostDaoImpl method persist.

@Override
@DB
public EngineHostVO persist(EngineHostVO host) {
    final String InsertSequenceSql = "INSERT INTO op_host(id) VALUES(?)";
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    EngineHostVO dbHost = super.persist(host);
    try {
        PreparedStatement pstmt = txn.prepareAutoCloseStatement(InsertSequenceSql);
        pstmt.setLong(1, dbHost.getId());
        pstmt.executeUpdate();
    } catch (SQLException e) {
        throw new CloudRuntimeException("Unable to persist the sequence number for this host");
    }
    saveDetails(host);
    loadDetails(dbHost);
    saveHostTags(host);
    loadHostTags(dbHost);
    txn.commit();
    return dbHost;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EngineHostVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO) PreparedStatement(java.sql.PreparedStatement) DB(com.cloud.utils.db.DB)

Example 4 with EngineHostVO

use of org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO in project cloudstack by apache.

the class ProvisioningTest method setUp.

@Override
@Before
public void setUp() {
    EngineDataCenterVO dc = new EngineDataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
    Mockito.when(dcDao.findByUuid(Matchers.anyString())).thenReturn(dc);
    Mockito.when(dcDao.persist((EngineDataCenterVO) Matchers.anyObject())).thenReturn(dc);
    EngineHostPodVO pod = new EngineHostPodVO("lab", 123, "10.0.0.1", "10.0.0.1", 24, "test");
    Mockito.when(_podDao.findByUuid(Matchers.anyString())).thenReturn(pod);
    Mockito.when(_podDao.persist((EngineHostPodVO) Matchers.anyObject())).thenReturn(pod);
    EngineClusterVO cluster = new EngineClusterVO();
    Mockito.when(_clusterDao.findByUuid(Matchers.anyString())).thenReturn(cluster);
    Mockito.when(_clusterDao.persist((EngineClusterVO) Matchers.anyObject())).thenReturn(cluster);
    EngineHostVO host = new EngineHostVO("68765876598");
    Mockito.when(_hostDao.findByUuid(Matchers.anyString())).thenReturn(host);
    Mockito.when(_hostDao.persist((EngineHostVO) Matchers.anyObject())).thenReturn(host);
}
Also used : EngineClusterVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineClusterVO) EngineHostVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO) EngineHostPodVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostPodVO) EngineDataCenterVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineDataCenterVO) Before(org.junit.Before)

Aggregations

EngineHostVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostVO)4 HostTagVO (com.cloud.host.HostTagVO)1 DB (com.cloud.utils.db.DB)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 UpdateBuilder (com.cloud.utils.db.UpdateBuilder)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 EngineClusterVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineClusterVO)1 EngineDataCenterVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineDataCenterVO)1 EngineHostPodVO (org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostPodVO)1 Before (org.junit.Before)1