Skip to content

Commit ccbcb08

Browse files
Pearl1594Pearl Dsilva
andauthored
server: Increase leniency to list templates on secondary stores that have been marked deleted by updating the db (#4713)
This PR aims at restoring the previous level of leniency in listing templates on stores that have been marked as deleted / removed by updating the DB. While Cloudstack doesn't allow deleting stores that have resources on them, it may so happen that users may mimic a deletion of a store by merely updating the DB. Under such a case, listing of templates is hampered due to an NPE that is caused. (as seen in #4606) Co-authored-by: Pearl Dsilva <pearl.dsilva@shapeblue.com>
1 parent a896760 commit ccbcb08

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.deployasis.TemplateDeployAsIsDetailVO;
3131
import com.cloud.deployasis.dao.TemplateDeployAsIsDetailsDao;
3232
import org.apache.cloudstack.api.ApiConstants;
33+
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
3334
import org.apache.cloudstack.utils.security.DigestHelper;
3435
import org.apache.log4j.Logger;
3536
import org.springframework.stereotype.Component;
@@ -161,10 +162,13 @@ public TemplateResponse newTemplateResponse(EnumSet<ApiConstants.DomainDetails>
161162
HashMap<String, String> downloadDetailInImageStores = null;
162163
for (TemplateDataStoreVO templateInStore : templatesInStore) {
163164
downloadDetailInImageStores = new HashMap<>();
164-
downloadDetailInImageStores.put("datastore", dataStoreDao.findById(templateInStore.getDataStoreId()).getName());
165-
downloadDetailInImageStores.put("downloadPercent", Integer.toString(templateInStore.getDownloadPercent()));
166-
downloadDetailInImageStores.put("downloadState", (templateInStore.getDownloadState() != null ? templateInStore.getDownloadState().toString() : ""));
167-
downloadProgressDetails.add(downloadDetailInImageStores);
165+
ImageStoreVO datastore = dataStoreDao.findById(templateInStore.getDataStoreId());
166+
if (datastore != null) {
167+
downloadDetailInImageStores.put("datastore", datastore.getName());
168+
downloadDetailInImageStores.put("downloadPercent", Integer.toString(templateInStore.getDownloadPercent()));
169+
downloadDetailInImageStores.put("downloadState", (templateInStore.getDownloadState() != null ? templateInStore.getDownloadState().toString() : ""));
170+
downloadProgressDetails.add(downloadDetailInImageStores);
171+
}
168172
}
169173

170174
TemplateResponse templateResponse = new TemplateResponse();

0 commit comments

Comments
 (0)