Skip to content

Commit

Permalink
Merge pull request #2 from beamline/flink
Browse files Browse the repository at this point in the history
Conversion to the Apache Flink underlying library
  • Loading branch information
delas authored Mar 25, 2022
2 parents 06159b9 + 622484c commit 67515de
Show file tree
Hide file tree
Showing 36 changed files with 1,101 additions and 835 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=1.8
70 changes: 63 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

<sonar.organization>beamline</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>

<flink.version>1.14.3</flink.version>
<log4j.version>2.17.2</log4j.version>
</properties>

<repositories>
Expand All @@ -34,7 +37,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>org.deckfour</groupId>
Expand All @@ -46,16 +49,44 @@
<artifactId>spex</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.11</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.11</artifactId>
<version>${flink.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>com.github.beamline</groupId>
<artifactId>graphviz</artifactId>
Expand All @@ -66,14 +97,39 @@
<artifactId>opencsv</artifactId>
<version>5.6</version>
</dependency>



<!-- For testing only -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.11</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.11</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.12</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
251 changes: 251 additions & 0 deletions src/main/java/beamline/events/BEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
package beamline.events;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.tuple.Pair;
import org.deckfour.xes.extension.std.XConceptExtension;
import org.deckfour.xes.extension.std.XTimeExtension;
import org.deckfour.xes.model.XAttribute;
import org.deckfour.xes.model.XAttributeBoolean;
import org.deckfour.xes.model.XAttributeContinuous;
import org.deckfour.xes.model.XAttributeDiscrete;
import org.deckfour.xes.model.XAttributeLiteral;
import org.deckfour.xes.model.XAttributeTimestamp;
import org.deckfour.xes.model.XTrace;

import beamline.exceptions.EventException;

/**
*
* @author Andrea Burattin
*/
public class BEvent implements Serializable, Comparable<BEvent> {

private static final long serialVersionUID = -7300189277034528917L;

private Map<String, Serializable> eventAttributes;
private Map<String, Serializable> traceAttributes;
private Map<String, Serializable> logAttributes;

public BEvent() {
this.eventAttributes = new HashMap<>();
this.traceAttributes = new HashMap<>();
this.logAttributes = new HashMap<>();
}

//
// Factories
//
/**
* Creates a new {@link XTrace} referring to one event
*
* @param activityName the name of the activity
* @param caseId the identifier of the process instance
* @param time the time when the event has happened
* @param eventAttributes a collection of string attributes for the event
* @return the new event
* @throws EventException this exception is thrown is incomplete information
* is provided
*/
public static BEvent create(
String processName,
String activityName,
String caseId,
Date time,
Collection<Pair<String, String>> eventAttributes) throws EventException {
if (processName == null || activityName == null || caseId == null) {
throw new EventException("Activity name or case id missing");
}

BEvent event = new BEvent();
event.setProcessName(processName);
event.setTraceName(caseId);
event.setEventName(activityName);
if (time == null) {
event.setTimestamp(new Date());
} else {
event.setTimestamp(time);
}

if (eventAttributes != null) {
for(Pair<String, String> a : eventAttributes) {
event.setEventAttribute(a.getLeft(), a.getRight());
}
}
return event;
}

/**
* Creates a new {@link XTrace} referring to one event
*
* @param activityName the name of the activity
* @param caseId the identifier of the process instance
* @param time the time when the event has happened
* @return the new event
* @throws EventException this exception is thrown is incomplete information
* is provided
*/
public static BEvent create(String processName, String activityName, String caseId, Date time) throws EventException {
return create(processName, activityName, caseId, time, null);
}

/**
* Creates a new {@link XTrace} referring to one event. The time of the
* event is set to the current time
*
* @param activityName the name of the activity
* @param caseId the identifier of the process instance
* @return the new event
* @throws EventException this exception is thrown is incomplete information
* is provided
*/
public static BEvent create(String processName, String activityName, String caseId) throws EventException {
return create(processName, activityName, caseId, null, null);
}

//
// Specific methods
//
public void setProcessName(String name) {
setLogAttribute(XConceptExtension.KEY_NAME, name);
}

public String getProcessName() {
return (String) logAttributes.get(XConceptExtension.KEY_NAME);
}

public void setTraceName(String name) {
setTraceAttribute(XConceptExtension.KEY_NAME, name);
}

public String getTraceName() {
return (String) traceAttributes.get(XConceptExtension.KEY_NAME);
}

public void setEventName(String name) {
setEventAttribute(XConceptExtension.KEY_NAME, name);
}

public String getEventName() {
return (String) eventAttributes.get(XConceptExtension.KEY_NAME);
}

public void setTimestamp(Date timestamp) {
setEventAttribute(XTimeExtension.KEY_TIMESTAMP, timestamp);
}

public Date getEventTime() {
return (Date) eventAttributes.get(XTimeExtension.KEY_TIMESTAMP);
}

//
// General methods
//

public Map<String, Serializable> getEventAttributes() {
return eventAttributes;
}

public Map<String, Serializable> getTraceAttributes() {
return traceAttributes;
}

public Map<String, Serializable> getLogAttributes() {
return logAttributes;
}

public void setEventAttribute(String name, Serializable value) {
eventAttributes.put(name, value);
}

public void setEventAttribute(String name, XAttribute value) {
setAttributeFromXAttribute(eventAttributes, name, value);
}

public void setTraceAttribute(String name, Serializable value) {
traceAttributes.put(name, value);
}

public void setTraceAttribute(String name, XAttribute value) {
setAttributeFromXAttribute(traceAttributes, name, value);
}

public void setLogAttribute(String name, Serializable value) {
logAttributes.put(name, value);
}

public void setLogAttribute(String name, XAttribute value) {
setAttributeFromXAttribute(logAttributes, name, value);
}

//
// Overrides
//

@Override
public String toString() {
return logAttributes.toString() + " - " + traceAttributes.toString() + " - " + eventAttributes.toString();
}

@Override
public int compareTo(BEvent o) {
if (getEventTime() == null || o.getEventTime() == null) {
return 0;
}
return getEventTime().compareTo(o.getEventTime());
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
BEvent other = (BEvent) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(logAttributes, other.logAttributes)
.append(traceAttributes, other.traceAttributes)
.append(eventAttributes, other.eventAttributes)
.isEquals();

}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(logAttributes)
.append(traceAttributes)
.append(eventAttributes)
.toHashCode();
}

//
// Private methods
//

private void setAttributeFromXAttribute(Map<String, Serializable> map, String name, XAttribute value) {
if (value instanceof XAttributeBoolean) {
map.put(name, ((XAttributeBoolean) value).getValue());
} else if (value instanceof XAttributeContinuous) {
map.put(name, ((XAttributeContinuous) value).getValue());
} else if (value instanceof XAttributeDiscrete) {
map.put(name, ((XAttributeDiscrete) value).getValue());
} else if (value instanceof XAttributeLiteral) {
map.put(name, ((XAttributeLiteral) value).getValue());
} else if (value instanceof XAttributeTimestamp) {
map.put(name, ((XAttributeTimestamp) value).getValue());
}
}
}
Loading

0 comments on commit 67515de

Please sign in to comment.