Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public WeblogDiscoveryEngine(Properties props, ESDriver es, SparkDriver spark) {
/**
* Get log file list from a directory
*
* @param logDir path to directory containing logs either local or in HDFS.
* @param logDir
* path to directory containing logs either local or in HDFS.
* @return a list of log files
*/
public List<String> getFileList(String logDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is buggy. We just want to throw the Exception... not continuously print the help arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quintinali please address this. It should not throw help. It should through the Exception e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewismc In my computer, the old code (
formatter.printHelp("MudrodEngine: 'dataDir' argument is mandatory. " + "User must also provide an ingest method.", true)) comes with an error “The method printHelp(String, Options) in the type HelpFormatter is not applicable for the arguments (String, boolean)”

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK what I am saying is that this code should be changed to the following

} catch (Exception e) {
  throw new RuntimeException(e)
}

...or something similar.

LOG.error("Error whilst parsing command line.", e);
}
}

private static void loadPathConfig(MudrodEngine me, String dataDir) {
public static void loadPathConfig(MudrodEngine me, String dataDir) {
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");
Expand All @@ -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");
Expand All @@ -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
Expand Up @@ -71,5 +71,4 @@ public Object execute() {
public Object execute(Object o) {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public int processSession(ESDriver es, String sessionId) throws IOException, Int
String[] keywordList = keywords.split(",");
for (String item : items) {
if (!Arrays.asList(keywordList).contains(item)) {
keywords = keywords + item + ",";
keywords = keywords + "," + item + ",";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not comment out code...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to resolve this.

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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sdap.mudrod.discoveryengine;

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO and method if nothing happens here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve most issued metioned above except the first one. In my computer, the old code (
formatter.printHelp("MudrodEngine: 'dataDir' argument is mandatory. " + "User must also provide an ingest method.", true)) comes with an error “The method printHelp(String, Options) in the type HelpFormatter is not applicable for the arguments (String, boolean)”

}

private static String getTestDataPath() {
File resourcesDirectory = new File("src/test/resources/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the Java ClassLoader...

getClass().getCLassLoader().getResource....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to address this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed using the ClassLoader. Something like

getClass().getClassLoader().getResource... or getResourceAsStream...

You need to make this change rather than passing around File objects OK.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you should always document your tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, testPreprocess_userHistory is not how to write Java methods. Please use camelCase as is shown elsewhere throughout the codebase.

// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is the same here. Change testPreprocess_clickStream to testPreprocessClickStream

// TODO compare clickStream data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments or else address TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved issue mentioned above

// String clickStreamcsvFile =
// "C:/Users/admin/Documents/GitHub/incubator-sdap-mudrod/core/clickStreamMatrix.csv";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never, ever, ever use path's to your local machine in code. This is a huge No-go. Remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted the useless code

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all of this code is duplicated, then factor it out and provide method parameters for the input data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed duplicated code

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")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are you testing here? You are comparing strings??? You are meant to be checking the functional operation of MUDROD code!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewismc This is the reason why I submit the pull request. I hope you can check the test cases and let me know whether the cases are the ones your team needs or not. The proprocess function in the WeblogDiscoveryEngine.java ingests a HTTP file and a FTP file and processes it to userhistory data and clickstream data. To test the function, I prepare a small size of http log and ftp log and process it with the function, and extract information from generated csv file to a map, and then compare the results with expected results.

Assert.assertEquals("failed in click stream result!", ""ostm_l2_ost_ogdr_gps"", String.join(",", map.get("sea surface topography")));

This code means the log ingester should find a use clicks ostm_l2_ost_ogdr_gps after searches "sea surface topography" from the test log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewismc Please let me know if you have any question regarding my explanation of this issue since this is the most important part of the unit testing. We need your confirmation to continue adding more test cases.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sdap.mudrod.driver;

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;

/**
* embedded elasticsearch server.
*/
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO

e.printStackTrace();
}

System.out.println(node.getNodeEnvironment().nodeId());
}

public Client getClient() {
return node.client();
}

public void shutdown() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are not using the content of this method... remove it.

Copy link
Member

Choose a reason for hiding this comment

The 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,27 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sdap.mudrod.driver;

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,50 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.sdap.mudrod.main;

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to start a new server for every test. We need to start one server which runs for the duration of the tests. Between tests, the data within the server should probably be deleted/truncated. This however depends on what tests you are running.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to add an Embedded Elasticsearch engine as you suggested. I found a solution from internet with the three files
"EmbeddedElasticsearchServer.java, PluginConfigurableNode.java, AbstractElasticsearchIntegrationTest.java". I added the three files in MUDROD but it fails to work. And if it works, it does start a new server for every test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you have addressed the comments here fully I will test the code locally and provide input as to why it is not working.

* test.
*
* @author Felix Müller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is Felix Muller?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???

*/
public abstract class AbstractElasticsearchIntegrationTest {

private static EmbeddedElasticsearchServer embeddedElasticsearchServer;

@BeforeClass
public static void startEmbeddedElasticsearchServer() {
embeddedElasticsearchServer = new EmbeddedElasticsearchServer();
}

@AfterClass
public static void shutdownEmbeddedElasticsearchServer() {
// embeddedElasticsearchServer.shutdown();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you not shutting the server down? If you are not doing so then you need to remove this method.

}

/**
* By using this method you can access the embedded server.
*/
protected Client getClient() {
return embeddedElasticsearchServer.getClient();
}
}
Loading