Skip to content

Commit 7195f88

Browse files
author
Daan Hoogland
committed
optimisation on OOBM and NPE guards
1 parent 24cc7df commit 7195f88

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ protected void runInContext() {
20062006
if (_resourceMgr.checkAndMaintain(host.getId())) {
20072007
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
20082008
final HostPodVO podVO = _podDao.findById(host.getPodId());
2009-
final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
2009+
final String hostDesc = AlertFormatUtils.describeHostLocation(host, dcVO, podVO);
20102010
_alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc,
20112011
"Host [" + hostDesc + "] is ready for maintenance");
20122012
}

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep
163163
}
164164

165165
if (!answer.getResult()) {
166-
String msg = String.format("Unable to attach storage pool %s to the host %s", pool, host);
166+
String msg = String.format("Unable to attach storage pool %s to the host %s", pool, host != null ? host : "id " + hostId);
167167
alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
168168
throw new CloudRuntimeException(String.format("Unable to establish connection from storage head to storage pool %s due to %s %s",
169169
pool, answer.getDetails(), pool.getUuid()));

plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/provider/DateraHostListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ private void sendModifyTargetsCommand(ModifyTargetsCommand cmd, long hostId) {
281281

282282
if (!answer.getResult()) {
283283
HostVO host = _hostDao.findById(hostId);
284-
String msg = String.format("Unable to modify targets on the following host: %s", host);
284+
String msg = String.format("Unable to modify targets on the following host: %s", host != null ? host : "id " + hostId);
285285

286-
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), msg, msg);
286+
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host != null ? host.getDataCenterId() : -1L, host != null ? host.getPodId() : null, msg, msg);
287287

288288
throw new CloudRuntimeException(msg);
289289
}
@@ -298,7 +298,7 @@ private void sendModifyStoragePoolCommand(ModifyStoragePoolCommand cmd, StorageP
298298

299299
if (!answer.getResult()) {
300300
HostVO host = _hostDao.findById(hostId);
301-
String msg = String.format("Unable to attach storage pool %s to host %s", storagePool, host);
301+
String msg = String.format("Unable to attach storage pool %s to host %s", storagePool, host != null ? host : "id " + hostId);
302302

303303
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, storagePool.getDataCenterId(), storagePool.getPodId(), msg, msg);
304304

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2853,7 +2853,7 @@ private void updateVmStateForFailedVmCreation(Long vmId, Long hostId) {
28532853

28542854
if (vm != null) {
28552855
if (vm.getState().equals(State.Stopped)) {
2856-
HostVO host = _hostDao.findById(hostId);
2856+
HostVO host = hostId != null ? _hostDao.findById(hostId) : null;
28572857
logger.debug("Destroying VM [{}] as it was unable to be deployed on Host: {}.", vm, host);
28582858
try {
28592859
_itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationFailedToError, null);

server/src/test/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImplTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,32 @@ public class OutOfBandManagementServiceImplTest {
9797

9898
private OutOfBandManagementServiceImpl service;
9999

100+
private static Field cacheField;
101+
private static Field executorField;
102+
private static Object originalCache;
103+
private static Object originalExecutor;
104+
100105
@BeforeClass
101106
public static void setUpStaticFields() throws Exception {
102-
Field cacheField = OutOfBandManagementServiceImpl.class.getDeclaredField("hostAlertCache");
107+
cacheField = OutOfBandManagementServiceImpl.class.getDeclaredField("hostAlertCache");
103108
cacheField.setAccessible(true);
109+
originalCache = cacheField.get(null);
104110
cacheField.set(null, CacheBuilder.newBuilder().build());
105111

106-
Field executorField = OutOfBandManagementServiceImpl.class.getDeclaredField("backgroundSyncBlockingExecutor");
112+
executorField = OutOfBandManagementServiceImpl.class.getDeclaredField("backgroundSyncBlockingExecutor");
107113
executorField.setAccessible(true);
114+
originalExecutor = executorField.get(null);
108115
executorField.set(null, Executors.newSingleThreadExecutor());
109116
}
110117

111118
@AfterClass
112119
public static void tearDownStaticFields() throws Exception {
113-
Field executorField = OutOfBandManagementServiceImpl.class.getDeclaredField("backgroundSyncBlockingExecutor");
114-
executorField.setAccessible(true);
115120
ExecutorService executor = (ExecutorService) executorField.get(null);
116121
executor.shutdownNow();
117122
executor.awaitTermination(5, TimeUnit.SECONDS);
123+
124+
cacheField.set(null, originalCache);
125+
executorField.set(null, originalExecutor);
118126
}
119127

120128
@Before

0 commit comments

Comments
 (0)