@@ -506,9 +506,6 @@ public SecondaryStorageVmVO startNew(long dataCenterId, SecondaryStorageVm.Role
506506 s_logger.debug("Unable to allocate secondary storage vm storage, remove the secondary storage vm record from DB, secondary storage vm id: " +
507507 secStorageVmId);
508508 }
509-
510- SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
511- new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, secStorageVmId, null, "Unable to allocate storage"));
512509 }
513510 return null;
514511 }
@@ -654,70 +651,83 @@ private void allocCapacity(long dataCenterId, SecondaryStorageVm.Role role) {
654651 }
655652 return;
656653 }
657-
658- boolean secStorageVmFromStoppedPool = false;
659- SecondaryStorageVmVO secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
660- if (secStorageVm == null) {
661- if (s_logger.isInfoEnabled()) {
662- s_logger.info("No stopped secondary storage vm is available, need to allocate a new secondary storage vm");
663- }
664-
665- if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
666- try {
667- secStorageVm = startNew(dataCenterId, role);
668- for (UploadVO upload : _uploadDao.listAll()) {
669- _uploadDao.expunge(upload.getId());
670- }
671- } finally {
672- _allocLock.unlock();
673- }
674- } else {
654+ SecondaryStorageVmVO secStorageVm = null;
655+ String errorString = null;
656+ try{
657+ boolean secStorageVmFromStoppedPool = false;
658+ secStorageVm = assignSecStorageVmFromStoppedPool(dataCenterId, role);
659+ if (secStorageVm == null) {
675660 if (s_logger.isInfoEnabled()) {
676- s_logger.info("Unable to acquire synchronization lock to allocate secStorageVm resource for standby capacity, wait for next scan ");
661+ s_logger.info("No stopped secondary storage vm is available, need to allocate a new secondary storage vm ");
677662 }
678- return;
679- }
680- } else {
681- if (s_logger.isInfoEnabled()) {
682- s_logger.info("Found a stopped secondary storage vm, bring it up to running pool. secStorageVm vm id : " + secStorageVm.getId());
683- }
684- secStorageVmFromStoppedPool = true;
685- }
686663
687- if (secStorageVm != null) {
688- long secStorageVmId = secStorageVm.getId();
689- GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVmId));
690- try {
691- if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
664+ if (_allocLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
692665 try {
693- secStorageVm = startSecStorageVm(secStorageVmId);
666+ secStorageVm = startNew(dataCenterId, role);
667+ for (UploadVO upload : _uploadDao.listAll()) {
668+ _uploadDao.expunge(upload.getId());
669+ }
694670 } finally {
695- secStorageVmLock .unlock();
671+ _allocLock .unlock();
696672 }
697673 } else {
698674 if (s_logger.isInfoEnabled()) {
699- s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " + secStorageVm.getId() );
675+ s_logger.info("Unable to acquire synchronization lock to allocate secStorageVm resource for standby capacity, wait for next scan" );
700676 }
701677 return;
702678 }
703- } finally {
704- secStorageVmLock.releaseRef();
705- }
706-
707- if (secStorageVm == null) {
679+ } else {
708680 if (s_logger.isInfoEnabled()) {
709- s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId +
710- ", will recycle it and start a new one");
681+ s_logger.info("Found a stopped secondary storage vm, bring it up to running pool. secStorageVm vm id : " + secStorageVm.getId());
711682 }
683+ secStorageVmFromStoppedPool = true;
684+ }
712685
713- if (secStorageVmFromStoppedPool) {
714- destroySecStorageVm(secStorageVmId);
686+ if (secStorageVm != null) {
687+ long secStorageVmId = secStorageVm.getId();
688+ GlobalLock secStorageVmLock = GlobalLock.getInternLock(getSecStorageVmLockName(secStorageVmId));
689+ try {
690+ if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) {
691+ try {
692+ secStorageVm = startSecStorageVm(secStorageVmId);
693+ } finally {
694+ secStorageVmLock.unlock();
695+ }
696+ } else {
697+ if (s_logger.isInfoEnabled()) {
698+ s_logger.info("Unable to acquire synchronization lock to start secStorageVm for standby capacity, secStorageVm vm id : " + secStorageVm.getId());
699+ }
700+ return;
701+ }
702+ } finally {
703+ secStorageVmLock.releaseRef();
715704 }
716- } else {
717- if (s_logger.isInfoEnabled()) {
718- s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
705+
706+ if (secStorageVm == null) {
707+ if (s_logger.isInfoEnabled()) {
708+ s_logger.info("Unable to start secondary storage vm for standby capacity, secStorageVm vm Id : " + secStorageVmId +
709+ ", will recycle it and start a new one");
710+ }
711+
712+ if (secStorageVmFromStoppedPool) {
713+ destroySecStorageVm(secStorageVmId);
714+ }
715+ } else {
716+ SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
717+ new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_UP, dataCenterId, secStorageVmId, secStorageVm, null));
718+ if (s_logger.isInfoEnabled()) {
719+ s_logger.info("Secondary storage vm " + secStorageVm.getHostName() + " is started");
720+ }
719721 }
720722 }
723+ }catch (Exception e){
724+ errorString = e.getMessage();
725+ }finally{
726+ // TODO - For now put all the alerts as creation failure. Distinguish between creation vs start failure in future.
727+ // Also add failure reason since startvm masks some of them.
728+ if(secStorageVm == null || secStorageVm.getState() != State.Running)
729+ SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this,
730+ new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE, dataCenterId, 0l, null, errorString));
721731 }
722732 }
723733
0 commit comments