5959import org .apache .cloudstack .affinity .AffinityGroupProcessor ;
6060import org .apache .cloudstack .affinity .AffinityGroupService ;
6161import org .apache .cloudstack .affinity .AffinityGroupVO ;
62- import org .apache .cloudstack .affinity .HostAffinityProcessor ;
63- import org .apache .cloudstack .affinity .HostAntiAffinityProcessor ;
62+ import org .apache .cloudstack .affinity .AffinityProcessorBase ;
6463import org .apache .cloudstack .affinity .dao .AffinityGroupDao ;
6564import org .apache .cloudstack .affinity .dao .AffinityGroupVMMapDao ;
6665import org .apache .cloudstack .annotation .AnnotationService ;
@@ -2579,14 +2578,14 @@ protected void validateNodesAgainstExistingWorkers(List<Long> nodeIds, Set<Long>
25792578 Long nodeHostId = node .getHostId ();
25802579 String nodeHostName = getHostName (nodeHostId );
25812580
2582- if (processor instanceof HostAntiAffinityProcessor ) {
2581+ if (AffinityProcessorBase . AFFINITY_TYPE_HOST_ANTI . equals ( affinityGroup . getType ()) ) {
25832582 if (existingWorkerHostIds .contains (nodeHostId )) {
25842583 throw new InvalidParameterValueException (String .format (
25852584 "Cannot add VM %s to cluster %s. VM is running on host %s which violates the cluster's " +
25862585 "host anti-affinity rule (affinity group: %s). Existing worker VMs are already running on this host." ,
25872586 node .getInstanceName (), cluster .getName (), nodeHostName , affinityGroup .getName ()));
25882587 }
2589- } else if (processor instanceof HostAffinityProcessor ) {
2588+ } else if (AffinityProcessorBase . AFFINITY_TYPE_HOST . equals ( affinityGroup . getType ()) ) {
25902589 if (!existingWorkerHostIds .isEmpty () && !existingWorkerHostIds .contains (nodeHostId )) {
25912590 List <String > existingHostNames = existingWorkerHostIds .stream ()
25922591 .map (this ::getHostName )
@@ -2604,7 +2603,7 @@ protected void validateNodesAgainstExistingWorkers(List<Long> nodeIds, Set<Long>
26042603
26052604 protected void validateNewNodesAntiAffinity (List <Long > nodeIds , AffinityGroupVO affinityGroup , KubernetesCluster cluster ) {
26062605 AffinityGroupProcessor processor = getAffinityGroupProcessor (affinityGroup .getType ());
2607- if (!( processor instanceof HostAntiAffinityProcessor )) {
2606+ if (processor == null || ! AffinityProcessorBase . AFFINITY_TYPE_HOST_ANTI . equals ( affinityGroup . getType () )) {
26082607 return ;
26092608 }
26102609
0 commit comments