2626import java .util .Collections ;
2727import java .util .Date ;
2828import java .util .HashMap ;
29- import java .util .Iterator ;
3029import java .util .LinkedHashMap ;
3130import java .util .List ;
3231import java .util .Map ;
4039import javax .inject .Inject ;
4140import javax .naming .ConfigurationException ;
4241
43- import org .apache .commons .collections .CollectionUtils ;
44- import org .apache .commons .collections .MapUtils ;
45- import org .apache .log4j .Logger ;
46-
4742import org .apache .cloudstack .affinity .dao .AffinityGroupVMMapDao ;
4843import org .apache .cloudstack .ca .CAManager ;
4944import org .apache .cloudstack .context .CallContext ;
7570import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
7671import org .apache .cloudstack .storage .to .VolumeObjectTO ;
7772import org .apache .cloudstack .utils .identity .ManagementServerNode ;
73+ import org .apache .commons .collections .CollectionUtils ;
74+ import org .apache .commons .collections .MapUtils ;
75+ import org .apache .log4j .Logger ;
7876
7977import com .cloud .agent .AgentManager ;
8078import com .cloud .agent .Listener ;
@@ -426,8 +424,9 @@ public void doInTransactionWithoutResult(final TransactionStatus status) throws
426424 }
427425
428426 try {
429- if (!vmProfile .getBootArgs ().contains ("ExternalLoadBalancerVm" ))
427+ if (!vmProfile .getBootArgs ().contains ("ExternalLoadBalancerVm" )) {
430428 _networkMgr .allocate (vmProfile , auxiliaryNetworks , extraDhcpOptions );
429+ }
431430 } catch (final ConcurrentOperationException e ) {
432431 throw new CloudRuntimeException ("Concurrent operation while trying to allocate resources for the VM" , e );
433432 }
@@ -1882,6 +1881,7 @@ public void destroy(final String vmUuid, final boolean expunge) throws AgentUnav
18821881 deleteVMSnapshots (vm , expunge );
18831882
18841883 Transaction .execute (new TransactionCallbackWithExceptionNoReturn <CloudRuntimeException >() {
1884+ @ Override
18851885 public void doInTransactionWithoutResult (final TransactionStatus status ) throws CloudRuntimeException {
18861886 VMInstanceVO vm = _vmDao .findByUuid (vmUuid );
18871887 try {
@@ -2305,7 +2305,7 @@ private Map<Volume, StoragePool> getPoolListForVolumesForMigration(VirtualMachin
23052305
23062306 return createMappingVolumeAndStoragePoolEnteredByUser (profile , targetHost , volumeToPool );
23072307 }
2308-
2308+
23092309 /**
23102310 * We create the mapping of volumes and storage pool to migrate the VMs according to the information sent by the user.
23112311 */
@@ -2327,8 +2327,8 @@ private Map<Volume, StoragePool> createMappingVolumeAndStoragePoolEnteredByUser(
23272327 volumeToPoolObjectMap .put (volume , targetPool );
23282328 }
23292329 return volumeToPoolObjectMap ;
2330- }
2331-
2330+ }
2331+
23322332 /**
23332333 * We create the default mapping of volumes and storage pools for the migration of the VM to the target host.
23342334 * If the current storage pool of one of the volumes is using local storage in the host, it then needs to be migrated to a local storage in the target host.
@@ -2347,7 +2347,7 @@ private Map<Volume, StoragePool> getDefaultMappingOfVolumesAndStoragePoolForMigr
23472347 }
23482348 return volumeToPoolObjectMap ;
23492349 }
2350-
2350+
23512351 /**
23522352 * We will add a mapping of volume to storage pool if needed. The conditions to add a mapping are the following:
23532353 * <ul>
@@ -2379,7 +2379,7 @@ private void createVolumeToStoragePoolMappingIfNeeded(VirtualMachineProfile prof
23792379 profile .getUuid (), targetHost .getUuid ()));
23802380 }
23812381 }
2382-
2382+
23832383 /**
23842384 * We use {@link StoragePoolAllocator} objects to find local storage pools connected to the targetHost where we would be able to allocate the given volume.
23852385 */
@@ -2408,7 +2408,7 @@ private List<StoragePool> getCandidateStoragePoolsToMigrateLocalVolume(VirtualMa
24082408 }
24092409 return poolList ;
24102410 }
2411-
2411+
24122412 private <T extends VMInstanceVO > void moveVmToMigratingState (final T vm , final Long hostId , final ItWorkVO work ) throws ConcurrentOperationException {
24132413 // Put the vm in migrating state.
24142414 try {
@@ -2915,8 +2915,11 @@ private String getControlNicIpForVM(VirtualMachine vm) {
29152915 if (vm .getType () == VirtualMachine .Type .ConsoleProxy || vm .getType () == VirtualMachine .Type .SecondaryStorageVm ) {
29162916 NicVO nic = _nicsDao .getControlNicForVM (vm .getId ());
29172917 return nic .getIPv4Address ();
2918- } else if (vm .getType () == VirtualMachine .Type .DomainRouter ) return vm .getPrivateIpAddress ();
2919- else return null ;
2918+ } else if (vm .getType () == VirtualMachine .Type .DomainRouter ) {
2919+ return vm .getPrivateIpAddress ();
2920+ } else {
2921+ return null ;
2922+ }
29202923 }
29212924 public Command cleanup (final String vmName ) {
29222925 VirtualMachine vm = _vmDao .findVMByInstanceName (vmName );
@@ -2985,67 +2988,6 @@ private void updateVmMetaData(Long vmId, String platform) {
29852988 _userVmDao .saveDetails (userVm );
29862989 }
29872990
2988- private void ensureVmRunningContext (final long hostId , VMInstanceVO vm , final Event cause ) throws OperationTimedoutException , ResourceUnavailableException ,
2989- NoTransitionException , InsufficientAddressCapacityException {
2990- final VirtualMachineGuru vmGuru = getVmGuru (vm );
2991-
2992- s_logger .debug ("VM state is starting on full sync so updating it to running" );
2993- vm = _vmDao .findById (vm .getId ());
2994-
2995- // grab outstanding work item if any
2996- final ItWorkVO work = _workDao .findByOutstandingWork (vm .getId (), vm .getState ());
2997- if (work != null ) {
2998- if (s_logger .isDebugEnabled ()) {
2999- s_logger .debug ("Found an outstanding work item for this vm " + vm + " in state:" + vm .getState () + ", work id:" + work .getId ());
3000- }
3001- }
3002-
3003- try {
3004- stateTransitTo (vm , cause , hostId );
3005- } catch (final NoTransitionException e1 ) {
3006- s_logger .warn (e1 .getMessage ());
3007- }
3008-
3009- s_logger .debug ("VM's " + vm + " state is starting on full sync so updating it to Running" );
3010- vm = _vmDao .findById (vm .getId ()); // this should ensure vm has the most
3011- // up to date info
3012-
3013- final VirtualMachineProfile profile = new VirtualMachineProfileImpl (vm );
3014- final List <NicVO > nics = _nicsDao .listByVmId (profile .getId ());
3015- for (final NicVO nic : nics ) {
3016- final Network network = _networkModel .getNetwork (nic .getNetworkId ());
3017- final NicProfile nicProfile =
3018- new NicProfile (nic , network , nic .getBroadcastUri (), nic .getIsolationUri (), null , _networkModel .isSecurityGroupSupportedInNetwork (network ),
3019- _networkModel .getNetworkTag (profile .getHypervisorType (), network ));
3020- profile .addNic (nicProfile );
3021- }
3022-
3023- final Commands cmds = new Commands (Command .OnError .Stop );
3024- s_logger .debug ("Finalizing commands that need to be send to complete Start process for the vm " + vm );
3025-
3026- if (vmGuru .finalizeCommandsOnStart (cmds , profile )) {
3027- if (cmds .size () != 0 ) {
3028- _agentMgr .send (vm .getHostId (), cmds );
3029- }
3030-
3031- if (vmGuru .finalizeStart (profile , vm .getHostId (), cmds , null )) {
3032- stateTransitTo (vm , cause , vm .getHostId ());
3033- } else {
3034- s_logger .error ("Unable to finish finialization for running vm: " + vm );
3035- }
3036- } else {
3037- s_logger .error ("Unable to finalize commands on start for vm: " + vm );
3038- }
3039-
3040- if (work != null ) {
3041- if (s_logger .isDebugEnabled ()) {
3042- s_logger .debug ("Updating outstanding work item to Done, id:" + work .getId ());
3043- }
3044- work .setStep (Step .Done );
3045- _workDao .update (work .getId (), work );
3046- }
3047- }
3048-
30492991 @ Override
30502992 public boolean isRecurring () {
30512993 return true ;
@@ -3827,7 +3769,7 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI
38273769
38283770 @ Override
38293771 public boolean replugNic (final Network network , final NicTO nic , final VirtualMachineTO vm , final ReservationContext context , final DeployDestination dest ) throws ConcurrentOperationException ,
3830- ResourceUnavailableException , InsufficientCapacityException {
3772+ ResourceUnavailableException , InsufficientCapacityException {
38313773 boolean result = true ;
38323774
38333775 final VMInstanceVO router = _vmDao .findById (vm .getId ());
@@ -3849,7 +3791,7 @@ public boolean replugNic(final Network network, final NicTO nic, final VirtualMa
38493791 s_logger .warn ("Unable to apply ReplugNic, vm " + router + " is not in the right state " + router .getState ());
38503792
38513793 throw new ResourceUnavailableException ("Unable to apply ReplugNic on the backend," + " vm " + vm + " is not in the right state" , DataCenter .class ,
3852- router .getDataCenterId ());
3794+ router .getDataCenterId ());
38533795 }
38543796
38553797 return result ;
@@ -4039,8 +3981,8 @@ public String getConfigComponentName() {
40393981 @ Override
40403982 public ConfigKey <?>[] getConfigKeys () {
40413983 return new ConfigKey <?>[] {ClusterDeltaSyncInterval , StartRetry , VmDestroyForcestop , VmOpCancelInterval , VmOpCleanupInterval , VmOpCleanupWait ,
4042- VmOpLockStateRetry ,
4043- VmOpWaitInterval , ExecuteInSequence , VmJobCheckInterval , VmJobTimeout , VmJobStateReportInterval , VmConfigDriveLabel };
3984+ VmOpLockStateRetry ,
3985+ VmOpWaitInterval , ExecuteInSequence , VmJobCheckInterval , VmJobTimeout , VmJobStateReportInterval , VmConfigDriveLabel };
40443986 }
40453987
40463988 public List <StoragePoolAllocator > getStoragePoolAllocators () {
0 commit comments