diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java index 9ffeae06e0b..c3e48b9b2f3 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java @@ -33,6 +33,12 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; +import com.cloud.storage.SnapshotVO; +import com.cloud.storage.dao.SnapshotDao; +import javax.inject.Inject; +import com.cloud.hypervisor.Hypervisor; +import java.util.ArrayList; +import com.cloud.utils.db.Filter; import javax.naming.ConfigurationException; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -54,9 +60,14 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase volumeIdSearch; private SearchBuilder volumeSearch; private SearchBuilder stateSearch; + private SearchBuilder parentSnapshotSearch; + private SearchBuilder snapshotVOSearch; + + public static ArrayList hypervisorsSupportingSnapshotsChaining = new ArrayList(); + + @Inject + private SnapshotDao _snapshotDao; - private final String parentSearch = "select store_id, store_role, snapshot_id from cloud.snapshot_store_ref where store_id = ? " - + " and store_role = ? and volume_id = ? and state = 'Ready'" + " order by created DESC " + " limit 1"; private final String findLatestSnapshot = "select store_id, store_role, snapshot_id from cloud.snapshot_store_ref where " + " store_role = ? and volume_id = ? and state = 'Ready'" + " order by created DESC " + @@ -128,6 +139,17 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase sc = parentSnapshotSearch.create(); + sc.setParameters("volume_id", volumeId); + sc.setParameters("store_role", role.toString()); + sc.setParameters("state", ObjectInDataStoreStateMachine.State.Ready.name()); + sc.setParameters("store_id", storeId); + + List snapshotList = listBy(sc, new Filter(SnapshotDataStoreVO.class, "created", false, null, null)); + if (snapshotList != null && snapshotList.size() != 0) { + return snapshotList.get(0); } - } catch (SQLException e) { - s_logger.debug("Failed to find parent snapshot: " + e.toString()); } return null; } @@ -419,4 +436,21 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase sc = snapshotVOSearch.create(); + sc.setParameters("volume_id", volumeId); + + SnapshotVO volSnapshot = _snapshotDao.findOneBy(sc); + + if (volSnapshot != null && hypervisorsSupportingSnapshotsChaining.contains(volSnapshot.getHypervisorType())) { + return true; + } + + return false; + } + }