Skip to content

Commit 9ec2a6c

Browse files
committed
CLOUDSTACK-8623: CPVM fails to start after MS is restarted during its initial start-up process
If SSVM cannot be started then the existing entry is removed and a new SSVM gets created. Made similar changes for CPVM as well. Also cleaned up some log messages in SSVM and CPVM manager code.
1 parent 76a1035 commit 9ec2a6c

4 files changed

Lines changed: 44 additions & 38 deletions

File tree

‎engine/schema/src/com/cloud/vm/ConsoleProxyVO.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public ConsoleProxyVO(long id, long serviceOfferingId, String name, long templat
7272
long accountId, long userId, int activeSession, boolean haEnabled) {
7373
super(id, serviceOfferingId, name, name, Type.ConsoleProxy, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
7474
this.activeSession = activeSession;
75+
this.dataCenterId = dataCenterId;
7576
}
7677

7778
protected ConsoleProxyVO() {

‎engine/schema/src/com/cloud/vm/SecondaryStorageVmVO.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public SecondaryStorageVmVO(long id, long serviceOfferingId, String name, long t
6767
long domainId, long accountId, long userId, Role role, boolean haEnabled) {
6868
super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, hypervisorType, guestOSId, domainId, accountId, userId, haEnabled);
6969
this.role = role;
70+
this.dataCenterId = dataCenterId;
7071
}
7172

7273
protected SecondaryStorageVmVO() {

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,7 @@ public ConsoleProxyVO startProxy(long proxyVmId, boolean ignoreRestartSetting) {
543543

544544
// For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null
545545
// as sooner or later, Starting/Migrating state will be transited to Running and Stopping will be transited
546-
// to
547-
// Stopped to allow
548-
// Starting of it
546+
// to Stopped to allow Starting of it
549547
s_logger.warn("Console proxy is not in correct state to be started: " + proxy.getState());
550548
return null;
551549
} catch (StorageUnavailableException e) {
@@ -889,32 +887,32 @@ private void allocCapacity(long dataCenterId) {
889887

890888
ConsoleProxyVO proxy = null;
891889
String errorString = null;
892-
try{
893-
if (_allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
894-
try {
895-
proxy = assignProxyFromStoppedPool(dataCenterId);
896-
if (proxy == null) {
897-
if (s_logger.isInfoEnabled()) {
898-
s_logger.info("No stopped console proxy is available, need to allocate a new console proxy");
899-
}
890+
try {
891+
boolean consoleProxyVmFromStoppedPool = false;
892+
proxy = assignProxyFromStoppedPool(dataCenterId);
893+
if (proxy == null) {
894+
if (s_logger.isInfoEnabled()) {
895+
s_logger.info("No stopped console proxy is available, need to allocate a new console proxy");
896+
}
900897

901-
try {
902-
proxy = startNew(dataCenterId);
903-
} catch (ConcurrentOperationException e) {
904-
s_logger.info("Concurrent Operation caught " + e);
905-
}
906-
} else {
907-
if (s_logger.isInfoEnabled()) {
908-
s_logger.info("Found a stopped console proxy, bring it up to running pool. proxy vm id : " + proxy.getId());
909-
}
898+
if (_allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
899+
try {
900+
proxy = startNew(dataCenterId);
901+
} catch (ConcurrentOperationException e) {
902+
s_logger.info("Concurrent operation exception caught " + e);
903+
} finally {
904+
_allocProxyLock.unlock();
905+
}
906+
} else {
907+
if (s_logger.isInfoEnabled()) {
908+
s_logger.info("Unable to acquire synchronization lock for console proxy vm allocation, wait for next scan");
910909
}
911-
} finally {
912-
_allocProxyLock.unlock();
913910
}
914911
} else {
915912
if (s_logger.isInfoEnabled()) {
916-
s_logger.info("Unable to acquire proxy allocation lock, skip for next time");
913+
s_logger.info("Found a stopped console proxy, starting it. Vm id : " + proxy.getId());
917914
}
915+
consoleProxyVmFromStoppedPool = true;
918916
}
919917

920918
if (proxy != null) {
@@ -927,19 +925,26 @@ private void allocCapacity(long dataCenterId) {
927925
}
928926
SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this,
929927
new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_UP, dataCenterId, proxy.getId(), proxy, null));
928+
} else {
929+
if (s_logger.isInfoEnabled()) {
930+
s_logger.info("Unable to start console proxy vm for standby capacity, vm id : " + proxyVmId + ", will recycle it and start a new one");
931+
}
932+
933+
if (consoleProxyVmFromStoppedPool) {
934+
destroyProxy(proxyVmId);
935+
}
930936
}
931937
}
932-
}catch (Exception e){
938+
} catch (Exception e) {
933939
errorString = e.getMessage();
934940
throw e;
935-
}finally {
941+
} finally {
936942
// TODO - For now put all the alerts as creation failure. Distinguish between creation vs start failure in future.
937943
// Also add failure reason since startvm masks some of them.
938-
if(proxy == null || proxy.getState() != State.Running)
944+
if (proxy == null || proxy.getState() != State.Running)
939945
SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this,
940946
new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE, dataCenterId, 0l, null, errorString));
941947
}
942-
943948
}
944949

945950
public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
@@ -1544,14 +1549,14 @@ public boolean canScan() {
15441549

15451550
if (!reserveStandbyCapacity()) {
15461551
if (s_logger.isDebugEnabled()) {
1547-
s_logger.debug("Reserving standby capacity is disable, skip capacity scan");
1552+
s_logger.debug("Reserving standby capacity is disabled, skip capacity scan");
15481553
}
15491554
return false;
15501555
}
15511556

15521557
List<StoragePoolVO> upPools = _storagePoolDao.listByStatus(StoragePoolStatus.Up);
15531558
if (upPools == null || upPools.size() == 0) {
1554-
s_logger.debug("Skip capacity scan due to there is no Primary Storage UPintenance mode");
1559+
s_logger.debug("Skip capacity scan as there is no Primary Storage in 'Up' state");
15551560
return false;
15561561
}
15571562

‎services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,13 @@ private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
656656

657657
if (!isSecondaryStorageVmRequired(dataCenterId)) {
658658
if (s_logger.isDebugEnabled()) {
659-
s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config");
659+
s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " according to zone config");
660660
}
661661
return;
662662
}
663663
SecondaryStorageVmVO secStorageVm = null;
664664
String errorString = null;
665-
try{
665+
try {
666666
boolean secStorageVmFromStoppedPool = false;
667667
secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
668668
if (secStorageVm == null) {
@@ -681,13 +681,13 @@ private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
681681
}
682682
} else {
683683
if (s_logger.isInfoEnabled()) {
684-
s_logger.info("Unable to acquire synchronization lock to allocate secStorageVm resource for standby capacity, wait for next scan");
684+
s_logger.info("Unable to acquire synchronization lock for secondary storage vm allocation, wait for next scan");
685685
}
686686
return;
687687
}
688688
} else {
689689
if (s_logger.isInfoEnabled()) {
690-
s_logger.info("Found a stopped secondary storage vm, bring it up to running pool. secStorageVm vm id : " + secStorageVm.getId());
690+
s_logger.info("Found a stopped secondary storage vm, starting it. Vm id : " + secStorageVm.getId());
691691
}
692692
secStorageVmFromStoppedPool = true;
693693
}
@@ -704,7 +704,7 @@ private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
704704
}
705705
} else {
706706
if (s_logger.isInfoEnabled()) {
707-
s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " + secStorageVm.getId());
707+
s_logger.info("Unable to acquire synchronization lock for starting secondary storage vm id : " + secStorageVm.getId());
708708
}
709709
return;
710710
}
@@ -714,8 +714,7 @@ private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
714714

715715
if (secStorageVm == null) {
716716
if (s_logger.isInfoEnabled()) {
717-
s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId +
718-
", will recycle it and start a new one");
717+
s_logger.info("Unable to start secondary storage vm for standby capacity, vm id : " + secStorageVmId + ", will recycle it and start a new one");
719718
}
720719

721720
if (secStorageVmFromStoppedPool) {
@@ -729,10 +728,10 @@ private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
729728
}
730729
}
731730
}
732-
}catch (Exception e){
731+
} catch (Exception e) {
733732
errorString = e.getMessage();
734733
throw e;
735-
}finally{
734+
} finally {
736735
// TODO - For now put all the alerts as creation failure. Distinguish between creation vs start failure in future.
737736
// Also add failure reason since startvm masks some of them.
738737
if(secStorageVm == null || secStorageVm.getState() != State.Running)

0 commit comments

Comments
 (0)