-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
173cb27
commit a6a2b17
Showing
4 changed files
with
182 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
warehouse/query-core/src/main/java/datawave/query/tables/ssdeep/SSDeepEventQueryLogic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package datawave.query.tables.ssdeep; | ||
|
||
import datawave.query.tables.chained.ChainedQueryTable; | ||
import datawave.webservice.query.Query; | ||
import datawave.webservice.query.configuration.GenericQueryConfiguration; | ||
import datawave.webservice.query.logic.QueryLogicTransformer; | ||
import org.apache.accumulo.core.client.AccumuloClient; | ||
import org.apache.accumulo.core.data.Key; | ||
import org.apache.accumulo.core.data.Value; | ||
import org.apache.accumulo.core.security.Authorizations; | ||
import org.apache.log4j.Logger; | ||
|
||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
|
||
public class SSDeepEventQueryLogic extends ChainedQueryTable<Entry<Key, Value>, Entry<Key, Value>> { | ||
|
||
private static final Logger log = Logger.getLogger(SSDeepEventQueryLogic.class); | ||
|
||
private Query q = null; | ||
|
||
public SSDeepEventQueryLogic() { super(); } | ||
|
||
@SuppressWarnings("CopyConstructorMissesField") | ||
public SSDeepEventQueryLogic(SSDeepEventQueryLogic other) { | ||
super(other); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
super.close(); | ||
} | ||
|
||
public GenericQueryConfiguration initialize(AccumuloClient client, Query settings, Set<Authorizations> auths) throws Exception { | ||
super.initialize(client, settings, auths); | ||
this.q = settings.duplicate(settings.getQueryName() + "_discovery_query"); | ||
|
||
log.debug("Initial settings parameters: " + settings.getParameters().toString()); | ||
GenericQueryConfiguration config = this.logic1.initialize(client, settings, auths); | ||
return config; | ||
} | ||
|
||
public void setupQuery(GenericQueryConfiguration config) throws Exception { | ||
if (null == this.getChainStrategy()) { | ||
final String error = "No ChainStrategy provided for SSDeepDiscoveryQueryLogic!"; | ||
log.error(error); | ||
throw new RuntimeException(error); | ||
} | ||
|
||
log.info("Setting up ssdeep query using config"); | ||
this.logic1.setupQuery(config); | ||
|
||
final Iterator<Entry<Key,Value>> iter1 = this.logic1.iterator(); | ||
|
||
log.info("Running chained discovery query"); | ||
this.iterator = this.getChainStrategy().runChainedQuery(config.getClient(), this.q, config.getAuthorizations(), iter1, this.logic2); | ||
} | ||
|
||
@Override | ||
public QueryLogicTransformer getTransformer(Query settings) { | ||
return this.logic2.getTransformer(settings); | ||
} | ||
|
||
@Override | ||
public SSDeepEventQueryLogic clone() throws CloneNotSupportedException { | ||
return new SSDeepEventQueryLogic(this); | ||
} | ||
|
||
public Set<String> getExampleQueries() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...e/query-core/src/test/java/datawave/query/tables/ssdeep/FullSSDeepEventChainStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package datawave.query.tables.ssdeep; | ||
|
||
import datawave.query.tables.chained.strategy.FullChainStrategy; | ||
import datawave.webservice.query.Query; | ||
import datawave.webservice.query.QueryImpl; | ||
import org.apache.accumulo.core.data.Key; | ||
import org.apache.accumulo.core.data.Value; | ||
|
||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
public class FullSSDeepEventChainStrategy extends FullChainStrategy<Map.Entry<Key, Value>, Map.Entry<Key, Value>> { | ||
@Override | ||
protected Query buildLatterQuery(Query initialQuery, Iterator<Map.Entry<Key, Value>> initialQueryResults, String latterLogicName) { | ||
log.debug("buildLatterQuery() called..."); | ||
StringBuilder b = new StringBuilder(); | ||
Set<String> ssdeepSeen = new HashSet<>(); | ||
while (initialQueryResults.hasNext()) { | ||
Map.Entry<Key, Value> result = initialQueryResults.next(); | ||
Key key = result.getKey(); | ||
String ssdeep = key.getColumnQualifier().toString(); | ||
if (ssdeepSeen.contains(ssdeep)) { | ||
continue; | ||
} | ||
log.debug("Added new ssdeep " + ssdeep); | ||
ssdeepSeen.add(ssdeep); | ||
if (b.length() > 0) { | ||
b.append(" OR "); | ||
} | ||
b.append("CHECKSUM_SSDEEP:\"").append(ssdeep).append("\""); | ||
} | ||
|
||
Query q = new QueryImpl(); // TODO, need to use a factory? don't hardcode this. | ||
q.setQuery(b.toString()); | ||
q.setId(UUID.randomUUID()); | ||
q.setPagesize(Integer.MAX_VALUE); // TODO: choose something reasonable. | ||
q.setQueryAuthorizations(initialQuery.getQueryAuthorizations()); | ||
q.setUserDN(initialQuery.getUserDN()); | ||
// TODO: set up a reasonable start and end date. | ||
return q; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters