-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow deploy Admin VMs and VRs in disabled zones/pods/clusters #3600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DaanHoogland
merged 3 commits into
apache:master
from
CLDIN:deploy-on-disabled-resources
May 28, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,20 @@ | |
| import javax.naming.ConfigurationException; | ||
|
|
||
| import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO; | ||
| import com.cloud.storage.VMTemplateVO; | ||
| import com.cloud.storage.dao.VMTemplateDao; | ||
| import com.cloud.user.AccountVO; | ||
| import com.cloud.user.dao.AccountDao; | ||
| import com.cloud.utils.StringUtils; | ||
| import com.cloud.exception.StorageUnavailableException; | ||
| import com.cloud.utils.db.Filter; | ||
| import com.cloud.utils.fsm.StateMachine2; | ||
|
|
||
| import org.apache.cloudstack.framework.config.ConfigKey; | ||
| import org.apache.cloudstack.framework.config.Configurable; | ||
| import org.apache.commons.collections.CollectionUtils; | ||
| import org.apache.commons.collections.MapUtils; | ||
| import org.apache.log4j.Logger; | ||
| import org.apache.cloudstack.affinity.AffinityGroupProcessor; | ||
| import org.apache.cloudstack.affinity.AffinityGroupService; | ||
| import org.apache.cloudstack.affinity.AffinityGroupVMMapVO; | ||
|
|
@@ -50,9 +64,6 @@ | |
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||
| import org.apache.cloudstack.utils.identity.ManagementServerNode; | ||
| import org.apache.commons.collections.CollectionUtils; | ||
| import org.apache.commons.collections.MapUtils; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import com.cloud.agent.AgentManager; | ||
| import com.cloud.agent.Listener; | ||
|
|
@@ -84,7 +95,6 @@ | |
| import com.cloud.exception.AffinityConflictException; | ||
| import com.cloud.exception.ConnectionException; | ||
| import com.cloud.exception.InsufficientServerCapacityException; | ||
| import com.cloud.exception.StorageUnavailableException; | ||
| import com.cloud.gpu.GPU; | ||
| import com.cloud.host.DetailVO; | ||
| import com.cloud.host.Host; | ||
|
|
@@ -97,7 +107,6 @@ | |
| import com.cloud.org.Cluster; | ||
| import com.cloud.org.Grouping; | ||
| import com.cloud.resource.ResourceManager; | ||
| import com.cloud.resource.ResourceState; | ||
| import com.cloud.service.ServiceOfferingDetailsVO; | ||
| import com.cloud.service.dao.ServiceOfferingDetailsDao; | ||
| import com.cloud.storage.DiskOfferingVO; | ||
|
|
@@ -107,31 +116,26 @@ | |
| import com.cloud.storage.StorageManager; | ||
| import com.cloud.storage.StoragePool; | ||
| import com.cloud.storage.StoragePoolHostVO; | ||
| import com.cloud.storage.VMTemplateVO; | ||
| import com.cloud.storage.Volume; | ||
| import com.cloud.storage.VolumeVO; | ||
| import com.cloud.storage.dao.DiskOfferingDao; | ||
| import com.cloud.storage.dao.GuestOSCategoryDao; | ||
| import com.cloud.storage.dao.GuestOSDao; | ||
| import com.cloud.storage.dao.StoragePoolHostDao; | ||
| import com.cloud.storage.dao.VMTemplateDao; | ||
| import com.cloud.storage.dao.VolumeDao; | ||
| import com.cloud.user.AccountManager; | ||
| import com.cloud.utils.DateUtil; | ||
| import com.cloud.utils.NumbersUtil; | ||
| import com.cloud.utils.Pair; | ||
| import com.cloud.utils.StringUtils; | ||
| import com.cloud.utils.component.Manager; | ||
| import com.cloud.utils.component.ManagerBase; | ||
| import com.cloud.utils.db.DB; | ||
| import com.cloud.utils.db.Filter; | ||
| import com.cloud.utils.db.SearchCriteria; | ||
| import com.cloud.utils.db.Transaction; | ||
| import com.cloud.utils.db.TransactionCallback; | ||
| import com.cloud.utils.db.TransactionStatus; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
| import com.cloud.utils.fsm.StateListener; | ||
| import com.cloud.utils.fsm.StateMachine2; | ||
| import com.cloud.vm.DiskProfile; | ||
| import com.cloud.vm.VMInstanceVO; | ||
| import com.cloud.vm.VirtualMachine; | ||
|
|
@@ -144,12 +148,14 @@ | |
| import static com.cloud.utils.NumbersUtil.toHumanReadableSize; | ||
|
|
||
| public class DeploymentPlanningManagerImpl extends ManagerBase implements DeploymentPlanningManager, Manager, Listener, | ||
| StateListener<State, VirtualMachine.Event, VirtualMachine> { | ||
| StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable { | ||
|
|
||
| private static final Logger s_logger = Logger.getLogger(DeploymentPlanningManagerImpl.class); | ||
| @Inject | ||
| AgentManager _agentMgr; | ||
| @Inject | ||
| private AccountDao accountDao; | ||
| @Inject | ||
| protected UserVmDao _vmDao; | ||
| @Inject | ||
| protected VMInstanceDao _vmInstanceDao; | ||
|
|
@@ -177,6 +183,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy | |
| @Inject | ||
| private VMTemplateDao templateDao; | ||
|
|
||
| private static final long ADMIN_ACCOUNT_ROLE_ID = 1l; | ||
| private static final long INITIAL_RESERVATION_RELEASE_CHECKER_DELAY = 30L * 1000L; // thirty seconds expressed in milliseconds | ||
| protected long _nodeId = -1; | ||
|
|
||
|
|
@@ -283,6 +290,8 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym | |
| s_logger.debug("Is ROOT volume READY (pool already allocated)?: " + (plan.getPoolId() != null ? "Yes" : "No")); | ||
| } | ||
|
|
||
| avoidDisabledResources(vmProfile, dc, avoids); | ||
|
|
||
| String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag); | ||
| String uefiFlag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.UefiFlag); | ||
|
|
||
|
|
@@ -311,17 +320,8 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym | |
| } | ||
|
|
||
| Pod pod = _podDao.findById(host.getPodId()); | ||
| // check if the cluster or the pod is disabled | ||
| if (pod.getAllocationState() != Grouping.AllocationState.Enabled) { | ||
| s_logger.warn("The Pod containing this host is in disabled state, PodId= " + pod.getId()); | ||
| return null; | ||
| } | ||
|
|
||
| Cluster cluster = _clusterDao.findById(host.getClusterId()); | ||
| if (cluster.getAllocationState() != Grouping.AllocationState.Enabled) { | ||
| s_logger.warn("The Cluster containing this host is in disabled state, PodId= " + cluster.getId()); | ||
| return null; | ||
| } | ||
|
|
||
| boolean displayStorage = getDisplayStorageFromVmProfile(vmProfile); | ||
| if (vm.getHypervisorType() == HypervisorType.BareMetal) { | ||
|
|
@@ -422,8 +422,15 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym | |
| s_logger.debug("The last host of this VM does not have required GPU devices available"); | ||
| } | ||
| } else { | ||
| if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) { | ||
| if (checkVmProfileAndHost(vmProfile, host)) { | ||
| if (host.getStatus() == Status.Up) { | ||
| boolean hostTagsMatch = true; | ||
| if(offering.getHostTag() != null){ | ||
| _hostDao.loadHostTags(host); | ||
| if (!(host.getHostTags() != null && host.getHostTags().contains(offering.getHostTag()))) { | ||
| hostTagsMatch = false; | ||
| } | ||
| } | ||
| if (hostTagsMatch) { | ||
| long cluster_id = host.getClusterId(); | ||
| ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, | ||
| "cpuOvercommitRatio"); | ||
|
|
@@ -573,6 +580,86 @@ private boolean getDisplayStorageFromVmProfile(VirtualMachineProfile vmProfile) | |
| return vmProfile == null || vmProfile.getTemplate() == null || !vmProfile.getTemplate().isDeployAsIs(); | ||
| } | ||
|
|
||
| /** | ||
| * Adds disabled resources (Data centers, Pods, Clusters, and hosts) to exclude list (avoid) in case of disabled state. | ||
| */ | ||
| public void avoidDisabledResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) { | ||
| if (vmProfile.getType().isUsedBySystem() && isRouterDeployableInDisabledResources()) { | ||
| return; | ||
| } | ||
|
|
||
| VMInstanceVO vm = _vmInstanceDao.findById(vmProfile.getId()); | ||
| AccountVO owner = accountDao.findById(vm.getAccountId()); | ||
| boolean isOwnerRoleIdAdmin = false; | ||
|
|
||
| if (owner != null && owner.getRoleId() != null && owner.getRoleId() == ADMIN_ACCOUNT_ROLE_ID) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DaanHoogland I fixed the issue raised on tests regarding VMs deployed on a project. Manual tests are looking good now; thanks :-) |
||
| isOwnerRoleIdAdmin = true; | ||
| } | ||
|
|
||
| if (isOwnerRoleIdAdmin && isAdminVmDeployableInDisabledResources()) { | ||
| return; | ||
| } | ||
|
|
||
| avoidDisabledDataCenters(dc, avoids); | ||
| avoidDisabledPods(dc, avoids); | ||
| avoidDisabledClusters(dc, avoids); | ||
| avoidDisabledHosts(dc, avoids); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the value of the ConfigKey 'allow.router.on.disabled.resources'. | ||
| * @note this method allows mocking and testing with the respective ConfigKey parameter. | ||
| */ | ||
| protected boolean isRouterDeployableInDisabledResources() { | ||
| return allowRouterOnDisabledResource.value(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the value of the ConfigKey 'allow.admin.vm.on.disabled.resources'. | ||
| * @note this method allows mocking and testing with the respective ConfigKey parameter. | ||
| */ | ||
| protected boolean isAdminVmDeployableInDisabledResources() { | ||
| return allowAdminVmOnDisabledResource.value(); | ||
| } | ||
|
|
||
| /** | ||
| * Adds disabled Hosts to the ExcludeList in order to avoid them at the deployment planner. | ||
| */ | ||
| protected void avoidDisabledHosts(DataCenter dc, ExcludeList avoids) { | ||
| List<HostVO> disabledHosts = _hostDao.listDisabledByDataCenterId(dc.getId()); | ||
| for (HostVO host : disabledHosts) { | ||
| avoids.addHost(host.getId()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Adds disabled Clusters to the ExcludeList in order to avoid them at the deployment planner. | ||
| */ | ||
| protected void avoidDisabledClusters(DataCenter dc, ExcludeList avoids) { | ||
| List<Long> pods = _podDao.listAllPods(dc.getId()); | ||
| for (Long podId : pods) { | ||
| List<Long> disabledClusters = _clusterDao.listDisabledClusters(dc.getId(), podId); | ||
| avoids.addClusterList(disabledClusters); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Adds disabled Pods to the ExcludeList in order to avoid them at the deployment planner. | ||
| */ | ||
| protected void avoidDisabledPods(DataCenter dc, ExcludeList avoids) { | ||
| List<Long> disabledPods = _podDao.listDisabledPods(dc.getId()); | ||
| avoids.addPodList(disabledPods); | ||
| } | ||
|
|
||
| /** | ||
| * Adds disabled Data Centers (Zones) to the ExcludeList in order to avoid them at the deployment planner. | ||
| */ | ||
| protected void avoidDisabledDataCenters(DataCenter dc, ExcludeList avoids) { | ||
| if (dc.getAllocationState() == Grouping.AllocationState.Disabled) { | ||
| avoids.addDataCenter(dc.getId()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public DeploymentPlanner getDeploymentPlannerByName(String plannerName) { | ||
| if (plannerName != null) { | ||
|
|
@@ -1092,11 +1179,6 @@ private DeployDestination checkClustersforDestination(List<Long> clusterList, Vi | |
| for (Long clusterId : clusterList) { | ||
| ClusterVO clusterVO = _clusterDao.findById(clusterId); | ||
|
|
||
| if (clusterVO.getAllocationState() == Grouping.AllocationState.Disabled && !plan.isMigrationPlan()) { | ||
| s_logger.debug("Cannot deploy in disabled cluster " + clusterId + ", skipping this cluster"); | ||
| avoid.addCluster(clusterVO.getId()); | ||
| } | ||
|
|
||
| if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) { | ||
| s_logger.debug("Cluster: " + clusterId + " has HyperVisorType that does not match the VM, skipping this cluster"); | ||
| avoid.addCluster(clusterVO.getId()); | ||
|
|
@@ -1110,7 +1192,9 @@ private DeployDestination checkClustersforDestination(List<Long> clusterList, Vi | |
| new DataCenterDeployment(plan.getDataCenterId(), clusterVO.getPodId(), clusterVO.getId(), null, plan.getPoolId(), null, plan.getReservationContext()); | ||
|
|
||
| Pod pod = _podDao.findById(clusterVO.getPodId()); | ||
| if (pod.getAllocationState() == Grouping.AllocationState.Enabled ) { | ||
| if (CollectionUtils.isNotEmpty(avoid.getPodsToAvoid()) && avoid.getPodsToAvoid().contains(pod.getId())) { | ||
| s_logger.debug("The cluster is in a disabled pod : " + pod.getId()); | ||
| } else { | ||
| // find suitable hosts under this cluster, need as many hosts as we | ||
| // get. | ||
| List<Host> suitableHosts = findSuitableHosts(vmProfile, potentialPlan, avoid, HostAllocator.RETURN_UPTO_ALL); | ||
|
|
@@ -1151,9 +1235,6 @@ private DeployDestination checkClustersforDestination(List<Long> clusterList, Vi | |
| s_logger.debug("No suitable hosts found under this Cluster: " + clusterId); | ||
| } | ||
| } | ||
| else { | ||
| s_logger.debug("The cluster is in a disabled pod : " + pod.getId()); | ||
| } | ||
|
|
||
| if (canAvoidCluster(clusterVO, avoid, plannerAvoidOutput, vmProfile)) { | ||
| avoid.addCluster(clusterVO.getId()); | ||
|
|
@@ -1739,4 +1820,14 @@ public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> t | |
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public ConfigKey<?>[] getConfigKeys() { | ||
| return new ConfigKey<?>[] {allowRouterOnDisabledResource, allowAdminVmOnDisabledResource}; | ||
| } | ||
|
|
||
| @Override | ||
| public String getConfigComponentName() { | ||
| return DeploymentPlanningManager.class.getSimpleName(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to unify this to listByDataCentyerIdAndState() internally, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, not what i meant but looks good as well. ( i said internally ;)