Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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,7 @@ public List<ClickStream> getClickStreamList(Properties props) {
RequestUrl requestURL = new RequestUrl();
String viewquery = "";
try {
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);
Expand All @@ -222,6 +225,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,126 @@
/*
* 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.Map;
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() {
}

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();
testPreprocessUserHistory();
testPreprocessClickStream();
}

private void testPreprocessUserHistory() throws IOException {
// compare user history data
String userHistorycsvFile = getTestDataPath() + "/userHistoryMatrix.csv";
HashMap<String, List<String>> map = extractPairFromCSV(userHistorycsvFile);
Assert.assertEquals("failed in history data result!", "195.219.98.7", String.join(",", map.get("sea surface topography")));
}

private void testPreprocessClickStream() throws IOException {
String clickStreamcsvFile = getTestDataPath() + "/clickStreamMatrix.csv";
System.out.println(clickStreamcsvFile);
HashMap<String, List<String>> map = extractPairFromCSV(clickStreamcsvFile);
System.out.println(map);
Assert.assertEquals("failed in click stream result!", "\"ostm_l2_ost_ogdr_gps\"", String.join(",", map.get("sea surface topography")));
}

private HashMap extractPairFromCSV(String csvfile){

BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(csvfile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line = null;
HashMap<String, List<String>> map = new HashMap<>();
int i = 0;
List<String> header = new LinkedList<>();
try {
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++) {
int value = Integer.parseInt(str[j]);
if (value > 0) {
if (!map.containsKey(str[0])) {
map.put(str[0], new ArrayList<>());
}
map.get(str[0]).add(header.get(j));
}
}
}
i += 1;
}
} catch (IOException e) {
e.printStackTrace();
}

return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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) {
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.

}

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,48 @@
/*
* 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.
*/
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();
}
}
Loading