Skip to content

Commit 26c559a

Browse files
Cleanups implemented while working on [CLOUDSTACK-10240]
1 parent d0baf33 commit 26c559a

File tree

5 files changed

+327
-425
lines changed

5 files changed

+327
-425
lines changed

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 21 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Collections;
2727
import java.util.Date;
2828
import java.util.HashMap;
29-
import java.util.Iterator;
3029
import java.util.LinkedHashMap;
3130
import java.util.List;
3231
import java.util.Map;
@@ -40,10 +39,6 @@
4039
import javax.inject.Inject;
4140
import 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-
4742
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
4843
import org.apache.cloudstack.ca.CAManager;
4944
import org.apache.cloudstack.context.CallContext;
@@ -75,6 +70,9 @@
7570
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
7671
import org.apache.cloudstack.storage.to.VolumeObjectTO;
7772
import 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

7977
import com.cloud.agent.AgentManager;
8078
import 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() {

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@
140140
import org.apache.cloudstack.api.command.admin.offering.DeleteServiceOfferingCmd;
141141
import org.apache.cloudstack.api.command.admin.offering.UpdateDiskOfferingCmd;
142142
import org.apache.cloudstack.api.command.admin.offering.UpdateServiceOfferingCmd;
143+
import org.apache.cloudstack.api.command.admin.outofbandmanagement.ChangeOutOfBandManagementPasswordCmd;
144+
import org.apache.cloudstack.api.command.admin.outofbandmanagement.ConfigureOutOfBandManagementCmd;
143145
import org.apache.cloudstack.api.command.admin.outofbandmanagement.DisableOutOfBandManagementForClusterCmd;
144146
import org.apache.cloudstack.api.command.admin.outofbandmanagement.DisableOutOfBandManagementForHostCmd;
145147
import org.apache.cloudstack.api.command.admin.outofbandmanagement.DisableOutOfBandManagementForZoneCmd;
146148
import org.apache.cloudstack.api.command.admin.outofbandmanagement.EnableOutOfBandManagementForClusterCmd;
147149
import org.apache.cloudstack.api.command.admin.outofbandmanagement.EnableOutOfBandManagementForHostCmd;
148150
import org.apache.cloudstack.api.command.admin.outofbandmanagement.EnableOutOfBandManagementForZoneCmd;
149-
import org.apache.cloudstack.api.command.admin.outofbandmanagement.ConfigureOutOfBandManagementCmd;
150151
import org.apache.cloudstack.api.command.admin.outofbandmanagement.IssueOutOfBandManagementPowerActionCmd;
151-
import org.apache.cloudstack.api.command.admin.outofbandmanagement.ChangeOutOfBandManagementPasswordCmd;
152152
import org.apache.cloudstack.api.command.admin.pod.CreatePodCmd;
153153
import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd;
154154
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
@@ -519,7 +519,6 @@
519519
import org.apache.cloudstack.config.Configuration;
520520
import org.apache.cloudstack.context.CallContext;
521521
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
522-
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
523522
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
524523
import org.apache.cloudstack.framework.config.ConfigDepot;
525524
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -549,8 +548,6 @@
549548
import com.cloud.alert.dao.AlertDao;
550549
import com.cloud.api.ApiDBUtils;
551550
import com.cloud.api.query.QueryManagerImpl;
552-
import com.cloud.api.query.dao.ServiceOfferingJoinDao;
553-
import com.cloud.api.query.vo.ServiceOfferingJoinVO;
554551
import com.cloud.capacity.Capacity;
555552
import com.cloud.capacity.CapacityVO;
556553
import com.cloud.capacity.dao.CapacityDao;
@@ -633,7 +630,6 @@
633630
import com.cloud.storage.GuestOSHypervisorVO;
634631
import com.cloud.storage.GuestOSVO;
635632
import com.cloud.storage.GuestOsCategory;
636-
import com.cloud.storage.ScopeType;
637633
import com.cloud.storage.StorageManager;
638634
import com.cloud.storage.StoragePool;
639635
import com.cloud.storage.Volume;
@@ -701,7 +697,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
701697
public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName());
702698

703699
static final ConfigKey<Integer> vmPasswordLength = new ConfigKey<Integer>("Advanced", Integer.class, "vm.password.length", "6",
704-
"Specifies the length of a randomly generated password", false);
700+
"Specifies the length of a randomly generated password", false);
705701
static final ConfigKey<Integer> sshKeyLength = new ConfigKey<Integer>("Advanced", Integer.class, "ssh.key.length",
706702
"2048", "Specifies custom SSH key length (bit)", true, ConfigKey.Scope.Global);
707703
@Inject
@@ -799,8 +795,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
799795
@Inject
800796
private HighAvailabilityManager _haMgr;
801797
@Inject
802-
private DataStoreManager dataStoreMgr;
803-
@Inject
804798
private HostTagsDao _hostTagsDao;
805799
@Inject
806800
private ConfigDepot _configDepot;
@@ -816,8 +810,6 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
816810
private GuestOsDetailsDao _guestOsDetailsDao;
817811
@Inject
818812
private KeystoreManager _ksMgr;
819-
@Inject
820-
private ServiceOfferingJoinDao serviceOfferingJoinDao;
821813

822814
private LockMasterListener _lockMasterListener;
823815
private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker"));
@@ -1134,9 +1126,9 @@ public Pair<List<? extends Host>, Integer> searchForServers(final ListHostsCmd c
11341126

11351127
@Override
11361128
public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>>
1137-
listHostsForMigrationOfVM(final Long vmId,
1138-
final Long startIndex,
1139-
final Long pageSize, final String keyword) {
1129+
listHostsForMigrationOfVM(final Long vmId,
1130+
final Long startIndex,
1131+
final Long pageSize, final String keyword) {
11401132
final Account caller = getCaller();
11411133
if (!_accountMgr.isRootAdmin(caller.getId())) {
11421134
if (s_logger.isDebugEnabled()) {
@@ -1362,11 +1354,6 @@ public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStorag
13621354
return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
13631355
}
13641356

1365-
if (!_volumeMgr.volumeOnSharedStoragePool(volume)) {
1366-
s_logger.info("Volume " + volume + " is on local storage. It cannot be migrated to another pool.");
1367-
return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
1368-
}
1369-
13701357
final Long instanceId = volume.getInstanceId();
13711358
VMInstanceVO vm = null;
13721359
if (instanceId != null) {
@@ -1407,13 +1394,12 @@ public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStorag
14071394
StoragePool srcVolumePool = _poolDao.findById(volume.getPoolId());
14081395
allPools = getAllStoragePoolCompatileWithVolumeSourceStoragePool(srcVolumePool);
14091396
allPools.remove(srcVolumePool);
1410-
14111397
suitablePools = findAllSuitableStoragePoolsForVm(volume, vm, srcVolumePool);
1412-
1398+
14131399
return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
14141400
}
1415-
1416-
1401+
1402+
14171403
/**
14181404
* This method looks for all storage pools that are compatible with the given volume.
14191405
* <ul>
@@ -1433,7 +1419,7 @@ private List<? extends StoragePool> getAllStoragePoolCompatileWithVolumeSourceSt
14331419
}
14341420
return storagePools;
14351421
}
1436-
1422+
14371423
/**
14381424
* Looks for all suitable storage pools to allocate the given volume.
14391425
* We take into account the service offering of the VM and volume to find suitable storage pools. It is also excluded from the search the current storage pool used by the volume.
@@ -1919,10 +1905,8 @@ public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListP
19191905
vlanSearch.and("vlanType", vlanSearch.entity().getVlanType(), SearchCriteria.Op.EQ);
19201906
sb.join("vlanSearch", vlanSearch, sb.entity().getVlanId(), vlanSearch.entity().getId(), JoinBuilder.JoinType.INNER);
19211907

1922-
boolean allocatedOnly = false;
19231908
if (isAllocated != null && isAllocated == true) {
19241909
sb.and("allocated", sb.entity().getAllocatedTime(), SearchCriteria.Op.NNULL);
1925-
allocatedOnly = true;
19261910
}
19271911

19281912
VlanType vlanType = null;
@@ -2180,7 +2164,7 @@ public GuestOS addGuestOs(final AddGuestOsCmd cmd) {
21802164
if(cmd.getDetails() != null && !cmd.getDetails().isEmpty()){
21812165
Map<String, String> detailsMap = cmd.getDetails();
21822166
for(Object key: detailsMap.keySet()){
2183-
_guestOsDetailsDao.addDetail(guestOsPersisted.getId(),(String) key,detailsMap.get((String) key), false);
2167+
_guestOsDetailsDao.addDetail(guestOsPersisted.getId(),(String) key,detailsMap.get(key), false);
21842168
}
21852169
}
21862170

@@ -2213,7 +2197,7 @@ public GuestOS updateGuestOs(final UpdateGuestOsCmd cmd) {
22132197
if(cmd.getDetails() != null && !cmd.getDetails().isEmpty()){
22142198
Map<String, String> detailsMap = cmd.getDetails();
22152199
for(Object key: detailsMap.keySet()){
2216-
_guestOsDetailsDao.addDetail(id,(String) key,detailsMap.get((String) key), false);
2200+
_guestOsDetailsDao.addDetail(id,(String) key,detailsMap.get(key), false);
22172201
}
22182202
}
22192203

0 commit comments

Comments
 (0)