Skip to content

Commit a4cecd2

Browse files
syedRohit Yadav
authored andcommitted
solidfire: Add NULL checks for various objects in SolidFire integration test API (#2205)
1 parent 619da91 commit a4cecd2

2 files changed

Lines changed: 41 additions & 18 deletions

File tree

plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/SolidFireIntegrationTestManagerImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
// under the License.
1717
package org.apache.cloudstack.solidfire;
1818

19-
import javax.inject.Inject;
20-
21-
import org.apache.cloudstack.storage.datastore.util.SolidFireUtil;
22-
import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil;
23-
import org.springframework.stereotype.Component;
24-
2519
import com.cloud.dc.ClusterDetailsDao;
2620
import com.cloud.dc.ClusterDetailsVO;
2721
import com.cloud.storage.VolumeDetailVO;
2822
import com.cloud.storage.VolumeVO;
2923
import com.cloud.storage.dao.VolumeDao;
3024
import com.cloud.storage.dao.VolumeDetailsDao;
31-
import com.cloud.user.AccountDetailsDao;
3225
import com.cloud.user.AccountDetailVO;
26+
import com.cloud.user.AccountDetailsDao;
3327
import com.cloud.utils.exception.CloudRuntimeException;
28+
import org.apache.cloudstack.storage.datastore.util.SolidFireUtil;
29+
import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil;
30+
import org.springframework.stereotype.Component;
31+
32+
import javax.inject.Inject;
3433

3534
@Component
3635
public class SolidFireIntegrationTestManagerImpl implements SolidFireIntegrationTestManager {
@@ -47,6 +46,9 @@ public long getSolidFireAccountId(String csAccountUuid, String storagePoolUuid)
4746
long storagePoolId = util.getStoragePoolIdForStoragePoolUuid(storagePoolUuid);
4847

4948
AccountDetailVO accountDetail = accountDetailsDao.findDetail(csAccountId, SolidFireUtil.getAccountKey(storagePoolId));
49+
if (accountDetail == null){
50+
throw new CloudRuntimeException("Unable to find SF account for storage " + storagePoolUuid + " for CS account " + csAccountUuid);
51+
}
5052
String sfAccountId = accountDetail.getValue();
5153

5254
return Long.parseLong(sfAccountId);

plugins/api/solidfire-intg-test/src/org/apache/cloudstack/util/solidfire/SolidFireIntegrationTestUtil.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.util.solidfire;
1818

19-
import java.util.ArrayList;
20-
import java.util.List;
21-
22-
import javax.inject.Inject;
23-
24-
import org.apache.cloudstack.api.response.solidfire.ApiVolumeSnapshotDetailsResponse;
25-
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
26-
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
27-
2819
import com.cloud.dc.ClusterVO;
2920
import com.cloud.dc.dao.ClusterDao;
3021
import com.cloud.storage.SnapshotVO;
@@ -35,6 +26,14 @@
3526
import com.cloud.storage.dao.VolumeDao;
3627
import com.cloud.user.Account;
3728
import com.cloud.user.dao.AccountDao;
29+
import com.cloud.utils.exception.CloudRuntimeException;
30+
import org.apache.cloudstack.api.response.solidfire.ApiVolumeSnapshotDetailsResponse;
31+
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
32+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
33+
34+
import javax.inject.Inject;
35+
import java.util.ArrayList;
36+
import java.util.List;
3837

3938
public class SolidFireIntegrationTestUtil {
4039
@Inject private AccountDao accountDao;
@@ -48,48 +47,70 @@ private SolidFireIntegrationTestUtil() {}
4847

4948
public long getAccountIdForAccountUuid(String accountUuid) {
5049
Account account = accountDao.findByUuid(accountUuid);
51-
50+
if (account == null){
51+
throw new CloudRuntimeException("Unable to find Account for ID: " + accountUuid);
52+
}
5253
return account.getAccountId();
5354
}
5455

5556
public long getAccountIdForVolumeUuid(String volumeUuid) {
5657
VolumeVO volume = volumeDao.findByUuid(volumeUuid);
58+
if (volume == null){
59+
throw new CloudRuntimeException("Unable to find Volume for ID: " + volumeUuid);
60+
}
5761

5862
return volume.getAccountId();
5963
}
6064

6165
public long getAccountIdForSnapshotUuid(String snapshotUuid) {
6266
SnapshotVO snapshot = snapshotDao.findByUuid(snapshotUuid);
63-
67+
if (snapshot == null){
68+
throw new CloudRuntimeException("Unable to find Volume for ID: " + snapshotUuid);
69+
}
6470
return snapshot.getAccountId();
6571
}
6672

6773
public long getClusterIdForClusterUuid(String clusterUuid) {
6874
ClusterVO cluster = clusterDao.findByUuid(clusterUuid);
75+
if (cluster == null){
76+
throw new CloudRuntimeException("Unable to find Volume for ID: " + clusterUuid);
77+
}
6978

7079
return cluster.getId();
7180
}
7281

7382
public long getStoragePoolIdForStoragePoolUuid(String storagePoolUuid) {
7483
StoragePoolVO storagePool = storagePoolDao.findByUuid(storagePoolUuid);
84+
if (storagePool == null){
85+
throw new CloudRuntimeException("Unable to find Volume for ID: " + storagePoolUuid);
86+
}
7587

7688
return storagePool.getId();
7789
}
7890

7991
public String getPathForVolumeUuid(String volumeUuid) {
8092
VolumeVO volume = volumeDao.findByUuid(volumeUuid);
93+
if (volume == null){
94+
throw new CloudRuntimeException("Unable to find Volume for ID: " + volumeUuid);
95+
}
8196

8297
return volume.getPath();
8398
}
8499

85100
public String getVolume_iScsiName(String volumeUuid) {
86101
VolumeVO volume = volumeDao.findByUuid(volumeUuid);
102+
if (volume == null){
103+
throw new CloudRuntimeException("Unable to find Volume for ID: " + volumeUuid);
104+
}
87105

88106
return volume.get_iScsiName();
89107
}
90108

91109
public List<ApiVolumeSnapshotDetailsResponse> getSnapshotDetails(String snapshotUuid) {
92110
SnapshotVO snapshot = snapshotDao.findByUuid(snapshotUuid);
111+
if (snapshot == null){
112+
throw new CloudRuntimeException("Unable to find Volume for ID: " + snapshotUuid);
113+
}
93114

94115
List<SnapshotDetailsVO> snapshotDetails = snapshotDetailsDao.listDetails(snapshot.getId());
95116

0 commit comments

Comments
 (0)