Skip to content

Commit

Permalink
re #2118: composite sequential execution mode (#2120)
Browse files Browse the repository at this point in the history
* re #2118: composite sequential / short circuit execution mode
* Added a short circuit execution mode
* Executes the logics in sequential order (logicName order)
* The first logic that returns results will disable the following logics
* Added some debugging in the RemoteHttpService to verify we are closing

Conflicts:
	web-services/common/src/main/java/datawave/webservice/common/remote/RemoteHttpService.java
	web-services/query/src/main/java/datawave/webservice/query/logic/composite/CompositeQueryLogic.java
	web-services/query/src/main/java/datawave/webservice/query/logic/composite/CompositeQueryLogicResults.java
	web-services/query/src/main/java/datawave/webservice/query/logic/composite/CompositeQueryLogicResultsIterator.java
	web-services/query/src/test/java/datawave/webservice/query/logic/composite/CompositeQueryLogicTest.java

Conflicts:
	web-services/query/src/main/java/datawave/webservice/query/logic/composite/CompositeQueryLogic.java
	web-services/query/src/main/java/datawave/webservice/query/logic/composite/CompositeQueryLogicResultsIterator.java
  • Loading branch information
ivakegg authored and hgklohr committed Oct 13, 2023
1 parent 7d0fff6 commit f0d0b5d
Show file tree
Hide file tree
Showing 6 changed files with 699 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ protected <T> T execute(HttpRequestBase request, IOFunction<T> resultConverter,

@PostConstruct
protected void init() {
log.info("Starting up RemoteHttpService " + System.identityHashCode(this));
objectMapper = objectMapperDecorator.decorate(new ObjectMapper());
voidResponseReader = objectMapper.readerFor(VoidResponse.class);

Expand Down Expand Up @@ -193,11 +194,14 @@ protected void init() {
log.error("Unable to retrieve aliases from KeyStore.");
throw new IllegalStateException(e);
}
log.info("Started up RemoteHttpService " + System.identityHashCode(this));
}

@PreDestroy
protected void shutdown() {
log.info("Shutting down RemoteHttpService " + System.identityHashCode(this));
executorService.submit(() -> {
log.info("Executing shutdown RemoteHttpService " + System.identityHashCode(RemoteHttpService.this));
long waitStart = System.currentTimeMillis();
long totalWait = 0;
while (activeExecutions.get() > 0 && totalWait < 60000L) {
Expand All @@ -213,7 +217,7 @@ protected void shutdown() {
} catch (IOException e) {
log.warn("Exception while shutting down HttpClient: " + e.getMessage(), e);
}

log.info("Shutdown RemoteHttpService " + System.identityHashCode(RemoteHttpService.this));
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package datawave.webservice.query.logic.composite;

import datawave.webservice.query.Query;
import datawave.webservice.query.QueryImpl;
import datawave.webservice.query.configuration.GenericQueryConfiguration;

import java.io.Serializable;

public class CompositeQueryConfiguration extends GenericQueryConfiguration implements Serializable {

private Query query = null;

// Specifies whether all queries must succeed initialization
private boolean allMustInitialize = false;

// Specifies whether queries are run sequentially. We stop after the first query that returns any results.
private boolean shortCircuitExecution = false;

public CompositeQueryConfiguration() {
super();
query = new QueryImpl();
}

/**
* Performs a deep copy of the provided CompositeQueryConfiguration into a new instance
*
* @param other
* - another CompositeQueryConfiguration instance
*/
public CompositeQueryConfiguration(CompositeQueryConfiguration other) {

// GenericQueryConfiguration copy first
super(other);
}

/**
* Factory method that instantiates an fresh CompositeQueryConfiguration
*
* @return - a clean CompositeQueryConfiguration
*/
public static CompositeQueryConfiguration create() {
return new CompositeQueryConfiguration();
}

/**
* Factory method that returns a deep copy of the provided CompositeQueryConfiguration
*
* @param other
* - another instance of a CompositeQueryConfiguration
* @return - copy of provided CompositeQueryConfiguration
*/
public static CompositeQueryConfiguration create(CompositeQueryConfiguration other) {
return new CompositeQueryConfiguration(other);
}

/**
* Factory method that creates a CompositeQueryConfiguration deep copy from a CompositeQueryLogic
*
* @param compositeQueryLogic
* - a configured CompositeQueryLogic
* @return - a CompositeQueryConfiguration
*/
public static CompositeQueryConfiguration create(CompositeQueryLogic compositeQueryLogic) {

CompositeQueryConfiguration config = create(compositeQueryLogic.getConfig());

return config;
}

/**
* Factory method that creates a CompositeQueryConfiguration from a CompositeQueryLogic and a Query
*
* @param compositeQueryLogic
* - a configured CompositeQueryLogic
* @param query
* - a configured Query object
* @return - a CompositeQueryConfiguration
*/
public static CompositeQueryConfiguration create(CompositeQueryLogic compositeQueryLogic, Query query) {
CompositeQueryConfiguration config = create(compositeQueryLogic);
config.setQuery(query);
return config;
}

public Query getQuery() {
return query;
}

public void setQuery(Query query) {
this.query = query;
}

public boolean isAllMustInitialize() {
return allMustInitialize;
}

public void setAllMustInitialize(boolean allMustInitialize) {
this.allMustInitialize = allMustInitialize;
}

public boolean isShortCircuitExecution() {
return shortCircuitExecution;
}

public void setShortCircuitExecution(boolean shortCircuitExecution) {
this.shortCircuitExecution = shortCircuitExecution;
}
}
Loading

0 comments on commit f0d0b5d

Please sign in to comment.