Commit f7b546d6 authored by Brian Long's avatar Brian Long
Browse files

readability cleanup

parent 00c2ddd1
Loading
Loading
Loading
Loading
+52 −46
Original line number Diff line number Diff line
@@ -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<Void> _action(long nodeDbId, ActionCallback callback, Long fullQueueExpireTimeMillis) throws TimeoutException, InterruptedException {
	private Future<Void> _action(
			final long nodeDbId,
			final ActionCallback callback,
			Long fullQueueExpireTimeMillis) throws TimeoutException, InterruptedException {
		List<com.inteligr8.alfresco.asie.model.ShardInstance> eligibleInstances = this.findPossibleShardInstances(nodeDbId);
		this.logger.debug("Will attempt to {} ACS node against {} shard instances: {}", this.getActionName(), eligibleInstances.size(), nodeDbId);
		
@@ -164,15 +164,36 @@ public abstract class AbstractNodeActionService implements DisposableBean {
			Callable<Void> callable = new Callable<>() {
				@Override
				public Void call() {
					try {
						actionToShard(nodeDbId, callback, instance);
					} catch (Exception e) {
						logger.error("An unexpected exception occurred", e);
						callback.error(instance, e.getMessage());
					}
					return null;
				}
			};
			
			if (fullQueueExpireTimeMillis == null) {
				future.combine(executor.submit(callable, -1L, null));
			} else {
				future.combine(executor.submit(callable, fullQueueExpireTimeMillis - System.currentTimeMillis(), TimeUnit.MILLISECONDS));
			}
		}
		
		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(apiService.isSecure() ? "https" : "http");
					CoreAdminApi api = apiService.createApi(url.toString(), CoreAdminApi.class);
		URL url = host.toUrl(this.apiService.isSecure() ? "https" : "http");
		CoreAdminApi api = this.apiService.createApi(url.toString(), CoreAdminApi.class);
		
					try {
						logger.debug("Performing {} of ACS node against shard instance: {}: {}", getActionName(), nodeDbId, instance);
		this.logger.debug("Performing {} of ACS node against shard instance: {}: {}", this.getActionName(), nodeDbId, instance);
		BaseResponse apiResponse = execute(api, core, nodeDbId);
						logger.trace("Performed {} of ACS node against shard instance: {}: {}", getActionName(), nodeDbId, instance);
		this.logger.trace("Performed {} of ACS node against shard instance: {}: {}", this.getActionName(), nodeDbId, instance);
		
		Action action = null;
		if (apiResponse instanceof ActionCoreResponse<?>) {
@@ -194,31 +215,16 @@ public abstract class AbstractNodeActionService implements DisposableBean {
		    	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());
		    			this.logger.debug("Performance of {} of ACS node against shard instance failed: {}: {}: {}",
		    					this.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());
		    			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()));
		    		}
			}
		}
					} catch (Exception e) {
						logger.error("An exception occurred", e);
						callback.error(instance, e.getMessage());
					}
					
					return null;
				}
			};
			
			if (fullQueueExpireTimeMillis == null) {
				future.combine(executor.submit(callable, -1L, null));
			} else {
				future.combine(executor.submit(callable, fullQueueExpireTimeMillis - System.currentTimeMillis(), TimeUnit.MILLISECONDS));
			}
		}
		
		return future;
	}
	
	protected abstract BaseResponse execute(CoreAdminApi api, String core, long nodeDbId);
@@ -227,9 +233,9 @@ public abstract class AbstractNodeActionService implements DisposableBean {
		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<com.inteligr8.alfresco.asie.model.ShardInstance> instances = new LinkedList<>();