Skip to content

Commit

Permalink
Merge pull request #42 from e-ucm/beaconingAndMaster
Browse files Browse the repository at this point in the history
Beaconing/master rebased and aggregation analysis
  • Loading branch information
gorco committed Feb 7, 2019
2 parents c64d8e2 + 54bbe4d commit fe45d2c
Show file tree
Hide file tree
Showing 77 changed files with 3,704 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<orderEntry type="library" name="Maven: com.google.guava:guava:16.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1" level="project" />
<orderEntry type="library" name="Maven: uk.com.robust-it:cloning:1.9.10" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.6" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.kafka:kafka-clients:0.10.0.1" level="project" />
<orderEntry type="library" name="Maven: net.jpountz.lz4:lz4:1.3.0" level="project" />
Expand All @@ -73,8 +75,6 @@
<orderEntry type="library" name="Maven: net.sf.jopt-simple:jopt-simple:4.9" level="project" />
<orderEntry type="module" module-name="real-time-default" scope="TEST" />
<orderEntry type="module" module-name="real-time-glp-example" />
<orderEntry type="library" name="Maven: uk.com.robust-it:cloning:1.9.10" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:2.6" level="project" />
<orderEntry type="module" module-name="real-time-overall-example" />
<orderEntry type="module" module-name="real-time-performance-example" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.storm:storm-core:1.1.1" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
public class BeaconingBundleTopologyBuilder implements
es.eucm.rage.realtime.topologies.TopologyBuilder {

private String o(String key) {
return OUT_KEY + "." + key;
}

@Override
public void build(TridentTopology tridentTopology,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/**
* Copyright © 2016 e-UCM (http://www.e-ucm.es/)
*
* 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 es.eucm.rage.realtime;

import com.google.gson.Gson;
import es.eucm.rage.realtime.simple.Analysis;
import es.eucm.rage.realtime.simple.DAnalysis;
import es.eucm.rage.realtime.simple.topologies.GLPTopologyBuilder;
import es.eucm.rage.realtime.simple.topologies.OverallTopologyBuilder;
import es.eucm.rage.realtime.topologies.TopologyBuilder;
import es.eucm.rage.realtime.utils.ESUtils;
import org.apache.http.HttpHost;
import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.serialization.LongSerializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.generated.StormTopology;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Test;

import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static org.junit.Assert.assertTrue;

/**
* Tests the {@link OverallTopologyBuilder} executed on a local cluster and
* receiving data from a local files VERBS_FILES
*/
public class BeaconingBundleGlpTest {

private static final String NOW_DATE = String.valueOf(new Date().getTime());
private static final String ES_HOST = "localhost";
private static final String ZOOKEEPER_URL = "localhost";
private static final String BOOTSTRAP_SERVERS = "0.0.0.0:9092";
private static final String TOPIC = "overall-test-topic-default-glp-kibana-analysis-"
+ NOW_DATE;
private static final Gson gson = new Gson();

private static final Producer<Long, String> producer = createProducer();

private static Producer<Long, String> createProducer() {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ProducerConfig.CLIENT_ID_CONFIG, "KafkaExampleProducer");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
LongSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
StringSerializer.class.getName());
return new KafkaProducer<>(props);
}

static void runProducer(final Map trace) {

try {
String msg = gson.toJson(trace, Map.class);
long index = (long) 0.4;
final ProducerRecord<Long, String> record = new ProducerRecord<>(
TOPIC, index, msg);

producer.send(record).get();

} catch (Exception e) {
assertTrue("Error sending to Kafka " + e.getMessage() + " cause "
+ e.getCause(), false);
} finally {
producer.flush();
// producer.close();
}
}

@Test
public void xAPIVerbsTest() throws IOException {

RestClient client = RestClient.builder(new HttpHost(ES_HOST, 9200))
.build();
client.performRequest("DELETE", "*");
/**
* Simple GLP: PARENT: "parent-" + NOW_DATE -> GLP_ID
*
* FIRST CHILD: "1-" + NOW_DATE -> leaf -> receives traces SECOND CHILD:
* "2-" + NOW_DATE -> leaf -> receives traces
* **/
String firstIndex = "1-" + NOW_DATE;
String secondIndex = "2-" + NOW_DATE;
String middleIndex = "middle-" + NOW_DATE;
String parentIndex = "parent-" + NOW_DATE; // GLP_ID
String analyticsGLPId = ESUtils.getAnalyticsGLPIndex(parentIndex);

RestHighLevelClient hClient = new RestHighLevelClient(client);

Map parentAnalytics = new HashMap();
parentAnalytics.put("testkey", "testval");
ArrayList childrenArray = new ArrayList<>(1);
childrenArray.add(middleIndex);
parentAnalytics.put(GLPTopologyBuilder.PARENT_CHILDREN_TRACE,
childrenArray);
IndexRequest indexParent = new IndexRequest(analyticsGLPId,
"analytics", parentIndex).source(parentAnalytics);

// MIDDLE CHILD

Map middleAnalytics = new HashMap();
ArrayList middleArray = new ArrayList<>(2);
middleArray.add(firstIndex);
middleArray.add(secondIndex);
middleAnalytics.put(GLPTopologyBuilder.PARENT_CHILDREN_TRACE,
middleArray);
middleAnalytics.put(TopologyBuilder.ANALYTICS_PARENT_ID_KEY,
parentIndex);
IndexRequest indexMiddle = new IndexRequest(analyticsGLPId,
"analytics", middleIndex).source(middleAnalytics);

Map firstChildAnalytics = new HashMap();

// Limits
Map firstChildLimits = new HashMap();
Map firstChildPartialThresholds = new HashMap();
firstChildPartialThresholds.put(
GLPTopologyBuilder.PARTIAL_THRESHOLD_SCORE, 0.3f);
firstChildPartialThresholds.put(GLPTopologyBuilder.LEARNING_OBJECTIVES,
0.3f);
firstChildPartialThresholds.put(GLPTopologyBuilder.COMPETENCIES, 0.3f);
firstChildLimits.put(GLPTopologyBuilder.PARTIAL_THRESHOLDS,
firstChildPartialThresholds);
firstChildAnalytics.put(GLPTopologyBuilder.LIMITS, firstChildLimits);

// Contributes
Map firstChildContributes = new HashMap();
Map firstChildContributesCompetencies = new HashMap();
firstChildContributesCompetencies.put("child1_comp1", 0.1f);
firstChildContributesCompetencies.put("child1_comp2", 0.1f);
firstChildContributes.put(GLPTopologyBuilder.COMPETENCIES,
firstChildContributesCompetencies);
Map firstChildContributesLearningObjectives = new HashMap();
firstChildContributesLearningObjectives.put("child1_lo1", 0.2f);
firstChildContributes.put(GLPTopologyBuilder.LEARNING_OBJECTIVES,
firstChildContributesLearningObjectives);
firstChildAnalytics.put(GLPTopologyBuilder.CONTRIBUTES,
firstChildContributes);

firstChildAnalytics.put(TopologyBuilder.ANALYTICS_PARENT_ID_KEY,
middleIndex);
IndexRequest indexFirstChild = new IndexRequest(analyticsGLPId,
"analytics", firstIndex).source(firstChildAnalytics);

Map secondChildAnalytics = new HashMap();

// Limits
Map secondChildLimits = new HashMap();
Map secondChildPartialThresholds = new HashMap();
secondChildPartialThresholds.put(
GLPTopologyBuilder.PARTIAL_THRESHOLD_SCORE, 0.5f);
secondChildPartialThresholds.put(
GLPTopologyBuilder.LEARNING_OBJECTIVES, 0.5f);
secondChildPartialThresholds.put(GLPTopologyBuilder.COMPETENCIES, 0.5f);
secondChildLimits.put(GLPTopologyBuilder.PARTIAL_THRESHOLDS,
secondChildPartialThresholds);
secondChildAnalytics.put(GLPTopologyBuilder.LIMITS, secondChildLimits);

// Contributes
Map secondChildContributes = new HashMap();
Map secondChildContributesCompetencies = new HashMap();
secondChildContributesCompetencies.put("child2_comp1", 0.6f);
secondChildContributes.put(GLPTopologyBuilder.COMPETENCIES,
secondChildContributesCompetencies);
Map secondChildContributesLearningObjectives = new HashMap();
secondChildContributesLearningObjectives.put("child2_lo1", 0.7f);
secondChildContributes.put(GLPTopologyBuilder.LEARNING_OBJECTIVES,
secondChildContributesLearningObjectives);
secondChildAnalytics.put(GLPTopologyBuilder.CONTRIBUTES,
secondChildContributes);

secondChildAnalytics.put(TopologyBuilder.ANALYTICS_PARENT_ID_KEY,
middleIndex);
IndexRequest indexSecondChild = new IndexRequest(analyticsGLPId,
"analytics", secondIndex).source(secondChildAnalytics);

hClient.index(indexParent);
hClient.index(indexMiddle);
hClient.index(indexFirstChild);
hClient.index(indexSecondChild);

Config conf = new Config();
conf.put(AbstractAnalysis.ZOOKEEPER_URL_FLUX_PARAM, ZOOKEEPER_URL);
conf.put(AbstractAnalysis.KAFKA_URL_FLUX_PARAM, ZOOKEEPER_URL + ":9092");
conf.put(AbstractAnalysis.ELASTICSEARCH_URL_FLUX_PARAM, ES_HOST);
conf.put(AbstractAnalysis.TOPIC_NAME_FLUX_PARAM, TOPIC);
// Test topology Builder configuration
conf.put(AbstractAnalysis.TOPIC_NAME_FLUX_PARAM, TOPIC);

StormTopology topology = new Analysis().getTopology(conf);
StormTopology dtopology = new DAnalysis().getTopology(conf);

LocalCluster cluster3 = new LocalCluster();
cluster3.submitTopology("realtime-" + NOW_DATE, conf, topology);

LocalCluster cluster = new LocalCluster();
cluster.submitTopology("realtime-default-" + NOW_DATE, conf, dtopology);

List<Map> traces = gson.fromJson(
new InputStreamReader(ClassLoader
.getSystemResourceAsStream("conflictive/traces.json")),
List.class);

for (int i = 0; i < traces.size(); ++i) {

Map traceMap = traces.get(i);

runProducer(traceMap);
}

try {
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public void xAPIVerbsTest() throws IOException {
conf.put(AbstractAnalysis.ZOOKEEPER_URL_FLUX_PARAM, ZOOKEEPER_URL);
conf.put(AbstractAnalysis.ELASTICSEARCH_URL_FLUX_PARAM, ES_HOST);
conf.put(AbstractAnalysis.TOPIC_NAME_FLUX_PARAM, TOPIC);
conf.put(AbstractAnalysis.KAFKA_URL_FLUX_PARAM, ZOOKEEPER_URL + ":9092");
// Test topology Builder configuration
conf.put(AbstractAnalysis.TOPIC_NAME_FLUX_PARAM, TOPIC);

Expand Down Expand Up @@ -275,7 +276,7 @@ public void xAPIVerbsTest() throws IOException {
}

try {
Thread.sleep(60000);
Thread.sleep(35000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -374,39 +375,9 @@ public void xAPIVerbsTest() throws IOException {

int totalParent = ((Double) hits.get("total")).intValue();

Response responseChild1 = client.performRequest("GET", "/" + firstIndex
+ "/_search?size=5000&q=*:*");

String responseStringChild1 = EntityUtils.toString(responseChild1
.getEntity());
Map<String, Object> responseDocsChild1 = (Map) gson.fromJson(
responseStringChild1, Map.class);

Map hitsChild1 = (Map) responseDocsChild1.get("hits");

int totalChild1 = ((Double) hitsChild1.get("total")).intValue();

Response responseChild2 = client.performRequest("GET", "/"
+ secondIndex + "/_search?size=5000&q=*:*");

String responseStringChild2 = EntityUtils.toString(responseChild2
.getEntity());
Map<String, Object> responseDocsChild2 = (Map) gson.fromJson(
responseStringChild2, Map.class);

Map hitsChild2 = (Map) responseDocsChild2.get("hits");

int totalChild2 = ((Double) hitsChild2.get("total")).intValue();

assertEquals(
"Total traces " + parentIndex + ", current " + totalParent,
totalChild1, 224);
assertEquals(
"Total traces " + parentIndex + ", current " + totalParent,
totalChild2, 343);
assertEquals(
"Total traces " + parentIndex + ", current " + totalParent,
totalParent, 605);
totalParent, 1777);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public void test() throws Exception {
Map<String, Object> conf = new HashedMap();
conf.put(AbstractAnalysis.ELASTICSEARCH_URL_FLUX_PARAM, ES_HOST);
conf.put(AbstractAnalysis.ZOOKEEPER_URL_FLUX_PARAM, ZOOKEEPER_URL);
conf.put(AbstractAnalysis.KAFKA_URL_FLUX_PARAM, ZOOKEEPER_URL + ":9092");
conf.put(AbstractAnalysis.TOPIC_NAME_FLUX_PARAM, TOPIC);

StormTopology topology = new Analysis().getTopology(conf);
Expand Down Expand Up @@ -295,7 +296,7 @@ public void test() throws Exception {

int total = ((Double) hits.get("total")).intValue();

assertEquals("Total traces " + parentIndex + ", current " + total, 7,
assertEquals("Total traces " + parentIndex + ", current " + total, 14,
total);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{statement={actor={account={homePage=http://a2:3000/, name=Anonymous}, name=quasiextraterritorial-palaeozoological-kite}, verb={id=http://adlnet.gov/expapi/verbs/initialized}, object={id=http://a2:3000/api/proxy/gleaner/games/5b165d4ac7171c007719bc61/5b165d4ac7171c007719bc62/game/LB_GAME_704, definition={type=https://w3id.org/xapi/seriousgames/activity-types/serious-game, extensions={gameplayId=5bbc771a5a2526008d425abb, versionId=5b165d4ac7171c007719bc62, activityId=5b165f9ec7171c007719bc66, session=1.0, firstSessionStarted=2018-10-09T09:38:34.345Z, currentSessionStarted=2018-10-09T09:38:34.345Z}}}, timestamp=2018-10-09T09:38:42.558Z}, out={name=quasiextraterritorial-palaeozoological-kite, timestamp=2018-10-09T09:38:42.558Z, event=initialized, target=LB_GAME_704, type=serious-game, gameplayId=5bbc771a5a2526008d425abb, versionId=5b165d4ac7171c007719bc62, activityId=5b165f9ec7171c007719bc66, session=1.0, firstSessionStarted=2018-10-09T09:38:34.345Z, currentSessionStarted=2018-10-09T09:38:34.345Z, uuidv4=0f80cd70-adf3-4adf-b1d8-e9bee648c7da}, playerId=5bbc771a5a2526008d425aba, gameplayId=5bbc771a5a2526008d425abb, versionId=5b165d4ac7171c007719bc62, activityId=5b165f9ec7171c007719bc66, classId=5b165e8ec7171c007719bc63}]

0 comments on commit fe45d2c

Please sign in to comment.