improve agentlb sort when host list not needed

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2024-09-13 10:25:31 +05:30
parent a1ee64344d
commit e1a5bd9ef2
3 changed files with 11 additions and 3 deletions

View File

@ -42,4 +42,8 @@ public interface IndirectAgentLBAlgorithm {
* @return true if the lists are equal, false if not
*/
boolean compare(final List<String> msList, final List<String> receivedMsList);
default boolean isHostListNeeded() {
return false;
}
}

View File

@ -86,9 +86,10 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
return msList;
}
final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm();
List<Long> hostIdList = orderedHostIdList;
if (hostIdList == null) {
hostIdList = getOrderedHostIdList(dcId);
hostIdList = algorithm.isHostListNeeded() ? getOrderedHostIdList(dcId) : new ArrayList<>();
}
// just in case we have a host in creating state make sure it is in the list:
@ -98,8 +99,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
}
hostIdList.add(hostId);
}
final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm();
return algorithm.sort(msList, hostIdList, hostId);
}

View File

@ -56,4 +56,9 @@ public class IndirectAgentLBRoundRobinAlgorithm implements IndirectAgentLBAlgori
public boolean compare(final List<String> msList, final List<String> receivedMsList) {
return msList != null && receivedMsList != null && msList.equals(receivedMsList);
}
@Override
public boolean isHostListNeeded() {
return true;
}
}