@@ -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
0 commit comments