|
26 | 26 | import javax.inject.Inject; |
27 | 27 | import javax.naming.ConfigurationException; |
28 | 28 |
|
29 | | -import com.cloud.utils.Pair; |
30 | 29 | import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; |
31 | 30 | import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; |
32 | 31 | import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; |
@@ -91,76 +90,89 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO |
91 | 90 | public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { |
92 | 91 | super.configure(name, params); |
93 | 92 |
|
94 | | - Pair<String, SearchCriteria.Op> storeIdEq = new Pair<>(STORE_ID, SearchCriteria.Op.EQ); |
95 | | - Pair<String, SearchCriteria.Op> storeRoleEq = new Pair<>(STORE_ROLE, SearchCriteria.Op.EQ); |
96 | | - Pair<String, SearchCriteria.Op> stateEq = new Pair<>(STATE, SearchCriteria.Op.EQ); |
97 | | - Pair<String, SearchCriteria.Op> stateNeq = new Pair<>(STATE, SearchCriteria.Op.NEQ); |
98 | | - Pair<String, SearchCriteria.Op> stateIn = new Pair<>(STATE, SearchCriteria.Op.IN); |
99 | | - Pair<String, SearchCriteria.Op> refCntNeq = new Pair<>(REF_CNT, SearchCriteria.Op.NEQ); |
100 | | - Pair<String, SearchCriteria.Op> idEq = new Pair<>(ID, SearchCriteria.Op.EQ); |
101 | | - Pair<String, SearchCriteria.Op> updateCountEq = new Pair<>(UPDATED_COUNT, SearchCriteria.Op.EQ); |
102 | | - Pair<String, SearchCriteria.Op> snapshotIdEq = new Pair<>(SNAPSHOT_ID, SearchCriteria.Op.EQ); |
103 | | - Pair<String, SearchCriteria.Op> volumeIdEq = new Pair<>(VOLUME_ID, SearchCriteria.Op.EQ); |
104 | | - Pair<String, SearchCriteria.Op> createdBetween = new Pair<>(CREATED, SearchCriteria.Op.BETWEEN); |
105 | | - |
| 93 | + // Note that snapshot_store_ref stores snapshots on primary as well as |
| 94 | + // those on secondary, so we need to |
| 95 | + // use (store_id, store_role) to search |
106 | 96 | storeSearch = createSearchBuilder(); |
107 | | - storeSearch.addAndConditions(storeIdEq, storeRoleEq, stateNeq); |
| 97 | + storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 98 | + storeSearch.and("store_role", storeSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 99 | + storeSearch.and("state", storeSearch.entity().getState(), SearchCriteria.Op.NEQ); |
108 | 100 | storeSearch.done(); |
109 | 101 |
|
110 | 102 | storeStateSearch = createSearchBuilder(); |
111 | | - storeStateSearch.addAndConditions(storeIdEq, stateEq); |
| 103 | + storeStateSearch.and("store_id", storeStateSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 104 | + storeStateSearch.and("state", storeStateSearch.entity().getState(), SearchCriteria.Op.EQ); |
112 | 105 | storeStateSearch.done(); |
113 | 106 |
|
114 | 107 | destroyedSearch = createSearchBuilder(); |
115 | | - destroyedSearch.addAndConditions(storeIdEq, storeRoleEq, stateEq); |
| 108 | + destroyedSearch.and("store_id", destroyedSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 109 | + destroyedSearch.and("store_role", destroyedSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 110 | + destroyedSearch.and("state", destroyedSearch.entity().getState(), SearchCriteria.Op.EQ); |
116 | 111 | destroyedSearch.done(); |
117 | 112 |
|
118 | 113 | cacheSearch = createSearchBuilder(); |
119 | | - cacheSearch.addAndConditions(storeIdEq, storeRoleEq, stateNeq, refCntNeq); |
| 114 | + cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 115 | + cacheSearch.and("store_role", cacheSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 116 | + cacheSearch.and("state", cacheSearch.entity().getState(), SearchCriteria.Op.NEQ); |
| 117 | + cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ); |
120 | 118 | cacheSearch.done(); |
121 | 119 |
|
122 | | - updateStateSearch = createSearchBuilder(); |
123 | | - updateStateSearch.addAndConditions(idEq, stateEq, updateCountEq); |
| 120 | + updateStateSearch = this.createSearchBuilder(); |
| 121 | + updateStateSearch.and("id", updateStateSearch.entity().getId(), SearchCriteria.Op.EQ); |
| 122 | + updateStateSearch.and("state", updateStateSearch.entity().getState(), SearchCriteria.Op.EQ); |
| 123 | + updateStateSearch.and("updatedCount", updateStateSearch.entity().getUpdatedCount(), SearchCriteria.Op.EQ); |
124 | 124 | updateStateSearch.done(); |
125 | 125 |
|
126 | 126 | snapshotSearch = createSearchBuilder(); |
127 | | - snapshotSearch.addAndConditions(snapshotIdEq, storeRoleEq, stateEq); |
| 127 | + snapshotSearch.and("snapshot_id", snapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); |
| 128 | + snapshotSearch.and("store_role", snapshotSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 129 | + snapshotSearch.and("state", snapshotSearch.entity().getState(), SearchCriteria.Op.EQ); |
128 | 130 | snapshotSearch.done(); |
129 | 131 |
|
130 | 132 | storeSnapshotSearch = createSearchBuilder(); |
131 | | - storeSnapshotSearch.addAndConditions(snapshotIdEq, storeIdEq, storeRoleEq, stateEq); |
| 133 | + storeSnapshotSearch.and("snapshot_id", storeSnapshotSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); |
| 134 | + storeSnapshotSearch.and("store_id", storeSnapshotSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 135 | + storeSnapshotSearch.and("store_role", storeSnapshotSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 136 | + storeSnapshotSearch.and("state", storeSnapshotSearch.entity().getState(), SearchCriteria.Op.EQ); |
132 | 137 | storeSnapshotSearch.done(); |
133 | 138 |
|
134 | 139 | snapshotIdSearch = createSearchBuilder(); |
135 | | - snapshotIdSearch.addAndConditions(snapshotIdEq); |
| 140 | + snapshotIdSearch.and("snapshot_id", snapshotIdSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); |
136 | 141 | snapshotIdSearch.done(); |
137 | 142 |
|
138 | 143 | volumeIdSearch = createSearchBuilder(); |
139 | | - volumeIdSearch.addAndConditions(volumeIdEq); |
| 144 | + volumeIdSearch.and("volume_id", volumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |
140 | 145 | volumeIdSearch.done(); |
141 | 146 |
|
142 | 147 | volumeSearch = createSearchBuilder(); |
143 | | - volumeSearch.addAndConditions(volumeIdEq, storeRoleEq, snapshotIdEq); |
| 148 | + volumeSearch.and("volume_id", volumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |
| 149 | + volumeSearch.and("store_role", volumeSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 150 | + volumeSearch.and("snapshot_id", volumeSearch.entity().getSnapshotId(), SearchCriteria.Op.EQ); |
144 | 151 | volumeSearch.done(); |
145 | 152 |
|
146 | 153 | volumeIdAndStateReadySearch = createSearchBuilder(); |
147 | | - volumeIdAndStateReadySearch.addAndConditions(volumeIdEq, stateEq); |
| 154 | + volumeIdAndStateReadySearch.and("volume_id", volumeIdAndStateReadySearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |
| 155 | + volumeIdAndStateReadySearch.and("state", volumeIdAndStateReadySearch.entity().getState(), SearchCriteria.Op.EQ); |
148 | 156 | volumeIdAndStateReadySearch.done(); |
149 | 157 |
|
150 | 158 | stateSearch = createSearchBuilder(); |
151 | | - stateSearch.addAndConditions(stateIn); |
| 159 | + stateSearch.and("state", stateSearch.entity().getState(), SearchCriteria.Op.IN); |
152 | 160 | stateSearch.done(); |
153 | 161 |
|
154 | 162 | parentSnapshotSearch = createSearchBuilder(); |
155 | | - parentSnapshotSearch.addAndConditions(volumeIdEq, storeIdEq, storeRoleEq, stateEq); |
| 163 | + parentSnapshotSearch.and("volume_id", parentSnapshotSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |
| 164 | + parentSnapshotSearch.and("store_id", parentSnapshotSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 165 | + parentSnapshotSearch.and("store_role", parentSnapshotSearch.entity().getRole(), SearchCriteria.Op.EQ); |
| 166 | + parentSnapshotSearch.and("state", parentSnapshotSearch.entity().getState(), SearchCriteria.Op.EQ); |
156 | 167 | parentSnapshotSearch.done(); |
157 | 168 |
|
158 | 169 | snapshotVOSearch = snapshotDao.createSearchBuilder(); |
159 | | - snapshotVOSearch.addAndConditions(volumeIdEq); |
| 170 | + snapshotVOSearch.and("volume_id", snapshotVOSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); |
160 | 171 | snapshotVOSearch.done(); |
161 | 172 |
|
162 | 173 | snapshotCreatedSearch = createSearchBuilder(); |
163 | | - snapshotCreatedSearch.addAndConditions(storeIdEq, createdBetween); |
| 174 | + snapshotCreatedSearch.and("store_id", snapshotCreatedSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ); |
| 175 | + snapshotCreatedSearch.and("created", snapshotCreatedSearch.entity().getCreated(), SearchCriteria.Op.BETWEEN); |
164 | 176 | snapshotCreatedSearch.done(); |
165 | 177 |
|
166 | 178 | return true; |
|
0 commit comments