4040import javax .inject .Inject ;
4141import javax .naming .ConfigurationException ;
4242
43- import org .apache .cloudstack .engine .subsystem .api .storage .PrimaryDataStoreInfo ;
4443import org .apache .log4j .Logger ;
4544
4645import org .apache .cloudstack .affinity .dao .AffinityGroupVMMapDao ;
4746import org .apache .cloudstack .context .CallContext ;
4847import org .apache .cloudstack .engine .orchestration .service .NetworkOrchestrationService ;
4948import org .apache .cloudstack .engine .orchestration .service .VolumeOrchestrationService ;
5049import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
50+ import org .apache .cloudstack .engine .subsystem .api .storage .PrimaryDataStoreInfo ;
5151import org .apache .cloudstack .engine .subsystem .api .storage .StoragePoolAllocator ;
5252import org .apache .cloudstack .framework .config .ConfigDepot ;
5353import org .apache .cloudstack .framework .config .ConfigKey ;
@@ -336,7 +336,7 @@ public void setHostAllocators(List<HostAllocator> _hostAllocators) {
336336
337337 // TODO, remove it after transient period is over
338338 static final ConfigKey <Boolean > VmJobEnabled = new ConfigKey <Boolean >("Advanced" ,
339- Boolean .class , "vm.job.enabled" , "true " ,
339+ Boolean .class , "vm.job.enabled" , "false " ,
340340 "True to enable new VM sync model. false to use the old way" , false );
341341
342342 static final ConfigKey <Long > VmJobCheckInterval = new ConfigKey <Long >("Advanced" ,
@@ -3698,7 +3698,7 @@ public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm, Reserv
36983698 @ Override
36993699 public VMInstanceVO reConfigureVm (String vmUuid , ServiceOffering oldServiceOffering ,
37003700 boolean reconfiguringOnExistingHost )
3701- throws ResourceUnavailableException , ConcurrentOperationException {
3701+ throws ResourceUnavailableException , InsufficientServerCapacityException , ConcurrentOperationException {
37023702
37033703 AsyncJobExecutionContext jobContext = AsyncJobExecutionContext .getCurrentExecutionContext ();
37043704 if (!VmJobEnabled .value () || jobContext .isJobDispatchedBy (VmWorkConstants .VM_WORK_JOB_DISPATCHER )) {
@@ -3716,20 +3716,21 @@ public VMInstanceVO reConfigureVm(String vmUuid, ServiceOffering oldServiceOffer
37163716 throw new RuntimeException ("Execution excetion" , e );
37173717 }
37183718
3719- AsyncJobVO jobVo = _entityMgr .findById (AsyncJobVO .class , outcome .getJob ().getId ());
3720- if (jobVo .getResultCode () == JobInfo .Status .SUCCEEDED .ordinal ()) {
3721- return _entityMgr .findById (VMInstanceVO .class , vm .getId ());
3722- } else {
3723- Object jobResult = _jobMgr .unmarshallResultObject (outcome .getJob ());
3724- if (jobResult != null ) {
3725- if (jobResult instanceof ResourceUnavailableException )
3726- throw (ResourceUnavailableException )jobResult ;
3727- else if (jobResult instanceof ConcurrentOperationException )
3728- throw (ConcurrentOperationException )jobResult ;
3729- }
3719+ Object jobResult = _jobMgr .unmarshallResultObject (outcome .getJob ());
3720+ if (jobResult != null ) {
3721+ if (jobResult instanceof ResourceUnavailableException )
3722+ throw (ResourceUnavailableException )jobResult ;
3723+ else if (jobResult instanceof ConcurrentOperationException )
3724+ throw (ConcurrentOperationException )jobResult ;
3725+ else if (jobResult instanceof InsufficientServerCapacityException )
3726+ throw (InsufficientServerCapacityException )jobResult ;
3727+ else if (jobResult instanceof Throwable ) {
3728+ s_logger .error ("Unhandled exception" , (Throwable )jobResult );
3729+ throw new RuntimeException ("Unhandled exception" , (Throwable )jobResult );
3730+ }
3731+ }
37303732
3731- throw new RuntimeException ("Failed with un-handled exception" );
3732- }
3733+ return (VMInstanceVO )vm ;
37333734 }
37343735 }
37353736
@@ -4668,7 +4669,7 @@ public Object[] doInTransaction(TransactionStatus status) {
46684669 }
46694670
46704671 public Outcome <VirtualMachine > reconfigureVmThroughJobQueue (
4671- final String vmUuid , final ServiceOffering oldServiceOffering , final boolean reconfiguringOnExistingHost ) {
4672+ final String vmUuid , final ServiceOffering newServiceOffering , final boolean reconfiguringOnExistingHost ) {
46724673
46734674 final CallContext context = CallContext .current ();
46744675 final User user = context .getCallingUser ();
@@ -4705,7 +4706,7 @@ public Object[] doInTransaction(TransactionStatus status) {
47054706
47064707 // save work context info (there are some duplications)
47074708 VmWorkReconfigure workInfo = new VmWorkReconfigure (user .getId (), account .getId (), vm .getId (),
4708- VirtualMachineManagerImpl .VM_WORK_JOB_HANDLER , oldServiceOffering , reconfiguringOnExistingHost );
4709+ VirtualMachineManagerImpl .VM_WORK_JOB_HANDLER , newServiceOffering . getId () , reconfiguringOnExistingHost );
47094710 workJob .setCmdInfo (VmWorkSerializer .serialize (workInfo ));
47104711
47114712 _jobMgr .submitAsyncJob (workJob , VmWorkConstants .VM_WORK_QUEUE , vm .getId ());
@@ -4833,7 +4834,10 @@ private Pair<JobInfo.Status, String> orchestrateReconfigure(VmWorkReconfigure wo
48334834 s_logger .info ("Unable to find vm " + work .getVmId ());
48344835 }
48354836 assert (vm != null );
4836- reConfigureVm (vm .getUuid (), work .getNewServiceOffering (),
4837+
4838+ ServiceOffering newServiceOffering = _offeringDao .findById (vm .getId (), work .getNewServiceOfferingId ());
4839+
4840+ reConfigureVm (vm .getUuid (), newServiceOffering ,
48374841 work .isSameHost ());
48384842 return new Pair <JobInfo .Status , String >(JobInfo .Status .SUCCEEDED , null );
48394843 }
0 commit comments