-
Notifications
You must be signed in to change notification settings - Fork 14
SDAP-161 MUDROD embedded unit test #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
70e84a1
9145156
d0e1345
70d1fbf
e8a9fce
b3ef470
08337c1
8b28adc
122b228
04c9cf3
73e1cee
af2a3d9
024d545
5d57792
da22f9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,7 +105,7 @@ public void preprocess() { | |
| startTime = System.currentTimeMillis(); | ||
| LOG.info("Processing logs dated {}", anInputList); | ||
|
|
||
| DiscoveryStepAbstract im = new ImportLogFile(this.props, this.es, this.spark); | ||
| /* DiscoveryStepAbstract im = new ImportLogFile(this.props, this.es, this.spark); | ||
| im.execute(); | ||
|
|
||
| DiscoveryStepAbstract cd = new CrawlerDetection(this.props, this.es, this.spark); | ||
|
|
@@ -118,15 +118,15 @@ public void preprocess() { | |
| ss.execute(); | ||
|
|
||
| DiscoveryStepAbstract rr = new RemoveRawLog(this.props, this.es, this.spark); | ||
| rr.execute(); | ||
| rr.execute();*/ | ||
|
|
||
| endTime = System.currentTimeMillis(); | ||
|
|
||
| LOG.info("Web log preprocessing for logs dated {} complete. Time elapsed {} seconds.", anInputList, (endTime - startTime) / 1000); | ||
| } | ||
|
|
||
| DiscoveryStepAbstract hg = new HistoryGenerator(this.props, this.es, this.spark); | ||
| hg.execute(); | ||
| /*DiscoveryStepAbstract hg = new HistoryGenerator(this.props, this.es, this.spark); | ||
|
||
| hg.execute();*/ | ||
|
|
||
| DiscoveryStepAbstract cg = new ClickStreamGenerator(this.props, this.es, this.spark); | ||
| cg.execute(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -391,12 +391,12 @@ public static void main(String[] args) { | |
| me.end(); | ||
| } catch (Exception e) { | ||
| HelpFormatter formatter = new HelpFormatter(); | ||
| formatter.printHelp("MudrodEngine: 'dataDir' argument is mandatory. " + "User must also provide an ingest method.", true); | ||
| formatter.printHelp("MudrodEngine: 'dataDir' argument is mandatory. " + "User must also provide an ingest method.", options, true); | ||
|
||
| LOG.error("Error whilst parsing command line.", e); | ||
| } | ||
| } | ||
|
|
||
| private static void loadPathConfig(MudrodEngine me, String dataDir) { | ||
| public static void loadPathConfig(MudrodEngine me, String dataDir) { | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| me.props.put(MudrodConstants.ONTOLOGY_INPUT_PATH, dataDir + "SWEET_ocean/"); | ||
| me.props.put(MudrodConstants.ONTOLOGY_PATH, dataDir + "ocean_triples.csv"); | ||
| me.props.put(MudrodConstants.USER_HISTORY_PATH, dataDir + "userhistorymatrix.csv"); | ||
|
|
@@ -405,7 +405,6 @@ private static void loadPathConfig(MudrodEngine me, String dataDir) { | |
| me.props.put(MudrodConstants.CLICKSTREAM_SVD_PATH, dataDir + "clickstreamsvdmatrix_tmp.csv"); | ||
| me.props.put(MudrodConstants.METADATA_SVD_PATH, dataDir + "metadatasvdMatrix_tmp.csv"); | ||
| me.props.put(MudrodConstants.RAW_METADATA_PATH, dataDir + me.props.getProperty(MudrodConstants.RAW_METADATA_TYPE)); | ||
|
|
||
| me.props.put(MudrodConstants.METADATA_TERM_MATRIX_PATH, dataDir + "metadata_term_tfidf.csv"); | ||
| me.props.put(MudrodConstants.METADATA_WORD_MATRIX_PATH, dataDir + "metadata_word_tfidf.csv"); | ||
| me.props.put(MudrodConstants.METADATA_SESSION_MATRIX_PATH, dataDir + "metadata_session_coocurrence_matrix.csv"); | ||
|
|
@@ -428,6 +427,5 @@ public SparkDriver getSparkDriver() { | |
| */ | ||
| public void setSparkDriver(SparkDriver sparkDriver) { | ||
| this.spark = sparkDriver; | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,5 +71,4 @@ public Object execute() { | |
| public Object execute(Object o) { | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,10 +26,13 @@ | |
|
|
||
| import java.io.UnsupportedEncodingException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| /** | ||
|
|
@@ -205,7 +208,8 @@ public List<ClickStream> getClickStreamList(Properties props) { | |
| RequestUrl requestURL = new RequestUrl(); | ||
| String viewquery = ""; | ||
| try { | ||
| String infoStr = requestURL.getSearchInfo(viewnode.getRequest()); | ||
| //String infoStr = requestURL.getSearchInfo(viewnode.getRequest()); | ||
|
||
| String infoStr = requestURL.getSearchInfo(viewnode.getReferer()); | ||
| viewquery = es.customAnalyzing(props.getProperty(MudrodConstants.ES_INDEX_NAME), infoStr); | ||
| } catch (UnsupportedEncodingException | InterruptedException | ExecutionException e) { | ||
| LOG.warn("Exception getting search info. Ignoring...", e); | ||
|
|
@@ -222,6 +226,8 @@ public List<ClickStream> getClickStreamList(Properties props) { | |
|
|
||
| if (viewquery != null && !"".equals(viewquery)) { | ||
| String[] queries = viewquery.trim().split(","); | ||
| Set<String> queryset = new HashSet<>(); | ||
| queryset.addAll(Arrays.asList(queries)); | ||
| if (queries.length > 0) { | ||
| for (String query : queries) { | ||
| ClickStream data = new ClickStream(query, dataset, download); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package org.apache.sdap.mudrod.discoveryengine; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import static org.junit.Assert.*; | ||
|
||
| import java.io.BufferedReader; | ||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.FileReader; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
| import org.apache.sdap.mudrod.driver.ESDriver; | ||
| import org.apache.sdap.mudrod.driver.SparkDriver; | ||
| import org.apache.sdap.mudrod.main.AbstractElasticsearchIntegrationTest; | ||
| import org.apache.sdap.mudrod.main.MudrodConstants; | ||
| import org.apache.sdap.mudrod.main.MudrodEngine; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| public class WeblogDiscoveryEngineTest extends AbstractElasticsearchIntegrationTest { | ||
|
|
||
| private static WeblogDiscoveryEngine weblogEngine = null; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() { | ||
| MudrodEngine mudrodEngine = new MudrodEngine(); | ||
| Properties props = mudrodEngine.loadConfig(); | ||
| ESDriver es = new ESDriver(props); | ||
| SparkDriver spark = new SparkDriver(props); | ||
| String dataDir = getTestDataPath(); | ||
| System.out.println(dataDir); | ||
| props.setProperty(MudrodConstants.DATA_DIR, dataDir); | ||
| MudrodEngine.loadPathConfig(mudrodEngine, dataDir); | ||
| weblogEngine = new WeblogDiscoveryEngine(props, es, spark); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() { | ||
| // TODO | ||
|
||
| } | ||
|
|
||
| private static String getTestDataPath() { | ||
| File resourcesDirectory = new File("src/test/resources/"); | ||
|
||
| String resourcedir = "/Testing_Data_1_3dayLog+Meta+Onto/"; | ||
| String dataDir = resourcesDirectory.getAbsolutePath() + resourcedir; | ||
| return dataDir; | ||
| } | ||
|
|
||
| @Test | ||
| public void testPreprocess() throws IOException { | ||
|
|
||
| weblogEngine.preprocess(); | ||
| testPreprocess_userHistory(); | ||
| testPreprocess_clickStream(); | ||
| } | ||
|
|
||
| private void testPreprocess_userHistory() throws IOException { | ||
|
||
| // compare user history data | ||
| String userHistorycsvFile = getTestDataPath() + "/userHistoryMatrix.csv"; | ||
| BufferedReader br = new BufferedReader(new FileReader(userHistorycsvFile)); | ||
| String line = null; | ||
| HashMap<String, List<String>> map = new HashMap<>(); | ||
| int i = 0; | ||
| List<String> header = new LinkedList<>(); | ||
| while ((line = br.readLine()) != null) { | ||
| if (i == 0) { | ||
| String str[] = line.split(","); | ||
| for (String s : str) { | ||
| header.add(s); | ||
| } | ||
| } else { | ||
| String str[] = line.split(","); | ||
| for (int j = 1; j < str.length; j++) { | ||
| if (!str[j].equals("0")) { | ||
| if (!map.containsKey(str[0])) { | ||
| map.put(str[0], new ArrayList<>()); | ||
| } | ||
| map.get(str[0]).add(header.get(j)); | ||
| } | ||
| } | ||
| } | ||
| i += 1; | ||
| } | ||
|
|
||
| Assert.assertEquals("failed in history data result!", "195.219.98.7", String.join(",", map.get("sea surface topography"))); | ||
| } | ||
|
|
||
| private void testPreprocess_clickStream() throws IOException { | ||
|
||
| // TODO compare clickStream data | ||
|
||
| // String clickStreamcsvFile = | ||
| // "C:/Users/admin/Documents/GitHub/incubator-sdap-mudrod/core/clickStreamMatrix.csv"; | ||
|
||
| String clickStreamcsvFile = getTestDataPath() + "/clickStreamMatrix.csv"; | ||
| System.out.println(clickStreamcsvFile); | ||
| BufferedReader br = new BufferedReader(new FileReader(clickStreamcsvFile)); | ||
| String line = null; | ||
| HashMap<String, List<String>> map = new HashMap<>(); | ||
|
|
||
| int i = 0; | ||
| List<String> header = new LinkedList<>(); | ||
| while ((line = br.readLine()) != null) { | ||
|
||
| if (i == 0) { | ||
| String str[] = line.split(","); | ||
| for (String s : str) { | ||
| header.add(s); | ||
| } | ||
| } else { | ||
| String str[] = line.split(","); | ||
| for (int j = 1; j < str.length; j++) { | ||
| if (!str[j].equals("0.0")) { // | ||
| if (!map.containsKey(str[0])) { | ||
| map.put(str[0], new ArrayList<>()); | ||
| } | ||
| map.get(str[0]).add(header.get(j)); | ||
| } | ||
| } | ||
| } | ||
| i += 1; | ||
| } | ||
| System.out.println(map); | ||
|
|
||
| Assert.assertEquals("failed in click stream result!", "\"ostm_l2_ost_ogdr_gps\"", String.join(",", map.get("sea surface topography"))); | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.apache.sdap.mudrod.driver; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import org.apache.commons.io.FileUtils; | ||
| import org.elasticsearch.client.Client; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.node.Node; | ||
| import org.elasticsearch.node.NodeValidationException; | ||
| import org.elasticsearch.transport.Netty3Plugin; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * Example implementation of an embedded elasticsearch server. | ||
| * | ||
| * @author Felix Müller | ||
| */ | ||
| public class EmbeddedElasticsearchServer { | ||
|
|
||
| private static final String DEFAULT_DATA_DIRECTORY = "target/elasticsearch-data"; | ||
|
|
||
| private Node node; | ||
| private final String dataDirectory; | ||
|
|
||
| public EmbeddedElasticsearchServer() { | ||
| this(DEFAULT_DATA_DIRECTORY); | ||
| } | ||
|
|
||
| public EmbeddedElasticsearchServer(String dataDirectory) { | ||
| this.dataDirectory = dataDirectory; | ||
|
|
||
| Settings.Builder settingsBuilder = Settings.builder(); | ||
| settingsBuilder.put("http.type", "netty3"); | ||
| settingsBuilder.put("transport.type", "netty3"); | ||
| settingsBuilder.put("cluster.name", "MurdorES").put("http.enabled", "false").put("path.data", dataDirectory).put("path.home", "/"); | ||
|
|
||
| Settings settings = settingsBuilder.build(); | ||
| Collection plugins = Arrays.asList(Netty3Plugin.class); | ||
| node = null; | ||
| try { | ||
| node = new PluginConfigurableNode(settings, plugins).start(); | ||
| System.out.println(node.toString()); | ||
| } catch (NodeValidationException e) { | ||
| // TODO Auto-generated catch block | ||
|
||
| e.printStackTrace(); | ||
| } | ||
|
|
||
| System.out.println(node.getNodeEnvironment().nodeId()); | ||
| } | ||
|
|
||
| public Client getClient() { | ||
| return node.client(); | ||
| } | ||
|
|
||
| public void shutdown() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are not using the content of this method... remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this method if it has no content and you are not overriding anything. |
||
| /*try { | ||
| node.close(); | ||
| } catch (IOException e) { | ||
| // TODO Auto-generated catch block | ||
| e.printStackTrace(); | ||
| } | ||
| deleteDataDirectory();*/ | ||
| } | ||
|
|
||
| private void deleteDataDirectory() { | ||
| try { | ||
| FileUtils.deleteDirectory(new File(dataDirectory)); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Could not delete data directory of embedded elasticsearch server", e); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.apache.sdap.mudrod.driver; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import java.util.Collection; | ||
|
|
||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.node.Node; | ||
| import org.elasticsearch.node.internal.InternalSettingsPreparer; | ||
| import org.elasticsearch.plugins.Plugin; | ||
|
|
||
| public class PluginConfigurableNode extends Node { | ||
| public PluginConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) { | ||
| super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.apache.sdap.mudrod.main; | ||
lewismc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import org.apache.sdap.mudrod.driver.EmbeddedElasticsearchServer; | ||
| import org.apache.sdap.mudrod.driver.EmbeddedElasticsearchServer; | ||
| import org.elasticsearch.client.Client; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| /** | ||
| * This is a helper class the starts an embedded elasticsearch server | ||
| * for each test. | ||
| * | ||
| * @author Felix Müller | ||
|
||
| */ | ||
| public abstract class AbstractElasticsearchIntegrationTest { | ||
|
|
||
| private static EmbeddedElasticsearchServer embeddedElasticsearchServer; | ||
|
|
||
| @BeforeClass | ||
| public static void startEmbeddedElasticsearchServer() { | ||
| embeddedElasticsearchServer = new EmbeddedElasticsearchServer(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void shutdownEmbeddedElasticsearchServer() { | ||
| //embeddedElasticsearchServer.shutdown(); | ||
| } | ||
|
|
||
| /** | ||
| * By using this method you can access the embedded server. | ||
| */ | ||
| protected Client getClient() { | ||
| return embeddedElasticsearchServer.getClient(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the issue SDAP-161 is described as being MUDROD embedded unit test there should therefore be no code other than en embedded Unit test...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, if you are going to comment out code that you do not intend to use... just remove it.