From f7b546d64045440b3d037c500cc872f94bc788cb Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Tue, 24 Mar 2026 21:28:34 -0400 Subject: [PATCH] readability cleanup --- .../service/AbstractNodeActionService.java | 98 ++++++++++--------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/shared/src/main/java/com/inteligr8/alfresco/asie/service/AbstractNodeActionService.java b/shared/src/main/java/com/inteligr8/alfresco/asie/service/AbstractNodeActionService.java index db8012f..2ce701e 100644 --- a/shared/src/main/java/com/inteligr8/alfresco/asie/service/AbstractNodeActionService.java +++ b/shared/src/main/java/com/inteligr8/alfresco/asie/service/AbstractNodeActionService.java @@ -13,15 +13,12 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.alfresco.model.ContentModel; import org.alfresco.repo.index.shard.Floc; import org.alfresco.repo.index.shard.Shard; import org.alfresco.repo.index.shard.ShardInstance; import org.alfresco.repo.index.shard.ShardRegistry; import org.alfresco.repo.index.shard.ShardState; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.search.SearchParameters; -import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.slf4j.Logger; @@ -151,7 +148,10 @@ public abstract class AbstractNodeActionService implements DisposableBean { } } - private Future _action(long nodeDbId, ActionCallback callback, Long fullQueueExpireTimeMillis) throws TimeoutException, InterruptedException { + private Future _action( + final long nodeDbId, + final ActionCallback callback, + Long fullQueueExpireTimeMillis) throws TimeoutException, InterruptedException { List eligibleInstances = this.findPossibleShardInstances(nodeDbId); this.logger.debug("Will attempt to {} ACS node against {} shard instances: {}", this.getActionName(), eligibleInstances.size(), nodeDbId); @@ -164,49 +164,12 @@ public abstract class AbstractNodeActionService implements DisposableBean { Callable callable = new Callable<>() { @Override public Void call() { - String core = instance.extractShard().getCoreName(); - SolrHost host = instance.extractNode(); - URL url = host.toUrl(apiService.isSecure() ? "https" : "http"); - CoreAdminApi api = apiService.createApi(url.toString(), CoreAdminApi.class); - try { - logger.debug("Performing {} of ACS node against shard instance: {}: {}", getActionName(), nodeDbId, instance); - BaseResponse apiResponse = execute(api, core, nodeDbId); - logger.trace("Performed {} of ACS node against shard instance: {}: {}", getActionName(), nodeDbId, instance); - - Action action = null; - if (apiResponse instanceof ActionCoreResponse) { - action = ((ActionCoreResponse) apiResponse).getCores().getByCore(core); - } else if (apiResponse instanceof ActionResponse) { - action = ((ActionResponse) apiResponse).getAction(); - } - - if (action == null) { - callback.unknownResult(instance); - } else { - switch (action.getStatus()) { - case Scheduled: - callback.scheduled(instance); - break; - case Success: - callback.success(instance); - break; - default: - if (apiResponse instanceof com.inteligr8.alfresco.asie.model.BaseResponse) { - com.inteligr8.alfresco.asie.model.BaseResponse asieResponse = (com.inteligr8.alfresco.asie.model.BaseResponse) apiResponse; - logger.debug("Performance of {} of ACS node against shard instance failed: {}: {}: {}", getActionName(), nodeDbId, instance, asieResponse.getException()); - callback.error(instance, asieResponse.getException()); - } else { - logger.debug("Performance of {} of ACS node against shard instance failed: {}: {}: {}", getActionName(), nodeDbId, instance, apiResponse.getResponseHeader().getStatus()); - callback.error(instance, String.valueOf(apiResponse.getResponseHeader().getStatus())); - } - } - } + actionToShard(nodeDbId, callback, instance); } catch (Exception e) { - logger.error("An exception occurred", e); + logger.error("An unexpected exception occurred", e); callback.error(instance, e.getMessage()); } - return null; } }; @@ -221,15 +184,58 @@ public abstract class AbstractNodeActionService implements DisposableBean { return future; } + @SuppressWarnings("unchecked") + protected void actionToShard(long nodeDbId, ActionCallback callback, com.inteligr8.alfresco.asie.model.ShardInstance instance) { + String core = instance.extractShard().getCoreName(); + SolrHost host = instance.extractNode(); + URL url = host.toUrl(this.apiService.isSecure() ? "https" : "http"); + CoreAdminApi api = this.apiService.createApi(url.toString(), CoreAdminApi.class); + + this.logger.debug("Performing {} of ACS node against shard instance: {}: {}", this.getActionName(), nodeDbId, instance); + BaseResponse apiResponse = execute(api, core, nodeDbId); + this.logger.trace("Performed {} of ACS node against shard instance: {}: {}", this.getActionName(), nodeDbId, instance); + + Action action = null; + if (apiResponse instanceof ActionCoreResponse) { + action = ((ActionCoreResponse) apiResponse).getCores().getByCore(core); + } else if (apiResponse instanceof ActionResponse) { + action = ((ActionResponse) apiResponse).getAction(); + } + + if (action == null) { + callback.unknownResult(instance); + } else { + switch (action.getStatus()) { + case Scheduled: + callback.scheduled(instance); + break; + case Success: + callback.success(instance); + break; + default: + if (apiResponse instanceof com.inteligr8.alfresco.asie.model.BaseResponse) { + com.inteligr8.alfresco.asie.model.BaseResponse asieResponse = (com.inteligr8.alfresco.asie.model.BaseResponse) apiResponse; + this.logger.debug("Performance of {} of ACS node against shard instance failed: {}: {}: {}", + this.getActionName(), nodeDbId, instance, asieResponse.getException()); + callback.error(instance, asieResponse.getException()); + } else { + this.logger.debug("Performance of {} of ACS node against shard instance failed: {}: {}: {}", + this.getActionName(), nodeDbId, instance, apiResponse.getResponseHeader().getStatus()); + callback.error(instance, String.valueOf(apiResponse.getResponseHeader().getStatus())); + } + } + } + } + protected abstract BaseResponse execute(CoreAdminApi api, String core, long nodeDbId); private List findPossibleShardInstances(long nodeDbId) { if (this.shardRegistry == null) throw new UnsupportedOperationException("ACS instances without a sharding configuration are not yet implemented"); - SearchParameters searchParams = new SearchParameters(); - searchParams.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); - searchParams.setQuery("@" + this.formatForFts(ContentModel.PROP_NODE_DBID) + ":" + nodeDbId); +// SearchParameters searchParams = new SearchParameters(); +// searchParams.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO); +// searchParams.setQuery("@" + this.formatForFts(ContentModel.PROP_NODE_DBID) + ":" + nodeDbId); List instances = new LinkedList<>();