Skip to content

Commit e23e6b0

Browse files
committed
CLOUDSTACK-3709:[Object_Store_Refactor][UI] Can't delete NFS Cache
storage through UI. Fixed at API side.
1 parent 0362b1b commit e23e6b0

10 files changed

Lines changed: 207 additions & 90 deletions

File tree

‎api/src/com/cloud/storage/StorageService.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
2323
import org.apache.cloudstack.api.command.admin.storage.CreateCacheStoreCmd;
2424
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
25+
import org.apache.cloudstack.api.command.admin.storage.DeleteCacheStoreCmd;
2526
import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
2627
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
2728
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
@@ -48,7 +49,7 @@ public interface StorageService{
4849
*/
4950
StoragePool createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException,
5051
UnknownHostException, ResourceUnavailableException;
51-
52+
5253
ImageStore createCacheStore(CreateCacheStoreCmd cmd);
5354

5455
/**
@@ -92,6 +93,8 @@ public StoragePool cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMainte
9293

9394
boolean deleteImageStore(DeleteImageStoreCmd cmd);
9495

96+
boolean deleteCacheStore(DeleteCacheStoreCmd cmd);
97+
9598
ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
9699

97100
}

‎client/tomcatconf/commands.properties.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ listImageStores=1
252252
deleteImageStore=1
253253
createCacheStore=1
254254
listCacheStores=1
255+
deleteCacheStore=1
255256

256257
#### host commands
257258
addHost=3

‎engine/api/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
import com.cloud.utils.fsm.StateDao;
2727

2828
public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Long>,
29-
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
29+
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
3030

3131
List<SnapshotDataStoreVO> listByStoreId(long id, DataStoreRole role);
3232

33-
void deletePrimaryRecordsForStore(long id);
33+
List<SnapshotDataStoreVO> listActiveOnCache(long id);
34+
35+
void deletePrimaryRecordsForStore(long id, DataStoreRole role);
3436

3537
SnapshotDataStoreVO findByStoreSnapshot(DataStoreRole role, long storeId, long snapshotId);
3638
SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long volumeId);

‎engine/api/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
import com.cloud.utils.fsm.StateDao;
2929

3030
public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Long>,
31-
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
31+
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
3232

3333
List<TemplateDataStoreVO> listByStoreId(long id);
3434

3535
List<TemplateDataStoreVO> listDestroyed(long storeId);
3636

37+
List<TemplateDataStoreVO> listActiveOnCache(long id);
38+
3739
void deletePrimaryRecordsForStore(long id);
3840

3941
void deletePrimaryRecordsForTemplate(long templateId);

‎engine/api/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import com.cloud.utils.fsm.StateDao;
2626

2727
public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>,
28-
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
28+
StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Event, DataObjectInStore> {
2929

3030
List<VolumeDataStoreVO> listByStoreId(long id);
3131

32+
List<VolumeDataStoreVO> listActiveOnCache(long id);
33+
3234
void deletePrimaryRecordsForStore(long id);
3335

3436
VolumeDataStoreVO findByVolume(long volumeId);

‎engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,23 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
4848
private SearchBuilder<SnapshotDataStoreVO> updateStateSearch;
4949
private SearchBuilder<SnapshotDataStoreVO> storeSearch;
5050
private SearchBuilder<SnapshotDataStoreVO> destroyedSearch;
51+
private SearchBuilder<SnapshotDataStoreVO> cacheSearch;
5152
private SearchBuilder<SnapshotDataStoreVO> snapshotSearch;
5253
private SearchBuilder<SnapshotDataStoreVO> storeSnapshotSearch;
5354
private String parentSearch = "select store_id, store_role, snapshot_id from cloud.snapshot_store_ref where store_id = ? " +
54-
" and store_role = ? and volume_id = ? and state = 'Ready'" +
55-
" order by created DESC " +
56-
" limit 1";
55+
" and store_role = ? and volume_id = ? and state = 'Ready'" +
56+
" order by created DESC " +
57+
" limit 1";
5758

5859

5960

6061
@Override
6162
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
6263
super.configure(name, params);
6364

65+
// Note that snapshot_store_ref stores snapshots on primary as well as
66+
// those on secondary, so we need to
67+
// use (store_id, store_role) to search
6468
storeSearch = createSearchBuilder();
6569
storeSearch.and("store_id", storeSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
6670
storeSearch.and("store_role", storeSearch.entity().getRole(), SearchCriteria.Op.EQ);
@@ -72,6 +76,13 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
7276
destroyedSearch.and("state", destroyedSearch.entity().getState(), SearchCriteria.Op.EQ);
7377
destroyedSearch.done();
7478

79+
cacheSearch = createSearchBuilder();
80+
cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
81+
cacheSearch.and("store_role", cacheSearch.entity().getRole(), SearchCriteria.Op.EQ);
82+
cacheSearch.and("state", cacheSearch.entity().getState(), SearchCriteria.Op.NEQ);
83+
cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ);
84+
cacheSearch.done();
85+
7586
updateStateSearch = this.createSearchBuilder();
7687
updateStateSearch.and("id", updateStateSearch.entity().getId(), Op.EQ);
7788
updateStateSearch.and("state", updateStateSearch.entity().getState(), Op.EQ);
@@ -115,14 +126,14 @@ public boolean updateState(State currentState, Event event, State nextState, Dat
115126
if (dbVol != null) {
116127
StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
117128
str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState())
118-
.append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
119-
.append(dbVol.getUpdated());
129+
.append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
130+
.append(dbVol.getUpdated());
120131
str.append(": New Data={id=").append(dataObj.getId()).append("; state=").append(nextState)
121-
.append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
122-
.append("; updatedTime=").append(dataObj.getUpdated());
132+
.append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
133+
.append("; updatedTime=").append(dataObj.getUpdated());
123134
str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState)
124-
.append("; event=").append(event).append("; updatecount=").append(oldUpdated)
125-
.append("; updatedTime=").append(oldUpdatedTime);
135+
.append("; event=").append(event).append("; updatecount=").append(oldUpdated)
136+
.append("; updatedTime=").append(oldUpdatedTime);
126137
} else {
127138
s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId()
128139
+ ", as there is no such object exists in the database anymore");
@@ -140,9 +151,10 @@ public List<SnapshotDataStoreVO> listByStoreId(long id, DataStoreRole role) {
140151
}
141152

142153
@Override
143-
public void deletePrimaryRecordsForStore(long id) {
154+
public void deletePrimaryRecordsForStore(long id, DataStoreRole role) {
144155
SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
145156
sc.setParameters("store_id", id);
157+
sc.setParameters("store_role", role);
146158
Transaction txn = Transaction.currentTxn();
147159
txn.start();
148160
remove(sc);
@@ -176,7 +188,7 @@ public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long vol
176188
return this.findByStoreSnapshot(role, sid, snid);
177189
}
178190
} catch (SQLException e) {
179-
s_logger.debug("Failed to find parent snapshot: " + e.toString());
191+
s_logger.debug("Failed to find parent snapshot: " + e.toString());
180192
} finally {
181193
txn.close();
182194
}
@@ -199,4 +211,14 @@ public List<SnapshotDataStoreVO> listDestroyed(long id) {
199211
sc.setParameters("state", ObjectInDataStoreStateMachine.State.Destroyed);
200212
return listBy(sc);
201213
}
214+
215+
@Override
216+
public List<SnapshotDataStoreVO> listActiveOnCache(long id) {
217+
SearchCriteria<SnapshotDataStoreVO> sc = cacheSearch.create();
218+
sc.setParameters("store_id", id);
219+
sc.setParameters("store_role", DataStoreRole.ImageCache);
220+
sc.setParameters("state", ObjectInDataStoreStateMachine.State.Destroyed);
221+
sc.setParameters("ref_cnt", 0);
222+
return listBy(sc);
223+
}
202224
}

‎engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
5151
private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class);
5252
private SearchBuilder<TemplateDataStoreVO> updateStateSearch;
5353
private SearchBuilder<TemplateDataStoreVO> storeSearch;
54+
private SearchBuilder<TemplateDataStoreVO> cacheSearch;
5455
private SearchBuilder<TemplateDataStoreVO> templateSearch;
5556
private SearchBuilder<TemplateDataStoreVO> templateRoleSearch;
5657
private SearchBuilder<TemplateDataStoreVO> storeTemplateSearch;
@@ -69,6 +70,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
6970
storeSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
7071
storeSearch.done();
7172

73+
cacheSearch = createSearchBuilder();
74+
cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
75+
cacheSearch.and("destroyed", cacheSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
76+
cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ);
77+
cacheSearch.done();
78+
7279
templateSearch = createSearchBuilder();
7380
templateSearch.and("template_id", templateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
7481
templateSearch.and("destroyed", templateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
@@ -148,14 +155,14 @@ public boolean updateState(State currentState, Event event, State nextState, Dat
148155
if (dbVol != null) {
149156
StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
150157
str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState())
151-
.append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
152-
.append(dbVol.getUpdated());
158+
.append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
159+
.append(dbVol.getUpdated());
153160
str.append(": New Data={id=").append(dataObj.getId()).append("; state=").append(nextState)
154-
.append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
155-
.append("; updatedTime=").append(dataObj.getUpdated());
161+
.append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
162+
.append("; updatedTime=").append(dataObj.getUpdated());
156163
str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState)
157-
.append("; event=").append(event).append("; updatecount=").append(oldUpdated)
158-
.append("; updatedTime=").append(oldUpdatedTime);
164+
.append("; event=").append(event).append("; updatecount=").append(oldUpdated)
165+
.append("; updatedTime=").append(oldUpdatedTime);
159166
} else {
160167
s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId()
161168
+ ", as there is no such object exists in the database anymore");
@@ -180,6 +187,17 @@ public List<TemplateDataStoreVO> listDestroyed(long id) {
180187
return listIncludingRemovedBy(sc);
181188
}
182189

190+
191+
@Override
192+
public List<TemplateDataStoreVO> listActiveOnCache(long id) {
193+
SearchCriteria<TemplateDataStoreVO> sc = cacheSearch.create();
194+
sc.setParameters("store_id", id);
195+
sc.setParameters("destroyed", false);
196+
sc.setParameters("ref_cnt", 0);
197+
return listIncludingRemovedBy(sc);
198+
}
199+
200+
183201
@Override
184202
public void deletePrimaryRecordsForStore(long id) {
185203
SearchCriteria<TemplateDataStoreVO> sc = storeSearch.create();
@@ -279,10 +297,11 @@ public TemplateDataStoreVO findByStoreTemplate(long storeId, long templateId, bo
279297
sc.setParameters("store_id", storeId);
280298
sc.setParameters("template_id", templateId);
281299
sc.setParameters("destroyed", false);
282-
if (!lock)
300+
if (!lock) {
283301
return findOneIncludingRemovedBy(sc);
284-
else
302+
} else {
285303
return lockOneRandomRow(sc, true);
304+
}
286305
}
287306

288307
@Override

‎engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
4343
private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
4444
private SearchBuilder<VolumeDataStoreVO> volumeSearch;
4545
private SearchBuilder<VolumeDataStoreVO> storeSearch;
46+
private SearchBuilder<VolumeDataStoreVO> cacheSearch;
4647
private SearchBuilder<VolumeDataStoreVO> storeVolumeSearch;
4748

4849
@Override
@@ -54,6 +55,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
5455
storeSearch.and("destroyed", storeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
5556
storeSearch.done();
5657

58+
cacheSearch = createSearchBuilder();
59+
cacheSearch.and("store_id", cacheSearch.entity().getDataStoreId(), SearchCriteria.Op.EQ);
60+
cacheSearch.and("destroyed", cacheSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
61+
cacheSearch.and("ref_cnt", cacheSearch.entity().getRefCnt(), SearchCriteria.Op.NEQ);
62+
cacheSearch.done();
63+
5764
volumeSearch = createSearchBuilder();
5865
volumeSearch.and("volume_id", volumeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
5966
volumeSearch.and("destroyed", volumeSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
@@ -99,14 +106,14 @@ public boolean updateState(State currentState, Event event, State nextState, Dat
99106
if (dbVol != null) {
100107
StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
101108
str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState())
102-
.append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
103-
.append(dbVol.getUpdated());
109+
.append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=")
110+
.append(dbVol.getUpdated());
104111
str.append(": New Data={id=").append(dataObj.getId()).append("; state=").append(nextState)
105-
.append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
106-
.append("; updatedTime=").append(dataObj.getUpdated());
112+
.append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount())
113+
.append("; updatedTime=").append(dataObj.getUpdated());
107114
str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState)
108-
.append("; event=").append(event).append("; updatecount=").append(oldUpdated)
109-
.append("; updatedTime=").append(oldUpdatedTime);
115+
.append("; event=").append(event).append("; updatecount=").append(oldUpdated)
116+
.append("; updatedTime=").append(oldUpdatedTime);
110117
} else {
111118
s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId()
112119
+ ", as there is no such object exists in the database anymore");
@@ -123,6 +130,15 @@ public List<VolumeDataStoreVO> listByStoreId(long id) {
123130
return listIncludingRemovedBy(sc);
124131
}
125132

133+
@Override
134+
public List<VolumeDataStoreVO> listActiveOnCache(long id) {
135+
SearchCriteria<VolumeDataStoreVO> sc = cacheSearch.create();
136+
sc.setParameters("store_id", id);
137+
sc.setParameters("destroyed", false);
138+
sc.setParameters("ref_cnt", 0);
139+
return listIncludingRemovedBy(sc);
140+
}
141+
126142
@Override
127143
public void deletePrimaryRecordsForStore(long id) {
128144
SearchCriteria<VolumeDataStoreVO> sc = storeSearch.create();
@@ -156,10 +172,11 @@ public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId, boolean
156172
sc.setParameters("store_id", storeId);
157173
sc.setParameters("volume_id", volumeId);
158174
sc.setParameters("destroyed", false);
159-
if (!lock)
175+
if (!lock) {
160176
return findOneIncludingRemovedBy(sc);
161-
else
177+
} else {
162178
return lockOneRandomRow(sc, true);
179+
}
163180
}
164181

165182
@Override

0 commit comments

Comments
 (0)