Search in sources :

Example 1 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO in project cloudstack by apache.

the class VMTemplatePoolDaoImpl method listByTemplateStatus.

@Override
public List<VMTemplateStoragePoolVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateStoragePoolVO.Status downloadState) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    List<VMTemplateStoragePoolVO> result = new ArrayList<VMTemplateStoragePoolVO>();
    String sql = DOWNLOADS_STATE_DC_POD;
    try (PreparedStatement pstmt = txn.prepareStatement(sql)) {
        pstmt.setLong(1, datacenterId);
        pstmt.setLong(2, podId);
        pstmt.setLong(3, templateId);
        pstmt.setString(4, downloadState.toString());
        try (ResultSet rs = pstmt.executeQuery()) {
            while (rs.next()) {
                // result.add(toEntityBean(rs, false)); TODO: this is buggy in
                // GenericDaoBase for hand constructed queries
                // ID column
                long id = rs.getLong(1);
                result.add(findById(id));
            }
        } catch (Exception e) {
            s_logger.warn("Exception: ", e);
        }
    } catch (Exception e) {
        s_logger.warn("Exception: ", e);
    }
    return result;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO in project cloudstack by apache.

the class TemplateDataFactoryImpl method getTemplate.

@Override
public TemplateInfo getTemplate(long templateId, DataStore store) {
    VMTemplateVO templ = imageDataDao.findById(templateId);
    if (store == null) {
        TemplateObject tmpl = TemplateObject.getTemplate(templ, null);
        return tmpl;
    }
    // verify if the given input parameters are consistent with our db data.
    boolean found = false;
    if (store.getRole() == DataStoreRole.Primary) {
        VMTemplateStoragePoolVO templatePoolVO = templatePoolDao.findByPoolTemplate(store.getId(), templateId);
        if (templatePoolVO != null) {
            found = true;
        }
    } else {
        TemplateDataStoreVO templateStoreVO = templateStoreDao.findByStoreTemplate(store.getId(), templateId);
        if (templateStoreVO != null) {
            found = true;
        }
    }
    if (s_logger.isDebugEnabled()) {
        if (!found) {
            s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole());
        } else {
            s_logger.debug("template " + templateId + " is already in store:" + store.getId() + ", type:" + store.getRole());
        }
    }
    TemplateObject tmpl = TemplateObject.getTemplate(templ, store);
    return tmpl;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 3 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO in project cloudstack by apache.

the class ObjectInDataStoreManagerImpl method create.

@Override
public DataObject create(DataObject obj, DataStore dataStore) {
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (obj.getType() == DataObjectType.TEMPLATE) {
            VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId());
            vo = templatePoolDao.persist(vo);
        } else if (obj.getType() == DataObjectType.SNAPSHOT) {
            SnapshotInfo snapshotInfo = (SnapshotInfo) obj;
            SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
            ss.setSnapshotId(obj.getId());
            ss.setDataStoreId(dataStore.getId());
            ss.setRole(dataStore.getRole());
            ss.setVolumeId(snapshotInfo.getVolumeId());
            // this is the virtual size of snapshot in primary storage.
            ss.setSize(snapshotInfo.getSize());
            // this physical size will get updated with actual size once the snapshot backup is done.
            ss.setPhysicalSize(snapshotInfo.getSize());
            SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
            if (snapshotDataStoreVO != null) {
                //Double check the snapshot is removed or not
                SnapshotVO parentSnap = snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
                if (parentSnap != null) {
                    ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
                } else {
                    s_logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId());
                }
            }
            ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
            ss = snapshotDataStoreDao.persist(ss);
        }
    } else {
        // Image store
        switch(obj.getType()) {
            case TEMPLATE:
                TemplateDataStoreVO ts = new TemplateDataStoreVO();
                ts.setTemplateId(obj.getId());
                ts.setDataStoreId(dataStore.getId());
                ts.setDataStoreRole(dataStore.getRole());
                String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId();
                if (dataStore.getTO() instanceof S3TO) {
                    TemplateInfo tmpl = (TemplateInfo) obj;
                    // for S3, we
                    installPath += "/" + tmpl.getUniqueName();
                // append
                // template name
                // in the path
                // for template
                // sync since we
                // don't have
                // template.properties
                // there
                }
                ts.setInstallPath(installPath);
                ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ts = templateDataStoreDao.persist(ts);
                break;
            case SNAPSHOT:
                SnapshotInfo snapshot = (SnapshotInfo) obj;
                SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
                ss.setSnapshotId(obj.getId());
                ss.setDataStoreId(dataStore.getId());
                ss.setRole(dataStore.getRole());
                ss.setSize(snapshot.getSize());
                ss.setVolumeId(snapshot.getVolumeId());
                SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshot.getVolumeId());
                if (snapshotDataStoreVO != null) {
                    ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
                }
                ss.setInstallPath(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshotDao.findById(obj.getId()).getAccountId() + "/" + snapshot.getVolumeId());
                ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ss = snapshotDataStoreDao.persist(ss);
                break;
            case VOLUME:
                VolumeDataStoreVO vs = new VolumeDataStoreVO();
                vs.setVolumeId(obj.getId());
                vs.setDataStoreId(dataStore.getId());
                vs.setInstallPath(TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + "/" + volumeDao.findById(obj.getId()).getAccountId() + "/" + obj.getId());
                vs.setState(ObjectInDataStoreStateMachine.State.Allocated);
                vs = volumeDataStoreDao.persist(vs);
                break;
        }
    }
    return this.get(obj, dataStore);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) S3TO(com.cloud.agent.api.to.S3TO)

Example 4 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO in project cloudstack by apache.

the class ObjectInDataStoreManagerImpl method delete.

@Override
public boolean delete(DataObject dataObj) {
    long objId = dataObj.getId();
    DataStore dataStore = dataObj.getDataStore();
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (dataObj.getType() == DataObjectType.TEMPLATE) {
            VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId);
            if (destTmpltPool != null) {
                return templatePoolDao.remove(destTmpltPool.getId());
            } else {
                s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete");
                return true;
            }
        }
    } else {
        // Image store
        switch(dataObj.getType()) {
            case TEMPLATE:
                TemplateDataStoreVO destTmpltStore = templateDataStoreDao.findByStoreTemplate(dataStore.getId(), objId);
                if (destTmpltStore != null) {
                    return templateDataStoreDao.remove(destTmpltStore.getId());
                } else {
                    s_logger.warn("Template " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case SNAPSHOT:
                SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
                if (destSnapshotStore != null) {
                    return snapshotDataStoreDao.remove(destSnapshotStore.getId());
                } else {
                    s_logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case VOLUME:
                VolumeDataStoreVO destVolumeStore = volumeDataStoreDao.findByStoreVolume(dataStore.getId(), objId);
                if (destVolumeStore != null) {
                    return volumeDataStoreDao.remove(destVolumeStore.getId());
                } else {
                    s_logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
        }
    }
    s_logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + ")");
    return false;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)

Example 5 with VMTemplateStoragePoolVO

use of com.cloud.storage.VMTemplateStoragePoolVO in project cloudstack by apache.

the class ObjectInDataStoreManagerImpl method deleteIfNotReady.

@Override
public boolean deleteIfNotReady(DataObject dataObj) {
    long objId = dataObj.getId();
    DataStore dataStore = dataObj.getDataStore();
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (dataObj.getType() == DataObjectType.TEMPLATE) {
            VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId);
            if (destTmpltPool != null && destTmpltPool.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                return templatePoolDao.remove(destTmpltPool.getId());
            } else {
                s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete");
                return true;
            }
        } else if (dataObj.getType() == DataObjectType.SNAPSHOT) {
            SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
            if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                snapshotDataStoreDao.remove(destSnapshotStore.getId());
            }
            return true;
        }
    } else {
        // Image store
        switch(dataObj.getType()) {
            case TEMPLATE:
                return true;
            case SNAPSHOT:
                SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
                if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                    return snapshotDataStoreDao.remove(destSnapshotStore.getId());
                } else {
                    s_logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case VOLUME:
                VolumeDataStoreVO destVolumeStore = volumeDataStoreDao.findByStoreVolume(dataStore.getId(), objId);
                if (destVolumeStore != null && destVolumeStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                    return volumeDataStoreDao.remove(destVolumeStore.getId());
                } else {
                    s_logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
        }
    }
    s_logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + "), no need to delete from object in store ref table");
    return false;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Aggregations

VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)30 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 VMTemplateVO (com.cloud.storage.VMTemplateVO)9 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)8 DB (com.cloud.utils.db.DB)5 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)5 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 SolidFireUtil (org.apache.cloudstack.storage.datastore.util.SolidFireUtil)4 Answer (com.cloud.agent.api.Answer)3 SnapshotVO (com.cloud.storage.SnapshotVO)3 SnapshotDetailsVO (com.cloud.storage.dao.SnapshotDetailsVO)3 NamedThreadFactory (com.cloud.utils.concurrency.NamedThreadFactory)3 ExecutorService (java.util.concurrent.ExecutorService)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)3 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)3 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)3