Skip to content

Commit 9f23fbe

Browse files
[Simulator] Fix NPE in SolidFireHostListener (#5955)
* [Simulator] Fix NPE in SolidFireHostListener * address comments * Update plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java Co-authored-by: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com> Co-authored-by: sureshanaparti <12028987+sureshanaparti@users.noreply.github.com>
1 parent 7aa9d3c commit 9f23fbe

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireHostListener.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ public boolean hostAdded(long hostId) {
7373
HostVO host = hostDao.findById(hostId);
7474

7575
if (host == null) {
76-
LOGGER.error("Failed to add host by SolidFireHostListener as host was not found with id = " + hostId);
76+
LOGGER.error(String.format("Failed to add host by SolidFireHostListener as host was not found with id = %s ", hostId));
7777

7878
return false;
7979
}
8080

81+
if (host.getClusterId() == null) {
82+
LOGGER.error("Failed to add host by SolidFireHostListener as host has no associated cluster id");
83+
return false;
84+
}
85+
8186
SolidFireUtil.hostAddedToCluster(hostId, host.getClusterId(), SolidFireUtil.PROVIDER_NAME,
82-
clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao);
87+
clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao);
8388

8489
handleVMware(host, true, ModifyTargetsCommand.TargetTypeToRemove.NEITHER);
8590

plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,18 @@ public boolean hostAdded(long hostId) {
6767
HostVO host = hostDao.findById(hostId);
6868

6969
if (host == null) {
70-
LOGGER.error("Failed to add host by SolidFireSharedHostListener as host was not found with id = " + hostId);
70+
LOGGER.error(String.format("Failed to add host by SolidFireSharedHostListener as host was not found with id = %s ", hostId));
7171

7272
return false;
7373
}
7474

75+
if (host.getClusterId() == null) {
76+
LOGGER.error("Failed to add host by SolidFireSharedHostListener as host has no associated cluster id");
77+
return false;
78+
}
79+
7580
SolidFireUtil.hostAddedToCluster(hostId, host.getClusterId(), SolidFireUtil.SHARED_PROVIDER_NAME,
76-
clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao);
81+
clusterDao, hostDao, storagePoolDao, storagePoolDetailsDao);
7782

7883
handleVMware(host, true, ModifyTargetsCommand.TargetTypeToRemove.NEITHER);
7984

0 commit comments

Comments
 (0)