Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <[email protected]>
  • Loading branch information
shwstppr committed Nov 5, 2024
1 parent 779d521 commit 7d43ce3
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 46 deletions.
5 changes: 3 additions & 2 deletions agent/conf/agent.properties
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ iscsi.session.cleanup.enabled=false
# Implicit host tags managed by agent.properties
# host.tags=

# Timeout(in seconds) for SSL handshake when agent connects to server
# Timeout(in seconds) for SSL handshake when agent connects to server. When no value is set then default value of 30s
# will be used
#ssl.handshake.timeout=

# Wait(in seconds) during agent reconnections
# Wait(in seconds) during agent reconnections. When no value is set then default value of 5s will be used
#backoff.seconds=
2 changes: 1 addition & 1 deletion agent/src/main/java/com/cloud/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public void sendStartup(final Link link) {

protected String retrieveHostname() {
if (logger.isTraceEnabled()) {
logger.trace(" Retrieving hostname " + serverResource.getClass().getSimpleName());
logger.trace("Retrieving hostname with resource={}", serverResource.getClass().getSimpleName());
}
final String result = Script.runSimpleBashScript(Script.getExecutableAbsolutePath("hostname"), 500);
if (StringUtils.isNotBlank(result)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl

protected ExecutorService _executor;
protected ThreadPoolExecutor _connectExecutor;
protected ThreadPoolExecutor _directAgentExecutor;
protected ScheduledExecutorService _directAgentExecutor;
protected ScheduledExecutorService _cronJobExecutor;
protected ScheduledExecutorService _monitorExecutor;

Expand Down Expand Up @@ -243,12 +243,13 @@ public boolean configure(final String name, final Map<String, Object> params) th
caService, RemoteAgentSslHandshakeTimeout.value());
logger.info("Listening on {} with {} workers.", Port.value(), Workers.value());

final int directAgentPoolSize = DirectAgentPoolSize.value();
// executes all agent commands other than cron and ping
_directAgentExecutor = new ThreadPoolExecutor(Math.max(agentTaskThreads/10, 1), DirectAgentPoolSize.value(), 120L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("DirectAgent"));
_directAgentExecutor = new ScheduledThreadPoolExecutor(directAgentPoolSize, new NamedThreadFactory("DirectAgent"));
// executes cron and ping agent commands
_cronJobExecutor = new ScheduledThreadPoolExecutor(DirectAgentPoolSize.value(), new NamedThreadFactory("DirectAgentCronJob"));
logger.debug("Created DirectAgentAttache pool with size: {}.", DirectAgentPoolSize.value());
_directAgentThreadCap = Math.round(DirectAgentPoolSize.value() * DirectAgentThreadCap.value()) + 1; // add 1 to always make the value > 0
_cronJobExecutor = new ScheduledThreadPoolExecutor(directAgentPoolSize, new NamedThreadFactory("DirectAgentCronJob"));
logger.debug("Created DirectAgentAttache pool with size: {}.", directAgentPoolSize);
_directAgentThreadCap = Math.round(directAgentPoolSize * DirectAgentThreadCap.value()) + 1; // add 1 to always make the value > 0

_monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor"));

Expand Down Expand Up @@ -1642,7 +1643,7 @@ public void pullAgentOutMaintenance(final long hostId) {
}
}

public ThreadPoolExecutor getDirectAgentPool() {
public ScheduledExecutorService getDirectAgentPool() {
return _directAgentExecutor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3803,7 +3803,6 @@ public int getTimeout() {
public boolean processCommands(final long agentId, final long seq, final Command[] cmds) {
boolean processed = false;
for (final Command cmd : cmds) {
// FIXME: PingRoutingCommand handler is DB & CPU hotspot
if (cmd instanceof PingRoutingCommand) {
final PingRoutingCommand ping = (PingRoutingCommand)cmd;
if (ping.getHostVmStateReport() != null) {
Expand Down
2 changes: 0 additions & 2 deletions engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,4 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {
List<CPU.CPUArch> getClustersArchsByZone(long zoneId);

List<ClusterVO> listClustersByArchAndZoneId(long zoneId, CPU.CPUArch arch);

List<Long> listAllIds();
}
18 changes: 4 additions & 14 deletions engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) {
sc.setParameters("zoneId", zoneId);
}
List<ClusterVO> clusters = listBy(sc);
List<HypervisorType> distinctHypervisors = new ArrayList<>(4);
for (ClusterVO cluster : clusters) {
distinctHypervisors.add(cluster.getHypervisorType());
}

return distinctHypervisors;
return clusters.stream()
.map(ClusterVO::getHypervisorType)
.distinct()
.collect(Collectors.toList());
}

@Override
Expand Down Expand Up @@ -346,12 +344,4 @@ public List<ClusterVO> listClustersByArchAndZoneId(long zoneId, CPU.CPUArch arch
sc.setParameters("arch", arch);
return listBy(sc);
}

@Override
public List<Long> listAllIds() {
GenericSearchBuilder<ClusterVO, Long> sb = createSearchBuilder(Long.class);
sb.selectFields(sb.entity().getId());
sb.done();
return customSearch(sb.create(), null);
}
}
2 changes: 0 additions & 2 deletions engine/schema/src/main/java/com/cloud/host/dao/HostDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ List<Long> findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(final Long
final List<ResourceState> resourceStates, final List<Type> types,
final List<Hypervisor.HypervisorType> hypervisorTypes);

List<Long> listAllIds();

List<HypervisorType> listDistinctHypervisorTypes(final Long zoneId);

List<HostVO> listByIds(final List<Long> ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1743,11 +1743,6 @@ public List<Long> findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(fin
return customSearch(sc, null);
}

@Override
public List<Long> listAllIds() {
return listIdsBy(null, null, null, null, null, null, null);
}

@Override
public List<HypervisorType> listDistinctHypervisorTypes(final Long zoneId) {
GenericSearchBuilder<HostVO, HypervisorType> sb = createSearchBuilder(HypervisorType.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,4 @@ Pair<List<Long>, Integer> searchForIdsAndCount(Long storagePoolId, String storag
String keyword, Filter searchFilter);

List<StoragePoolVO> listByIds(List<Long> ids);

List<Long> listAllIds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,4 @@ private SearchCriteria<StoragePoolVO> createStoragePoolSearchCriteria(Long stora
sc.setParameters("parent", 0);
return sc;
}

@Override
public List<Long> listAllIds() {
GenericSearchBuilder<StoragePoolVO, Long> sb = createSearchBuilder(Long.class);
sb.selectFields(sb.entity().getId());
sb.done();
return customSearch(sb.create(), null);
}
}
5 changes: 5 additions & 0 deletions framework/db/src/main/java/com/cloud/utils/db/GenericDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public interface GenericDao<T, ID extends Serializable> {
*/
List<T> listAll(Filter filter);

/**
* Look IDs for all active rows.
*/
List<ID> listAllIds();

/**
* Search for the entity beans
* @param sc
Expand Down
29 changes: 29 additions & 0 deletions framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,35 @@ public List<T> listAll(final Filter filter) {
return executeList(sql.toString());
}

private Object getIdObject() {
T entity = (T)_searchEnhancer.create();
try {
Method m = _entityBeanType.getMethod("getId");
return m.invoke(entity);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
logger.warn(String.format("Unable to get ID object for entity: %s", _entityBeanType.getSimpleName()));
}
return null;
}

@Override
public List<ID> listAllIds() {
Object idObj = getIdObject();
if (idObj == null) {
return Collections.emptyList();
}
Class<ID> clazz = (Class<ID>)idObj.getClass();
GenericSearchBuilder<T, ID> sb = createSearchBuilder(clazz);
try {
Method m = sb.entity().getClass().getMethod("getId");
sb.selectFields(m.invoke(sb.entity()));
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
return Collections.emptyList();
}
sb.done();
return customSearch(sb.create(), null);
}

@Override
public boolean expunge(final ID id) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public Type getType() {
public PingCommand getCurrentStatus(long id) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
//MockConfigurationVO config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(), agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingCommand");
MockConfigurationVO config = null;
if (config != null) {
Map<String, String> configParameters = config.getParameters();
Expand All @@ -123,7 +122,6 @@ public PingCommand getCurrentStatus(long id) {
}
}

//config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(), agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingRoutingWithNwGroupsCommand");
config = null;
if (config != null) {
String message = config.getJsonResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,9 @@ protected void cleanupConnectedHostConnectionForFailedStorage(DataStore primaryS
@Override
public void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope scope,
boolean handleExceptionsPartially, boolean errorOnNoUpHost) throws CloudRuntimeException {
if (CollectionUtils.isEmpty(hostIds)) {
return;
}
CopyOnWriteArrayList<Long> poolHostIds = new CopyOnWriteArrayList<>();
ExecutorService executorService = Executors.newFixedThreadPool(Math.max(1, Math.min(hostIds.size(),
StoragePoolHostConnectWorkers.value())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public String getConfigComponentName() {

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {RoleService.EnableDynamicApiChecker, RoleService.DynamicApiCheckerCachePeriod};
return new ConfigKey<?>[] {EnableDynamicApiChecker, DynamicApiCheckerCachePeriod};
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions server/src/test/java/com/cloud/user/MockUsageEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.naming.ConfigurationException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -142,6 +143,11 @@ public List<UsageEventVO> listAll(Filter filter) {
return null;
}

@Override
public List<Long> listAllIds() {
return Collections.emptyList();
}

@Override
public List<UsageEventVO> search(SearchCriteria<UsageEventVO> sc,
Filter filter) {
Expand Down

0 comments on commit 7d43ce3

Please sign in to comment.