From 822e4265fad2d5d1f5525d34d1b19ed3fec391a2 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 14:42:23 +0200 Subject: [PATCH 01/36] add WorkerMetadata class --- .../org/aksw/iguana/cc/model/WorkerMetadata.java | 9 +++++++++ .../aksw/iguana/cc/query/handler/QueryHandler.java | 10 +++++++++- .../org/aksw/iguana/cc/worker/AbstractWorker.java | 12 ++++++++++++ src/main/java/org/aksw/iguana/cc/worker/Worker.java | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java diff --git a/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java b/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java new file mode 100644 index 00000000..7965d2ac --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java @@ -0,0 +1,9 @@ +package org.aksw.iguana.cc.model; + +public record WorkerMetadata( + int workerID, + String workerType, + double timeout, + int numberOfQueries, + String[] queries +) {} diff --git a/src/main/java/org/aksw/iguana/cc/query/handler/QueryHandler.java b/src/main/java/org/aksw/iguana/cc/query/handler/QueryHandler.java index b6e72e14..dee5bfab 100644 --- a/src/main/java/org/aksw/iguana/cc/query/handler/QueryHandler.java +++ b/src/main/java/org/aksw/iguana/cc/query/handler/QueryHandler.java @@ -207,7 +207,15 @@ private void initLanguageProcessor() { } } - private String getQueryId(int i) { + public String getQueryId(int i) { return this.queryList.getName() + ":" + i; } + + public String[] getAllQueryIds() { + String[] out = new String[queryList.size()]; + for (int i = 0; i < queryList.size(); i++) { + out[i] = getQueryId(i); + } + return out; + } } diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index 4b760a69..aba8fb70 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -3,6 +3,7 @@ import org.aksw.iguana.cc.config.CONSTANTS; import org.aksw.iguana.cc.config.elements.Connection; import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; @@ -288,4 +289,15 @@ private void setWorkerType() { this.workerType = this.getClass().getName(); } } + + @Override + public WorkerMetadata getMetadata() { + return new WorkerMetadata( + this.workerID, + this.workerType, + (double) this.extra.get(CONSTANTS.WORKER_TIMEOUT_MS), + this.queryHandler.getQueryCount(), + this.queryHandler.getAllQueryIds() + ); + } } diff --git a/src/main/java/org/aksw/iguana/cc/worker/Worker.java b/src/main/java/org/aksw/iguana/cc/worker/Worker.java index 7580e911..1e1c6183 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/Worker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/Worker.java @@ -1,5 +1,6 @@ package org.aksw.iguana.cc.worker; +import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; import org.aksw.iguana.cc.tasks.impl.Stresstest; @@ -95,4 +96,5 @@ public interface Worker extends Runnable{ */ void endAtNoOfQueryMixes(Long noOfQueryMixes); + WorkerMetadata getMetadata(); } From a21c5555d736e837069694cc54edf90d85cb5c7f Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 15:48:13 +0200 Subject: [PATCH 02/36] add StresstestMetadata class --- .../iguana/cc/model/StresstestMetadata.java | 20 ++++++++++ .../aksw/iguana/cc/tasks/AbstractTask.java | 10 ++--- .../aksw/iguana/cc/tasks/impl/Stresstest.java | 38 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java diff --git a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java b/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java new file mode 100644 index 00000000..5632c850 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java @@ -0,0 +1,20 @@ +package org.aksw.iguana.cc.model; + +import org.apache.jena.rdf.model.Model; + +// TODO: maybe extract parts to generic taskmetadata class +public record StresstestMetadata( + String suiteID, + String expID, + String taskID, + String datasetID, + String conID, + String conVersion, + String taskname, + String classname, + double timelimit, + long noOfQueryMixes, + WorkerMetadata[] workers, + String simpleTriple, + Model tripleStats +) {} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java index 79778f93..88b32b59 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java @@ -33,11 +33,11 @@ public abstract class AbstractTask implements Task { * will be send to the resultprocessor */ protected Properties metaData = new Properties(); - private String expID; - private String suiteID; - private String datasetID; - private String conID; - private String taskName; + protected String expID; + protected String suiteID; + protected String datasetID; + protected String conID; + protected String taskName; /** * Creates an AbstractTask with the TaskID diff --git a/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java index e89faee6..838c0822 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java @@ -2,6 +2,8 @@ import org.aksw.iguana.cc.config.CONSTANTS; import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.tasks.AbstractTask; import org.aksw.iguana.cc.worker.Worker; import org.aksw.iguana.cc.worker.WorkerFactory; @@ -333,4 +335,40 @@ public long getExecutedQueries() { return ret; } + public StresstestMetadata getMetadata() { + String classname; + if (this.getClass().isAnnotationPresent(Shorthand.class)) { + classname = this.getClass().getAnnotation(Shorthand.class).value(); + } else { + classname = this.getClass().getCanonicalName(); + } + + WorkerMetadata[] workerMetadata = new WorkerMetadata[this.workers.size()]; + for (int i = 0; i < this.workers.size(); i++) { + workerMetadata[i] = this.workers.get(i).getMetadata(); + } + + StringWriter sw = new StringWriter(); + Model tripleStats = ModelFactory.createDefaultModel(); + for (Worker worker : this.workers) { + tripleStats.add(worker.getQueryHandler().getTripleStats(this.taskID)); + } + RDFDataMgr.write(sw, tripleStats, RDFFormat.NTRIPLES); + + return new StresstestMetadata( + suiteID, + expID, + taskID, + datasetID, + conID, + con.getVersion(), + taskName, + classname, + this.timeLimit, + this.noOfQueryMixes, + workerMetadata, + sw.toString(), + tripleStats + ); + } } From 64515f659aa9df45b8203dac2f99b977d433badf Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 15:53:32 +0200 Subject: [PATCH 03/36] rename config classes --- .../org/aksw/iguana/cc/config/IguanaConfig.java | 12 ++++++------ .../{Connection.java => ConnectionConfig.java} | 2 +- .../elements/{Dataset.java => DatasetConfig.java} | 2 +- .../config/elements/{Task.java => TaskConfig.java} | 2 +- .../aksw/iguana/cc/controller/TaskController.java | 6 +++--- .../org/aksw/iguana/cc/tasks/AbstractTask.java | 6 +++--- src/main/java/org/aksw/iguana/cc/tasks/Task.java | 6 +++--- .../java/org/aksw/iguana/cc/tasks/TaskManager.java | 4 ++-- .../org/aksw/iguana/cc/tasks/impl/Stresstest.java | 4 ++-- .../org/aksw/iguana/cc/worker/AbstractWorker.java | 8 ++++---- .../iguana/cc/worker/impl/CLIInputFileWorker.java | 4 ++-- .../cc/worker/impl/CLIInputPrefixWorker.java | 4 ++-- .../aksw/iguana/cc/worker/impl/CLIInputWorker.java | 4 ++-- .../org/aksw/iguana/cc/worker/impl/CLIWorker.java | 4 ++-- .../aksw/iguana/cc/worker/impl/HttpGetWorker.java | 4 ++-- .../aksw/iguana/cc/worker/impl/HttpPostWorker.java | 4 ++-- .../org/aksw/iguana/cc/worker/impl/HttpWorker.java | 4 ++-- .../cc/worker/impl/MultipleCLIInputWorker.java | 4 ++-- .../aksw/iguana/cc/worker/impl/UPDATEWorker.java | 4 ++-- .../aksw/iguana/cc/tasks/impl/StresstestTest.java | 6 +++--- .../org/aksw/iguana/cc/worker/HTTPWorkerTest.java | 6 +++--- .../org/aksw/iguana/cc/worker/MockupWorker.java | 4 ++-- .../aksw/iguana/cc/worker/UPDATEWorkerTest.java | 8 ++++---- .../iguana/cc/worker/impl/CLIWorkersTests.java | 14 +++++++------- .../iguana/cc/worker/impl/HttpPostWorkerTest.java | 6 +++--- 25 files changed, 66 insertions(+), 66 deletions(-) rename src/main/java/org/aksw/iguana/cc/config/elements/{Connection.java => ConnectionConfig.java} (96%) rename src/main/java/org/aksw/iguana/cc/config/elements/{Dataset.java => DatasetConfig.java} (95%) rename src/main/java/org/aksw/iguana/cc/config/elements/{Task.java => TaskConfig.java} (94%) diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index 221776c5..58e82c3b 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -45,11 +45,11 @@ public class IguanaConfig { .getLogger(IguanaConfig.class); @JsonProperty(required = true) - private List datasets; + private List datasets; @JsonProperty(required = true) - private List connections; + private List connections; @JsonProperty(required = true) - private List tasks; + private List tasks; @JsonProperty private String preScriptHook; @JsonProperty @@ -73,11 +73,11 @@ public void start() throws ExecuteException, IOException { //generate ExpID int expID = 0; - for(Dataset dataset: datasets){ + for(DatasetConfig dataset: datasets){ expID++; Integer taskID = 0; - for(Connection con : connections){ - for(Task task : tasks) { + for(ConnectionConfig con : connections){ + for(TaskConfig task : tasks) { taskID++; String[] args = new String[] {}; if(preScriptHook!=null){ diff --git a/src/main/java/org/aksw/iguana/cc/config/elements/Connection.java b/src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java similarity index 96% rename from src/main/java/org/aksw/iguana/cc/config/elements/Connection.java rename to src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java index ed91b120..b53d5f71 100644 --- a/src/main/java/org/aksw/iguana/cc/config/elements/Connection.java +++ b/src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java @@ -7,7 +7,7 @@ /** * A connection configuration class */ -public class Connection implements Serializable { +public class ConnectionConfig implements Serializable { @JsonProperty(required = true) private String name; diff --git a/src/main/java/org/aksw/iguana/cc/config/elements/Dataset.java b/src/main/java/org/aksw/iguana/cc/config/elements/DatasetConfig.java similarity index 95% rename from src/main/java/org/aksw/iguana/cc/config/elements/Dataset.java rename to src/main/java/org/aksw/iguana/cc/config/elements/DatasetConfig.java index 6bbb0c06..d067b715 100644 --- a/src/main/java/org/aksw/iguana/cc/config/elements/Dataset.java +++ b/src/main/java/org/aksw/iguana/cc/config/elements/DatasetConfig.java @@ -7,7 +7,7 @@ * * Will set the name and if it was set in the config file the fileName */ -public class Dataset { +public class DatasetConfig { @JsonProperty(required = true) private String name; diff --git a/src/main/java/org/aksw/iguana/cc/config/elements/Task.java b/src/main/java/org/aksw/iguana/cc/config/elements/TaskConfig.java similarity index 94% rename from src/main/java/org/aksw/iguana/cc/config/elements/Task.java rename to src/main/java/org/aksw/iguana/cc/config/elements/TaskConfig.java index 1dd10893..5b09b3e4 100644 --- a/src/main/java/org/aksw/iguana/cc/config/elements/Task.java +++ b/src/main/java/org/aksw/iguana/cc/config/elements/TaskConfig.java @@ -9,7 +9,7 @@ /** * The task configuration class, sets the class name and it's configuration */ -public class Task implements Serializable { +public class TaskConfig implements Serializable { @JsonProperty(required = true) private Map configuration = new HashMap<>(); diff --git a/src/main/java/org/aksw/iguana/cc/controller/TaskController.java b/src/main/java/org/aksw/iguana/cc/controller/TaskController.java index b0e589ab..26f9652b 100644 --- a/src/main/java/org/aksw/iguana/cc/controller/TaskController.java +++ b/src/main/java/org/aksw/iguana/cc/controller/TaskController.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.controller; -import org.aksw.iguana.cc.config.elements.Connection; -import org.aksw.iguana.cc.config.elements.Task; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; +import org.aksw.iguana.cc.config.elements.TaskConfig; import org.aksw.iguana.cc.tasks.TaskFactory; import org.aksw.iguana.cc.tasks.TaskManager; import org.slf4j.Logger; @@ -20,7 +20,7 @@ public class TaskController { private static final Logger LOGGER = LoggerFactory.getLogger(TaskController.class); - public void startTask(String[] ids, String dataset, Connection con, Task task) { + public void startTask(String[] ids, String dataset, ConnectionConfig con, TaskConfig task) { TaskManager tmanager = new TaskManager(); String className = task.getClassName(); TaskFactory factory = new TaskFactory(); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java index 88b32b59..388dec96 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java @@ -3,7 +3,7 @@ */ package org.aksw.iguana.cc.tasks; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.commons.annotation.Shorthand; import org.aksw.iguana.commons.constants.COMMON; import org.aksw.iguana.rp.experiment.ExperimentManager; @@ -26,7 +26,7 @@ public abstract class AbstractTask implements Task { private ExperimentManager rpControl = ExperimentManager.getInstance(); protected String taskID; - protected Connection con; + protected ConnectionConfig con; /** * Properties to add task specific metaData before start and execute which then @@ -53,7 +53,7 @@ public AbstractTask() { * @see org.aksw.iguana.tp.tasks.Task#init() */ @Override - public void init(String[] ids, String dataset, Connection con, String taskName) { + public void init(String[] ids, String dataset, ConnectionConfig con, String taskName) { this.suiteID=ids[0]; this.expID=ids[1]; this.taskID=ids[2]; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/Task.java b/src/main/java/org/aksw/iguana/cc/tasks/Task.java index fe3b1cc3..3bd6b0b7 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/Task.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/Task.java @@ -3,7 +3,7 @@ */ package org.aksw.iguana.cc.tasks; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import java.io.IOException; import java.util.Properties; @@ -52,7 +52,7 @@ public interface Task { * @param con the current connection to execute the task against * @param taskName the taskName */ - void init(String[] ids, String dataset, Connection con, String taskName); + void init(String[] ids, String dataset, ConnectionConfig con, String taskName); /** * Will initialize the task @@ -60,7 +60,7 @@ public interface Task { * @param dataset the dataset name * @param con the current connection to execute the task against */ - default void init(String[] ids, String dataset, Connection con){ + default void init(String[] ids, String dataset, ConnectionConfig con){ init(ids, dataset, con, null); } } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/TaskManager.java b/src/main/java/org/aksw/iguana/cc/tasks/TaskManager.java index f2d806c8..22e8b860 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/TaskManager.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/TaskManager.java @@ -3,7 +3,7 @@ */ package org.aksw.iguana.cc.tasks; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import java.io.IOException; import java.util.concurrent.TimeoutException; @@ -32,7 +32,7 @@ public void setTask(Task task){ * @throws IOException * @throws TimeoutException */ - public void startTask(String[] ids, String dataset, Connection con, String taskName) throws IOException, TimeoutException{ + public void startTask(String[] ids, String dataset, ConnectionConfig con, String taskName) throws IOException, TimeoutException{ this.task.init(ids, dataset, con, taskName); this.task.addMetaData(); this.task.start(); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java index 838c0822..a61cd110 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.tasks.impl; import org.aksw.iguana.cc.config.CONSTANTS; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.StresstestMetadata; import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.tasks.AbstractTask; @@ -140,7 +140,7 @@ public void addMetaData() { @Override - public void init(String[] ids, String dataset, Connection connection, String taskName) { + public void init(String[] ids, String dataset, ConnectionConfig connection, String taskName) { super.init(ids, dataset, connection, taskName); initWorkers(); diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index aba8fb70..da039ed0 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.worker; import org.aksw.iguana.cc.config.CONSTANTS; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; @@ -53,7 +53,7 @@ public abstract class AbstractWorker implements Worker { * The workerType is only used in logging messages. */ protected String workerType; - protected Connection connection; + protected ConnectionConfig connection; protected Map queries; protected Double timeLimit; @@ -65,14 +65,14 @@ public abstract class AbstractWorker implements Worker { protected long executedQueries; protected Properties extra = new Properties(); protected Instant startTime; - protected Connection con; + protected ConnectionConfig con; protected int queryHash; protected QueryHandler queryHandler; private Collection results = new LinkedList<>(); private Random latencyRandomizer; private Long endAtNOQM = null; - public AbstractWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency) { + public AbstractWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency) { this.taskID = taskID; this.workerID = workerID; this.con = connection; diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputFileWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputFileWorker.java index 50515b43..5660a73d 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputFileWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputFileWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; @@ -22,7 +22,7 @@ public class CLIInputFileWorker extends MultipleCLIInputWorker { private final String dir; - public CLIInputFileWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError, @Nullable Integer numberOfProcesses, String directory) { + public CLIInputFileWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError, @Nullable Integer numberOfProcesses, String directory) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency, initFinished, queryFinished, queryError, numberOfProcesses); this.dir = directory; } diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputPrefixWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputPrefixWorker.java index 19e37cdd..e2112021 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputPrefixWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputPrefixWorker.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; @@ -23,7 +23,7 @@ public class CLIInputPrefixWorker extends MultipleCLIInputWorker { private final String prefix; private final String suffix; - public CLIInputPrefixWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError, @Nullable Integer numberOfProcesses, String queryPrefix, String querySuffix) { + public CLIInputPrefixWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError, @Nullable Integer numberOfProcesses, String queryPrefix, String querySuffix) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency, initFinished, queryFinished, queryError, numberOfProcesses); this.prefix = queryPrefix; this.suffix = querySuffix; diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputWorker.java index 32f0b099..70b30acb 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIInputWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.utils.CLIProcessManager; import org.aksw.iguana.cc.worker.AbstractWorker; @@ -35,7 +35,7 @@ public class CLIInputWorker extends AbstractWorker { private final String error; private Process process; - public CLIInputWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError) { + public CLIInputWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency); this.initFinished = initFinished; this.queryFinished = queryFinished; diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIWorker.java index e6315ec3..fb5b0fd1 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/CLIWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/CLIWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.worker.AbstractWorker; import org.aksw.iguana.commons.annotation.Nullable; @@ -32,7 +32,7 @@ public class CLIWorker extends AbstractWorker { private final Logger LOGGER = LoggerFactory.getLogger(getClass()); - public CLIWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency) { + public CLIWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency); } diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/HttpGetWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/HttpGetWorker.java index aa279de1..857d0395 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/HttpGetWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/HttpGetWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; import org.apache.http.HttpHeaders; @@ -24,7 +24,7 @@ public class HttpGetWorker extends HttpWorker { protected String responseType = null; - public HttpGetWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, @Nullable String parameterName, @Nullable String responseType) { + public HttpGetWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, @Nullable String parameterName, @Nullable String responseType) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency); if (parameterName != null) { diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/HttpPostWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/HttpPostWorker.java index 2043b5bf..c6f884da 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/HttpPostWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/HttpPostWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; import org.apache.http.HttpHeaders; @@ -24,7 +24,7 @@ public class HttpPostWorker extends HttpGetWorker { private String contentType = "text/plain"; - public HttpPostWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, @Nullable String parameterName, @Nullable String responseType, @Nullable String contentType) { + public HttpPostWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, @Nullable String parameterName, @Nullable String responseType, @Nullable String contentType) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency, parameterName, responseType); if (parameterName == null) { diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/HttpWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/HttpWorker.java index 06428020..d9151232 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/HttpWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/HttpWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.model.QueryResultHashKey; import org.aksw.iguana.cc.worker.AbstractWorker; @@ -50,7 +50,7 @@ public abstract class HttpWorker extends AbstractWorker { protected Instant requestStartTime; protected long tmpExecutedQueries = 0; - public HttpWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency) { + public HttpWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency); this.timeoutExecutorPool.setRemoveOnCancelPolicy(true); } diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/MultipleCLIInputWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/MultipleCLIInputWorker.java index b30e9849..355aa376 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/MultipleCLIInputWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/MultipleCLIInputWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.utils.CLIProcessManager; import org.aksw.iguana.cc.worker.AbstractWorker; @@ -42,7 +42,7 @@ public class MultipleCLIInputWorker extends AbstractWorker { protected int numberOfProcesses = 5; private Process currentProcess; - public MultipleCLIInputWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError, @Nullable Integer numberOfProcesses) { + public MultipleCLIInputWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, String initFinished, String queryFinished, String queryError, @Nullable Integer numberOfProcesses) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency); this.initFinished = initFinished; this.queryFinished = queryFinished; diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java index b6843423..2a9ff03a 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.worker.impl.update.UpdateTimer; import org.aksw.iguana.commons.annotation.Nullable; @@ -26,7 +26,7 @@ public class UPDATEWorker extends HttpPostWorker { private int queryCount; - public UPDATEWorker(String taskID, Integer workerID, Connection connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, @Nullable String timerStrategy) { + public UPDATEWorker(String taskID, Integer workerID, ConnectionConfig connection, Map queries, @Nullable Integer timeLimit, @Nullable Integer timeOut, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, @Nullable String timerStrategy) { super(taskID, workerID, connection, queries, timeLimit, timeOut, fixedLatency, gaussianLatency, null, null, "application/sparql-update"); this.timerStrategy = timerStrategy; } diff --git a/src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java b/src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java index 3f5efbdc..d444b38a 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.tasks.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.tasks.MockupStorage; import org.aksw.iguana.cc.worker.MockupWorker; import org.aksw.iguana.cc.worker.Worker; @@ -33,8 +33,8 @@ private List> getWorkers(int threads, String[] queries) { return workers; } - private Connection getConnection() { - Connection con = new Connection(); + private ConnectionConfig getConnection() { + ConnectionConfig con = new ConnectionConfig(); con.setName("test"); con.setEndpoint("test/sparql"); return con; diff --git a/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java b/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java index 469fa982..97838617 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java +++ b/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.lang.impl.SPARQLLanguageProcessor; import org.aksw.iguana.cc.utils.FileUtils; import org.aksw.iguana.cc.worker.impl.HttpGetWorker; @@ -158,8 +158,8 @@ private HttpWorker getWorker(String taskID, Integer latencyFixed, Integer gaussi } - private Connection getConnection() { - Connection con = new Connection(); + private ConnectionConfig getConnection() { + ConnectionConfig con = new ConnectionConfig(); con.setName("test"); con.setPassword("test"); con.setUser("abc"); diff --git a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java index 38c756d7..043fdd98 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java +++ b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.commons.annotation.Nullable; @@ -12,7 +12,7 @@ public class MockupWorker extends AbstractWorker { private int counter = 0; private final String[] queries; - public MockupWorker(String[] stringQueries, Integer workerID, @Nullable Integer timeLimit, Connection connection, String taskID) { + public MockupWorker(String[] stringQueries, Integer workerID, @Nullable Integer timeLimit, ConnectionConfig connection, String taskID) { super(taskID, workerID, connection, getQueryConfig(), 0, timeLimit, 0, 0); this.queries = stringQueries; } diff --git a/src/test/java/org/aksw/iguana/cc/worker/UPDATEWorkerTest.java b/src/test/java/org/aksw/iguana/cc/worker/UPDATEWorkerTest.java index 53fe806c..3b131049 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/UPDATEWorkerTest.java +++ b/src/test/java/org/aksw/iguana/cc/worker/UPDATEWorkerTest.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.worker.impl.UPDATEWorker; import org.aksw.iguana.cc.worker.impl.update.UpdateTimer; import org.aksw.iguana.commons.time.TimeUtils; @@ -117,7 +117,7 @@ public void cleanup() throws IOException { public void testWorkflow() throws InterruptedException { String taskID = "124/1/1"; int timeLimit = 2000; - Connection con = getConnection(); + ConnectionConfig con = getConnection(); UPDATEWorker worker = new UPDATEWorker(taskID, 1, con, this.queriesFile, timeLimit, null, null, null, this.timerStrategy); worker.run(); Instant now = worker.startTime; @@ -162,8 +162,8 @@ private double getQueryWaitTime(String timerStrategy, Double fixedValue, long re } - private Connection getConnection() { - Connection con = new Connection(); + private ConnectionConfig getConnection() { + ConnectionConfig con = new ConnectionConfig(); con.setName("test"); con.setEndpoint(this.service); diff --git a/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java b/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java index 8ec21bb3..44d63b1f 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java +++ b/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.utils.FileUtils; import org.aksw.iguana.commons.constants.COMMON; import org.junit.After; @@ -33,7 +33,7 @@ public void deleteFile() { @Test public void checkMultipleProcesses() { - Connection con = new Connection(); + ConnectionConfig con = new ConnectionConfig(); con.setEndpoint("src/test/resources/cli/echoinput.sh " + f.getAbsolutePath()); MultipleCLIInputWorker worker = new MultipleCLIInputWorker("123/1/1", 1, con, getQueryConfig(), null, null, null, null, "init finished", "rows", "query fail", 2); assertEquals(2, worker.processList.size()); @@ -60,7 +60,7 @@ public void checkMultipleProcesses() { @Test public void checkFileInput() throws IOException { //check if file is created and used - Connection con = new Connection(); + ConnectionConfig con = new ConnectionConfig(); String dir = UUID.randomUUID().toString(); con.setEndpoint("src/test/resources/cli/echoinput.sh " + f.getAbsolutePath()); CLIInputFileWorker worker = new CLIInputFileWorker("123/1/1", 1, con, getQueryConfig(), null, null, null, null, "init finished", "rows", "query fail", 1, dir); @@ -78,7 +78,7 @@ public void checkFileInput() throws IOException { @Test public void checkInput() throws IOException { // check if connection stays - Connection con = new Connection(); + ConnectionConfig con = new ConnectionConfig(); con.setEndpoint("src/test/resources/cli/echoinput.sh " + f.getAbsolutePath()); CLIInputWorker worker = new CLIInputWorker("123/1/1", 1, con, getQueryConfig(), null, null, null, null, "init finished", "rows", "query fail"); @@ -110,7 +110,7 @@ public void checkInput() throws IOException { @Test public void checkPrefix() throws IOException { // check if connection stays - Connection con = new Connection(); + ConnectionConfig con = new ConnectionConfig(); con.setEndpoint("src/test/resources/cli/echoinput.sh " + f.getAbsolutePath()); CLIInputPrefixWorker worker = new CLIInputPrefixWorker("123/1/1", 1, con, getQueryConfig(), null, null, null, null, "init finished", "rows", "query fail", 1, "prefix", "suffix"); @@ -141,7 +141,7 @@ public void checkPrefix() throws IOException { public void checkCLI() throws IOException { //check if simple cli works // public CLIWorker(String taskID, Connection connection, String queriesFile, @Nullable Integer timeOut, @Nullable Integer timeLimit, @Nullable Integer fixedLatency, @Nullable Integer gaussianLatency, Integer workerID) { - Connection con = new Connection(); + ConnectionConfig con = new ConnectionConfig(); con.setUser("user1"); con.setPassword("pwd"); @@ -151,7 +151,7 @@ public void checkCLI() throws IOException { String content = FileUtils.readFile(f.getAbsolutePath()); assertEquals("test () user1:pwd test+%28%29\n", content); - con = new Connection(); + con = new ConnectionConfig(); con.setEndpoint("/bin/echo \"$QUERY$ $USER$:$PASSWORD$ $ENCODEDQUERY$\" > " + f.getAbsolutePath() + " | /bin/printf \"HeaderDoesNotCount\na\na\""); worker = new CLIWorker("123/1/1", 1, con, getQueryConfig(), null, null, null, null); worker.executeQuery("test ()", "1"); diff --git a/src/test/java/org/aksw/iguana/cc/worker/impl/HttpPostWorkerTest.java b/src/test/java/org/aksw/iguana/cc/worker/impl/HttpPostWorkerTest.java index 4fff0e5b..631319a2 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/impl/HttpPostWorkerTest.java +++ b/src/test/java/org/aksw/iguana/cc/worker/impl/HttpPostWorkerTest.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.worker.impl; -import org.aksw.iguana.cc.config.elements.Connection; +import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.apache.http.client.methods.HttpPost; import org.junit.Test; @@ -37,10 +37,10 @@ public void buildRequest() throws IOException { assertEquals(query, content); } - private Connection getConnection() { + private ConnectionConfig getConnection() { String service = "http://localhost:3030"; - Connection con = new Connection(); + ConnectionConfig con = new ConnectionConfig(); con.setName("test"); con.setPassword("test"); con.setUser("abc"); From 49287fc0e04e3626daff036cc85a9bf96ccd29be Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:03:31 +0200 Subject: [PATCH 04/36] rename package --- docs/shorthand-mapping.md | 2 +- .../aksw/iguana/cc/tasks/{impl => stresstest}/Stresstest.java | 2 +- src/main/java/org/aksw/iguana/cc/worker/Worker.java | 2 +- .../iguana/cc/tasks/{impl => stresstest}/StresstestTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/org/aksw/iguana/cc/tasks/{impl => stresstest}/Stresstest.java (99%) rename src/test/java/org/aksw/iguana/cc/tasks/{impl => stresstest}/StresstestTest.java (99%) diff --git a/docs/shorthand-mapping.md b/docs/shorthand-mapping.md index 49cdd864..756550dc 100644 --- a/docs/shorthand-mapping.md +++ b/docs/shorthand-mapping.md @@ -1,6 +1,6 @@ | Shorthand | Class Name | |------------------------|-----------------------------------------------------------| -| Stresstest | `org.aksw.iguana.cc.tasks.impl.Stresstest` | +| Stresstest | `org.aksw.iguana.cc.tasks.stresstest.Stresstest` | | ---------- | ------- | | lang.RDF | `org.aksw.iguana.cc.lang.impl.RDFLanguageProcessor` | | lang.SPARQL | `org.aksw.iguana.cc.lang.impl.SPARQLLanguageProcessor` | diff --git a/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java similarity index 99% rename from src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index a61cd110..447a4db9 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/impl/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -1,4 +1,4 @@ -package org.aksw.iguana.cc.tasks.impl; +package org.aksw.iguana.cc.tasks.stresstest; import org.aksw.iguana.cc.config.CONSTANTS; import org.aksw.iguana.cc.config.elements.ConnectionConfig; diff --git a/src/main/java/org/aksw/iguana/cc/worker/Worker.java b/src/main/java/org/aksw/iguana/cc/worker/Worker.java index 1e1c6183..341bdd3a 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/Worker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/Worker.java @@ -2,7 +2,7 @@ import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; -import org.aksw.iguana.cc.tasks.impl.Stresstest; +import org.aksw.iguana.cc.tasks.stresstest.Stresstest; import java.io.IOException; import java.util.Collection; diff --git a/src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java similarity index 99% rename from src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java rename to src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java index d444b38a..6fac9446 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/impl/StresstestTest.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java @@ -1,4 +1,4 @@ -package org.aksw.iguana.cc.tasks.impl; +package org.aksw.iguana.cc.tasks.stresstest; import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.tasks.MockupStorage; From 38179793abb3188d6858c9064e15c690bb7f5736 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:40:27 +0200 Subject: [PATCH 05/36] make QueryExecutionStats a record --- .../iguana/cc/model/QueryExecutionStats.java | 63 +++---------------- 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/model/QueryExecutionStats.java b/src/main/java/org/aksw/iguana/cc/model/QueryExecutionStats.java index 3103e277..c15a6b47 100644 --- a/src/main/java/org/aksw/iguana/cc/model/QueryExecutionStats.java +++ b/src/main/java/org/aksw/iguana/cc/model/QueryExecutionStats.java @@ -3,60 +3,13 @@ /** * Wrapper for a query execution. */ -public class QueryExecutionStats { - private String queryID; - private long responseCode; - private double executionTime; - private long resultSize; - - public QueryExecutionStats(String queryID, long responseCode, double executionTime) - { - this.queryID = queryID; - this.responseCode = responseCode; - this.executionTime = executionTime; - } - - - public QueryExecutionStats(String queryID, long responseCode, double executionTime, long resultSize) - { - this.queryID = queryID; - this.responseCode = responseCode; - this.executionTime = executionTime; - this.resultSize = resultSize; - } - - public QueryExecutionStats() { - } - - public String getQueryID() { - return queryID; - } - - public void setQueryID(String queryID) { - this.queryID = queryID; - } - - public long getResponseCode() { - return responseCode; - } - - public void setResponseCode(long responseCode) { - this.responseCode = responseCode; - } - - public double getExecutionTime() { - return executionTime; - } - - public void setExecutionTime(double executionTime) { - this.executionTime = executionTime; - } - - public long getResultSize() { - return resultSize; - } - - public void setResultSize(long resultSize) { - this.resultSize = resultSize; +public record QueryExecutionStats ( + String queryID, + long responseCode, + double executionTime, + long resultSize +) { + public QueryExecutionStats(String queryID, long responseCode, double executionTime) { + this(queryID, responseCode, executionTime, 0); } } From 5fbd6b65d85b660cc2427ae6c3439cfdd1d88bf7 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:42:31 +0200 Subject: [PATCH 06/36] use primitives for constants --- .../java/org/aksw/iguana/commons/constants/COMMON.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/aksw/iguana/commons/constants/COMMON.java b/src/main/java/org/aksw/iguana/commons/constants/COMMON.java index 3851193a..1a63bc9b 100644 --- a/src/main/java/org/aksw/iguana/commons/constants/COMMON.java +++ b/src/main/java/org/aksw/iguana/commons/constants/COMMON.java @@ -91,13 +91,13 @@ public class COMMON { public static final String WORKER_ID = "workerID"; /* Various status codes to denote the status of query execution and to prepare QueryExecutionStats object */ - public static final Long QUERY_UNKNOWN_EXCEPTION = 0L; + public static final long QUERY_UNKNOWN_EXCEPTION = 0L; - public static final Long QUERY_SUCCESS = 1L; + public static final long QUERY_SUCCESS = 1L; - public static final Long QUERY_SOCKET_TIMEOUT = -1L; + public static final long QUERY_SOCKET_TIMEOUT = -1L; - public static final Long QUERY_HTTP_FAILURE = -2L; + public static final long QUERY_HTTP_FAILURE = -2L; public static final String EXPERIMENT_TASK_CLASS_ID_KEY = "actualTaskClass" ; From f31eea791c1bc86e3b41bf4c840318fa62347ff5 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:44:16 +0200 Subject: [PATCH 07/36] remove usage of Properties class for saving worker results --- .../aksw/iguana/cc/worker/AbstractWorker.java | 23 ++------- .../org/aksw/iguana/cc/worker/Worker.java | 4 +- .../iguana/cc/worker/impl/UPDATEWorker.java | 20 -------- .../aksw/iguana/cc/worker/HTTPWorkerTest.java | 32 ++++++------- .../aksw/iguana/cc/worker/MockupWorker.java | 15 +++--- .../cc/worker/impl/CLIWorkersTests.java | 47 ++++++++++--------- 6 files changed, 51 insertions(+), 90 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index da039ed0..b1db54df 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -68,7 +68,7 @@ public abstract class AbstractWorker implements Worker { protected ConnectionConfig con; protected int queryHash; protected QueryHandler queryHandler; - private Collection results = new LinkedList<>(); + private Collection results = new LinkedList<>(); private Random latencyRandomizer; private Long endAtNOQM = null; @@ -186,18 +186,7 @@ protected HttpContext getAuthContext(String endpoint) { public synchronized void addResults(QueryExecutionStats results) { if (!this.endSignal && !hasExecutedNoOfQueryMixes(this.endAtNOQM)) { - // create Properties store it in List - Properties result = new Properties(); - result.setProperty(COMMON.EXPERIMENT_TASK_ID_KEY, this.taskID); - result.put(COMMON.RECEIVE_DATA_TIME, results.getExecutionTime()); - result.put(COMMON.RECEIVE_DATA_SUCCESS, results.getResponseCode()); - result.put(COMMON.RECEIVE_DATA_SIZE, results.getResultSize()); - result.put(COMMON.QUERY_HASH, queryHash); - result.setProperty(COMMON.QUERY_ID_KEY, results.getQueryID()); - result.put(COMMON.PENALTY, this.timeOut); - // Add extra Meta Key, worker ID and worker Type - result.put(COMMON.EXTRA_META_KEY, this.extra); - setResults(result); + this.results.add(results); this.executedQueries++; // @@ -207,16 +196,12 @@ public synchronized void addResults(QueryExecutionStats results) { } } - protected synchronized void setResults(Properties result) { - this.results.add(result); - } - @Override - public synchronized Collection popQueryResults() { + public synchronized Collection popQueryResults() { if (this.results.isEmpty()) { return null; } - Collection ret = this.results; + Collection ret = this.results; this.results = new LinkedList<>(); return ret; } diff --git a/src/main/java/org/aksw/iguana/cc/worker/Worker.java b/src/main/java/org/aksw/iguana/cc/worker/Worker.java index 341bdd3a..65900bce 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/Worker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/Worker.java @@ -1,12 +1,12 @@ package org.aksw.iguana.cc.worker; +import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; import org.aksw.iguana.cc.tasks.stresstest.Stresstest; import java.io.IOException; import java.util.Collection; -import java.util.Properties; /** * Interface for the Worker Thread used in the {@link Stresstest} @@ -71,7 +71,7 @@ public interface Worker extends Runnable{ * * @return list of Properties to send to RabbitMQ */ - Collection popQueryResults(); + Collection popQueryResults(); boolean isTerminated(); diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java index 2a9ff03a..1b2a6074 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java @@ -1,16 +1,13 @@ package org.aksw.iguana.cc.worker.impl; import org.aksw.iguana.cc.config.elements.ConnectionConfig; -import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.worker.impl.update.UpdateTimer; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; import java.io.IOException; import java.time.Instant; import java.util.Map; -import java.util.Properties; import static org.aksw.iguana.commons.time.TimeUtils.durationInMilliseconds; @@ -50,23 +47,6 @@ public void waitTimeMs() { super.waitTimeMs(); } - @Override - public synchronized void addResults(QueryExecutionStats results) { - // create Properties store it in List - Properties result = new Properties(); - result.setProperty(COMMON.EXPERIMENT_TASK_ID_KEY, this.taskID); - result.put(COMMON.RECEIVE_DATA_TIME, results.getExecutionTime()); - result.put(COMMON.RECEIVE_DATA_SUCCESS, results.getResponseCode()); - result.put(COMMON.RECEIVE_DATA_SIZE, results.getResultSize()); - result.put(COMMON.QUERY_HASH, this.queryHash); - result.setProperty(COMMON.QUERY_ID_KEY, results.getQueryID()); - result.put(COMMON.PENALTY, this.timeOut); - // Add extra Meta Key, worker ID and worker Type - result.put(COMMON.EXTRA_META_KEY, this.extra); - setResults(result); - this.executedQueries++; - } - @Override public void getNextQuery(StringBuilder queryStr, StringBuilder queryID) throws IOException { // If there is no more update send end signal, as there is nothing to do anymore diff --git a/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java b/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java index 97838617..7e46d206 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java +++ b/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java @@ -2,11 +2,11 @@ import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.lang.impl.SPARQLLanguageProcessor; +import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.utils.FileUtils; import org.aksw.iguana.cc.worker.impl.HttpGetWorker; import org.aksw.iguana.cc.worker.impl.HttpPostWorker; import org.aksw.iguana.cc.worker.impl.HttpWorker; -import org.aksw.iguana.commons.constants.COMMON; import org.junit.*; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -117,30 +117,29 @@ public void testExecution() throws InterruptedException { getWorker.executeQuery(this.query, this.queryID); //as the result processing is in the background we have to wait for it. Thread.sleep(1000); - Collection results = getWorker.popQueryResults(); + Collection results = getWorker.popQueryResults(); assertEquals(1, results.size()); - Properties p = results.iterator().next(); + QueryExecutionStats p = results.iterator().next(); - assertEquals(taskID, p.get(COMMON.EXPERIMENT_TASK_ID_KEY)); + assertEquals(taskID, getWorker.taskID); - assertEquals(this.queryID, p.get(COMMON.QUERY_ID_KEY)); - assertEquals(180000.0, p.get(COMMON.PENALTY)); - assertTrue(((Properties) p.get(COMMON.EXTRA_META_KEY)).isEmpty()); + assertEquals(this.queryID, p.queryID()); + assertEquals(180000.0, getWorker.timeOut.doubleValue()); if (isPost) { - assertEquals(200.0, (double) p.get(COMMON.RECEIVE_DATA_TIME), 20.0); + assertEquals(200.0, p.executionTime(), 20.0); } else { - assertEquals(100.0, (double) p.get(COMMON.RECEIVE_DATA_TIME), 20.0); + assertEquals(100.0, p.executionTime(), 20.0); } if (isFail) { - assertEquals(-2L, p.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(0L, p.get(COMMON.RECEIVE_DATA_SIZE)); + assertEquals(-2L, p.responseCode()); + assertEquals(0L, p.executionTime()); } else { - assertEquals(1L, p.get(COMMON.RECEIVE_DATA_SUCCESS)); + assertEquals(1L, p.executionTime()); if (this.responseType != null && this.responseType.equals("text/plain")) { - assertEquals(4L, p.get(COMMON.RECEIVE_DATA_SIZE)); + assertEquals(4L, p.executionTime()); } if (this.responseType == null || this.responseType.equals(SPARQLLanguageProcessor.QUERY_RESULT_TYPE_JSON)) { - assertEquals(2L, p.get(COMMON.RECEIVE_DATA_SIZE)); + assertEquals(2L, p.resultSize()); } } assertEquals(1, getWorker.getExecutedQueries()); @@ -209,10 +208,7 @@ public void testWorkflow() throws InterruptedException { } assertEquals(expectedSize, getWorker.getExecutedQueries()); // check pop query results - Collection results = getWorker.popQueryResults(); - for (Properties p : results) { - assertEquals(queryHash, p.get(COMMON.QUERY_HASH)); - } + Collection results = getWorker.popQueryResults(); assertEquals(expectedSize, results.size()); for (long i = 1; i < expectedSize; i++) { assertTrue(getWorker.hasExecutedNoOfQueryMixes(i)); diff --git a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java index 043fdd98..5094571b 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java +++ b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java @@ -29,20 +29,19 @@ private static Map getQueryConfig() { @Override public void executeQuery(String query, String queryID) { - QueryExecutionStats results = new QueryExecutionStats(); long execTime = this.workerID * 10 + 100; + long responseCode; + long resultSize; try { Thread.sleep(execTime); - results.setResponseCode(200); - results.setResultSize(this.workerID * 100 + 100); + responseCode = 200; + resultSize = this.workerID * 100 + 100; } catch (InterruptedException e) { e.printStackTrace(); - results.setResponseCode(400); - results.setResultSize(0); + responseCode = 400; + resultSize = 0; } - results.setExecutionTime(execTime); - results.setQueryID(queryID); - super.addResults(results); + super.addResults(new QueryExecutionStats(queryID, responseCode, execTime, resultSize)); } @Override diff --git a/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java b/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java index 44d63b1f..9aca35f8 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java +++ b/src/test/java/org/aksw/iguana/cc/worker/impl/CLIWorkersTests.java @@ -1,6 +1,7 @@ package org.aksw.iguana.cc.worker.impl; import org.aksw.iguana.cc.config.elements.ConnectionConfig; +import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.utils.FileUtils; import org.aksw.iguana.commons.constants.COMMON; import org.junit.After; @@ -85,23 +86,23 @@ public void checkInput() throws IOException { worker.executeQuery("test", "1"); worker.executeQuery("SELECT whatever", "1"); assertEquals("test\nSELECT whatever\n", FileUtils.readFile(f.getAbsolutePath())); - Collection succeededResults = worker.popQueryResults(); + Collection succeededResults = worker.popQueryResults(); assertEquals(2, succeededResults.size()); - Properties succ = succeededResults.iterator().next(); - assertEquals(COMMON.QUERY_SUCCESS, succ.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(3L, succ.get(COMMON.RECEIVE_DATA_SIZE)); + QueryExecutionStats succ = succeededResults.iterator().next(); + assertEquals(COMMON.QUERY_SUCCESS, succ.responseCode()); + assertEquals(3L, succ.responseCode()); succ = succeededResults.iterator().next(); - assertEquals(COMMON.QUERY_SUCCESS, succ.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(3L, succ.get(COMMON.RECEIVE_DATA_SIZE)); + assertEquals(COMMON.QUERY_SUCCESS, succ.responseCode()); + assertEquals(3L, succ.responseCode()); // check fail worker.executeQuery("fail", "2"); assertEquals("test\nSELECT whatever\nfail\n", FileUtils.readFile(f.getAbsolutePath())); - Collection failedResults = worker.popQueryResults(); + Collection failedResults = worker.popQueryResults(); assertEquals(1, failedResults.size()); - Properties fail = failedResults.iterator().next(); - assertEquals(COMMON.QUERY_UNKNOWN_EXCEPTION, fail.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(0L, fail.get(COMMON.RECEIVE_DATA_SIZE)); + QueryExecutionStats fail = failedResults.iterator().next(); + assertEquals(COMMON.QUERY_UNKNOWN_EXCEPTION, fail.responseCode()); + assertEquals(0L, fail.resultSize()); worker.stopSending(); @@ -117,23 +118,23 @@ public void checkPrefix() throws IOException { worker.executeQuery("test", "1"); worker.executeQuery("SELECT whatever", "1"); assertEquals("prefix test suffix\nprefix SELECT whatever suffix\n", FileUtils.readFile(f.getAbsolutePath())); - Collection succeededResults = worker.popQueryResults(); + Collection succeededResults = worker.popQueryResults(); assertEquals(2, succeededResults.size()); - Properties succ = succeededResults.iterator().next(); - assertEquals(COMMON.QUERY_SUCCESS, succ.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(3L, succ.get(COMMON.RECEIVE_DATA_SIZE)); + QueryExecutionStats succ = succeededResults.iterator().next(); + assertEquals(COMMON.QUERY_SUCCESS, succ.responseCode()); + assertEquals(3L, succ.resultSize()); succ = succeededResults.iterator().next(); - assertEquals(COMMON.QUERY_SUCCESS, succ.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(3L, succ.get(COMMON.RECEIVE_DATA_SIZE)); + assertEquals(COMMON.QUERY_SUCCESS, succ.responseCode()); + assertEquals(3L, succ.resultSize()); // check fail worker.executeQuery("fail", "2"); assertEquals("prefix test suffix\nprefix SELECT whatever suffix\nprefix fail suffix\n", FileUtils.readFile(f.getAbsolutePath())); - Collection failedResults = worker.popQueryResults(); + Collection failedResults = worker.popQueryResults(); assertEquals(1, failedResults.size()); - Properties fail = failedResults.iterator().next(); - assertEquals(COMMON.QUERY_UNKNOWN_EXCEPTION, fail.get(COMMON.RECEIVE_DATA_SUCCESS)); - assertEquals(0L, fail.get(COMMON.RECEIVE_DATA_SIZE)); + QueryExecutionStats fail = failedResults.iterator().next(); + assertEquals(COMMON.QUERY_UNKNOWN_EXCEPTION, fail.responseCode()); + assertEquals(0L, fail.resultSize()); worker.stopSending(); } @@ -157,10 +158,10 @@ public void checkCLI() throws IOException { worker.executeQuery("test ()", "1"); content = FileUtils.readFile(f.getAbsolutePath()); assertEquals("test () : test+%28%29\n", content); - Collection results = worker.popQueryResults(); + Collection results = worker.popQueryResults(); assertEquals(1, results.size()); - Properties p = results.iterator().next(); - assertEquals(2L, p.get(COMMON.RECEIVE_DATA_SIZE)); + QueryExecutionStats p = results.iterator().next(); + assertEquals(2L, p.resultSize()); } private Map getQueryConfig() { From 0ada2f729cec0ce07f9b9724ef2fed9625c22eb6 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:32:58 +0200 Subject: [PATCH 08/36] add queryHash to WorkerMetadata --- src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java | 3 ++- src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java b/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java index 7965d2ac..0e19bacc 100644 --- a/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java +++ b/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java @@ -5,5 +5,6 @@ public record WorkerMetadata( String workerType, double timeout, int numberOfQueries, - String[] queries + int queryHash, + String[] queryIDs ) {} diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index b1db54df..9b5729e3 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -282,6 +282,7 @@ public WorkerMetadata getMetadata() { this.workerType, (double) this.extra.get(CONSTANTS.WORKER_TIMEOUT_MS), this.queryHandler.getQueryCount(), + this.queryHandler.hashCode(), this.queryHandler.getAllQueryIds() ); } From 8897c39a512ddcdc243bbd6e7ff75204a3364eb4 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:34:53 +0200 Subject: [PATCH 09/36] add every unique queryID to StresstestMetadata --- src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java | 3 +++ .../java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java b/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java index 5632c850..9adbc3ae 100644 --- a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java +++ b/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java @@ -2,6 +2,8 @@ import org.apache.jena.rdf.model.Model; +import java.util.Set; + // TODO: maybe extract parts to generic taskmetadata class public record StresstestMetadata( String suiteID, @@ -15,6 +17,7 @@ public record StresstestMetadata( double timelimit, long noOfQueryMixes, WorkerMetadata[] workers, + Set queryIDs, String simpleTriple, Model tripleStats ) {} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index 447a4db9..6ef30c5a 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -343,9 +343,11 @@ public StresstestMetadata getMetadata() { classname = this.getClass().getCanonicalName(); } + Set queryIDs = new HashSet<>(); WorkerMetadata[] workerMetadata = new WorkerMetadata[this.workers.size()]; for (int i = 0; i < this.workers.size(); i++) { workerMetadata[i] = this.workers.get(i).getMetadata(); + queryIDs.addAll(Arrays.asList(workerMetadata[i].queryIDs())); } StringWriter sw = new StringWriter(); @@ -367,6 +369,7 @@ public StresstestMetadata getMetadata() { this.timeLimit, this.noOfQueryMixes, workerMetadata, + queryIDs, sw.toString(), tripleStats ); From b900689df1bfd46a6ebc66e09fdbdc68aaf8e9a6 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:35:43 +0200 Subject: [PATCH 10/36] add new Metric abstract class and interfaces --- .../cc/tasks/stresstest/metrics/Metric.java | 27 +++++++++++++++++++ .../metrics/ModelWritingMetric.java | 19 +++++++++++++ .../tasks/stresstest/metrics/QueryMetric.java | 9 +++++++ .../tasks/stresstest/metrics/TaskMetric.java | 10 +++++++ .../stresstest/metrics/WorkerMetric.java | 10 +++++++ 5 files changed, 75 insertions(+) create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/QueryMetric.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java new file mode 100644 index 00000000..6a94021d --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java @@ -0,0 +1,27 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics; + +public abstract class Metric { + private String name; + private String abbreviation; + private String description; + + public Metric(String name, String abbreviation, String description) { + this.name = name; + this.abbreviation = abbreviation; + this.description = description; + } + + + public String getDescription(){ + return this.description; + } + + public String getName(){ + return this.name; + } + + + public String getAbbreviation(){ + return this.abbreviation; + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java new file mode 100644 index 00000000..8de0cb64 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java @@ -0,0 +1,19 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; + +import javax.annotation.Nonnull; +import java.util.List; +import java.util.Map; + +public interface ModelWritingMetric { + default @Nonnull Model createMetricModel(StresstestMetadata task, List[][] data) { + return ModelFactory.createDefaultModel(); + }; + default @Nonnull Model createMetricModel(StresstestMetadata task, Map> data) { + return ModelFactory.createDefaultModel(); + }; +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/QueryMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/QueryMetric.java new file mode 100644 index 00000000..f4a793f1 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/QueryMetric.java @@ -0,0 +1,9 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics; + +import org.aksw.iguana.cc.model.QueryExecutionStats; + +import java.util.List; + +public interface QueryMetric { + Number calculateQueryMetric(List data); +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java new file mode 100644 index 00000000..7a360478 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java @@ -0,0 +1,10 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; + +import java.util.List; + +public interface TaskMetric { + Number calculateTaskMetric(StresstestMetadata task, List[][] data); +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java new file mode 100644 index 00000000..20373259 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java @@ -0,0 +1,10 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.WorkerMetadata; + +import java.util.List; + +public interface WorkerMetric { + Number calculateWorkerMetric(WorkerMetadata worker, List[] data); +} From d2d4d13a9cbfcb29f2d13dee6132192a06dc2f33 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:37:31 +0200 Subject: [PATCH 11/36] add static namespace classes --- .../aksw/iguana/commons/rdf/IGUANA_BASE.java | 17 +++ .../org/aksw/iguana/commons/rdf/IONT.java | 26 ++++ .../org/aksw/iguana/commons/rdf/IPROP.java | 111 ++++++++++++++++++ .../org/aksw/iguana/commons/rdf/IRES.java | 41 +++++++ 4 files changed, 195 insertions(+) create mode 100644 src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java create mode 100644 src/main/java/org/aksw/iguana/commons/rdf/IONT.java create mode 100644 src/main/java/org/aksw/iguana/commons/rdf/IPROP.java create mode 100644 src/main/java/org/aksw/iguana/commons/rdf/IRES.java diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java b/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java new file mode 100644 index 00000000..b36e1faa --- /dev/null +++ b/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java @@ -0,0 +1,17 @@ +package org.aksw.iguana.commons.rdf; + +public class IGUANA_BASE { + public static final String NS = "http://iguana-benchmark.eu" + "/"; + public static final String PREFIX = "iguana"; + + private IGUANA_BASE() { + } + + /** + * The RDF-friendly version of the IGUANA namespace + * with trailing / character. + */ + public static String getURI() { + return NS; + } +} diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IONT.java b/src/main/java/org/aksw/iguana/commons/rdf/IONT.java new file mode 100644 index 00000000..59058d7e --- /dev/null +++ b/src/main/java/org/aksw/iguana/commons/rdf/IONT.java @@ -0,0 +1,26 @@ +package org.aksw.iguana.commons.rdf; + +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; + +public class IONT { + public static final String NS = IGUANA_BASE.NS + "class" + "/"; + public static final String PREFIX = "iont"; + + public static final Resource suite = ResourceFactory.createResource(NS + "Suite"); + public static final Resource experiment = ResourceFactory.createResource(NS + "Experiment"); + public static final Resource dataset = ResourceFactory.createResource(NS + "Dataset"); + public static final Resource task = ResourceFactory.createResource(NS + "Task"); + public static final Resource connection = ResourceFactory.createResource(NS + "Connection"); + public static final Resource stresstest = ResourceFactory.createResource(NS + "Stresstest"); + public static final Resource worker = ResourceFactory.createResource(NS + "Worker"); + public static final Resource executedQuery = ResourceFactory.createResource(NS + "ExecutedQuery"); + public static final Resource query = ResourceFactory.createResource(NS + "Query"); + public static final Resource metric = ResourceFactory.createResource(NS + "Metric"); + + public static Resource getMetricClass(Metric metric) { + // TODO: compare with stresstest class + return ResourceFactory.createResource(NS + "metric/" + metric.getAbbreviation()); + } +} diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IPROP.java b/src/main/java/org/aksw/iguana/commons/rdf/IPROP.java new file mode 100644 index 00000000..81eeddd2 --- /dev/null +++ b/src/main/java/org/aksw/iguana/commons/rdf/IPROP.java @@ -0,0 +1,111 @@ +package org.aksw.iguana.commons.rdf; + +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.apache.jena.rdf.model.Property; +import org.apache.jena.rdf.model.ResourceFactory; + +public class IPROP { + public static final String NS = IGUANA_BASE.NS + "properties" + "/"; + public static final String PREFIX = "iprop"; + + private IPROP() { + } + + /** + * The RDF-friendly version of the IPROP namespace + * with trailing / character. + */ + public static String getURI() { + return NS; + } + + public static Property createMetricProperty(Metric metric) { + return ResourceFactory.createProperty(NS + metric.getAbbreviation()); + } + + /* + * SPARQL query properties + */ + public static final Property aggregations; + public static final Property filter; + public static final Property groupBy; + public static final Property having; + public static final Property offset; + public static final Property optional; + public static final Property orderBy; + public static final Property triples; + public static final Property union; + + /* + * Query Stats + */ + public static final Property failed; + public static final Property penalizedQPS; + public static final Property QPS; + public static final Property queryExecution; + public static final Property timeOuts; + + public static final Property totalTime; + public static final Property unknownException; + public static final Property wrongCodes; + public static final Property succeeded = ResourceFactory.createProperty(NS, "succeeded"); + + /* + * Each Query Stats + */ + public static final Property code; + public static final Property queryID; + public static final Property resultSize; + public static final Property run; + public static final Property success; + public static final Property time; + + public static final Property experiment = ResourceFactory.createProperty(NS, "experiment"); + public static final Property dataset = ResourceFactory.createProperty(NS, "dataset"); + public static final Property task = ResourceFactory.createProperty(NS, "task"); + public static final Property connection = ResourceFactory.createProperty(NS, "connection"); + public static final Property query = ResourceFactory.createProperty(NS, "query"); + public static final Property metric = ResourceFactory.createProperty(NS, "metric"); + public static final Property workerResult = ResourceFactory.createProperty(NS, "workerResult"); + public static final Property version = ResourceFactory.createProperty(NS, "version"); + public static final Property timeLimit = ResourceFactory.createProperty(NS, "timeLimit"); + public static final Property noOfQueryMixes = ResourceFactory.createProperty(NS, "noOfQueryMixes"); + public static final Property noOfWorkers = ResourceFactory.createProperty(NS, "noOfWorkers"); + public static final Property workerID = ResourceFactory.createProperty(NS, "workerID"); + public static final Property workerType = ResourceFactory.createProperty(NS, "workerType"); + public static final Property noOfQueries = ResourceFactory.createProperty(NS, "noOfQueries"); + public static final Property timeOut = ResourceFactory.createProperty(NS, "timeOut"); + public static final Property startDate = ResourceFactory.createProperty(NS, "startDate"); + public static final Property endDate = ResourceFactory.createProperty(NS, "endDate"); + + static { + + // SPARQL query properties + aggregations = ResourceFactory.createProperty(NS, "aggregations"); + filter = ResourceFactory.createProperty(NS, "filter"); + groupBy = ResourceFactory.createProperty(NS, "groupBy"); + having = ResourceFactory.createProperty(NS, "having"); + offset = ResourceFactory.createProperty(NS, "offset"); + optional = ResourceFactory.createProperty(NS, "optional"); + orderBy = ResourceFactory.createProperty(NS, "orderBy"); + triples = ResourceFactory.createProperty(NS, "triples"); + union = ResourceFactory.createProperty(NS, "union"); + // Query Stats + failed = ResourceFactory.createProperty(NS, "failed"); + penalizedQPS = ResourceFactory.createProperty(NS, "penalizedQPS"); + QPS = ResourceFactory.createProperty(NS, "QPS"); + queryExecution = ResourceFactory.createProperty(NS, "queryExecution"); + timeOuts = ResourceFactory.createProperty(NS, "timeOuts"); + + totalTime = ResourceFactory.createProperty(NS, "totalTime"); + unknownException = ResourceFactory.createProperty(NS, "unknownException"); + wrongCodes = ResourceFactory.createProperty(NS, "wrongCodes"); + // Each Query Stats + code = ResourceFactory.createProperty(NS, "code"); + queryID = ResourceFactory.createProperty(NS, "queryID"); + resultSize = ResourceFactory.createProperty(NS, "resultSize"); + run = ResourceFactory.createProperty(NS, "run"); + success = ResourceFactory.createProperty(NS, "success"); + time = ResourceFactory.createProperty(NS, "time"); + } +} diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IRES.java b/src/main/java/org/aksw/iguana/commons/rdf/IRES.java new file mode 100644 index 00000000..0e0ad18f --- /dev/null +++ b/src/main/java/org/aksw/iguana/commons/rdf/IRES.java @@ -0,0 +1,41 @@ +package org.aksw.iguana.commons.rdf; + +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; + +public class IRES { + public static final String NS = IGUANA_BASE.NS + "resource" + "/"; + public static final String PREFIX = "ires"; + + private IRES() { + } + + /** + * The RDF-friendly version of the IRES namespace + * with trailing / character. + */ + public static String getURI() { + return NS; + } + + public static Resource getResource(String id) { + return ResourceFactory.createResource(NS + id); + } + + public static Resource getWorkerResource(String taskID, int workerID) { + return ResourceFactory.createResource(NS + taskID + "/" + workerID); + } + + public static Resource getTaskQueryResource(String taskID, String queryID) { + return ResourceFactory.createResource(NS + taskID + "/" + queryID); + } + + public static Resource getWorkerQueryResource(String taskID, int workerID, String queryID) { + return ResourceFactory.createResource(NS + taskID + "/" + workerID + "/" + queryID); + } + + public static Resource getMetricResource(Metric metric) { + return ResourceFactory.createResource(NS + metric.getAbbreviation()); + } +} From 8d19105015c5698399fbc6f0040c248e7f2f47b3 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:47:55 +0200 Subject: [PATCH 12/36] introduce new StresstestResultProcessor --- .../cc/tasks/stresstest/Stresstest.java | 30 +-- .../stresstest/StresstestResultProcessor.java | 226 ++++++++++++++++++ 2 files changed, 241 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index 6ef30c5a..8e89d006 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -2,6 +2,7 @@ import org.aksw.iguana.cc.config.CONSTANTS; import org.aksw.iguana.cc.config.elements.ConnectionConfig; +import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.model.StresstestMetadata; import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.tasks.AbstractTask; @@ -16,7 +17,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.io.StringWriter; import java.time.Instant; import java.util.*; @@ -44,6 +44,10 @@ public class Stresstest extends AbstractTask { private Long noOfQueryMixes; private Instant startTime; + private StresstestResultProcessor rp; + + private Calendar startDate; + private Calendar endDate; public Stresstest(Integer timeLimit, List> workers) { this(timeLimit, workers, null); @@ -53,6 +57,7 @@ public Stresstest(Integer timeLimit, List> workers, Map> workers, Integer noOfQueryMixes) { @@ -63,6 +68,7 @@ public Stresstest(List> workers, Map warmup, this.noOfQueryMixes = noOfQueryMixes.longValue(); this.workerConfig = workers; this.warmupConfig = warmup; + this.rp = new StresstestResultProcessor(this.getMetadata()); } private void initWorkers() { @@ -115,6 +121,7 @@ private int createWorker(Map workerConfig, List workersT public void generateTripleStats() { StringWriter sw = new StringWriter(); Model tripleStats = ModelFactory.createDefaultModel(); + // TODO: workers might have the same queries, the following code thus adds unnecessary redundancy for (Worker worker : this.workers) { tripleStats.add(worker.getQueryHandler().getTripleStats(this.taskID)); } @@ -155,6 +162,7 @@ public void init(String[] ids, String dataset, ConnectionConfig connection, Stri */ @Override public void execute() { + this.startDate = GregorianCalendar.getInstance(); warmup(); LOGGER.info("Task with ID {{}} will be executed now", this.taskID); // Execute each Worker in ThreadPool @@ -197,6 +205,7 @@ public void execute() { LOGGER.error("Problems shutting down", e1); } } + this.endDate = GregorianCalendar.getInstance(); } private void loopSleep() { @@ -209,29 +218,20 @@ private void loopSleep() { } private void sendWorkerResult(Worker worker) { - Collection props = worker.popQueryResults(); + Collection props = worker.popQueryResults(); if (props == null) { return; } - for (Properties results : props) { - try { - - // send results via RabbitMQ - LOGGER.debug("[TaskID: {{}}] Send results", this.taskID); - this.sendResults(results); - LOGGER.debug("[TaskID: {{}}] results could be send", this.taskID); - } catch (IOException e) { - LOGGER.error("[TaskID: {{}}] Could not send results due to exc.", this.taskID, e); - LOGGER.error("[TaskID: {{}}] Results: {{}}", this.taskID, results); - } - } + LOGGER.debug("[TaskID: {{}}] Send results", this.taskID); + this.rp.processQueryExecutions(worker.getMetadata(), props); + LOGGER.debug("[TaskID: {{}}] results could be send", this.taskID); } @Override public void close() { - super.close(); + rp.calculateAndSaveMetrics(startDate, endDate); } protected long warmup() { diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java new file mode 100644 index 00000000..6f120b64 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -0,0 +1,226 @@ +package org.aksw.iguana.cc.tasks.stresstest; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.*; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; +import org.aksw.iguana.commons.rdf.IRES; +import org.apache.jena.rdf.model.*; +import org.apache.jena.vocabulary.RDF; +import org.apache.jena.vocabulary.RDFS; + +import java.util.*; + +public class StresstestResultProcessor { + + private StresstestMetadata metadata; + private List metrics; + + /** + * This array contains each query execution, grouped by each worker and each query. + */ + private List[][] queryExecutions; + + /** + * This map contains each query execution, grouped by each query of the task. + */ + private Map> ab; + + private Resource taskRes; + + public StresstestResultProcessor(StresstestMetadata metadata) { + this.metadata = metadata; + this.taskRes = IRES.getResource(metadata.taskID()); + + WorkerMetadata[] workers = metadata.workers(); + this.queryExecutions = new List[workers.length][]; + for (int i = 0; i < workers.length; i++) { + this.queryExecutions[i] = new List[workers[i].numberOfQueries()]; + for (int j = 0; j < workers[i].numberOfQueries(); j++) { + this.queryExecutions[i][j] = new LinkedList<>(); + } + } + ab = new HashMap<>(); + } + + /** + * This method stores the given query executions statistics from a worker to their appropriate data location. + * + * @param worker the worker that has executed the queries + * @param data a collection of the query execution statistics + */ + public void processQueryExecutions(WorkerMetadata worker, Collection data) { + for(QueryExecutionStats stat : data) { + // The queryIDs returned by the queryHandler are Strings, in the form of ':'. + int queryID = Integer.valueOf(stat.queryID().substring(stat.queryID().indexOf(":") + 1)); + queryExecutions[worker.workerID()][queryID].add(stat); + + if (ab.containsKey(stat.queryID())) { + ab.get(stat.queryID()).add(stat); + } else { + ab.put(stat.queryID(), new LinkedList<>()); + ab.get(stat.queryID()).add(stat); + } + } + } + + /** + * This method calculates the metrics and creates the RDF model of the result, which will be sent to the storages. + * It uses the given data that was passed with the 'processQueryExecutions' method. + * + * @param start the start date of the task + * @param end the end date of the task + */ + public void calculateAndSaveMetrics(Calendar start, Calendar end) { + Model m = ModelFactory.createDefaultModel(); + Resource suiteRes = IRES.getResource(metadata.suiteID()); + Resource experimentRes = IRES.getResource(metadata.expID()); + Resource datasetRes = IRES.getResource(metadata.datasetID()); + Resource connectionRes = IRES.getResource(metadata.conID()); + + m.add(suiteRes, IPROP.experiment, experimentRes); + m.add(suiteRes, RDF.type, IONT.suite); + m.add(experimentRes, IPROP.dataset, datasetRes); + m.add(experimentRes, RDF.type, IONT.experiment); + m.add(experimentRes, IPROP.task, taskRes); + m.add(datasetRes, RDFS.label, ResourceFactory.createTypedLiteral(metadata.datasetID())); + m.add(datasetRes, RDF.type, IONT.dataset); + m.add(taskRes, IPROP.connection, connectionRes); + m.add(taskRes, IPROP.noOfQueryMixes, ResourceFactory.createTypedLiteral(metadata.noOfQueryMixes())); + m.add(taskRes, IPROP.noOfWorkers, ResourceFactory.createTypedLiteral(metadata.workers().length)); + m.add(taskRes, IPROP.timeLimit, ResourceFactory.createTypedLiteral(metadata.timelimit())); + m.add(taskRes, RDF.type, IONT.task); + + // TODO: Maybe not hardcode this, instead have the classname stored inside the metadata to make this class reusable for other tasks + m.add(taskRes, RDF.type, IONT.stresstest); + if (metadata.conVersion() != null) { + m.add(connectionRes, IPROP.version, ResourceFactory.createTypedLiteral(metadata.conVersion())); + } + m.add(connectionRes, RDFS.label, ResourceFactory.createTypedLiteral(metadata.conID())); + m.add(connectionRes, RDF.type, IONT.connection); + + for (WorkerMetadata worker : metadata.workers()) { + Resource workerRes = IRES.getWorkerResource(metadata.taskID(), worker.workerID()); + m.add(taskRes, IPROP.workerResult, workerRes); + m.add(workerRes, IPROP.workerID, ResourceFactory.createTypedLiteral(worker.workerID())); + m.add(workerRes, IPROP.workerType, ResourceFactory.createTypedLiteral(worker.workerType())); + m.add(workerRes, IPROP.noOfQueries, ResourceFactory.createTypedLiteral(worker.queryIDs().length)); + m.add(workerRes, IPROP.timeOut, ResourceFactory.createTypedLiteral(worker.timeout())); + m.add(workerRes, RDF.type, IONT.worker); + } + + if (metadata.tripleStats() != null) { + m.add(metadata.tripleStats()); + // Connect task and workers to the Query objects, that store the triple stats. + // TODO: should be reworked soon after fixing triple stat generation + for (WorkerMetadata worker : metadata.workers()) { + for (String queryID : worker.queryIDs()) { + Resource workerQueryRes = IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), queryID); + Resource queryRes = IRES.getResource(worker.queryHash() + "/" + queryID); + m.add(workerQueryRes, IPROP.queryID, queryRes); + } + + for (String queryID : metadata.queryIDs()) { + Resource taskQueryRes = IRES.getTaskQueryResource(metadata.taskID(), queryID); + Resource queryRes = IRES.getResource(worker.queryHash() + "/" + queryID); + m.add(taskQueryRes, IPROP.queryID, queryRes); + } + } + } + + // TODO: is the simple triple attribute even used for anything? + + for (Metric metric : metrics) { + m.add(this.createMetricModel(metric)); + } + + for (String queryID : metadata.queryIDs()) { + m.add(taskRes, IPROP.query, IRES.getTaskQueryResource(metadata.taskID(), queryID)); + } + + for (WorkerMetadata worker : metadata.workers()) { + for (String queryID : worker.queryIDs()) { + Resource workerRes = IRES.getWorkerResource(metadata.taskID(), worker.workerID()); + m.add(workerRes, IPROP.query, IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), queryID)); + } + } + + m.add(taskRes, IPROP.startDate, ResourceFactory.createTypedLiteral(start)); + m.add(taskRes, IPROP.endDate, ResourceFactory.createTypedLiteral(end)); + + // TODO: store m + } + + /** + * For a given metric this method calculates the metric with the stored data and creates the appropriate + * RDF related to that metric. + * + * @param metric the metric that should be calculated + * @return the result model of the metric + */ + private Model createMetricModel(Metric metric) { + Model m = ModelFactory.createDefaultModel(); + Property metricProp = IPROP.createMetricProperty(metric); + Resource metricRes = IRES.getMetricResource(metric); + + if (metric instanceof ModelWritingMetric) { + m.add(((ModelWritingMetric) metric).createMetricModel(metadata, queryExecutions)); + m.add(((ModelWritingMetric) metric).createMetricModel(metadata, ab)); + return m; + } + + if (metric instanceof TaskMetric) { + Number metricValue = ((TaskMetric) metric).calculateTaskMetric(metadata, queryExecutions); + if (metricValue != null) { + Literal lit = ResourceFactory.createTypedLiteral(metricValue); + m.add(taskRes, metricProp, lit); + } + m.add(taskRes, IPROP.metric, metricRes); + } + + if (metric instanceof WorkerMetric) { + for (WorkerMetadata worker : metadata.workers()) { + Resource workerRes = IRES.getWorkerResource(metadata.taskID(), worker.workerID()); + Number metricValue = ((WorkerMetric) metric).calculateWorkerMetric(worker, queryExecutions[worker.workerID()]); + if (metricValue != null) { + Literal lit = ResourceFactory.createTypedLiteral(metricValue); + m.add(workerRes, metricProp, lit); + } + m.add(workerRes, IPROP.metric, metricRes); + } + } + + if (metric instanceof QueryMetric) { + // queries grouped by worker + for (WorkerMetadata worker : metadata.workers()) { + for (int i = 0; i < worker.numberOfQueries(); i++) { + Number metricValue = ((QueryMetric) metric).calculateQueryMetric(queryExecutions[worker.workerID()][i]); + if (metricValue != null) { + Literal lit = ResourceFactory.createTypedLiteral(metricValue); + Resource queryRes = IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), worker.queryIDs()[i]); + m.add(queryRes, metricProp, lit); + } + } + } + + // queries grouped by task + for (String queryID : ab.keySet()) { + Number metricValue = ((QueryMetric) metric).calculateQueryMetric(ab.get(queryID)); + if (metricValue != null) { + Literal lit = ResourceFactory.createTypedLiteral(metricValue); + Resource queryRes = IRES.getTaskQueryResource(metadata.taskID(), queryID); + m.add(queryRes, metricProp, lit); + } + } + } + + m.add(metricRes, RDFS.label, metric.getName()); + m.add(metricRes, RDFS.comment, metric.getDescription()); + m.add(metricRes, RDF.type, IONT.getMetricClass(metric)); + m.add(metricRes, RDF.type, IONT.metric); + + return m; + } +} From bd184cad5b63274900f6cd7e41edcc30b4e53ce2 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:04:52 +0200 Subject: [PATCH 13/36] move storage package --- src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java | 4 ++-- .../org/aksw/iguana/cc/config/elements/StorageConfig.java | 2 +- .../iguana/{rp => cc/tasks/stresstest}/storage/Storage.java | 2 +- .../{rp => cc/tasks/stresstest}/storage/StorageManager.java | 2 +- .../tasks/stresstest}/storage/TripleBasedStorage.java | 2 +- .../tasks/stresstest}/storage/impl/NTFileStorage.java | 4 ++-- .../tasks/stresstest}/storage/impl/RDFFileStorage.java | 4 ++-- .../tasks/stresstest}/storage/impl/TriplestoreStorage.java | 4 ++-- .../java/org/aksw/iguana/rp/controller/RPController.java | 6 +++--- .../org/aksw/iguana/rp/experiment/ExperimentManager.java | 2 +- .../java/org/aksw/iguana/rp/metrics/AbstractMetric.java | 2 +- src/main/java/org/aksw/iguana/rp/metrics/Metric.java | 2 +- src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java | 6 +++--- src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java | 2 +- .../org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java | 2 +- .../java/org/aksw/iguana/rp/metrics/impl/MetricTest.java | 2 +- .../org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java | 3 ++- .../org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java | 5 ++--- .../aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java | 1 + src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java | 2 +- src/test/resources/controller_test.properties | 4 ++-- 21 files changed, 32 insertions(+), 31 deletions(-) rename src/main/java/org/aksw/iguana/{rp => cc/tasks/stresstest}/storage/Storage.java (93%) rename src/main/java/org/aksw/iguana/{rp => cc/tasks/stresstest}/storage/StorageManager.java (97%) rename src/main/java/org/aksw/iguana/{rp => cc/tasks/stresstest}/storage/TripleBasedStorage.java (99%) rename src/main/java/org/aksw/iguana/{rp => cc/tasks/stresstest}/storage/impl/NTFileStorage.java (93%) rename src/main/java/org/aksw/iguana/{rp => cc/tasks/stresstest}/storage/impl/RDFFileStorage.java (94%) rename src/main/java/org/aksw/iguana/{rp => cc/tasks/stresstest}/storage/impl/TriplestoreStorage.java (95%) diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index 58e82c3b..db48fc2a 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -7,8 +7,8 @@ import org.aksw.iguana.rp.controller.RPController; import org.aksw.iguana.rp.metrics.Metric; import org.aksw.iguana.rp.metrics.impl.*; -import org.aksw.iguana.rp.storage.Storage; -import org.aksw.iguana.rp.storage.impl.NTFileStorage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; import org.apache.commons.exec.ExecuteException; import org.apache.commons.lang3.SerializationUtils; import org.slf4j.Logger; diff --git a/src/main/java/org/aksw/iguana/cc/config/elements/StorageConfig.java b/src/main/java/org/aksw/iguana/cc/config/elements/StorageConfig.java index 60226c30..5fe6127e 100644 --- a/src/main/java/org/aksw/iguana/cc/config/elements/StorageConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/elements/StorageConfig.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.aksw.iguana.commons.factory.TypedFactory; -import org.aksw.iguana.rp.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/aksw/iguana/rp/storage/Storage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java similarity index 93% rename from src/main/java/org/aksw/iguana/rp/storage/Storage.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java index 4ed7d77e..fff5ac70 100644 --- a/src/main/java/org/aksw/iguana/rp/storage/Storage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java @@ -1,4 +1,4 @@ -package org.aksw.iguana.rp.storage; +package org.aksw.iguana.cc.tasks.stresstest.storage; import org.apache.jena.rdf.model.Model; diff --git a/src/main/java/org/aksw/iguana/rp/storage/StorageManager.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java similarity index 97% rename from src/main/java/org/aksw/iguana/rp/storage/StorageManager.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java index 1621b786..3499ff63 100644 --- a/src/main/java/org/aksw/iguana/rp/storage/StorageManager.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java @@ -1,4 +1,4 @@ -package org.aksw.iguana.rp.storage; +package org.aksw.iguana.cc.tasks.stresstest.storage; import org.apache.jena.rdf.model.Model; import org.slf4j.Logger; diff --git a/src/main/java/org/aksw/iguana/rp/storage/TripleBasedStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java similarity index 99% rename from src/main/java/org/aksw/iguana/rp/storage/TripleBasedStorage.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java index eb4c15de..59bb813c 100644 --- a/src/main/java/org/aksw/iguana/rp/storage/TripleBasedStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java @@ -1,7 +1,7 @@ /** * */ -package org.aksw.iguana.rp.storage; +package org.aksw.iguana.cc.tasks.stresstest.storage; import org.aksw.iguana.commons.constants.COMMON; import org.apache.jena.rdf.model.Model; diff --git a/src/main/java/org/aksw/iguana/rp/storage/impl/NTFileStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java similarity index 93% rename from src/main/java/org/aksw/iguana/rp/storage/impl/NTFileStorage.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java index 12b7f78c..09d961e2 100644 --- a/src/main/java/org/aksw/iguana/rp/storage/impl/NTFileStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java @@ -1,10 +1,10 @@ /** * */ -package org.aksw.iguana.rp.storage.impl; +package org.aksw.iguana.cc.tasks.stresstest.storage.impl; +import org.aksw.iguana.cc.tasks.stresstest.storage.TripleBasedStorage; import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.rp.storage.TripleBasedStorage; import org.apache.jena.riot.RDFDataMgr; import org.apache.jena.riot.RDFFormat; import org.slf4j.Logger; diff --git a/src/main/java/org/aksw/iguana/rp/storage/impl/RDFFileStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java similarity index 94% rename from src/main/java/org/aksw/iguana/rp/storage/impl/RDFFileStorage.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java index d797e0fd..4ec42c97 100644 --- a/src/main/java/org/aksw/iguana/rp/storage/impl/RDFFileStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java @@ -1,7 +1,7 @@ -package org.aksw.iguana.rp.storage.impl; +package org.aksw.iguana.cc.tasks.stresstest.storage.impl; +import org.aksw.iguana.cc.tasks.stresstest.storage.TripleBasedStorage; import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.rp.storage.TripleBasedStorage; import org.apache.jena.riot.Lang; import org.apache.jena.riot.RDFDataMgr; import org.apache.jena.riot.RDFLanguages; diff --git a/src/main/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java similarity index 95% rename from src/main/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorage.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java index a832efd2..a6c35fdf 100644 --- a/src/main/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java @@ -1,10 +1,10 @@ /** * */ -package org.aksw.iguana.rp.storage.impl; +package org.aksw.iguana.cc.tasks.stresstest.storage.impl; +import org.aksw.iguana.cc.tasks.stresstest.storage.TripleBasedStorage; import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.rp.storage.TripleBasedStorage; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; import org.apache.http.auth.UsernamePasswordCredentials; diff --git a/src/main/java/org/aksw/iguana/rp/controller/RPController.java b/src/main/java/org/aksw/iguana/rp/controller/RPController.java index a589c6ee..f9866d6a 100644 --- a/src/main/java/org/aksw/iguana/rp/controller/RPController.java +++ b/src/main/java/org/aksw/iguana/rp/controller/RPController.java @@ -7,8 +7,8 @@ import org.aksw.iguana.rp.experiment.ExperimentManager; import org.aksw.iguana.rp.metrics.Metric; import org.aksw.iguana.rp.metrics.MetricManager; -import org.aksw.iguana.rp.storage.Storage; -import org.aksw.iguana.rp.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +16,7 @@ /** * This is the Main Controller. - * It will start the ResultProcessor, initialize the {@link org.aksw.iguana.rp.storage.StorageManager} and the {@link org.aksw.iguana.rp.metrics.MetricManager} + * It will start the ResultProcessor, initialize the {@link StorageManager} and the {@link org.aksw.iguana.rp.metrics.MetricManager} * * @author f.conrads * diff --git a/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java b/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java index 49228c28..263d736b 100644 --- a/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java +++ b/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java @@ -2,7 +2,7 @@ import org.aksw.iguana.commons.constants.COMMON; import org.aksw.iguana.rp.metrics.MetricManager; -import org.aksw.iguana.rp.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java index 61e0e2b2..6d5baff3 100644 --- a/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java +++ b/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java @@ -2,7 +2,7 @@ import org.aksw.iguana.commons.annotation.Shorthand; import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.rp.vocab.Vocab; import org.apache.jena.rdf.model.*; import org.apache.jena.vocabulary.RDF; diff --git a/src/main/java/org/aksw/iguana/rp/metrics/Metric.java b/src/main/java/org/aksw/iguana/rp/metrics/Metric.java index dcc5b013..8ae729e5 100644 --- a/src/main/java/org/aksw/iguana/rp/metrics/Metric.java +++ b/src/main/java/org/aksw/iguana/rp/metrics/Metric.java @@ -1,6 +1,6 @@ package org.aksw.iguana.rp.metrics; -import org.aksw.iguana.rp.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import java.util.Properties; diff --git a/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java b/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java index 6baf2560..5c1c4bfd 100644 --- a/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java +++ b/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java @@ -6,9 +6,9 @@ import org.aksw.iguana.rp.metrics.Metric; import org.aksw.iguana.rp.metrics.MetricManager; import org.aksw.iguana.rp.metrics.impl.*; -import org.aksw.iguana.rp.storage.Storage; -import org.aksw.iguana.rp.storage.StorageManager; -import org.aksw.iguana.rp.storage.impl.NTFileStorage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; diff --git a/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java b/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java index 94c7694f..45641fd5 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java @@ -1,6 +1,6 @@ package org.aksw.iguana.cc.tasks; -import org.aksw.iguana.rp.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; diff --git a/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java index 6fac9446..1ab5b345 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java @@ -8,7 +8,7 @@ import org.aksw.iguana.rp.experiment.ExperimentManager; import org.aksw.iguana.rp.metrics.MetricManager; import org.aksw.iguana.rp.metrics.impl.EachQueryMetric; -import org.aksw.iguana.rp.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.junit.Ignore; import org.junit.Test; diff --git a/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java b/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java index 950a40c2..6c09b56a 100644 --- a/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java +++ b/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java @@ -5,7 +5,7 @@ import org.aksw.iguana.commons.constants.COMMON; import org.aksw.iguana.rp.metrics.Metric; -import org.aksw.iguana.rp.storage.StorageManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.rp.utils.EqualityStorage; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java index 224ffba8..b23f566b 100644 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java +++ b/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java @@ -3,8 +3,9 @@ */ package org.aksw.iguana.rp.storage.impl; +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.apache.jena.rdf.model.*; import org.apache.jena.vocabulary.RDFS; import org.junit.Test; diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java index c44ec3e9..43201f06 100644 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java +++ b/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java @@ -3,8 +3,8 @@ */ package org.aksw.iguana.rp.storage.impl; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.RDFFileStorage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.apache.jena.rdf.model.*; import org.apache.jena.riot.RDFLanguages; import org.apache.jena.vocabulary.RDFS; @@ -14,7 +14,6 @@ import java.io.FileReader; import java.io.IOException; import java.util.List; -import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java index c9251fdd..d36ee424 100644 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java +++ b/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java @@ -3,6 +3,7 @@ */ package org.aksw.iguana.rp.storage.impl; +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.TriplestoreStorage; import org.aksw.iguana.commons.constants.COMMON; import org.aksw.iguana.rp.utils.ServerMock; import org.apache.jena.rdf.model.Model; diff --git a/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java b/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java index 46b35b69..e2cdf44a 100644 --- a/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java +++ b/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java @@ -3,7 +3,7 @@ */ package org.aksw.iguana.rp.utils; -import org.aksw.iguana.rp.storage.Storage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; diff --git a/src/test/resources/controller_test.properties b/src/test/resources/controller_test.properties index ffb11acc..38ade377 100644 --- a/src/test/resources/controller_test.properties +++ b/src/test/resources/controller_test.properties @@ -27,9 +27,9 @@ metric4.class=org.aksw.iguana.rp.metrics.impl.NoQPHMetric ## Storages to use ## ################################## store1.class=org.aksw.iguana.rp.storage.imp.PropertiesSenderStorage -store2.class=org.aksw.iguana.rp.storage.impl.NTFileStorage +store2.class=org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage store2.constructorArgs=results_test.nt -store3.class=org.aksw.iguana.rp.storage.impl.TriplestoreStorage +store3.class=org.aksw.iguana.cc.tasks.stresstest.storage.impl.TriplestoreStorage store3.constructorArgs=http://localhost:3030/das/sparql,http://localhost:3030/das/update store4.class=org.aksw.iguana.rp.storage.impl.FileStorage store4.constructorArgs=result_storage From e0bd17e3849374dbe8a85fd15f6e84fedfe8b6df Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:27:17 +0200 Subject: [PATCH 14/36] refactor Storage interface to make storages have only one public method --- .../cc/tasks/stresstest/storage/Storage.java | 39 +--- .../stresstest/storage/StorageManager.java | 46 +---- .../storage/TripleBasedStorage.java | 167 +----------------- .../storage/impl/NTFileStorage.java | 50 +++--- .../storage/impl/RDFFileStorage.java | 15 +- .../storage/impl/TriplestoreStorage.java | 8 +- .../iguana/rp/metrics/AbstractMetric.java | 5 +- .../aksw/iguana/cc/tasks/MockupStorage.java | 21 +-- .../rp/storage/impl/NTFileStorageTest.java | 41 +---- .../rp/storage/impl/RDFFileStorageTest.java | 5 +- .../storage/impl/TriplestoreStorageTest.java | 35 +--- .../aksw/iguana/rp/utils/EqualityStorage.java | 25 +-- 12 files changed, 53 insertions(+), 404 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java index fff5ac70..a17363c8 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java @@ -2,8 +2,6 @@ import org.apache.jena.rdf.model.Model; -import java.util.Properties; - /** * Interface for the Result Storages * @@ -11,40 +9,11 @@ * */ public interface Storage { - - - - /** - * Add Triples as they are - * @param data - */ - public void addData(Model data); - /** - * Add meta data from the experiment task - * for example: Query ID and Query text, ExperimentID, WorkerID,... - * - * @param p - */ - public void addMetaData(Properties p); - - /** - * Commit a DataBlock to the Storage. - * Keep in mind, that all received Data is from the metrics and should be saved as it is. - * + * Stores the task result into the storage. + * + * @param data the given result model */ - public void commit(); - - - /** - * Will tell the storage that the task with taskID ended - * @param taskID - */ - public void endTask(String taskID); - - - public default void close(){ - } - + void storeResult(Model data); } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java index 3499ff63..e5e0b69f 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java @@ -15,10 +15,9 @@ */ public class StorageManager { - private static final Logger LOGGER = LoggerFactory - .getLogger(StorageManager.class); + private static final Logger LOGGER = LoggerFactory.getLogger(StorageManager.class); - private Set storages = new HashSet(); + private Set storages = new HashSet<>(); private static StorageManager instance; @@ -54,28 +53,12 @@ public Set getStorages(){ * Simply adds a Model * @param m */ - public void addData(Model m){ + public void storeResult(Model m){ for(Storage s : storages){ - s.addData(m); + s.storeResult(m); } } - - /** - * Will add the MetaData to each Storage - * @param p - */ - public void addMetaData(Properties p){ - for(Storage s : storages){ - try{ - s.addMetaData(p); - }catch(Exception e){ - LOGGER.error("Could not store meta data in "+s.getClass().getSimpleName()+" for Properties "+p, e); - } - } - } - - @Override public String toString(){ StringBuilder ret = new StringBuilder(); @@ -88,28 +71,7 @@ public String toString(){ return ret.toString(); } - /** - * Will call the commit method of each storage - */ - public void commit() { - for(Storage s: storages){ - s.commit(); - } - } - - public void endTask(String taskID) { - for(Storage s: storages){ - s.endTask(taskID); - } - } - public void addStorages(List storages) { this.storages.addAll(storages); } - - public void close() { - for(Storage storage : storages){ - storage.close(); - } - } } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java index 59bb813c..59911330 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/TripleBasedStorage.java @@ -6,18 +6,6 @@ import org.aksw.iguana.commons.constants.COMMON; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.ResourceFactory; -import org.apache.jena.rdf.model.Statement; -import org.apache.jena.vocabulary.RDF; -import org.apache.jena.vocabulary.RDFS; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Properties; -import java.util.Set; /** * This Storage will save all the metric results as triples @@ -28,165 +16,14 @@ public abstract class TripleBasedStorage implements Storage { protected String baseUri = COMMON.BASE_URI; - private String resource = COMMON.RES_BASE_URI; - private String properties = COMMON.PROP_BASE_URI; - - - protected Model metricResults = createPrefixModel(); - - private String suiteClassUri = baseUri + "/class/Suite"; - private String expClassUri = baseUri + "/class/Experiment"; - private String taskClassUri = baseUri + "/class/Task"; - private String conClassUri = baseUri + "/class/Connection"; - private String datasetClassUri = baseUri + "/class/Dataset"; - - - private String classUri = RDF.type.getURI(); - private String rdfsUri = "http://www.w3.org/2000/01/rdf-schema#"; - private String xsdUri = "http://www.w3.org/2001/XMLSchema#"; - - - protected Model createPrefixModel() { - Model metricResults = ModelFactory.createDefaultModel(); - metricResults.setNsPrefix("iprop", COMMON.PROP_BASE_URI); - metricResults.setNsPrefix("iont", COMMON.CLASS_BASE_URI); - metricResults.setNsPrefix("ires", COMMON.RES_BASE_URI); - metricResults.setNsPrefix("lsqr", "http://lsq.aksw.org/res/"); - return metricResults; - } - - - /* - * (non-Javadoc) - * - * @see org.aksw.iguana.rp.storage.Storage#addMetaData(java.util.Properties) - */ - @Override - public void addMetaData(Properties p) { - - String suiteUrl = getUrlWithResourcePrefix(p, COMMON.SUITE_ID_KEY); - String expUrl = getUrlWithResourcePrefix(p, COMMON.EXPERIMENT_ID_KEY); - String taskUrl = getUrlWithResourcePrefix(p, COMMON.EXPERIMENT_TASK_ID_KEY); - - String datasetUrl = getUrlWithResourcePrefix(p, COMMON.DATASET_ID_KEY); - String conName = p.getProperty(COMMON.CONNECTION_ID_KEY); - if(p.containsKey(COMMON.CONNECTION_VERSION_KEY)){ - conName+="-"+p.getProperty(COMMON.CONNECTION_VERSION_KEY); - } - String connUrl = getUrlWithResourcePrefix(conName); - - String actualTaskID = getUrlWithResourcePrefix(p, COMMON.EXPERIMENT_TASK_CLASS_ID_KEY); - - - metricResults.add(createStatement(suiteUrl, getUrlWithPropertyPrefix("experiment"), expUrl, true)); - metricResults.add(createStatement(suiteUrl, classUri, suiteClassUri, true)); - metricResults.add(createStatement(expUrl, getUrlWithPropertyPrefix("task"), taskUrl, true)); - metricResults.add(createStatement(expUrl, getUrlWithPropertyPrefix("dataset"), datasetUrl, true)); - metricResults.add(createStatement(expUrl, classUri, expClassUri, true)); - metricResults.add(createStatement(taskUrl, getUrlWithPropertyPrefix("connection"), connUrl, true)); - if(p.containsKey(COMMON.EXPERIMENT_TASK_NAME_KEY)){ - metricResults.add(metricResults.createResource(taskUrl), RDFS.label, p.getProperty(COMMON.EXPERIMENT_TASK_NAME_KEY)); - } - - metricResults.add(createStatement(connUrl, classUri, conClassUri, true)); - metricResults.add(createStatement(datasetUrl, classUri, datasetClassUri, true)); - metricResults.add(createStatement(taskUrl, classUri, taskClassUri, true)); - metricResults.add(createStatement(taskUrl, classUri, actualTaskID, true)); - - addExtraMetadata(p, taskUrl); - metricResults.add(metricResults.createResource(datasetUrl), RDFS.label, p.getProperty(COMMON.DATASET_ID_KEY)); - metricResults.add(metricResults.createResource(connUrl), RDFS.label, p.getProperty(COMMON.CONNECTION_ID_KEY)); - if(p.containsKey(COMMON.CONNECTION_VERSION_KEY)) { - metricResults.add(metricResults.createResource(connUrl), ResourceFactory.createProperty(getUrlWithPropertyPrefix("version")), p.getProperty(COMMON.CONNECTION_VERSION_KEY)); - } - - if(p.containsKey(COMMON.QUERY_STATS)) { - Model queryStats = (Model) p.get(COMMON.QUERY_STATS); - metricResults.add(queryStats); - } - - Calendar cal = GregorianCalendar.getInstance(); - metricResults.add(metricResults.createResource(taskUrl), - ResourceFactory.createProperty(rdfsUri + "startDate"), metricResults.createTypedLiteral(cal)); - } - - private String getUrlWithResourcePrefix(Properties p, String key) { - return getUrlWithResourcePrefix(p.getProperty(key)); - } - - private String getUrlWithResourcePrefix(String suffix) { - try { - String[] suffixParts = suffix.split("/"); - for (int i = 0; i < suffixParts.length; i++) - suffixParts[i] = URLEncoder.encode(suffixParts[i], StandardCharsets.UTF_8.toString()); - return resource + String.join("/", suffixParts); - } catch (UnsupportedEncodingException e) { - return resource + suffix.hashCode(); - } - } - - private String getUrlWithPropertyPrefix(String suffix) { - try { - String[] suffixParts = suffix.split("/"); - for (int i = 0; i < suffixParts.length; i++) - suffixParts[i] = URLEncoder.encode(suffixParts[i], StandardCharsets.UTF_8.toString()); - return properties + String.join("/", suffixParts); - } catch (UnsupportedEncodingException e) { - return properties + suffix.hashCode(); - } - } - - private Statement createStatement(String subject, String predicate, Object object) - { - return metricResults.createStatement(metricResults.createResource(subject), ResourceFactory.createProperty(predicate), metricResults.createTypedLiteral(object)); - } - - private Statement createStatement(String subject, String predicate, String object, boolean isObjectUri) - { - if(isObjectUri) - return metricResults.createStatement(metricResults.createResource(subject), ResourceFactory.createProperty(predicate), metricResults.createResource(object)); - else - return metricResults.createStatement(metricResults.createResource(subject), ResourceFactory.createProperty(predicate), object); - } - - private void addExtraMetadata(Properties p, String taskUrl) { - Properties extra = (Properties) p.get(COMMON.EXTRA_META_KEY); - for (Object obj : extra.keySet()) { - if (p.containsKey(COMMON.EXTRA_IS_RESOURCE_KEY) && ((Set) p.get(COMMON.EXTRA_IS_RESOURCE_KEY)).contains(obj)) { - metricResults.add(createStatement( - taskUrl, - getUrlWithResourcePrefix(obj.toString()), - getUrlWithResourcePrefix(extra.get(obj).toString()), - true)); - } else { - metricResults.add(createStatement( - taskUrl, - getUrlWithPropertyPrefix(obj.toString()), - extra.get(obj))); - } - } - } + protected Model metricResults = ModelFactory.createDefaultModel(); @Override public String toString() { return this.getClass().getSimpleName(); } - /** - * Ends the task and adds a rdfs:endDate triple with the current time - * @param taskID - */ - public void endTask(String taskID) { - Calendar cal = GregorianCalendar.getInstance(); - String taskUrl = getUrlWithResourcePrefix(taskID); - metricResults.add(metricResults.add(metricResults.createResource(taskUrl), - ResourceFactory.createProperty(rdfsUri + "endDate"), metricResults.createTypedLiteral(cal))); - } - - - public void addData(Model data){ + public void storeResult(Model data){ metricResults.add(data); } - - } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java index 09d961e2..9bb4d9be 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java @@ -5,6 +5,7 @@ import org.aksw.iguana.cc.tasks.stresstest.storage.TripleBasedStorage; import org.aksw.iguana.commons.annotation.Shorthand; +import org.apache.jena.rdf.model.Model; import org.apache.jena.riot.RDFDataMgr; import org.apache.jena.riot.RDFFormat; import org.slf4j.Logger; @@ -25,46 +26,47 @@ @Shorthand("NTFileStorage") public class NTFileStorage extends TripleBasedStorage { - private static final Logger LOGGER = LoggerFactory - .getLogger(NTFileStorage.class); - - private StringBuilder file; - + private static final Logger LOGGER = LoggerFactory.getLogger(NTFileStorage.class); + + private final StringBuilder file; + /** * Uses a generated file called results_{DD}-{MM}-{YYYY}_{HH}-{mm}.nt */ public NTFileStorage() { Calendar now = Calendar.getInstance(); - + this.file = new StringBuilder(); file.append("results_") - .append( - String.format("%d-%02d-%02d_%02d-%02d.%03d", - now.get(Calendar.YEAR), - now.get(Calendar.MONTH) + 1, - now.get(Calendar.DAY_OF_MONTH), - now.get(Calendar.HOUR_OF_DAY), - now.get(Calendar.MINUTE), - now.get(Calendar.MILLISECOND) + .append( + String.format("%d-%02d-%02d_%02d-%02d.%03d", + now.get(Calendar.YEAR), + now.get(Calendar.MONTH) + 1, + now.get(Calendar.DAY_OF_MONTH), + now.get(Calendar.HOUR_OF_DAY), + now.get(Calendar.MINUTE), + now.get(Calendar.MILLISECOND) + ) ) - ) - .append(".nt"); + .append(".nt"); } /** * Uses the provided filename + * * @param fileName */ - public NTFileStorage(String fileName){ + public NTFileStorage(String fileName) { this.file = new StringBuilder(fileName); } - + /* (non-Javadoc) * @see org.aksw.iguana.rp.storage.Storage#commit() */ @Override - public void commit() { - try (OutputStream os = new FileOutputStream(file.toString(), true)) { + public void storeResult(Model data) { + super.storeResult(data); + try (OutputStream os = new FileOutputStream(file.toString(), true)) { RDFDataMgr.write(os, metricResults, RDFFormat.NTRIPLES); metricResults.removeAll(); } catch (IOException e) { @@ -72,15 +74,13 @@ public void commit() { } } - - @Override - public String toString(){ + public String toString() { return this.getClass().getSimpleName(); } - public String getFileName(){ + public String getFileName() { return this.file.toString(); } - } + diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java index 4ec42c97..10ee6781 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/RDFFileStorage.java @@ -2,6 +2,7 @@ import org.aksw.iguana.cc.tasks.stresstest.storage.TripleBasedStorage; import org.aksw.iguana.commons.annotation.Shorthand; +import org.apache.jena.rdf.model.Model; import org.apache.jena.riot.Lang; import org.apache.jena.riot.RDFDataMgr; import org.apache.jena.riot.RDFLanguages; @@ -19,7 +20,7 @@ public class RDFFileStorage extends TripleBasedStorage { private static final Logger LOGGER = LoggerFactory.getLogger(RDFFileStorage.class.getName()); private Lang lang = Lang.TTL; - private StringBuilder file; + private final StringBuilder file; /** * Uses a generated file called results_{DD}-{MM}-{YYYY}_{HH}-{mm}.ttl @@ -49,19 +50,11 @@ public RDFFileStorage() { public RDFFileStorage(String fileName){ this.file = new StringBuilder(fileName); this.lang= RDFLanguages.filenameToLang(fileName, Lang.TTL); - - } - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.storage.Storage#commit() - */ - @Override - public void commit() { - } @Override - public void close(){ + public void storeResult(Model data){ + super.storeResult(data); try (OutputStream os = new FileOutputStream(file.toString(), true)) { RDFDataMgr.write(os, metricResults, this.lang); metricResults.removeAll(); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java index a6c35fdf..be9bad95 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java @@ -12,6 +12,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.HttpClients; +import org.apache.jena.rdf.model.Model; import org.apache.jena.riot.Lang; import org.apache.jena.riot.RDFDataMgr; import org.apache.jena.update.UpdateExecutionFactory; @@ -34,8 +35,8 @@ public class TriplestoreStorage extends TripleBasedStorage { private UpdateRequest blockRequest = UpdateFactory.create(); - private String updateEndpoint; - private String endpoint; + private final String updateEndpoint; + private final String endpoint; private String user; private String pwd; @@ -67,7 +68,8 @@ public TriplestoreStorage(String endpoint, String updateEndpoint){ * @see org.aksw.iguana.rp.storage.Storage#commit() */ @Override - public void commit() { + public void storeResult(Model data) { + super.storeResult(data); if (metricResults.size() == 0) return; diff --git a/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java index 6d5baff3..cfeacb7b 100644 --- a/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java +++ b/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java @@ -206,7 +206,7 @@ public Property getMetricProperty(){ } public void sendData(Model m){ - this.storageManager.addData(m); + this.storageManager.storeResult(m); } @Override @@ -244,8 +244,7 @@ public void close() { } m.add(getTaskResource(), Vocab.worker2metric, metricRes); - this.storageManager.addData(m); - this.storageManager.commit(); + this.storageManager.storeResult(m); this.dataContainer.clear(); } diff --git a/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java b/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java index 45641fd5..9b1aa20b 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java @@ -11,30 +11,13 @@ public class MockupStorage implements Storage { private Model m = ModelFactory.createDefaultModel(); - private Set meta = new HashSet(); + private Set meta = new HashSet<>(); @Override - public void addData(Model data) { - + public void storeResult(Model data) { m.add(data); } - @Override - public void addMetaData(Properties p) { - //do nothing - meta.add(p); - } - - @Override - public void commit() { - //do nothing - } - - @Override - public void endTask(String taskID) { - //do nothing - } - public Model getModel() { return m; } diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java index b23f566b..e954943a 100644 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java +++ b/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java @@ -4,7 +4,6 @@ package org.aksw.iguana.rp.storage.impl; import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; -import org.aksw.iguana.commons.constants.COMMON; import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.apache.jena.rdf.model.*; import org.apache.jena.vocabulary.RDFS; @@ -14,7 +13,6 @@ import java.io.FileReader; import java.io.IOException; import java.util.List; -import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -23,7 +21,6 @@ * * This will test the NTFileStorage in short. * - * * @author f.conrads * */ @@ -39,46 +36,10 @@ public void dataTest() throws IOException{ Model m = ModelFactory.createDefaultModel(); m.read(new FileReader("src/test/resources/nt/results_test1.nt"), null, "N-TRIPLE"); - store.addData(m); - store.commit(); + store.storeResult(m); assertEqual("results_test2.nt","src/test/resources/nt/results_test1.nt", true); new File("results_test2.nt").delete(); - } - - @Test - public void metaTest() throws IOException{ - Storage store = new NTFileStorage("results_test.nt"); - new File("results_test.nt").delete(); - - Properties extraMeta = new Properties(); - extraMeta.setProperty("a", "b"); - - Properties p = new Properties(); - p.put(COMMON.EXPERIMENT_TASK_ID_KEY, "1/1/1"); - p.setProperty(COMMON.EXPERIMENT_ID_KEY, "1/1"); - p.setProperty(COMMON.CONNECTION_ID_KEY, "virtuoso"); - p.setProperty(COMMON.SUITE_ID_KEY, "1"); - p.setProperty(COMMON.DATASET_ID_KEY, "dbpedia"); - p.put(COMMON.RECEIVE_DATA_START_KEY, "true"); - p.put(COMMON.EXPERIMENT_TASK_CLASS_ID_KEY, "ClassName"); - p.put(COMMON.EXTRA_META_KEY, new Properties()); - p.put(COMMON.NO_OF_QUERIES, 2); - - store.addMetaData(p); - store.commit(); - assertEqual("results_test.nt", "src/test/resources/nt/nt_results_woMeta.nt", false); - new File("results_test.nt").delete(); - store = new NTFileStorage("results_test2.nt"); - - p.put(COMMON.EXTRA_META_KEY, extraMeta); - store.addMetaData(p); - store.commit(); - assertEqual("results_test2.nt", "src/test/resources/nt/nt_results_wMeta.nt", false); - - new File("results_test2.nt").delete(); - - } /** diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java index 43201f06..f2445902 100644 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java +++ b/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java @@ -22,7 +22,6 @@ * * This will test the RDFFileStorage in short. * - * * @author l.conrads * */ @@ -38,9 +37,7 @@ public void dataTest() throws IOException{ Model m = ModelFactory.createDefaultModel(); m.read(new FileReader("src/test/resources/nt/results_test1.nt"), null, "N-TRIPLE"); - store.addData(m); - store.commit(); - store.close(); + store.storeResult(m); assertEqual("results_test2.ttl","src/test/resources/nt/results_test1.nt", true); new File("results_test2.ttl").delete(); diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java index d36ee424..5098a658 100644 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java +++ b/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.Properties; import static org.junit.Assert.assertEquals; @@ -53,34 +52,6 @@ public class TriplestoreStorageTest { private String dataExp = "INSERT DATA {\n"+ " \"c\" .\n"+ "}"; - - /** - * @throws IOException - */ - @Test - public void metaTest() throws IOException{ - fastServerContainer = new ServerMock(); - fastServer = new ContainerServer(fastServerContainer); - fastConnection = new SocketConnection(fastServer); - SocketAddress address1 = new InetSocketAddress(FAST_SERVER_PORT); - fastConnection.connect(address1); - - String host = "http://localhost:8023"; - TriplestoreStorage store = new TriplestoreStorage(host, host); - Properties p = new Properties(); - p.put(COMMON.EXPERIMENT_TASK_ID_KEY, "1/1/1"); - p.setProperty(COMMON.EXPERIMENT_ID_KEY, "1/1"); - p.setProperty(COMMON.CONNECTION_ID_KEY, "virtuoso"); - p.setProperty(COMMON.SUITE_ID_KEY, "1"); - p.setProperty(COMMON.DATASET_ID_KEY, "dbpedia"); - p.put(COMMON.EXPERIMENT_TASK_CLASS_ID_KEY, "ClassName"); - p.put(COMMON.RECEIVE_DATA_START_KEY, "true"); - p.put(COMMON.EXTRA_META_KEY, new Properties()); - p.put(COMMON.NO_OF_QUERIES, 2); - store.addMetaData(p); - store.commit(); - assertEquals(metaExp.trim(), fastServerContainer.getActualContent().trim().replaceAll("[0-9][0-9][0-9][0-9]\\-[0-9][0-9]\\-[0-9][0-9]T[0-9][0-9]\\:[0-9][0-9]\\:[0-9][0-9]\\.[0-9]+Z", "???"));//2020-09-21T22:06:45.109Z - } /** * @throws IOException @@ -89,8 +60,7 @@ public void metaTest() throws IOException{ public void close() throws IOException { fastConnection.close(); } - - + /** * @throws IOException */ @@ -107,8 +77,7 @@ public void dataTest() throws IOException{ Model m = ModelFactory.createDefaultModel(); m.add(ResourceFactory.createResource(COMMON.RES_BASE_URI+"a"), ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"b") , "c"); - store.addData(m); - store.commit(); + store.storeResult(m); assertEquals(dataExp.trim(),fastServerContainer.getActualContent().trim()); } diff --git a/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java b/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java index e2cdf44a..ea9f5cf9 100644 --- a/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java +++ b/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java @@ -7,8 +7,6 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; -import java.util.Properties; - /** * Class to help the Unit Metric Tests.
* @@ -21,7 +19,6 @@ */ public class EqualityStorage implements Storage{ - private Model expectedModel; private Model actualModel = ModelFactory.createDefaultModel(); @@ -34,7 +31,7 @@ public EqualityStorage( Model expectedModel) { @Override - public void addData(Model data) { + public void storeResult(Model data) { this.actualModel.add(data); } @@ -45,24 +42,4 @@ public Model getExpectedModel(){ public Model getActualModel(){ return this.actualModel; } - - - // NOTHING TO DO IN THE FOLLOWING METHODS - @Override - public void addMetaData(Properties p) { - //explicity empty - } - - @Override - public void commit() { - //explicity empty - } - - - @Override - public void endTask(String taskID) { - // TODO Auto-generated method stub - - } - } From 7fa5ad1d6cbdedbc768ca31a651fa804e0920bce Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:39:24 +0200 Subject: [PATCH 15/36] add MetricManager class --- .../aksw/iguana/cc/config/IguanaConfig.java | 19 +++++++++---------- .../cc/config/elements/MetricConfig.java | 2 +- .../stresstest/StresstestResultProcessor.java | 15 +++++++++++---- .../cc/tasks/stresstest/metrics/Metric.java | 6 +++--- .../stresstest/metrics/MetricManager.java | 15 +++++++++++++++ 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/MetricManager.java diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index db48fc2a..c223d662 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -3,9 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.aksw.iguana.cc.config.elements.*; import org.aksw.iguana.cc.controller.TaskController; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.MetricManager; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.commons.script.ScriptExecutor; -import org.aksw.iguana.rp.controller.RPController; -import org.aksw.iguana.rp.metrics.Metric; import org.aksw.iguana.rp.metrics.impl.*; import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; @@ -41,8 +42,7 @@ */ public class IguanaConfig { - private static final Logger LOGGER = LoggerFactory - .getLogger(IguanaConfig.class); + private static final Logger LOGGER = LoggerFactory.getLogger(IguanaConfig.class); @JsonProperty(required = true) private List datasets; @@ -66,7 +66,7 @@ public class IguanaConfig { * @throws ExecuteException */ public void start() throws ExecuteException, IOException { - RPController rpController = initResultProcessor(); + initResultProcessor(); TaskController controller = new TaskController(); //get SuiteID String suiteID = generateSuiteID(); @@ -110,12 +110,11 @@ public void start() throws ExecuteException, IOException { } } } - rpController.close(); LOGGER.info("Finished benchmark"); } - private RPController initResultProcessor() { + private void initResultProcessor() { //If storage or metric is empty use default if(this.storages== null || this.storages.isEmpty()){ storages = new ArrayList<>(); @@ -156,9 +155,9 @@ private RPController initResultProcessor() { for(MetricConfig config : this.metrics){ metrics.add(config.createMetric()); } - RPController controller = new RPController(); - controller.init(storages, metrics); - return controller; + + StorageManager.getInstance().addStorages(storages); + MetricManager.setMetrics(metrics); } diff --git a/src/main/java/org/aksw/iguana/cc/config/elements/MetricConfig.java b/src/main/java/org/aksw/iguana/cc/config/elements/MetricConfig.java index ac504ca1..7f5ba852 100644 --- a/src/main/java/org/aksw/iguana/cc/config/elements/MetricConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/elements/MetricConfig.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.config.elements; import com.fasterxml.jackson.annotation.JsonProperty; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.commons.factory.TypedFactory; -import org.aksw.iguana.rp.metrics.Metric; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index 6f120b64..cae167b8 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -4,6 +4,7 @@ import org.aksw.iguana.cc.model.StresstestMetadata; import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.*; +import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.commons.rdf.IONT; import org.aksw.iguana.commons.rdf.IPROP; import org.aksw.iguana.commons.rdf.IRES; @@ -15,7 +16,7 @@ public class StresstestResultProcessor { - private StresstestMetadata metadata; + private final StresstestMetadata metadata; private List metrics; /** @@ -28,11 +29,12 @@ public class StresstestResultProcessor { */ private Map> ab; - private Resource taskRes; + private final Resource taskRes; public StresstestResultProcessor(StresstestMetadata metadata) { this.metadata = metadata; this.taskRes = IRES.getResource(metadata.taskID()); + this.metrics = MetricManager.getMetrics(); WorkerMetadata[] workers = metadata.workers(); this.queryExecutions = new List[workers.length][]; @@ -54,7 +56,7 @@ public StresstestResultProcessor(StresstestMetadata metadata) { public void processQueryExecutions(WorkerMetadata worker, Collection data) { for(QueryExecutionStats stat : data) { // The queryIDs returned by the queryHandler are Strings, in the form of ':'. - int queryID = Integer.valueOf(stat.queryID().substring(stat.queryID().indexOf(":") + 1)); + int queryID = Integer.parseInt(stat.queryID().substring(stat.queryID().indexOf(":") + 1)); queryExecutions[worker.workerID()][queryID].add(stat); if (ab.containsKey(stat.queryID())) { @@ -150,7 +152,12 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { m.add(taskRes, IPROP.startDate, ResourceFactory.createTypedLiteral(start)); m.add(taskRes, IPROP.endDate, ResourceFactory.createTypedLiteral(end)); - // TODO: store m + m.setNsPrefix(IPROP.PREFIX, IPROP.NS); + m.setNsPrefix(IONT.PREFIX, IONT.NS); + m.setNsPrefix(IRES.PREFIX, IRES.NS); + m.setNsPrefix("lsqr", "http://lsq.aksw.org/res/"); + + StorageManager.getInstance().storeResult(m); } /** diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java index 6a94021d..2e6a7940 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/Metric.java @@ -1,9 +1,9 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics; public abstract class Metric { - private String name; - private String abbreviation; - private String description; + private final String name; + private final String abbreviation; + private final String description; public Metric(String name, String abbreviation, String description) { this.name = name; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/MetricManager.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/MetricManager.java new file mode 100644 index 00000000..5320774f --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/MetricManager.java @@ -0,0 +1,15 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics; + +import java.util.List; + +public class MetricManager { + private static List metrics; + + public static void setMetrics(List metrics) { + MetricManager.metrics = metrics; + } + + public static List getMetrics() { + return MetricManager.metrics; + } +} From 8257eb0827a0393ffb3be9b0a468319237b9e634 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:41:54 +0200 Subject: [PATCH 16/36] remove rp package --- .../aksw/iguana/cc/config/IguanaConfig.java | 23 +- .../cc/lang/AbstractLanguageProcessor.java | 8 +- .../org/aksw/iguana/cc/lang/QueryWrapper.java | 36 ++- .../cc/lang/impl/RDFLanguageProcessor.java | 8 +- .../cc/lang/impl/SPARQLLanguageProcessor.java | 27 +- .../aksw/iguana/cc/tasks/AbstractTask.java | 23 +- .../iguana/rp/controller/RPController.java | 51 ---- .../rp/experiment/ExperimentManager.java | 124 --------- .../iguana/rp/metrics/AbstractMetric.java | 251 ------------------ .../org/aksw/iguana/rp/metrics/Metric.java | 89 ------- .../aksw/iguana/rp/metrics/MetricManager.java | 110 -------- .../iguana/rp/metrics/impl/AvgQPSMetric.java | 86 ------ .../rp/metrics/impl/EachQueryMetric.java | 120 --------- .../rp/metrics/impl/F1MeasureMetric.java | 132 --------- .../iguana/rp/metrics/impl/NoQMetric.java | 82 ------ .../iguana/rp/metrics/impl/NoQPHMetric.java | 91 ------- .../iguana/rp/metrics/impl/QMPHMetric.java | 64 ----- .../iguana/rp/metrics/impl/QPSMetric.java | 231 ---------------- .../java/org/aksw/iguana/rp/vocab/Vocab.java | 32 --- .../aksw/iguana/cc/config/WorkflowTest.java | 39 ++- .../cc/tasks/stresstest/StresstestTest.java | 13 +- .../iguana/rp/metrics/impl/MetricTest.java | 140 ---------- .../rp/storage/impl/NTFileStorageTest.java | 71 ----- .../rp/storage/impl/RDFFileStorageTest.java | 74 ------ .../storage/impl/TriplestoreStorageTest.java | 84 ------ .../aksw/iguana/rp/utils/EqualityStorage.java | 45 ---- .../org/aksw/iguana/rp/utils/ServerMock.java | 55 ---- 27 files changed, 72 insertions(+), 2037 deletions(-) delete mode 100644 src/main/java/org/aksw/iguana/rp/controller/RPController.java delete mode 100644 src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/Metric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/MetricManager.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/AvgQPSMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/EachQueryMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/F1MeasureMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/NoQMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/NoQPHMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/QMPHMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/metrics/impl/QPSMetric.java delete mode 100644 src/main/java/org/aksw/iguana/rp/vocab/Vocab.java delete mode 100644 src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java delete mode 100644 src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java delete mode 100644 src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java delete mode 100644 src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java delete mode 100644 src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java delete mode 100644 src/test/java/org/aksw/iguana/rp/utils/ServerMock.java diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index c223d662..8f9109ac 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -7,7 +7,6 @@ import org.aksw.iguana.cc.tasks.stresstest.metrics.MetricManager; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.commons.script.ScriptExecutor; -import org.aksw.iguana.rp.metrics.impl.*; import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; import org.apache.commons.exec.ExecuteException; @@ -124,27 +123,9 @@ private void initResultProcessor() { } if(this.metrics == null || this.metrics.isEmpty()){ LOGGER.info("No metrics were set. Using default metrics."); - metrics = new ArrayList<>(); - MetricConfig config = new MetricConfig(); - config.setClassName(QMPHMetric.class.getCanonicalName()); - metrics.add(config); - config = new MetricConfig(); - config.setClassName(QPSMetric.class.getCanonicalName()); - Map configMap = new HashMap<>(); - configMap.put("penalty", 180000); - config.setConfiguration(configMap); - metrics.add(config); - config = new MetricConfig(); - config.setClassName(NoQPHMetric.class.getCanonicalName()); - metrics.add(config); - config = new MetricConfig(); - config.setClassName(AvgQPSMetric.class.getCanonicalName()); - metrics.add(config); - config = new MetricConfig(); - config.setClassName(NoQMetric.class.getCanonicalName()); - metrics.add(config); - + // TODO: set default metrics } + //Create Storages List storages = new ArrayList<>(); for(StorageConfig config : this.storages){ diff --git a/src/main/java/org/aksw/iguana/cc/lang/AbstractLanguageProcessor.java b/src/main/java/org/aksw/iguana/cc/lang/AbstractLanguageProcessor.java index b31da62b..10cce5b0 100644 --- a/src/main/java/org/aksw/iguana/cc/lang/AbstractLanguageProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/lang/AbstractLanguageProcessor.java @@ -1,8 +1,9 @@ package org.aksw.iguana.cc.lang; import org.aksw.iguana.commons.constants.COMMON; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; import org.aksw.iguana.commons.streams.Streams; -import org.aksw.iguana.rp.vocab.Vocab; import org.apache.http.Header; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.jena.rdf.model.Model; @@ -34,8 +35,9 @@ public Model generateTripleStats(List queries, String resourcePref Model model = ModelFactory.createDefaultModel(); for(QueryWrapper wrappedQuery : queries) { Resource subject = ResourceFactory.createResource(COMMON.RES_BASE_URI + resourcePrefix + "/" + wrappedQuery.getId()); - model.add(subject, RDF.type, Vocab.queryClass); - model.add(subject, Vocab.rdfsID, wrappedQuery.getId()); + model.add(subject, RDF.type, IONT.query); + // TODO: fix this + model.add(subject, IPROP.queryID, ResourceFactory.createTypedLiteral(wrappedQuery.getId())); model.add(subject, RDFS.label, wrappedQuery.getQuery().toString()); } return model; diff --git a/src/main/java/org/aksw/iguana/cc/lang/QueryWrapper.java b/src/main/java/org/aksw/iguana/cc/lang/QueryWrapper.java index 080a8791..07ca5fb7 100644 --- a/src/main/java/org/aksw/iguana/cc/lang/QueryWrapper.java +++ b/src/main/java/org/aksw/iguana/cc/lang/QueryWrapper.java @@ -1,31 +1,41 @@ package org.aksw.iguana.cc.lang; +import java.math.BigInteger; + /** * Util class to wrap a Query of what ever class it may be and it's id */ public class QueryWrapper { + private final Object query; + private final int id; + private final String fullId; - private Object query; - private String id; + public QueryWrapper(Object query, String fullId) { + this.query = query; + int i = fullId.length(); + while (i > 0 && Character.isDigit(fullId.charAt(i - 1))) { + i--; + } - public QueryWrapper(Object query, String id){ - this.query=query; - this.id=id; + this.id = Integer.parseInt(fullId.substring(i)); + this.fullId = fullId; } - public Object getQuery() { - return query; + public QueryWrapper(Object query, String prefix, int id) { + this.query = query; + this.id = id; + this.fullId = prefix + id; } - public void setQuery(Object query) { - this.query = query; + public Object getQuery() { + return query; } - public String getId() { - return id; + public BigInteger getId() { + return BigInteger.valueOf(id); } - public void setId(String id) { - this.id = id; + public String getFullId() { + return fullId; } } diff --git a/src/main/java/org/aksw/iguana/cc/lang/impl/RDFLanguageProcessor.java b/src/main/java/org/aksw/iguana/cc/lang/impl/RDFLanguageProcessor.java index a69e5e67..80e68e1d 100644 --- a/src/main/java/org/aksw/iguana/cc/lang/impl/RDFLanguageProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/lang/impl/RDFLanguageProcessor.java @@ -5,7 +5,8 @@ import org.aksw.iguana.cc.lang.QueryWrapper; import org.aksw.iguana.commons.annotation.Shorthand; import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.vocab.Vocab; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; import org.apache.http.Header; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.jena.rdf.model.Model; @@ -49,8 +50,9 @@ public Model generateTripleStats(List queries, String resourcePref Model model = ModelFactory.createDefaultModel(); for(QueryWrapper wrappedQuery : queries) { Resource subject = ResourceFactory.createResource(COMMON.RES_BASE_URI + resourcePrefix + "/" + wrappedQuery.getId()); - model.add(subject, RDF.type, Vocab.queryClass); - model.add(subject, Vocab.rdfsID, wrappedQuery.getId().replace(queryPrefix, "").replace("sparql", "")); + model.add(subject, RDF.type, IONT.query); + // TODO: fix this + model.add(subject, IPROP.queryID, ResourceFactory.createTypedLiteral(wrappedQuery.getId())); model.add(subject, RDFS.label, wrappedQuery.getQuery().toString()); } return model; diff --git a/src/main/java/org/aksw/iguana/cc/lang/impl/SPARQLLanguageProcessor.java b/src/main/java/org/aksw/iguana/cc/lang/impl/SPARQLLanguageProcessor.java index d1710485..5711f87d 100644 --- a/src/main/java/org/aksw/iguana/cc/lang/impl/SPARQLLanguageProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/lang/impl/SPARQLLanguageProcessor.java @@ -6,8 +6,8 @@ import org.aksw.iguana.cc.utils.SPARQLQueryStatistics; import org.aksw.iguana.commons.annotation.Shorthand; import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.vocab.Vocab; -import org.apache.commons.lang.StringUtils; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; import org.apache.http.Header; import org.apache.http.HeaderElement; import org.apache.http.HttpEntity; @@ -70,23 +70,24 @@ public Model generateTripleStats(List queries, String resourcePref Model model = ModelFactory.createDefaultModel(); for(QueryWrapper wrappedQuery : queries) { Resource subject = ResourceFactory.createResource(COMMON.RES_BASE_URI + resourcePrefix + "/" + wrappedQuery.getId()); - model.add(subject, RDF.type, Vocab.queryClass); - model.add(subject, Vocab.rdfsID, wrappedQuery.getId().replace("sparql", "")); + model.add(subject, RDF.type, IONT.query); + // TODO: queryID is already used in a different context + model.add(subject, IPROP.queryID, ResourceFactory.createTypedLiteral(wrappedQuery.getId())); model.add(subject, RDFS.label, wrappedQuery.getQuery().toString()); try { Query q = QueryFactory.create(wrappedQuery.getQuery().toString()); SPARQLQueryStatistics qs2 = new SPARQLQueryStatistics(); qs2.getStatistics(q); - model.add(subject, Vocab.aggrProperty, model.createTypedLiteral(qs2.aggr==1)); - model.add(subject, Vocab.filterProperty, model.createTypedLiteral(qs2.filter==1)); - model.add(subject, Vocab.groupByProperty, model.createTypedLiteral(qs2.groupBy==1)); - model.add(subject, Vocab.havingProperty, model.createTypedLiteral(qs2.having==1)); - model.add(subject, Vocab.triplesProperty, model.createTypedLiteral(qs2.triples)); - model.add(subject, Vocab.offsetProperty, model.createTypedLiteral(qs2.offset==1)); - model.add(subject, Vocab.optionalProperty, model.createTypedLiteral(qs2.optional==1)); - model.add(subject, Vocab.orderByProperty, model.createTypedLiteral(qs2.orderBy==1)); - model.add(subject, Vocab.unionProperty, model.createTypedLiteral(qs2.union==1)); + model.add(subject, IPROP.aggregations, model.createTypedLiteral(qs2.aggr==1)); + model.add(subject, IPROP.filter, model.createTypedLiteral(qs2.filter==1)); + model.add(subject, IPROP.groupBy, model.createTypedLiteral(qs2.groupBy==1)); + model.add(subject, IPROP.having, model.createTypedLiteral(qs2.having==1)); + model.add(subject, IPROP.triples, model.createTypedLiteral(qs2.triples)); + model.add(subject, IPROP.offset, model.createTypedLiteral(qs2.offset==1)); + model.add(subject, IPROP.optional, model.createTypedLiteral(qs2.optional==1)); + model.add(subject, IPROP.orderBy, model.createTypedLiteral(qs2.orderBy==1)); + model.add(subject, IPROP.union, model.createTypedLiteral(qs2.union==1)); model.add(subject, OWL.sameAs, getLSQHash(q)); }catch(Exception e){ LOGGER.warn("Query statistics could not be created. Not using SPARQL?"); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java index 388dec96..713324d2 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java @@ -6,7 +6,6 @@ import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.commons.annotation.Shorthand; import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.experiment.ExperimentManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +23,6 @@ public abstract class AbstractTask implements Task { private Logger LOGGER = LoggerFactory.getLogger(getClass()); - private ExperimentManager rpControl = ExperimentManager.getInstance(); protected String taskID; protected ConnectionConfig con; @@ -64,28 +62,13 @@ public void init(String[] ids, String dataset, ConnectionConfig con, String task } @Override - public void start() { - // send to ResultProcessor - rpControl.receiveData(metaData); - - } + public void start() {} @Override - public void sendResults(Properties data) throws IOException { - data.setProperty(COMMON.EXPERIMENT_TASK_ID_KEY, this.taskID); - rpControl.receiveData(data); - } + public void sendResults(Properties data) throws IOException {} @Override - public void close() { - Properties end = new Properties(); - // set exp task id - end.setProperty(COMMON.EXPERIMENT_TASK_ID_KEY, this.taskID); - // set end flag - end.put(COMMON.RECEIVE_DATA_END_KEY, true); - // send to ResultProcessor - rpControl.receiveData(end); - } + public void close() {} @Override public void addMetaData() { diff --git a/src/main/java/org/aksw/iguana/rp/controller/RPController.java b/src/main/java/org/aksw/iguana/rp/controller/RPController.java deleted file mode 100644 index f9866d6a..00000000 --- a/src/main/java/org/aksw/iguana/rp/controller/RPController.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.controller; - - -import org.aksw.iguana.rp.experiment.ExperimentManager; -import org.aksw.iguana.rp.metrics.Metric; -import org.aksw.iguana.rp.metrics.MetricManager; -import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; -import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -/** - * This is the Main Controller. - * It will start the ResultProcessor, initialize the {@link StorageManager} and the {@link org.aksw.iguana.rp.metrics.MetricManager} - * - * @author f.conrads - * - */ -public class RPController { - - - private static final Logger LOGGER = LoggerFactory - .getLogger(RPController.class); - private StorageManager storageManager; - - - /** - * This will initialize the MainController. - */ - public void init(List storages, List metrics){ - //add storages to StoragesManager - storageManager = StorageManager.getInstance(); - storageManager.addStorages(storages); - LOGGER.info("Storages : {{}}", storageManager); - //Add default metrics to MetricsManager - MetricManager globalMetricsManager = MetricManager.getInstance(); - globalMetricsManager.addMetrics(metrics); - LOGGER.info("GlobalMetrics : {{}}", globalMetricsManager); - ExperimentManager emanager = new ExperimentManager(globalMetricsManager, storageManager); - - } - - public void close() { - storageManager.close(); - } -} diff --git a/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java b/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java deleted file mode 100644 index 263d736b..00000000 --- a/src/main/java/org/aksw/iguana/rp/experiment/ExperimentManager.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.aksw.iguana.rp.experiment; - -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.MetricManager; -import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * The ExperimentManager manages the incoming properties from the - * tasks and sort them to the correct experiments - * One Experiment is simply a {@link org.aksw.iguana.rp.metrics.MetricManager} - * - * @author f.conrads - */ -public class ExperimentManager { - - private static final Logger LOGGER = LoggerFactory - .getLogger(ExperimentManager.class); - - private Map experiments = new HashMap(); - private MetricManager globalMetricManager; - - private StorageManager storageManager; - - private static ExperimentManager instance; - - public synchronized static ExperimentManager getInstance(){ - if (instance == null) { - instance = new ExperimentManager(MetricManager.getInstance(), StorageManager.getInstance()); - } - return instance; - } - - - /** - * Initialize the ExperimentManager with the global {@link org.aksw.iguana.rp.metrics.MetricManager} - * @param globalMetricManager - */ - public ExperimentManager(MetricManager globalMetricManager, StorageManager storageManager){ - this.globalMetricManager = globalMetricManager; - this.storageManager = storageManager; - } - - /** - * - * @param p - */ - public void receiveData(Properties p){ - //check if start, content, end - if(p.containsKey(COMMON.RECEIVE_DATA_START_KEY)){ - startExperimentTask(p); - } - else if(p.containsKey(COMMON.RECEIVE_DATA_END_KEY)){ - endExperimentTask(p); - } - else{ - content(p); - } - } - - /** - * This will start an experiment. This will initialize the following things - * Queries, Metrics, Resultsizes, Workers, Tasks, Suite(?), metricsManager - * - * @param p - */ - private void startExperimentTask(Properties p){ - //Check if properties contains an experiment ID, if not do nothing. - if(!p.containsKey(COMMON.EXPERIMENT_TASK_ID_KEY)){ - LOGGER.error("Could not find experiment task ID in properties."); - LOGGER.error("Will ignore this properties object {}", p.toString()); - return; - } - //Get the Experiment task ID - String taskID = p.getProperty(COMMON.EXPERIMENT_TASK_ID_KEY); - LOGGER.info("Got start flag for experiment task ID {}", taskID); - - - //Add metricManager to experiments - experiments.put(taskID, globalMetricManager); - - globalMetricManager.addMetaData(p); - //check all the properties. (Queries, Results, Workers) and add them to the Storages - storageManager.addMetaData(p); - LOGGER.info("Will start experiment task with ID {} now.", taskID); - } - - /** - * Will sort the properties to the correct experiment according to their IDs - * It will simply add the properties to the {@link org.aksw.iguana.rp.metrics.MetricManager} - * @param p - */ - private void content(Properties p){ - String taskID = p.getProperty(COMMON.EXPERIMENT_TASK_ID_KEY); - LOGGER.debug("Got content for experiment task ID: {} ", taskID); - if(experiments.containsKey(taskID)) - experiments.get(taskID).receiveData(p); - else - LOGGER.warn("Got content for experiment task ID: {} but task never start", taskID); - } - - /** - * This will end the experiment and start the close method of the associated metrics - * @param p - */ - private void endExperimentTask(Properties p){ - String taskID = p.getProperty(COMMON.EXPERIMENT_TASK_ID_KEY); - storageManager.endTask(taskID); - storageManager.commit(); - LOGGER.info("Got end Flag for experiment task ID {}", taskID); - if(experiments.containsKey(taskID)){ - experiments.get(taskID).close(); - experiments.remove(taskID); - } - else{ - LOGGER.warn("Could not find Experiment Task with ID: {}.", taskID); - } - } -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java deleted file mode 100644 index cfeacb7b..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/AbstractMetric.java +++ /dev/null @@ -1,251 +0,0 @@ -package org.aksw.iguana.rp.metrics; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; -import org.aksw.iguana.rp.vocab.Vocab; -import org.apache.jena.rdf.model.*; -import org.apache.jena.vocabulary.RDF; -import org.apache.jena.vocabulary.RDFS; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * Abstract Metric class which implements the method sendData - * so the final Metric class can send their final data via this command to the storages - * - * @author f.conrads - * - */ -public abstract class AbstractMetric implements Metric{ - - protected StorageManager storageManager = StorageManager.getInstance(); - - protected Properties metaData = new Properties(); - - protected Map dataContainer = new HashMap(); - - protected String name; - protected String shortName; - protected String description; - - /** - * This constructor will not set name, Short name and description - * Thus the final Metric class has to set them itself. - */ - public AbstractMetric(){ - } - - /** - * Will create an Metric class with the name, short name and description - * - * @param name - * @param shortName - * @param description - */ - public AbstractMetric(String name, String shortName, String description){ - this.name=name; - this.shortName=shortName; - this.description=description; - } - - @Override - public void setStorageManager(StorageManager smanager){ - this.storageManager = smanager; - } - - @Override - public StorageManager getStorageManager(){ - return this.storageManager; - } - - @Override - public String getDescription(){ - return this.description; - } - - @Override - public String getName(){ - return this.name; - } - - @Override - public String getShortName(){ - return this.shortName; - } - - - /** - * Will add the Meta Data to the Metric - */ - @Override - public void setMetaData(Properties metaData){ - this.metaData = metaData; - } - - - /** - * Will return the Properties Object with the associated key: EXTRA_META_KEY
- * if this key does not exists: recv will be returned - * - * @param recv - * @return - */ - protected Properties getExtraMeta(Properties recv){ - if(recv.containsKey(COMMON.EXTRA_META_KEY)) - return (Properties) recv.get(COMMON.EXTRA_META_KEY); - return recv; - } - - - - /** - * Will create a subject node string from the recv object (ExperimentTaskID and extraMeta Hash) - * @param recv - * @return - */ - protected String getSubjectFromExtraMeta(Properties recv){ - String subject = metaData.getProperty(COMMON.EXPERIMENT_TASK_ID_KEY); - Properties extraMeta = getExtraMeta(recv); - if (!extraMeta.isEmpty()) { - subject += "/" + recv.get(COMMON.WORKER_ID); - } - return subject; - } - - /** - * Will add the data to a in memory container which can be assessed by extra - * - * @param extra - * @param data - */ - protected void addDataToContainer(Properties extra, Properties data){ - this.dataContainer.put(extra, data); - } - - /** - * Getting the data Properties from the data container associated to extra - * - * @param extra - * @return - */ - protected Properties getDataFromContainer(Properties extra){ - return this.dataContainer.get(extra); - } - - /** - * Assuming that the results are Integer objects, this will - * 1. if no data for extra exists, create the data from the results object - * 2. if the data exists, sum the corresponding - * - * for example: - * container has data object e1:(a:10, b:12) - * new results for e1 are (a:2, b:5) - * The new container data will be (a:12, b:17) - * - * @param extra - * @param results - */ - protected void processData(Properties extra, Properties results){ - Properties tmp = getDataFromContainer(extra); - if(tmp!=null){ - for(Object obj : results.keySet()){ - if(tmp.get(obj.toString()) instanceof Long) { - Long res = (long) tmp.get(obj.toString()); - tmp.put(obj.toString(),res+(long)results.get(obj)); - } - else if(tmp.get(obj.toString()) instanceof Integer) { - int res = (int) tmp.get(obj.toString()); - tmp.put(obj.toString(),res+(int)results.get(obj)); - } - else if(tmp.get(obj.toString()) instanceof Double) { - double res = (double) tmp.get(obj.toString()); - tmp.put(obj.toString(),res+(double)results.get(obj)); - } - } - } - else{ - tmp = new Properties(); - for(Object obj : results.keySet()){ - if(results.get(obj) instanceof Long) - tmp.put(obj.toString(),(long)results.get(obj)); - if(results.get(obj) instanceof Double) - tmp.put(obj.toString(),(double)results.get(obj)); - if(results.get(obj) instanceof Integer) - tmp.put(obj.toString(),(int)results.get(obj)); - } - } - addDataToContainer(extra, tmp); - } - - - /** - * Creates a Statement connecting a the subject to the Task Resource using the iprop:workerResult property as follows - * ires:Task1 iprop:workerResult subject - * @param subject - * @return - */ - protected Statement getConnectingStatement(Resource subject) { - return ResourceFactory.createStatement(getTaskResource(), Vocab.workerResult, subject); - } - - public Resource getTaskResource(){ - String subject = metaData.getProperty(COMMON.EXPERIMENT_TASK_ID_KEY); - return ResourceFactory.createResource(COMMON.RES_BASE_URI+subject); - } - - public Resource getSubject(Properties recv){ - String id = this.getSubjectFromExtraMeta(recv); - return ResourceFactory.createResource(COMMON.RES_BASE_URI+id); - } - - public Property getMetricProperty(){ - return ResourceFactory.createProperty(COMMON.PROP_BASE_URI+shortName); - } - - public void sendData(Model m){ - this.storageManager.storeResult(m); - } - - @Override - public void close() { - //Add metric description and worker class - Model m = ModelFactory.createDefaultModel(); - String label = this.getClass().getCanonicalName(); - if(this.getClass().isAnnotationPresent(Shorthand.class)){ - label = getClass().getAnnotation(Shorthand.class).value(); - } - Literal labelRes = ResourceFactory.createPlainLiteral(label); - Literal commentRes = ResourceFactory.createPlainLiteral(this.description); - Resource classRes = ResourceFactory.createResource(COMMON.CLASS_BASE_URI+"metric/"+label); - Resource metricRes = ResourceFactory.createResource(COMMON.RES_BASE_URI+this.getShortName()); - //Resource metricClass = ResourceFactory.createResource(COMMON.CLASS_BASE_URI+this.getShortName()); - - m.add(metricRes, RDFS.label, this.getName()); - m.add(metricRes, RDFS.comment, commentRes); - //adding type iguana:metric - m.add(metricRes, RDF.type, Vocab.metricClass); - //adding type iguana:metric/SPECIFIC_METRIC_CLASS - m.add(metricRes, RDF.type, classRes); - m.add(metricRes, RDFS.label, labelRes); - - for(Properties key : dataContainer.keySet()) { - - Resource subject = ResourceFactory.createResource(COMMON.RES_BASE_URI+getSubjectFromExtraMeta(key)); - m.add(subject, - RDF.type, - Vocab.workerClass); - for(Object k : key.keySet()) { - m.add(subject, ResourceFactory.createProperty(COMMON.PROP_BASE_URI+k), ResourceFactory.createTypedLiteral(key.get(k))); - } - m.add(subject, Vocab.worker2metric, metricRes); - } - m.add(getTaskResource(), Vocab.worker2metric, metricRes); - - this.storageManager.storeResult(m); - - this.dataContainer.clear(); - } -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/Metric.java b/src/main/java/org/aksw/iguana/rp/metrics/Metric.java deleted file mode 100644 index 8ae729e5..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/Metric.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.aksw.iguana.rp.metrics; - -import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; - -import java.util.Properties; - -/** - * This is the Interface for all Metrics - * - * @author f.conrads - * - */ -public interface Metric { - - /** - * This method should implement what to do with one result.

- * - * For example: No Of Queries Per Hour will get the time query time - * add the time to a variable which keeps track of the total time of all executed queries - * and increase the number of executed queries if the query was successfully executed.

- * - * Be aware, that in this example, the Metric could be stopped as soon as one hour is reached, - * or it could be calculate in the close method.

- * - * Assuming, the totaltime is in minutes (it should be calculated in ms though) - * Latter one will result in the following formular:
- * m = 60 * queries / totaltime

- * - * The actual keys of the properties will depend on the core.
- * The stress test will send different keys than a completeness test.
- * Thus not all metrics are available for each test.
- * Hence it should be implemented if the Metric cannot calculate the test results - * that it will just close itself without adding results. - * - * - * @param p - */ - public void receiveData(Properties p); - - public void setStorageManager(StorageManager sManager); - - public StorageManager getStorageManager(); - /** - * This method will be called, as soon as the associated Experiment Task is finished. - * - * Not all metrics are available for each test. - * Hence it should be implemented if the Metric cannot calculate the test results - * that it will just close itself without adding results. - * The {@link org.aksw.iguana.rp.metrics.MetricManager} will try to close the Metric still, - * thus it should be checked if that was the case. - * - */ - public void close(); - - - /** - * This method should return a short description of what the Metric will calculate - * - * For example (No. of Queries Per Hour): "Will sum up all successful executed Queries in one hour." - * - * @return - */ - public String getDescription(); - - /** - * This method should return the Metric Name - * - * For example: "Query Mixes Per Hour" - * - * @return - */ - public String getName(); - - /** - * This method should return an abbreviated version of the Metric name. - * - * For example (Query Mixes Per Hour): "QMPH" - * @return - */ - public String getShortName(); - - /** - * This method will be called by the {@link org.aksw.iguana.rp.experiment.ExperimentManager} to - * provide meta data such as the number of query mixes. - * - * @param metaData - */ - public void setMetaData(Properties metaData); -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/MetricManager.java b/src/main/java/org/aksw/iguana/rp/metrics/MetricManager.java deleted file mode 100644 index 2a1aff10..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/MetricManager.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.metrics; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -/** - * - * The MetricManager will manage all {@link org.aksw.iguana.rp.metrics.Metric} - * - * @author f.conrads - * - */ -public class MetricManager { - - private static final Logger LOGGER = LoggerFactory - .getLogger(MetricManager.class); - - private Set metrics = new HashSet(); - - private static MetricManager instance; - - public synchronized static MetricManager getInstance() { - if (instance == null) { - instance = new MetricManager(); - } - return instance; - } - - /** - * WIll add a metric to the manager - * @param metric - */ - public void addMetric(Metric metric){ - if(metric==null){ - return; - } - metrics.add(metric); - } - - public Set getMetrics(){ - return metrics; - } - - /** - * Will add the meta Data to all metrics - * @param metaData - */ - public void addMetaData(Properties metaData){ - for(Metric m : metrics){ - m.setMetaData(metaData); - } - } - /** - * This will message the received properties to all defined metrics. - * - * @param p - */ - public void receiveData(Properties p){ - Set remove = new HashSet(); - for(Metric m : metrics){ - try{ - m.receiveData(p); - }catch(Exception e){ - LOGGER.warn("Could not use metric {}, Cause: {}",m.getShortName(),e); - remove.add(m); - } - } - metrics.removeAll(remove); - } - - @Override - public String toString(){ - StringBuilder ret =new StringBuilder(); - - Iterator it = metrics.iterator(); - for(int i=0;i remove = new HashSet(); - for(Metric m : metrics){ - try{ - m.close(); - m.getStorageManager().commit(); - - }catch(Exception e){ - LOGGER.error("Could not use metric "+m.getShortName()+". Cause: {}",e); - - } - } - metrics.removeAll(remove); - } - - public void addMetrics(List metrics) { - this.metrics.addAll(metrics); - } -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/AvgQPSMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/AvgQPSMetric.java deleted file mode 100644 index b729cf06..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/AvgQPSMetric.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.apache.jena.rdf.model.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * Calculates the average queries per second - */ -@Shorthand("AvgQPS") -public class AvgQPSMetric extends QPSMetric { - public AvgQPSMetric() { - super( - "Average Queries Per Second", - "AvgQPS", - "Will calculate the overall average queries Per second. Further on it will save the totaltime of each query, the failure and the success"); - } - - public AvgQPSMetric(Integer penalty) { - super( - "Average Queries Per Second", - "AvgQPS", - "Will calculate the overall average queries Per second. Further on it will save the totaltime of each query, the failure and the success"); - this.penalty=penalty; - } - - - - @Override - public void close() { - super.close(); - } - - @Override - protected void qpsClose(){ - Model m = ModelFactory.createDefaultModel(); - Map map = new HashMap(); - Property property = getMetricProperty(); - Property penalziedProp = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"penalized"+shortName); - for(Properties key : dataContainer.keySet()){ - Properties value = dataContainer.get(key); - Double avgQps=0.0; - Double penalizedAvgQps=0.0; - for(Object queryID : value.keySet()){ - Object[] resArr = (Object[]) value.get(queryID); - Double qps = (long)resArr[1]*1.0/((double)resArr[0]/1000.0); - Double penalizedQPS = (long)resArr[1]*1.0/((double)resArr[7]/1000.0); - map.putIfAbsent(queryID, new Number[]{Double.valueOf(0), Long.valueOf(0), Double.valueOf(0)}); - - Number[] current =map.get(queryID); - Long succ = (long)resArr[1]+(Long)current[1]; - Double time = (double)resArr[0]+(Double)current[0]; - Double penTime = (double)resArr[7]+(Double)current[2]; - map.put(queryID, new Number[]{time, succ, penTime}); - avgQps+=qps; - penalizedAvgQps+=penalizedQPS; - } - avgQps = avgQps/value.size(); - penalizedAvgQps = penalizedAvgQps/value.size(); - Resource subject = getSubject(key); - m.add(getConnectingStatement(subject)); - m.add(subject, property, ResourceFactory.createTypedLiteral(avgQps)); - m.add(subject, penalziedProp, ResourceFactory.createTypedLiteral(penalizedAvgQps)); - - } - Double avgQps=0.0; - Double penalizedAvgQps=0.0; - for(Object queryID : map.keySet()) { - Double qps = (Long)map.get(queryID)[1]*1.0/((Double)map.get(queryID)[0]/1000.0); - Double penalizedQPS = (long)map.get(queryID)[1]*1.0/((double)map.get(queryID)[2]/1000.0); - avgQps+=qps; - penalizedAvgQps+=penalizedQPS; - } - avgQps = avgQps/map.size(); - penalizedAvgQps= penalizedAvgQps/map.size(); - m.add(getTaskResource(), property, ResourceFactory.createTypedLiteral(avgQps)); - m.add(getTaskResource(), penalziedProp, ResourceFactory.createTypedLiteral(penalizedAvgQps)); - this.sendData(m); - this.storageManager.commit(); - } - -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/EachQueryMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/EachQueryMetric.java deleted file mode 100644 index 74cb5f23..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/EachQueryMetric.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.AbstractMetric; -import org.apache.jena.rdf.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * - * This metric will send every query execution time to the storages. Also it - * will provide if the query succeeded or failed. - * - * @author f.conrads - * - */ -@Shorthand("EachQuery") -public class EachQueryMetric extends AbstractMetric { - - private static Property queryProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"query"); - private static Property execProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"queryExecution"); - private static Property resultSize = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"resultSize"); - private static Property timeProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"time"); - private static Property successProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"success"); - private static Property runProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"run"); - private static Property queryIDProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"queryID"); - private static Property errorCodeProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"code"); - - - private Map queryRunMap = new HashMap(); - - protected static Logger LOGGER = LoggerFactory - .getLogger(EachQueryMetric.class); - - /** - * - */ - public EachQueryMetric() { - super("Each Query Execution", "EachQuery", - "Will save every query execution time."); - } - - /* - * (non-Javadoc) - * - * @see org.aksw.iguana.rp.metrics.Metric#receiveData(java.util.Properties) - */ - @Override - public void receiveData(Properties p) { - // set Subject Node, hash out of task ID and if not empty the extra - // properties - Model m = ModelFactory.createDefaultModel(); - - String worker = getSubjectFromExtraMeta((Properties) p.get(COMMON.EXTRA_META_KEY)); - - - LOGGER.debug(this.getShortName() + " has received " + p); - - double time = (double) p.get(COMMON.RECEIVE_DATA_TIME); - Boolean success = (Boolean) (((long) p.get(COMMON.RECEIVE_DATA_SUCCESS))>0?true:false); - String queryID = p.getProperty(COMMON.QUERY_ID_KEY); - long err = (long) p.get(COMMON.RECEIVE_DATA_SUCCESS); - String subject = worker+"/"+queryID; - - long run=1; - if(queryRunMap.containsKey(subject)){ - run = queryRunMap.get(subject)+1; - } - //set subject2 node subject/noOfRun - String subject2 = subject+"/"+run; - - //as triples - Resource workerRes = ResourceFactory.createResource(COMMON.RES_BASE_URI+worker); - - Resource queryRes = ResourceFactory.createResource(COMMON.RES_BASE_URI+subject); - - Resource subRes = ResourceFactory.createResource(COMMON.RES_BASE_URI+subject2); - m.add(getConnectingStatement(workerRes)); - m.add(workerRes, queryProperty , queryRes); - m.add(queryRes, execProperty , subRes); - m.add(subRes, timeProperty, ResourceFactory.createTypedLiteral(time)); - m.add(subRes, successProperty, ResourceFactory.createTypedLiteral(success)); - if(p.containsKey(COMMON.QUERY_HASH)) { - int queryHash = Integer.parseInt(p.get(COMMON.QUERY_HASH).toString()); - m.add(subRes, queryIDProperty, ResourceFactory.createResource(COMMON.RES_BASE_URI+queryHash+"/"+queryID)); - } - else{ - m.add(subRes, queryIDProperty, ResourceFactory.createTypedLiteral(queryID)); - } - m.add(subRes, runProperty, ResourceFactory.createTypedLiteral(run)); - m.add(subRes, errorCodeProperty, ResourceFactory.createTypedLiteral(err)); - if(p.containsKey(COMMON.RECEIVE_DATA_SIZE)) { - long resSize = Long.parseLong(p.get(COMMON.RECEIVE_DATA_SIZE).toString()); - m.add(subRes, resultSize, ResourceFactory.createTypedLiteral(resSize)); - } - - sendData(m); - queryRunMap.put(subject, run); - } - - /* - * (non-Javadoc) - * - * @see org.aksw.iguana.rp.metrics.Metric#close() - */ - @Override - public void close() { - // Nothing to do here, as each query was sent to the Storages yet. - super.close(); - } - -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/F1MeasureMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/F1MeasureMetric.java deleted file mode 100644 index b0194945..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/F1MeasureMetric.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.AbstractMetric; -import org.apache.jena.rdf.model.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * provides a metric to measure F1, recall and precision if provided tp,fp,fn. - * Calculates micro and macro f1, recall and precision as well. - */ -@Shorthand("F1Measure") -public class F1MeasureMetric extends AbstractMetric { - - private static Property queryProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"query"); - private static Property queryIDProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"queryID"); - private static Property queryStringProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"queryString"); - private static Property tpProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"tp"); - private static Property fpProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"fp"); - private static Property fnProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"fn"); - private static Property precisionProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"precision"); - private static Property recallProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"recall"); - private static Property f1Property = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"f1"); - private static Property microPrecisionProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"microPrecision"); - private static Property microRecallProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"microRecall"); - private static Property microF1Property = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"microF1"); - private static Property macroPrecisionProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"macroPrecision"); - private static Property macroRecallProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"macroRecall"); - private static Property macroF1Property = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"macroF1"); - - - private static final int TP_RESULTS = 0; - - private static final int FP_RESULTS = 1; - - private static final int FN_RESULTS = 2; - - private static final int QUERY_ID = 0; - - private static final int QUERY_STRING = 1; - - private static final int DOUBLE_RESULTS = 2; - - private Map rawResults = new HashMap(); - - public F1MeasureMetric() { - super("F1 Measure", "F1Measure", "Will calculate Micro and Macro F1 measure"); - } - - @Override - public void receiveData(Properties p) { - String queryID = p.get(COMMON.QUERY_ID_KEY).toString(); - String queryString = p.get(COMMON.QUERY_STRING).toString(); - double[] doubleResults = (double[])p.get(COMMON.DOUBLE_RAW_RESULTS); - Object[] rawResult = new Object[3]; - rawResult[QUERY_ID] = queryID; - rawResult[QUERY_STRING] = queryString; - rawResult[DOUBLE_RESULTS] = doubleResults; - rawResults.put(queryID, rawResult); - } - - @Override - public void close() { - String subject = getSubjectFromExtraMeta(new Properties()); - - Model m = ModelFactory.createDefaultModel(); - Resource subRes= ResourceFactory.createResource(COMMON.RES_BASE_URI+subject); - - double[] globalMeasure = new double[] {0,0,0}; - double[] globalRaw = new double[] {0,0,0}; - int i=0; - for(String key : rawResults.keySet()) { - Object[] rawResult = rawResults.get(key); - String queryURI = COMMON.RES_BASE_URI+subject+"/"+rawResult[QUERY_ID].toString(); - Resource queryURIRes = ResourceFactory.createResource(queryURI); - m.add(subRes, queryProperty, queryURIRes); - m.add(queryURIRes, queryIDProperty, ResourceFactory.createTypedLiteral(rawResult[QUERY_ID])); - m.add(queryURIRes, queryStringProperty, ResourceFactory.createTypedLiteral(rawResult[QUERY_STRING].toString().replaceAll("(<|>)", ""))); - - double[] rawDoubleResults = (double[])rawResult[DOUBLE_RESULTS]; - m.add(queryURIRes, tpProperty, ResourceFactory.createTypedLiteral(rawDoubleResults[TP_RESULTS])); - m.add(queryURIRes, fpProperty, ResourceFactory.createTypedLiteral(rawDoubleResults[FP_RESULTS])); - m.add(queryURIRes, fnProperty, ResourceFactory.createTypedLiteral(rawDoubleResults[FN_RESULTS])); - - globalRaw[TP_RESULTS]+=rawDoubleResults[TP_RESULTS]; - globalRaw[FP_RESULTS]+=rawDoubleResults[FP_RESULTS]; - globalRaw[FN_RESULTS]+=rawDoubleResults[FN_RESULTS]; - double[] measure = calculateMeasure(rawDoubleResults); - m.add(queryURIRes, precisionProperty, ResourceFactory.createTypedLiteral(measure[0])); - m.add(queryURIRes, recallProperty, ResourceFactory.createTypedLiteral(measure[1])); - m.add(queryURIRes, f1Property, ResourceFactory.createTypedLiteral(measure[2])); - - globalMeasure[0] += measure[0]; - globalMeasure[1] += measure[1]; - globalMeasure[2] += measure[2]; - } - Properties results = new Properties(); - double[] microMeasure = calculateMeasure(globalRaw); - m.add(subRes, microPrecisionProperty, ResourceFactory.createTypedLiteral(microMeasure[0])); - m.add(subRes, microRecallProperty, ResourceFactory.createTypedLiteral(microMeasure[1])); - m.add(subRes, microF1Property, ResourceFactory.createTypedLiteral(microMeasure[2])); - m.add(subRes, macroPrecisionProperty, ResourceFactory.createTypedLiteral(globalMeasure[0]/rawResults.size())); - m.add(subRes, macroRecallProperty, ResourceFactory.createTypedLiteral(globalMeasure[1]/rawResults.size())); - m.add(subRes, macroF1Property, ResourceFactory.createTypedLiteral(globalMeasure[2]/rawResults.size())); - sendData(m); - super.close(); - } - - private double[] calculateMeasure(double[] rawDoubleResults) { - double[] measure = new double[] {0,0,0}; - double tp = rawDoubleResults[TP_RESULTS]; - double fp = rawDoubleResults[FP_RESULTS]; - double fn = rawDoubleResults[FN_RESULTS]; - if(tp==0&&fp==0&&fn==0) { - return new double[]{1,1,1}; - } - if(fp!=0||tp!=0) { - measure[0] = tp/(tp+fp); - } - if(fp!=0||tp!=0) { - measure[1] = tp/(tp+fn); - } - if(measure[0]!=0 || measure[1]!=0) - measure[2] = 2*measure[0]*measure[1]/(measure[0]+measure[1]); - return measure; - } - -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/NoQMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/NoQMetric.java deleted file mode 100644 index 61e1f0a2..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/NoQMetric.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.AbstractMetric; -import org.apache.jena.rdf.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Properties; - -/** - * Counts the number of all successfully executed queries - */ -@Shorthand("NoQ") -public class NoQMetric extends AbstractMetric { - - protected static final Object TOTAL_TIME = "totalTime"; - protected static final Object TOTAL_SUCCESS = "totalSuccess"; - - - protected static Logger LOGGER = LoggerFactory.getLogger(NoQPHMetric.class); - - - protected long hourInMS = 3600000; - - - public NoQMetric(){ - super("Number Of Queries", "NoQ", "Will calculate the number of queries which could be executed successfully."); - } - - protected NoQMetric(String name, String shortName, String description){ - super(name, shortName, description); - } - - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.metrics.Metric#receiveData(java.util.Properties) - */ - @Override - public void receiveData(Properties p) { - LOGGER.debug(this.getShortName()+" has received "+p); - double time = Double.parseDouble(p.get(COMMON.RECEIVE_DATA_TIME).toString()); - Integer success = (long)p.get(COMMON.RECEIVE_DATA_SUCCESS)>0?1:0; - - Properties results = new Properties(); - results.put(TOTAL_TIME, time); - results.put(TOTAL_SUCCESS, success); - - Properties extra = getExtraMeta(p); - processData(extra, results); - } - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.metrics.Metric#close() - */ - @Override - public void close() { - callbackClose(); - super.close(); - - } - - protected void callbackClose() { - Model m = ModelFactory.createDefaultModel(); - Property property = getMetricProperty(); - long sum = 0; - for(Properties key : dataContainer.keySet()){ - Double totalTime = (Double) dataContainer.get(key).get(TOTAL_TIME); - Integer success = (Integer) dataContainer.get(key).get(TOTAL_SUCCESS); - sum+=success; - Resource subject = getSubject(key); - m.add(getConnectingStatement(subject)); - m.add(subject, property, ResourceFactory.createTypedLiteral(success)); - } - m.add(getTaskResource(), property, ResourceFactory.createTypedLiteral(sum)); - sendData(m); - } - - - -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/NoQPHMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/NoQPHMetric.java deleted file mode 100644 index ad92b92c..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/NoQPHMetric.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.AbstractMetric; -import org.apache.jena.rdf.model.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Properties; - -/** - * - * The Number Of Queries Per Hour Metric - * - * @author f.conrads - * - */ -@Shorthand("NoQPH") -public class NoQPHMetric extends AbstractMetric { - - protected static final Object TOTAL_TIME = "totalTime"; - protected static final Object TOTAL_SUCCESS = "totalSuccess"; - - - protected static Logger LOGGER = LoggerFactory.getLogger(NoQPHMetric.class); - - - protected long hourInMS = 3600000; - - - public NoQPHMetric(){ - super("Number Of Queries Per Hour", "NoQPH", "Will calculate the number of queries which could be executed successfully per Hour."); - } - - protected NoQPHMetric(String name, String shortName, String description){ - super(name, shortName, description); - } - - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.metrics.Metric#receiveData(java.util.Properties) - */ - @Override - public void receiveData(Properties p) { - LOGGER.debug(this.getShortName()+" has received "+p); - double time = Double.parseDouble(p.get(COMMON.RECEIVE_DATA_TIME).toString()); - Integer success = (long)p.get(COMMON.RECEIVE_DATA_SUCCESS)>0?1:0; - - Properties results = new Properties(); - results.put(TOTAL_TIME, time); - results.put(TOTAL_SUCCESS, success); - - Properties extra = getExtraMeta(p); - processData(extra, results); - } - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.metrics.Metric#close() - */ - @Override - public void close() { - callbackClose(); - super.close(); - - } - - protected void callbackClose() { - Model m = ModelFactory.createDefaultModel(); - Property property = getMetricProperty(); - Double sum = 0.0; - for(Properties key : dataContainer.keySet()){ - Double totalTime = (Double) dataContainer.get(key).get(TOTAL_TIME); - Integer success = (Integer) dataContainer.get(key).get(TOTAL_SUCCESS); - Double noOfQueriesPerHour = hourInMS*success*1.0/totalTime; - sum+=noOfQueriesPerHour; - Resource subject = getSubject(key); - m.add(getConnectingStatement(subject)); - m.add(subject, property, ResourceFactory.createTypedLiteral(noOfQueriesPerHour)); - } - - m.add(getTaskResource(), property, ResourceFactory.createTypedLiteral(sum)); - sendData(m); - } - - - - } diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/QMPHMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/QMPHMetric.java deleted file mode 100644 index 0c0b5a35..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/QMPHMetric.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.apache.jena.rdf.model.*; -import org.slf4j.LoggerFactory; - -import java.util.Properties; - -/** - * - * The Query Mixes Per Hour Metric - * - * @author f.conrads - * - */ -@Shorthand("QMPH") -public class QMPHMetric extends NoQPHMetric { - - public QMPHMetric(){ - super("Query Mixes Per Hour", "QMPH", "Will calculate the query mixes which could be executed successfully per Hour."); - LOGGER = LoggerFactory.getLogger(QMPHMetric.class); - } - - - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.metrics.Metric#close() - */ - @Override - public void close() { - callbackClose(); - super.close(); - } - - /** - * callback which will be called in close - */ - @Override - protected void callbackClose(){ - Model m = ModelFactory.createDefaultModel(); - Property property = getMetricProperty(); - Double sum = 0.0; - for(Properties key : dataContainer.keySet()){ - Double totalTime = (double) dataContainer.get(key).get(TOTAL_TIME); - Integer success = (Integer) dataContainer.get(key).get(TOTAL_SUCCESS); - - double noOfQueriesPerHour = hourInMS*success*1.0/totalTime; - - int noOfQueryMixes = (int) key.get(COMMON.NO_OF_QUERIES); - Double qmph=noOfQueriesPerHour*1.0/noOfQueryMixes; - - sum+=qmph; - Resource subject = getSubject(key); - m.add(getConnectingStatement(subject)); - m.add(subject, property, ResourceFactory.createTypedLiteral(qmph)); - } - m.add(getTaskResource(), property, ResourceFactory.createTypedLiteral(sum)); - sendData(m); - } -} diff --git a/src/main/java/org/aksw/iguana/rp/metrics/impl/QPSMetric.java b/src/main/java/org/aksw/iguana/rp/metrics/impl/QPSMetric.java deleted file mode 100644 index ffdb6f77..00000000 --- a/src/main/java/org/aksw/iguana/rp/metrics/impl/QPSMetric.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.AbstractMetric; -import org.apache.jena.rdf.model.*; -import org.apache.jena.vocabulary.RDF; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -/** - * Queries Per Second Metric implementation - * - * @author f.conrads - * - */ -@Shorthand("QPS") -public class QPSMetric extends AbstractMetric { - - protected static Logger LOGGER = LoggerFactory.getLogger(QPSMetric.class); - - private static Property queryProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"query"); - private static Property failProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"failed"); - private static Property succeededProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"succeeded"); - private static Property ttProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"totalTime"); - private static Property resultSize = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"resultSize"); - private static Property timeOuts = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"timeOuts"); - private static Property unknownException = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"unknownException"); - private static Property wrongCodes = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"wrongCodes"); - private static Property penalizedQPSProperty = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"penalizedQPS"); - private static Property queryID = ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"queryID"); - - protected long hourInMS = 3600000; - protected Integer penalty = null; - private boolean noPenalty= false; - - public QPSMetric() { - super( - "Queries Per Second", - "QPS", - "Will calculate for each query the amount of how many times the query could be executed succesfully in one second." - + " Further on it will save the totaltime of each query, the failure and the success"); - } - - public QPSMetric(Integer penalty) { - super( - "Queries Per Second", - "QPS", - "Will calculate for each query the amount of how many times the query could be executed succesfully in one second." - + " Further on it will save the totaltime of each query, the failure and the success"); - this.penalty = penalty; - } - - public QPSMetric(String name, String shortName, String description) { - super(name, shortName, description); - } - - @Override - public void receiveData(Properties p) { - //Save success and time of each query - LOGGER.debug(this.getShortName() + " has received " + p); - double time = Double.parseDouble(p.get(COMMON.RECEIVE_DATA_TIME).toString()); - long tmpSuccess = Long.parseLong(p.get(COMMON.RECEIVE_DATA_SUCCESS).toString()); - long success = tmpSuccess>0?1:0; - long failure = success==1?0:1; - long timeout = tmpSuccess==COMMON.QUERY_SOCKET_TIMEOUT?1:0; - long unknown = tmpSuccess==COMMON.QUERY_UNKNOWN_EXCEPTION?1:0; - long wrongCode = tmpSuccess==COMMON.QUERY_HTTP_FAILURE?1:0; - Double penalty=getPenalty(p); - - long size=-1; - double penalizedTime=getPenalizedTime(penalty, failure, time); - if(p.containsKey(COMMON.RECEIVE_DATA_SIZE)) { - size = Long.parseLong(p.get(COMMON.RECEIVE_DATA_SIZE).toString()); - } - String queryID = p.getProperty(COMMON.QUERY_ID_KEY); - int queryHash = Integer.parseInt(p.get(COMMON.QUERY_HASH).toString()); - Properties extra = getExtraMeta(p); - - Properties tmp = putResults(extra, time, success, failure, timeout, unknown, wrongCode, penalizedTime, size, queryHash, queryID); - addDataToContainer(extra, tmp); - - } - - private Properties putResults(Properties extra, double time, long success, long failure, long timeout, long unknown, long wrongCode, double penalizedTime, long size, int queryHash, String queryID) { - Properties tmp = getDataFromContainer(extra); - if(tmp!=null && tmp.containsKey(queryID)){ - Object[] oldArr = (Object[]) tmp.get(queryID); - oldArr[0] = (double) oldArr[0] + time; - oldArr[1] = (long) oldArr[1] + success; - oldArr[2] = (long) oldArr[2] + failure; - if((long)oldArr[3] map = new HashMap(); - Model m = ModelFactory.createDefaultModel(); - - for(Properties key : dataContainer.keySet()){ - Properties value = dataContainer.get(key); - Resource subjectParent = getSubject(key); - m.add(getConnectingStatement(subjectParent)); - addToModel(value, subjectParent, m, map); - } - Resource subjectParent = getTaskResource(); - addToModel( map, subjectParent, m, null); - sendData(m); - } - - private void addToModel(Map value, Resource subjectParent, Model m, Map map){ - Property qpsProperty = getMetricProperty(); - - for(Object queryID : value.keySet()){ - Object[] resArr = (Object[]) value.get(queryID); - if(map!=null) - mergeResults(map, queryID, resArr); - Double qps = (long)resArr[1]*1.0/((double)resArr[0]/1000.0); - Double pqps = (long)resArr[1]*1.0/((double)resArr[7]/1000.0); - - Resource query = ResourceFactory.createResource(subjectParent.getURI()+"/"+queryID); - m.add(subjectParent, queryProperty, query); - m.add(query, qpsProperty, ResourceFactory.createTypedLiteral(qps)); - m.add(query, ttProperty, ResourceFactory.createTypedLiteral((double)resArr[0])); - m.add(query, succeededProperty, ResourceFactory.createTypedLiteral((long)resArr[1])); - m.add(query, failProperty, ResourceFactory.createTypedLiteral((long)resArr[2])); - if((long)resArr[3]!=-1L) { - m.add(query, resultSize, ResourceFactory.createTypedLiteral((long)resArr[3])); - } - else{ - m.add(query, resultSize, ResourceFactory.createTypedLiteral("?")); - } - m.add(query, timeOuts, ResourceFactory.createTypedLiteral((long)resArr[4])); - m.add(query, unknownException, ResourceFactory.createTypedLiteral((long)resArr[5])); - m.add(query, wrongCodes, ResourceFactory.createTypedLiteral((long)resArr[6])); - if(!noPenalty) { - m.add(query, penalizedQPSProperty, ResourceFactory.createTypedLiteral(pqps)); - } - m.add(query, QPSMetric.queryID, ResourceFactory.createResource(COMMON.RES_BASE_URI+(int)resArr[8]+ "/" + queryID.toString())); - m.add(query, RDF.type, ResourceFactory.createResource(COMMON.CLASS_BASE_URI+"ExecutedQuery")); - } - } - - private void mergeResults(Map map, Object queryID, Object[] resArr) { - if(map.containsKey(queryID)){ - Object[] currentResults = (Object[])map.get(queryID); - Object[] newResults = new Object[currentResults.length]; - for(int i=0;i()); } @Test @@ -112,17 +108,17 @@ public void noDefaultTest() throws IOException { Storage s = storages.iterator().next(); assertTrue(s instanceof MockupStorage); - MetricManager metricManager = MetricManager.getInstance(); - Set metrics = metricManager.getMetrics(); + List metrics = MetricManager.getMetrics(); assertEquals(2, metrics.size()); - Set> seen = new HashSet>(); + Set> seen = new HashSet<>(); for(Metric m : metrics){ seen.add(m.getClass()); } assertEquals(2, seen.size()); - assertTrue(seen.contains(QMPHMetric.class)); - assertTrue(seen.contains(QPSMetric.class)); + // TODO: fix test + // assertTrue(seen.contains(QMPHMetric.class)); + // assertTrue(seen.contains(QPSMetric.class)); } @Test @@ -138,20 +134,21 @@ public void initTest() throws IOException { assertTrue(s instanceof NTFileStorage); File del = new File(((NTFileStorage)s).getFileName()); del.delete(); - MetricManager metricManager = MetricManager.getInstance(); - Set metrics = metricManager.getMetrics(); + + List metrics = MetricManager.getMetrics(); assertEquals(5, metrics.size()); - Set> seen = new HashSet>(); + Set> seen = new HashSet<>(); for(Metric m : metrics){ seen.add(m.getClass()); } assertEquals(5, seen.size()); - assertTrue(seen.contains(QMPHMetric.class)); - assertTrue(seen.contains(QPSMetric.class)); - assertTrue(seen.contains(AvgQPSMetric.class)); - assertTrue(seen.contains(NoQPHMetric.class)); - assertTrue(seen.contains(NoQMetric.class)); + // TODO: fix test + // assertTrue(seen.contains(QMPHMetric.class)); + // assertTrue(seen.contains(QPSMetric.class)); + // assertTrue(seen.contains(AvgQPSMetric.class)); + // assertTrue(seen.contains(NoQPHMetric.class)); + // assertTrue(seen.contains(NoQMetric.class)); } } diff --git a/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java index 1ab5b345..87e8c5d7 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java @@ -4,10 +4,6 @@ import org.aksw.iguana.cc.tasks.MockupStorage; import org.aksw.iguana.cc.worker.MockupWorker; import org.aksw.iguana.cc.worker.Worker; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.experiment.ExperimentManager; -import org.aksw.iguana.rp.metrics.MetricManager; -import org.aksw.iguana.rp.metrics.impl.EachQueryMetric; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.junit.Ignore; import org.junit.Test; @@ -42,14 +38,9 @@ private ConnectionConfig getConnection() { private void init(){ StorageManager storageManager = StorageManager.getInstance(); - MetricManager mmanger = MetricManager.getInstance(); - mmanger.addMetric(new EachQueryMetric()); - ExperimentManager rpController = ExperimentManager.getInstance(); - Properties p = new Properties(); - p.put(COMMON.RECEIVE_DATA_START_KEY, "true"); - p.put(COMMON.EXPERIMENT_TASK_ID_KEY, "1/1/1"); + // TODO: fix tests + // MetricManager.setMetrics(List.of(new EachQueryMetric())); MockupStorage storage = new MockupStorage(); - rpController.receiveData(p); storageManager.addStorage(storage); } diff --git a/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java b/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java deleted file mode 100644 index 6c09b56a..00000000 --- a/src/test/java/org/aksw/iguana/rp/metrics/impl/MetricTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.metrics.impl; - -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.metrics.Metric; -import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; -import org.aksw.iguana.rp.utils.EqualityStorage; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; - -/** - * This will do a small test with every implemented Metric - * - * @author f.conrads - * - */ -@RunWith(Parameterized.class) -public class MetricTest { - - private final Model goldenModel; - private Properties extra = new Properties(); - private Metric m; - private boolean sendPenalty; - - /** - * @return Configurations to test - */ - @Parameters - public static Collection data() { - List testConfigs = new ArrayList(); - - testConfigs.add(new Object[] { new NoQPHMetric(),"src/test/resources/nt/noqphtest.nt", false}); - testConfigs.add(new Object[] { new QPSMetric(), "src/test/resources/nt/qpstest.nt", false}); - //check if penalty will be used if send. - testConfigs.add(new Object[] { new QPSMetric(), "src/test/resources/nt/qpspenaltytest.nt", true}); - testConfigs.add(new Object[] { new QPSMetric(1000), "src/test/resources/nt/qpspenaltytest.nt", false}); - //Test if 2000 will be used instead of provided 1000 - testConfigs.add(new Object[] { new QPSMetric(2000), "src/test/resources/nt/qpspenaltytest2.nt", true}); - testConfigs.add(new Object[] { new AvgQPSMetric(), "src/test/resources/nt/avgqpstest.nt", false}); - testConfigs.add(new Object[] { new AvgQPSMetric(2000), "src/test/resources/nt/penaltyavgqpstest.nt", true}); - - testConfigs.add(new Object[] { new NoQMetric(), "src/test/resources/nt/noqtest.nt", false}); - testConfigs.add(new Object[] { new QMPHMetric(), "src/test/resources/nt/qmphtest.nt", false}); - testConfigs.add(new Object[] { new EachQueryMetric(), "src/test/resources/nt/eqtest.nt", false}); - testConfigs.add(new Object[] { new F1MeasureMetric(), "src/test/resources/nt/f1test.nt", false}); - - return testConfigs; - } - - - - public MetricTest(Metric m, String golden, boolean sendPenalty) throws FileNotFoundException { - - //meta = new Triple("1/1/1/"+extra.hashCode(), "a", "b"); - this.m = m; - this.goldenModel = ModelFactory.createDefaultModel(); - this.goldenModel.read(new FileReader(golden), null, "N-TRIPLE"); - this.sendPenalty=sendPenalty; - } - - @Test - public void modelTest(){ - Model[] data = test(m, goldenModel); - //assert equals all triples in one are the same as the other - assertEquals(data[0].size(), data[1].size()); - data[0].remove(data[1]); - //if size was the same, and after EXPECTED <- EXPECTED/ACTUAL is either 0 if EXPECTED=ACTUAL or not zero, and the size of expected is bigger than 0 - assertEquals(0, data[0].size()); - } - - - public Model[] test(Metric metric, Model golden){ - - StorageManager smanager = new StorageManager(); - EqualityStorage storage = new EqualityStorage(golden); - smanager.addStorage(storage); - metric.setStorageManager(smanager); - metric.setMetaData(createMetaData()); - Properties extraMeta = new Properties(); - extraMeta.put(COMMON.WORKER_ID, "0"); - extraMeta.put(COMMON.NO_OF_QUERIES, 2); - metric.receiveData(createData(200, "sparql1", "1123",120, 1, extraMeta)); - metric.receiveData(createData(250, "sparql2", "1125",100,1, extraMeta)); - extraMeta = new Properties(); - extraMeta.put(COMMON.WORKER_ID, "1"); - extraMeta.put(COMMON.NO_OF_QUERIES, 2); - metric.receiveData(createData(150, "sparql1", "1123", null, 1, extraMeta)); - metric.receiveData(createData(100, "sparql2", "1125",null,-2L, extraMeta)); - - metric.close(); - return new Model[]{storage.getExpectedModel(), storage.getActualModel()}; - - } - - private Properties createData(double time, String queryID, String queryHash, Integer resultSize, long success, Properties extraMeta) { - Properties p = new Properties(); - p.setProperty(COMMON.EXPERIMENT_TASK_ID_KEY, "1/1/1"); - p.put(COMMON.RECEIVE_DATA_SUCCESS, success); - p.put(COMMON.RECEIVE_DATA_TIME, time); - p.put(COMMON.QUERY_ID_KEY, queryID); - p.put(COMMON.QUERY_HASH, queryHash); - p.put(COMMON.QUERY_STRING, "SELECT * {?s ?p ?o}"); - //tp=time/5, fp=time/10, fn=8 - p.put(COMMON.DOUBLE_RAW_RESULTS, new double[]{time/5.0, time/10.0, 8}); - if(this.sendPenalty) - p.put(COMMON.PENALTY, 1000); - if(resultSize!=null) - p.put(COMMON.RECEIVE_DATA_SIZE, resultSize); - p.put(COMMON.EXTRA_META_KEY, extraMeta); - return p; - } - - private Properties createMetaData() { - Properties p = new Properties(); - p.put(COMMON.EXPERIMENT_TASK_ID_KEY, "1/1/1"); - p.setProperty(COMMON.EXPERIMENT_ID_KEY, "1/1"); - p.setProperty(COMMON.CONNECTION_ID_KEY, "virtuoso"); - p.setProperty(COMMON.SUITE_ID_KEY, "1"); - p.setProperty(COMMON.DATASET_ID_KEY, "dbpedia"); - p.put(COMMON.RECEIVE_DATA_START_KEY, "true"); - p.put(COMMON.EXTRA_META_KEY, extra); - p.put(COMMON.NO_OF_QUERIES, 2); - return p; - } -} diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java deleted file mode 100644 index e954943a..00000000 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/NTFileStorageTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.storage.impl; - -import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; -import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; -import org.apache.jena.rdf.model.*; -import org.apache.jena.vocabulary.RDFS; -import org.junit.Test; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * - * This will test the NTFileStorage in short. - * - * @author f.conrads - * - */ -public class NTFileStorageTest { - - - @Test - public void dataTest() throws IOException{ - Storage store = new NTFileStorage("results_test2.nt"); - - new File("results_test2.nt").delete(); - - Model m = ModelFactory.createDefaultModel(); - m.read(new FileReader("src/test/resources/nt/results_test1.nt"), null, "N-TRIPLE"); - - store.storeResult(m); - assertEqual("results_test2.nt","src/test/resources/nt/results_test1.nt", true); - new File("results_test2.nt").delete(); - - } - - /** - * Checks if two ntriple files are equal by loading them into a model and check if they have the same size - * and by removing the actual model from the expected, if the new size after removal equals 0 they are the same - * - * @param actualFile - * @param expectedFile - * @throws IOException - */ - public void assertEqual(String actualFile, String expectedFile, boolean ignoreDate) throws IOException{ - Model expected = ModelFactory.createDefaultModel(); - expected.read(new FileReader(expectedFile), null, "N-TRIPLE"); - Model actual = ModelFactory.createDefaultModel(); - actual.read(new FileReader(actualFile), null, "N-TRIPLE"); - assertEquals(expected.size(), actual.size()); - expected.remove(actual); - if(!ignoreDate){ - //Remove startDate as they are different, just check if actual contains a start date - Property startDate =ResourceFactory.createProperty(RDFS.getURI()+"startDate"); - assertTrue(actual.contains(null, startDate, (RDFNode)null)); - List stmts = expected.listStatements(null, startDate, (RDFNode)null).toList(); - assertEquals(1, stmts.size()); - expected.remove(stmts); - } - - assertEquals(0, expected.size()); - } -} diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java deleted file mode 100644 index f2445902..00000000 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/RDFFileStorageTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.storage.impl; - -import org.aksw.iguana.cc.tasks.stresstest.storage.impl.RDFFileStorage; -import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; -import org.apache.jena.rdf.model.*; -import org.apache.jena.riot.RDFLanguages; -import org.apache.jena.vocabulary.RDFS; -import org.junit.Test; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * - * This will test the RDFFileStorage in short. - * - * @author l.conrads - * - */ -public class RDFFileStorageTest { - - - @Test - public void dataTest() throws IOException{ - Storage store = new RDFFileStorage("results_test2.ttl"); - - new File("results_test2.ttl").delete(); - - Model m = ModelFactory.createDefaultModel(); - m.read(new FileReader("src/test/resources/nt/results_test1.nt"), null, "N-TRIPLE"); - - store.storeResult(m); - - assertEqual("results_test2.ttl","src/test/resources/nt/results_test1.nt", true); - new File("results_test2.ttl").delete(); - - } - - - /** - * Checks if two ntriple files are equal by loading them into a model and check if they have the same size - * and by removing the actual model from the expected, if the new size after removal equals 0 they are the same - * - * @param actualFile - * @param expectedFile - * @throws IOException - */ - public void assertEqual(String actualFile, String expectedFile, boolean ignoreDate) throws IOException{ - Model expected = ModelFactory.createDefaultModel(); - expected.read(new FileReader(expectedFile), null, "N-TRIPLE"); - Model actual = ModelFactory.createDefaultModel(); - actual.read(new FileReader(actualFile), null, RDFLanguages.filenameToLang(actualFile).getName()); - assertEquals(expected.size(), actual.size()); - expected.remove(actual); - if(!ignoreDate){ - //Remove startDate as they are different, just check if actual contains a start date - Property startDate =ResourceFactory.createProperty(RDFS.getURI()+"startDate"); - assertTrue(actual.contains(null, startDate, (RDFNode)null)); - List stmts = expected.listStatements(null, startDate, (RDFNode)null).toList(); - assertEquals(1, stmts.size()); - expected.remove(stmts); - } - - assertEquals(0, expected.size()); - } -} diff --git a/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java b/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java deleted file mode 100644 index 5098a658..00000000 --- a/src/test/java/org/aksw/iguana/rp/storage/impl/TriplestoreStorageTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.storage.impl; - -import org.aksw.iguana.cc.tasks.stresstest.storage.impl.TriplestoreStorage; -import org.aksw.iguana.commons.constants.COMMON; -import org.aksw.iguana.rp.utils.ServerMock; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.ResourceFactory; -import org.junit.After; -import org.junit.Test; -import org.simpleframework.http.core.ContainerServer; -import org.simpleframework.transport.connect.SocketConnection; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; - -import static org.junit.Assert.assertEquals; - -/** - * Will test if the TriplestoreStorage sends the correct INSERT command to a Mock Server - * - * @author f.conrads - * - */ -public class TriplestoreStorageTest { - - private static final int FAST_SERVER_PORT = 8023; - private ServerMock fastServerContainer; - private ContainerServer fastServer; - private SocketConnection fastConnection; - - private String metaExp = "INSERT DATA {\n" + - " .\n" + - " .\n" + - " .\n" + - " \"dbpedia\" .\n" + - " .\n" + - " \"virtuoso\" .\n" + - " .\n" + - " \"???\"^^ .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" + - "}"; - - private String dataExp = "INSERT DATA {\n"+ -" \"c\" .\n"+ -"}"; - - /** - * @throws IOException - */ - @After - public void close() throws IOException { - fastConnection.close(); - } - - /** - * @throws IOException - */ - @Test - public void dataTest() throws IOException{ - fastServerContainer = new ServerMock(); - fastServer = new ContainerServer(fastServerContainer); - fastConnection = new SocketConnection(fastServer); - SocketAddress address1 = new InetSocketAddress(FAST_SERVER_PORT); - fastConnection.connect(address1); - - String host = "http://localhost:8023"; - TriplestoreStorage store = new TriplestoreStorage(host, host); - - Model m = ModelFactory.createDefaultModel(); - m.add(ResourceFactory.createResource(COMMON.RES_BASE_URI+"a"), ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"b") , "c"); - store.storeResult(m); - assertEquals(dataExp.trim(),fastServerContainer.getActualContent().trim()); - } - -} diff --git a/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java b/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java deleted file mode 100644 index ea9f5cf9..00000000 --- a/src/test/java/org/aksw/iguana/rp/utils/EqualityStorage.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - */ -package org.aksw.iguana.rp.utils; - -import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; - -/** - * Class to help the Unit Metric Tests.
- * - * Will be initialized with an Array of Triple[]. - * It will be checked if the first received Data is equal to the first Array Object - * the second recv Data will be checked against the second Object and so on. - * - * @author f.conrads - * - */ -public class EqualityStorage implements Storage{ - - private Model expectedModel; - private Model actualModel = ModelFactory.createDefaultModel(); - - - - public EqualityStorage( Model expectedModel) { - this.expectedModel = expectedModel; - } - - - - @Override - public void storeResult(Model data) { - this.actualModel.add(data); - } - - public Model getExpectedModel(){ - return this.expectedModel; - } - - public Model getActualModel(){ - return this.actualModel; - } -} diff --git a/src/test/java/org/aksw/iguana/rp/utils/ServerMock.java b/src/test/java/org/aksw/iguana/rp/utils/ServerMock.java deleted file mode 100644 index 1db72d07..00000000 --- a/src/test/java/org/aksw/iguana/rp/utils/ServerMock.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.aksw.iguana.rp.utils; - -import org.simpleframework.http.Request; -import org.simpleframework.http.Response; -import org.simpleframework.http.Status; -import org.simpleframework.http.core.Container; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -/** - * Server Mock representing a TS - * - * @author f.conrads - * - */ -public class ServerMock implements Container { - - private static final Logger LOGGER = LoggerFactory.getLogger(ServerMock.class); - private String actualContent; - - - @Override - public void handle(Request request, Response resp) { - String content=null; - try { - content = request.getContent(); - } catch (IOException e) { - LOGGER.error("Got exception.", e); - } - this.actualContent=content; - resp.setCode(Status.OK.code); - try { - resp.getOutputStream().close(); - } catch (IOException e) { - LOGGER.error("Could not close Response Output Stream"); - } - } - - /** - * @return the actualContent - */ - public String getActualContent() { - return actualContent; - } - - /** - * @param actualContent the actualContent to set - */ - public void setActualContent(String actualContent) { - this.actualContent = actualContent; - } - -} From a104f86a9719703311f59cd0ea23544ac5f38856 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 21:35:18 +0200 Subject: [PATCH 17/36] use Optional class for nullable objects --- .../aksw/iguana/cc/model/StresstestMetadata.java | 11 ++++++----- .../iguana/cc/tasks/stresstest/Stresstest.java | 16 +++++++++------- .../stresstest/StresstestResultProcessor.java | 15 ++++++++------- .../aksw/iguana/cc/worker/AbstractWorker.java | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java b/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java index 9adbc3ae..906f5854 100644 --- a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java +++ b/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java @@ -2,6 +2,7 @@ import org.apache.jena.rdf.model.Model; +import java.util.Optional; import java.util.Set; // TODO: maybe extract parts to generic taskmetadata class @@ -11,13 +12,13 @@ public record StresstestMetadata( String taskID, String datasetID, String conID, - String conVersion, + Optional conVersion, String taskname, String classname, - double timelimit, - long noOfQueryMixes, + Optional timelimit, + Optional noOfQueryMixes, WorkerMetadata[] workers, Set queryIDs, - String simpleTriple, - Model tripleStats + Optional simpleTriple, + Optional tripleStats ) {} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index 8e89d006..07b88f11 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -57,7 +57,6 @@ public Stresstest(Integer timeLimit, List> workers, Map> workers, Integer noOfQueryMixes) { @@ -68,7 +67,6 @@ public Stresstest(List> workers, Map warmup, this.noOfQueryMixes = noOfQueryMixes.longValue(); this.workerConfig = workers; this.warmupConfig = warmup; - this.rp = new StresstestResultProcessor(this.getMetadata()); } private void initWorkers() { @@ -153,6 +151,7 @@ public void init(String[] ids, String dataset, ConnectionConfig connection, Stri initWorkers(); addMetaData(); generateTripleStats(); + this.rp = new StresstestResultProcessor(this.getMetadata()); } /* @@ -350,6 +349,7 @@ public StresstestMetadata getMetadata() { queryIDs.addAll(Arrays.asList(workerMetadata[i].queryIDs())); } + // TODO: workers might have the same queries, the following code thus adds unnecessary redundancy StringWriter sw = new StringWriter(); Model tripleStats = ModelFactory.createDefaultModel(); for (Worker worker : this.workers) { @@ -357,21 +357,23 @@ public StresstestMetadata getMetadata() { } RDFDataMgr.write(sw, tripleStats, RDFFormat.NTRIPLES); + // TODO: check for correct values + return new StresstestMetadata( suiteID, expID, taskID, datasetID, conID, - con.getVersion(), + Optional.ofNullable(con.getVersion("")), taskName, classname, - this.timeLimit, - this.noOfQueryMixes, + Optional.ofNullable(this.timeLimit), + Optional.ofNullable(this.noOfQueryMixes), workerMetadata, queryIDs, - sw.toString(), - tripleStats + Optional.ofNullable(sw.toString()), + Optional.ofNullable(tripleStats) ); } } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index cae167b8..ee5ed9a6 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -90,16 +90,17 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { m.add(datasetRes, RDFS.label, ResourceFactory.createTypedLiteral(metadata.datasetID())); m.add(datasetRes, RDF.type, IONT.dataset); m.add(taskRes, IPROP.connection, connectionRes); - m.add(taskRes, IPROP.noOfQueryMixes, ResourceFactory.createTypedLiteral(metadata.noOfQueryMixes())); + if (metadata.noOfQueryMixes().isPresent()) + m.add(taskRes, IPROP.noOfQueryMixes, ResourceFactory.createTypedLiteral(metadata.noOfQueryMixes().get())); m.add(taskRes, IPROP.noOfWorkers, ResourceFactory.createTypedLiteral(metadata.workers().length)); - m.add(taskRes, IPROP.timeLimit, ResourceFactory.createTypedLiteral(metadata.timelimit())); + if (metadata.timelimit().isPresent()) + m.add(taskRes, IPROP.timeLimit, ResourceFactory.createTypedLiteral(metadata.timelimit().get())); m.add(taskRes, RDF.type, IONT.task); // TODO: Maybe not hardcode this, instead have the classname stored inside the metadata to make this class reusable for other tasks m.add(taskRes, RDF.type, IONT.stresstest); - if (metadata.conVersion() != null) { - m.add(connectionRes, IPROP.version, ResourceFactory.createTypedLiteral(metadata.conVersion())); - } + if (metadata.conVersion().isPresent()) + m.add(connectionRes, IPROP.version, ResourceFactory.createTypedLiteral(metadata.conVersion().get())); m.add(connectionRes, RDFS.label, ResourceFactory.createTypedLiteral(metadata.conID())); m.add(connectionRes, RDF.type, IONT.connection); @@ -113,8 +114,8 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { m.add(workerRes, RDF.type, IONT.worker); } - if (metadata.tripleStats() != null) { - m.add(metadata.tripleStats()); + if (metadata.tripleStats().isPresent()) { + m.add(metadata.tripleStats().get()); // Connect task and workers to the Query objects, that store the triple stats. // TODO: should be reworked soon after fixing triple stat generation for (WorkerMetadata worker : metadata.workers()) { diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index 9b5729e3..eb936527 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -280,7 +280,7 @@ public WorkerMetadata getMetadata() { return new WorkerMetadata( this.workerID, this.workerType, - (double) this.extra.get(CONSTANTS.WORKER_TIMEOUT_MS), + this.timeOut, this.queryHandler.getQueryCount(), this.queryHandler.hashCode(), this.queryHandler.getAllQueryIds() From 60d3a75de6cf02e430a65401b841a34bd0a08eec Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Sat, 1 Jul 2023 21:58:30 +0200 Subject: [PATCH 18/36] bring back accidentally removed test classes --- .../org/aksw/iguana/cc/tasks/ServerMock.java | 55 ++++++++++++ .../tasks/storage/impl/NTFileStorageTest.java | 71 ++++++++++++++++ .../storage/impl/RDFFileStorageTest.java | 74 ++++++++++++++++ .../storage/impl/TriplestoreStorageTest.java | 84 +++++++++++++++++++ 4 files changed, 284 insertions(+) create mode 100644 src/test/java/org/aksw/iguana/cc/tasks/ServerMock.java create mode 100644 src/test/java/org/aksw/iguana/cc/tasks/storage/impl/NTFileStorageTest.java create mode 100644 src/test/java/org/aksw/iguana/cc/tasks/storage/impl/RDFFileStorageTest.java create mode 100644 src/test/java/org/aksw/iguana/cc/tasks/storage/impl/TriplestoreStorageTest.java diff --git a/src/test/java/org/aksw/iguana/cc/tasks/ServerMock.java b/src/test/java/org/aksw/iguana/cc/tasks/ServerMock.java new file mode 100644 index 00000000..b70b0d4a --- /dev/null +++ b/src/test/java/org/aksw/iguana/cc/tasks/ServerMock.java @@ -0,0 +1,55 @@ +package org.aksw.iguana.cc.tasks; + +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; +import org.simpleframework.http.Status; +import org.simpleframework.http.core.Container; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * Server Mock representing a TS + * + * @author f.conrads + * + */ +public class ServerMock implements Container { + + private static final Logger LOGGER = LoggerFactory.getLogger(ServerMock.class); + private String actualContent; + + + @Override + public void handle(Request request, Response resp) { + String content=null; + try { + content = request.getContent(); + } catch (IOException e) { + LOGGER.error("Got exception.", e); + } + this.actualContent=content; + resp.setCode(Status.OK.code); + try { + resp.getOutputStream().close(); + } catch (IOException e) { + LOGGER.error("Could not close Response Output Stream"); + } + } + + /** + * @return the actualContent + */ + public String getActualContent() { + return actualContent; + } + + /** + * @param actualContent the actualContent to set + */ + public void setActualContent(String actualContent) { + this.actualContent = actualContent; + } + +} diff --git a/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/NTFileStorageTest.java b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/NTFileStorageTest.java new file mode 100644 index 00000000..79739c6a --- /dev/null +++ b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/NTFileStorageTest.java @@ -0,0 +1,71 @@ +/** + * + */ +package org.aksw.iguana.cc.tasks.storage.impl; + +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; +import org.apache.jena.rdf.model.*; +import org.apache.jena.vocabulary.RDFS; +import org.junit.Test; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + * This will test the NTFileStorage in short. + * + * @author f.conrads + * + */ +public class NTFileStorageTest { + + + @Test + public void dataTest() throws IOException{ + Storage store = new NTFileStorage("results_test2.nt"); + + new File("results_test2.nt").delete(); + + Model m = ModelFactory.createDefaultModel(); + m.read(new FileReader("src/test/resources/nt/results_test1.nt"), null, "N-TRIPLE"); + + store.storeResult(m); + assertEqual("results_test2.nt","src/test/resources/nt/results_test1.nt", true); + new File("results_test2.nt").delete(); + + } + + /** + * Checks if two ntriple files are equal by loading them into a model and check if they have the same size + * and by removing the actual model from the expected, if the new size after removal equals 0 they are the same + * + * @param actualFile + * @param expectedFile + * @throws IOException + */ + public void assertEqual(String actualFile, String expectedFile, boolean ignoreDate) throws IOException{ + Model expected = ModelFactory.createDefaultModel(); + expected.read(new FileReader(expectedFile), null, "N-TRIPLE"); + Model actual = ModelFactory.createDefaultModel(); + actual.read(new FileReader(actualFile), null, "N-TRIPLE"); + assertEquals(expected.size(), actual.size()); + expected.remove(actual); + if(!ignoreDate){ + //Remove startDate as they are different, just check if actual contains a start date + Property startDate =ResourceFactory.createProperty(RDFS.getURI()+"startDate"); + assertTrue(actual.contains(null, startDate, (RDFNode)null)); + List stmts = expected.listStatements(null, startDate, (RDFNode)null).toList(); + assertEquals(1, stmts.size()); + expected.remove(stmts); + } + + assertEquals(0, expected.size()); + } +} diff --git a/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/RDFFileStorageTest.java b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/RDFFileStorageTest.java new file mode 100644 index 00000000..757d0e6a --- /dev/null +++ b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/RDFFileStorageTest.java @@ -0,0 +1,74 @@ +/** + * + */ +package org.aksw.iguana.cc.tasks.storage.impl; + +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.RDFFileStorage; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; +import org.apache.jena.rdf.model.*; +import org.apache.jena.riot.RDFLanguages; +import org.apache.jena.vocabulary.RDFS; +import org.junit.Test; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + * This will test the RDFFileStorage in short. + * + * @author l.conrads + * + */ +public class RDFFileStorageTest { + + + @Test + public void dataTest() throws IOException{ + Storage store = new RDFFileStorage("results_test2.ttl"); + + new File("results_test2.ttl").delete(); + + Model m = ModelFactory.createDefaultModel(); + m.read(new FileReader("src/test/resources/nt/results_test1.nt"), null, "N-TRIPLE"); + + store.storeResult(m); + + assertEqual("results_test2.ttl","src/test/resources/nt/results_test1.nt", true); + new File("results_test2.ttl").delete(); + + } + + + /** + * Checks if two ntriple files are equal by loading them into a model and check if they have the same size + * and by removing the actual model from the expected, if the new size after removal equals 0 they are the same + * + * @param actualFile + * @param expectedFile + * @throws IOException + */ + public void assertEqual(String actualFile, String expectedFile, boolean ignoreDate) throws IOException{ + Model expected = ModelFactory.createDefaultModel(); + expected.read(new FileReader(expectedFile), null, "N-TRIPLE"); + Model actual = ModelFactory.createDefaultModel(); + actual.read(new FileReader(actualFile), null, RDFLanguages.filenameToLang(actualFile).getName()); + assertEquals(expected.size(), actual.size()); + expected.remove(actual); + if(!ignoreDate){ + //Remove startDate as they are different, just check if actual contains a start date + Property startDate =ResourceFactory.createProperty(RDFS.getURI()+"startDate"); + assertTrue(actual.contains(null, startDate, (RDFNode)null)); + List stmts = expected.listStatements(null, startDate, (RDFNode)null).toList(); + assertEquals(1, stmts.size()); + expected.remove(stmts); + } + + assertEquals(0, expected.size()); + } +} diff --git a/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/TriplestoreStorageTest.java b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/TriplestoreStorageTest.java new file mode 100644 index 00000000..c1d883f8 --- /dev/null +++ b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/TriplestoreStorageTest.java @@ -0,0 +1,84 @@ +/** + * + */ +package org.aksw.iguana.cc.tasks.storage.impl; + +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.TriplestoreStorage; +import org.aksw.iguana.commons.constants.COMMON; +import org.aksw.iguana.cc.tasks.ServerMock; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.ResourceFactory; +import org.junit.After; +import org.junit.Test; +import org.simpleframework.http.core.ContainerServer; +import org.simpleframework.transport.connect.SocketConnection; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +import static org.junit.Assert.assertEquals; + +/** + * Will test if the TriplestoreStorage sends the correct INSERT command to a Mock Server + * + * @author f.conrads + * + */ +public class TriplestoreStorageTest { + + private static final int FAST_SERVER_PORT = 8023; + private ServerMock fastServerContainer; + private ContainerServer fastServer; + private SocketConnection fastConnection; + + private String metaExp = "INSERT DATA {\n" + + " .\n" + + " .\n" + + " .\n" + + " \"dbpedia\" .\n" + + " .\n" + + " \"virtuoso\" .\n" + + " .\n" + + " \"???\"^^ .\n" + + " .\n" + + " .\n" + + " .\n" + + " .\n" + + " .\n" + + "}"; + + private String dataExp = "INSERT DATA {\n"+ +" \"c\" .\n"+ +"}"; + + /** + * @throws IOException + */ + @After + public void close() throws IOException { + fastConnection.close(); + } + + /** + * @throws IOException + */ + @Test + public void dataTest() throws IOException{ + fastServerContainer = new ServerMock(); + fastServer = new ContainerServer(fastServerContainer); + fastConnection = new SocketConnection(fastServer); + SocketAddress address1 = new InetSocketAddress(FAST_SERVER_PORT); + fastConnection.connect(address1); + + String host = "http://localhost:8023"; + TriplestoreStorage store = new TriplestoreStorage(host, host); + + Model m = ModelFactory.createDefaultModel(); + m.add(ResourceFactory.createResource(COMMON.RES_BASE_URI+"a"), ResourceFactory.createProperty(COMMON.PROP_BASE_URI+"b") , "c"); + store.storeResult(m); + assertEquals(dataExp.trim(),fastServerContainer.getActualContent().trim()); + } + +} From e1a97499fef28d6972214d8627f6a68758f05abf Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Tue, 4 Jul 2023 19:03:52 +0200 Subject: [PATCH 19/36] implement metrics --- .../stresstest/StresstestResultProcessor.java | 2 - .../metrics/ModelWritingMetric.java | 5 +- .../metrics/impl/AggregatedStatistics.java | 100 ++++++++++++++++++ .../tasks/stresstest/metrics/impl/AvgQPS.java | 51 +++++++++ .../metrics/impl/EachQueryExecution.java | 52 +++++++++ .../cc/tasks/stresstest/metrics/impl/NoQ.java | 43 ++++++++ .../tasks/stresstest/metrics/impl/NoQPH.java | 53 ++++++++++ .../stresstest/metrics/impl/PAvgQPS.java | 56 ++++++++++ .../tasks/stresstest/metrics/impl/PQPS.java | 45 ++++++++ .../tasks/stresstest/metrics/impl/QMPH.java | 54 ++++++++++ .../cc/tasks/stresstest/metrics/impl/QPS.java | 39 +++++++ .../org/aksw/iguana/commons/rdf/IRES.java | 6 ++ 12 files changed, 502 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QPS.java diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index ee5ed9a6..aecf6a6c 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -117,7 +117,6 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { if (metadata.tripleStats().isPresent()) { m.add(metadata.tripleStats().get()); // Connect task and workers to the Query objects, that store the triple stats. - // TODO: should be reworked soon after fixing triple stat generation for (WorkerMetadata worker : metadata.workers()) { for (String queryID : worker.queryIDs()) { Resource workerQueryRes = IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), queryID); @@ -176,7 +175,6 @@ private Model createMetricModel(Metric metric) { if (metric instanceof ModelWritingMetric) { m.add(((ModelWritingMetric) metric).createMetricModel(metadata, queryExecutions)); m.add(((ModelWritingMetric) metric).createMetricModel(metadata, ab)); - return m; } if (metric instanceof TaskMetric) { diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java index 8de0cb64..9f02796e 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java @@ -12,8 +12,9 @@ public interface ModelWritingMetric { default @Nonnull Model createMetricModel(StresstestMetadata task, List[][] data) { return ModelFactory.createDefaultModel(); - }; + } + default @Nonnull Model createMetricModel(StresstestMetadata task, Map> data) { return ModelFactory.createDefaultModel(); - }; + } } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java new file mode 100644 index 00000000..c2a9027f --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java @@ -0,0 +1,100 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.ModelWritingMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; +import org.aksw.iguana.commons.rdf.IRES; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.vocabulary.RDF; + +import javax.annotation.Nonnull; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.time.Duration; +import java.util.List; +import java.util.Map; + +@Shorthand("ExecutedQuery") +public class AggregatedStatistics extends Metric implements ModelWritingMetric { + + public AggregatedStatistics() { + super("Aggregated Execution Statistics", "", "Sums up the statistics of each query execution for each query a worker and task has. The result size only contains the value of the last execution."); + } + + @Override + @Nonnull + public Model createMetricModel(StresstestMetadata task, List[][] data) { + Model m = ModelFactory.createDefaultModel(); + for (WorkerMetadata worker : task.workers()) { + for (int i = 0; i < worker.numberOfQueries(); i++) { + Resource queryRes = IRES.getWorkerQueryResource(task.taskID(), worker.workerID(), worker.queryIDs()[i]); + m.add(createExecutedQuery(data[worker.workerID()][i], queryRes)); + } + } + return m; + } + + @Override + @Nonnull + public Model createMetricModel(StresstestMetadata task, Map> data) { + Model m = ModelFactory.createDefaultModel(); + for (String queryID : data.keySet()) { + Resource queryRes = IRES.getTaskQueryResource(task.taskID(), queryID); + m.add(createExecutedQuery(data.get(queryID), queryRes)); + } + return m; + } + + private static Model createExecutedQuery(List data, Resource queryRes) { + Model m = ModelFactory.createDefaultModel(); + BigInteger succeeded = BigInteger.ZERO; + BigInteger failed = BigInteger.ZERO; + BigInteger resultSize = BigInteger.ZERO; + BigInteger wrongCodes = BigInteger.ZERO; + BigInteger timeOuts = BigInteger.ZERO; + BigInteger unknownExceptions = BigInteger.ZERO; + Duration totalTime = Duration.ZERO; + + for (QueryExecutionStats exec : data) { + // TODO: make response code integer + switch ((int) exec.responseCode()) { + case (int) COMMON.QUERY_SUCCESS -> succeeded = succeeded.add(BigInteger.ONE); + case (int) COMMON.QUERY_SOCKET_TIMEOUT -> { + timeOuts = timeOuts.add(BigInteger.ONE); + failed = failed.add(BigInteger.ONE); + } + case (int) COMMON.QUERY_HTTP_FAILURE -> { + wrongCodes = wrongCodes.add(BigInteger.ONE); + failed = failed.add(BigInteger.ONE); + } + case (int) COMMON.QUERY_UNKNOWN_EXCEPTION -> { + unknownExceptions = unknownExceptions.add(BigInteger.ONE); + failed = failed.add(BigInteger.ONE); + } + } + + totalTime = totalTime.plusNanos((long) (exec.executionTime() * 1000000)); + resultSize = BigInteger.valueOf(exec.resultSize()); + } + + m.add(queryRes, IPROP.succeeded, ResourceFactory.createTypedLiteral(succeeded)); + m.add(queryRes, IPROP.failed, ResourceFactory.createTypedLiteral(failed)); + m.add(queryRes, IPROP.resultSize, ResourceFactory.createTypedLiteral(resultSize)); + m.add(queryRes, IPROP.timeOuts, ResourceFactory.createTypedLiteral(timeOuts)); + m.add(queryRes, IPROP.wrongCodes, ResourceFactory.createTypedLiteral(wrongCodes)); + m.add(queryRes, IPROP.unknownException, ResourceFactory.createTypedLiteral(unknownExceptions)); + m.add(queryRes, IPROP.totalTime, ResourceFactory.createTypedLiteral(new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 6))); + m.add(queryRes, RDF.type, IONT.executedQuery); + + return m; + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java new file mode 100644 index 00000000..032e50d0 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java @@ -0,0 +1,51 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; +import org.aksw.iguana.commons.annotation.Shorthand; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; + +@Shorthand("AvgQPS") +public class AvgQPS extends Metric implements TaskMetric, WorkerMetric { + + public AvgQPS() { + super("Average Queries per Second", "AvgQPS", "This metric calculates the average QPS between all queries."); + } + + // TODO: check if this is correct + @Override + public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { + BigDecimal sum = BigDecimal.ZERO; + for (WorkerMetadata worker : task.workers()) { + sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker, data[worker.workerID()])); + } + + try { + return sum.divide(BigDecimal.valueOf(data.length), 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } + + @Override + public Number calculateWorkerMetric(WorkerMetadata worker, List[] data) { + BigDecimal sum = BigDecimal.ZERO; + QPS qpsmetric = new QPS(); + for (List datum : data) { + sum = sum.add((BigDecimal) qpsmetric.calculateQueryMetric(datum)); + } + + try { + return sum.divide(BigDecimal.valueOf(data.length), 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java new file mode 100644 index 00000000..bddef57a --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java @@ -0,0 +1,52 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.ModelWritingMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; +import org.aksw.iguana.commons.rdf.IPROP; +import org.aksw.iguana.commons.rdf.IRES; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; + +import javax.annotation.Nonnull; +import java.math.BigInteger; +import java.util.List; + +@Shorthand("EachQuery") +public class EachQueryExecution extends Metric implements ModelWritingMetric { + + public EachQueryExecution() { + super("Each Query Execution", "EachQuery", "This metric saves the statistics of each query execution."); + } + + @Override + @Nonnull + public Model createMetricModel(StresstestMetadata task, List[][] data) { + Model m = ModelFactory.createDefaultModel(); + for (WorkerMetadata worker : task.workers()) { + for (int i = 0; i < worker.numberOfQueries(); i++) { + Resource queryRes = IRES.getWorkerQueryResource(task.taskID(), worker.workerID(), worker.queryIDs()[i]); + Resource query = IRES.getResource(worker.queryHash() + "/" + worker.queryIDs()[i]); + BigInteger run = BigInteger.ONE; + for (QueryExecutionStats exec : data[worker.workerID()][i]) { + Resource runRes = IRES.getWorkerQueryRunResource(task.taskID(), worker.workerID(), worker.queryIDs()[i], run); + m.add(queryRes, IPROP.queryExecution, runRes); + m.add(runRes, IPROP.time, ResourceFactory.createTypedLiteral(exec.executionTime())); + m.add(runRes, IPROP.success, ResourceFactory.createTypedLiteral(exec.responseCode() == COMMON.QUERY_SUCCESS)); + m.add(runRes, IPROP.run, ResourceFactory.createTypedLiteral(run)); + m.add(runRes, IPROP.code, ResourceFactory.createTypedLiteral(exec.responseCode())); + m.add(runRes, IPROP.resultSize, ResourceFactory.createTypedLiteral(exec.resultSize())); + m.add(runRes, IPROP.queryID, query); + run = run.add(BigInteger.ONE); + } + } + } + return m; + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java new file mode 100644 index 00000000..8fc64d83 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java @@ -0,0 +1,43 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; + +import java.math.BigInteger; +import java.util.List; + +@Shorthand("NoQ") +public class NoQ extends Metric implements TaskMetric, WorkerMetric { + + public NoQ() { + super("Number of Queries", "NoQ", "This metric calculates the number of successfully executed queries."); + } + + @Override + public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { + BigInteger sum = BigInteger.ZERO; + for (WorkerMetadata worker : task.workers()) { + sum = sum.add((BigInteger) this.calculateWorkerMetric(worker, data[worker.workerID()])); + } + return sum; + } + + @Override + public Number calculateWorkerMetric(WorkerMetadata worker, List[] data) { + BigInteger sum = BigInteger.ZERO; + for (List datum : data) { + for (QueryExecutionStats exec : datum) { + if (exec.responseCode() == COMMON.QUERY_SUCCESS) { + sum = sum.add(BigInteger.ONE); + } + } + } + return sum; + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java new file mode 100644 index 00000000..bba17643 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java @@ -0,0 +1,53 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.time.Duration; +import java.util.List; + +@Shorthand("NoQPH") +public class NoQPH extends Metric implements TaskMetric, WorkerMetric { + + public NoQPH() { + super("Number of Queries per Hour", "NoQPH", "This metric calculates the number of successfully executed queries per hour."); + } + @Override + public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { + BigDecimal sum = BigDecimal.ZERO; + for (WorkerMetadata worker : task.workers()) { + sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker, data[worker.workerID()])); + } + return sum; + } + + @Override + public Number calculateWorkerMetric(WorkerMetadata worker, List[] data) { + BigDecimal successes = BigDecimal.ZERO; + Duration totalTime = Duration.ZERO; + for (List datum : data) { + for (QueryExecutionStats exec : datum) { + if (exec.responseCode() == COMMON.QUERY_SUCCESS) { + successes = successes.add(BigDecimal.ONE); + totalTime = totalTime.plusNanos((long) exec.executionTime() * 1000000); + } + } + } + BigDecimal tt = (new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 9)).divide(BigDecimal.valueOf(3600), 20, RoundingMode.HALF_UP); + + try { + return successes.divide(tt, 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java new file mode 100644 index 00000000..4441ca30 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java @@ -0,0 +1,56 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; +import org.aksw.iguana.commons.annotation.Shorthand; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; + +@Shorthand("PAvgQPS") +public class PAvgQPS extends Metric implements TaskMetric, WorkerMetric { + + private final long penalty; + + public PAvgQPS(long penalty) { + super("Penalized Average Queries per Second", "AvgQPS", "This metric calculates the average QPS between all queries. Failed executions receive a time penalty."); + this.penalty = penalty; + } + + @Override + public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { + BigDecimal sum = BigDecimal.ZERO; + for (WorkerMetadata worker : task.workers()) { + sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker, data[worker.workerID()])); + } + + try { + return sum.divide(BigDecimal.valueOf(data.length), 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } + + @Override + public Number calculateWorkerMetric(WorkerMetadata worker, List[] data) { + BigDecimal sum = BigDecimal.ZERO; + PQPS pqpsmetric = new PQPS(penalty); + for (List datum : data) { + sum = sum.add((BigDecimal) pqpsmetric.calculateQueryMetric(datum)); + } + if (data.length == 0) { + return BigDecimal.ZERO; + } + + try { + return sum.divide(BigDecimal.valueOf(data.length), 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java new file mode 100644 index 00000000..09d92675 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java @@ -0,0 +1,45 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.QueryMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.time.Duration; +import java.util.List; + +@Shorthand("PQPS") +public class PQPS extends Metric implements QueryMetric { + + private final long penalty; + + public PQPS(long penalty) { + super("Penalized Queries per Second", "PQPS", "This metric calculates for each query the amount of executions per second. Failed executions receive a time penalty."); + this.penalty = penalty; + } + + @Override + public Number calculateQueryMetric(List data) { + BigDecimal successes = BigDecimal.ZERO; + Duration totalTime = Duration.ZERO; + for (QueryExecutionStats exec : data) { + successes = successes.add(BigDecimal.ONE); + if (exec.responseCode() == COMMON.QUERY_SUCCESS) { + totalTime = totalTime.plusNanos((long) exec.executionTime() * 1000000); + } else { + totalTime = totalTime.plusMillis(penalty); + } + } + BigDecimal tt = (new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 9)); + + try { + return successes.divide(tt, 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java new file mode 100644 index 00000000..4b624541 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java @@ -0,0 +1,54 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.time.Duration; +import java.util.List; + +@Shorthand("QMPH") +public class QMPH extends Metric implements TaskMetric, WorkerMetric { + + public QMPH() { + super("Query Mixes per Hour", "QMPH", "This metric calculates the amount of query mixes (a given set of queries) that are executed per hour."); + } + @Override + public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { + BigDecimal sum = BigDecimal.ZERO; + for (WorkerMetadata worker : task.workers()) { + sum = sum.add((BigDecimal) this.calculateWorkerMetric(worker, data[worker.workerID()])); + } + return sum; + } + + @Override + public Number calculateWorkerMetric(WorkerMetadata worker, List[] data) { + BigDecimal successes = BigDecimal.ZERO; + BigDecimal noq = BigDecimal.valueOf(worker.numberOfQueries()); + Duration totalTime = Duration.ZERO; + for (List datum : data) { + for (QueryExecutionStats exec : datum) { + if (exec.responseCode() == COMMON.QUERY_SUCCESS) { + successes = successes.add(BigDecimal.ONE); + totalTime = totalTime.plusNanos((long) exec.executionTime() * 1000000); + } + } + } + BigDecimal tt = (new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 9)).divide(BigDecimal.valueOf(3600), 20, RoundingMode.HALF_UP); + + try { + return successes.divide(tt, 10, RoundingMode.HALF_UP).divide(noq, 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } +} diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QPS.java new file mode 100644 index 00000000..888c7bb4 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QPS.java @@ -0,0 +1,39 @@ +package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; + +import org.aksw.iguana.cc.model.QueryExecutionStats; +import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; +import org.aksw.iguana.cc.tasks.stresstest.metrics.QueryMetric; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.constants.COMMON; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.time.Duration; +import java.util.List; + +@Shorthand("QPS") +public class QPS extends Metric implements QueryMetric { + + public QPS() { + super("Queries per Second", "QPS", "This metric calculates for each query the amount of executions per second."); + } + + @Override + public Number calculateQueryMetric(List data) { + BigDecimal successes = BigDecimal.ZERO; + Duration totalTime = Duration.ZERO; + for (QueryExecutionStats exec : data) { + if (exec.responseCode() == COMMON.QUERY_SUCCESS) { + successes = successes.add(BigDecimal.ONE); + totalTime = totalTime.plusNanos((long) exec.executionTime() * 1000000); + } + } + BigDecimal tt = (new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 9)); + try { + return successes.divide(tt, 10, RoundingMode.HALF_UP); + } catch (ArithmeticException e) { + return BigDecimal.ZERO; + } + } +} diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IRES.java b/src/main/java/org/aksw/iguana/commons/rdf/IRES.java index 0e0ad18f..f98f5f25 100644 --- a/src/main/java/org/aksw/iguana/commons/rdf/IRES.java +++ b/src/main/java/org/aksw/iguana/commons/rdf/IRES.java @@ -4,6 +4,8 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.ResourceFactory; +import java.math.BigInteger; + public class IRES { public static final String NS = IGUANA_BASE.NS + "resource" + "/"; public static final String PREFIX = "ires"; @@ -38,4 +40,8 @@ public static Resource getWorkerQueryResource(String taskID, int workerID, Strin public static Resource getMetricResource(Metric metric) { return ResourceFactory.createResource(NS + metric.getAbbreviation()); } + + public static Resource getWorkerQueryRunResource(String taskID, int workerID, String queryID, BigInteger run) { + return ResourceFactory.createResource(NS + taskID + "/" + "workerID" + "/" + queryID + "/" + run); + } } From 01ec1a613af2a75b0f174507027d882756c88c65 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:17:14 +0200 Subject: [PATCH 20/36] remove unused code --- .../aksw/iguana/cc/tasks/AbstractTask.java | 40 +------------------ .../cc/tasks/stresstest/Stresstest.java | 17 +------- .../storage/impl/NTFileStorage.java | 3 -- .../storage/impl/TriplestoreStorage.java | 5 +-- .../aksw/iguana/cc/worker/AbstractWorker.java | 9 ----- 5 files changed, 5 insertions(+), 69 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java index 713324d2..ae9de8d4 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/AbstractTask.java @@ -4,12 +4,6 @@ package org.aksw.iguana.cc.tasks; import org.aksw.iguana.cc.config.elements.ConnectionConfig; -import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; import java.util.Properties; /** @@ -21,16 +15,9 @@ */ public abstract class AbstractTask implements Task { - private Logger LOGGER = LoggerFactory.getLogger(getClass()); - protected String taskID; protected ConnectionConfig con; - /** - * Properties to add task specific metaData before start and execute which then - * will be send to the resultprocessor - */ - protected Properties metaData = new Properties(); protected String expID; protected String suiteID; protected String datasetID; @@ -65,35 +52,12 @@ public void init(String[] ids, String dataset, ConnectionConfig con, String task public void start() {} @Override - public void sendResults(Properties data) throws IOException {} + public void sendResults(Properties data) {} @Override public void close() {} @Override - public void addMetaData() { - // set exp Task ID - metaData.setProperty(COMMON.EXPERIMENT_TASK_ID_KEY, this.taskID); - // set start flag - metaData.put(COMMON.RECEIVE_DATA_START_KEY, true); - // - metaData.setProperty(COMMON.EXPERIMENT_ID_KEY, this.expID); - metaData.setProperty(COMMON.SUITE_ID_KEY, this.suiteID); - metaData.setProperty(COMMON.DATASET_ID_KEY, this.datasetID); - metaData.setProperty(COMMON.CONNECTION_ID_KEY, this.conID); - if(this.taskName!=null) { - metaData.setProperty(COMMON.EXPERIMENT_TASK_NAME_KEY, this.taskName); - } - if(this.con.getVersion()!=null) { - metaData.setProperty(COMMON.CONNECTION_VERSION_KEY, this.con.getVersion()); - } - String className=this.getClass().getCanonicalName(); - if(this.getClass().isAnnotationPresent(Shorthand.class)){ - className = this.getClass().getAnnotation(Shorthand.class).value(); - } - metaData.setProperty(COMMON.EXPERIMENT_TASK_CLASS_ID_KEY, className); - this.metaData.put(COMMON.EXTRA_META_KEY, new Properties()); - } - + public void addMetaData() {} } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index 07b88f11..c2944db2 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -1,6 +1,5 @@ package org.aksw.iguana.cc.tasks.stresstest; -import org.aksw.iguana.cc.config.CONSTANTS; import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.model.StresstestMetadata; @@ -9,7 +8,6 @@ import org.aksw.iguana.cc.worker.Worker; import org.aksw.iguana.cc.worker.WorkerFactory; import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.riot.RDFDataMgr; @@ -124,24 +122,13 @@ public void generateTripleStats() { tripleStats.add(worker.getQueryHandler().getTripleStats(this.taskID)); } RDFDataMgr.write(sw, tripleStats, RDFFormat.NTRIPLES); - this.metaData.put(COMMON.SIMPLE_TRIPLE_KEY, sw.toString()); - this.metaData.put(COMMON.QUERY_STATS, tripleStats); } /** * Add extra Meta Data */ @Override - public void addMetaData() { - super.addMetaData(); - Properties extraMeta = new Properties(); - if (this.timeLimit != null) - extraMeta.put(CONSTANTS.TIME_LIMIT, this.timeLimit); - if (this.noOfQueryMixes != null) - extraMeta.put(CONSTANTS.NO_OF_QUERY_MIXES, this.noOfQueryMixes); - extraMeta.put("noOfWorkers", this.workers.size()); - this.metaData.put(COMMON.EXTRA_META_KEY, extraMeta); - } + public void addMetaData() {} @Override @@ -373,7 +360,7 @@ public StresstestMetadata getMetadata() { workerMetadata, queryIDs, Optional.ofNullable(sw.toString()), - Optional.ofNullable(tripleStats) + Optional.of(tripleStats) ); } } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java index 9bb4d9be..cd94e3e1 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/NTFileStorage.java @@ -60,9 +60,6 @@ public NTFileStorage(String fileName) { this.file = new StringBuilder(fileName); } - /* (non-Javadoc) - * @see org.aksw.iguana.rp.storage.Storage#commit() - */ @Override public void storeResult(Model data) { super.storeResult(data); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java index be9bad95..3623fc39 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/TriplestoreStorage.java @@ -63,10 +63,7 @@ public TriplestoreStorage(String endpoint, String updateEndpoint){ this.endpoint=endpoint; this.updateEndpoint=updateEndpoint; } - - /* (non-Javadoc) - * @see org.aksw.iguana.rp.storage.Storage#commit() - */ + @Override public void storeResult(Model data) { super.storeResult(data); diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index eb936527..ed59b357 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -1,13 +1,11 @@ package org.aksw.iguana.cc.worker; -import org.aksw.iguana.cc.config.CONSTANTS; import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; -import org.aksw.iguana.commons.constants.COMMON; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -63,7 +61,6 @@ public abstract class AbstractWorker implements Worker { protected boolean endSignal = false; protected long executedQueries; - protected Properties extra = new Properties(); protected Instant startTime; protected ConnectionConfig con; protected int queryHash; @@ -106,12 +103,6 @@ public void waitTimeMs() { * send it if not aborted yet to the ResultProcessor Module */ public void startWorker() { - // set extra meta key to send late - this.extra = new Properties(); - this.extra.put(CONSTANTS.WORKER_ID_KEY, this.workerID); - this.extra.setProperty(CONSTANTS.WORKER_TYPE_KEY, this.workerType); - this.extra.put(CONSTANTS.WORKER_TIMEOUT_MS, this.timeOut); - this.extra.put(COMMON.NO_OF_QUERIES, this.queryHandler.getQueryCount()); // For Update and Logging purpose get startTime of Worker this.startTime = Instant.now(); From 6c74a9f1d62fba8661c6b98b45e7eb1b0a3b442f Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:35:56 +0200 Subject: [PATCH 21/36] move classes --- .../java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java | 4 ++-- .../cc/{model => tasks/stresstest}/StresstestMetadata.java | 3 ++- .../cc/tasks/stresstest/StresstestResultProcessor.java | 3 +-- .../cc/tasks/stresstest/metrics/ModelWritingMetric.java | 2 +- .../aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java | 2 +- .../iguana/cc/tasks/stresstest/metrics/WorkerMetric.java | 2 +- .../tasks/stresstest/metrics/impl/AggregatedStatistics.java | 4 ++-- .../aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java | 5 ++--- .../cc/tasks/stresstest/metrics/impl/EachQueryExecution.java | 4 ++-- .../aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java | 4 ++-- .../aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java | 4 ++-- .../iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java | 4 ++-- .../aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java | 4 ++-- src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java | 1 - src/main/java/org/aksw/iguana/cc/worker/Worker.java | 1 - .../org/aksw/iguana/cc/{model => worker}/WorkerMetadata.java | 2 +- 16 files changed, 23 insertions(+), 26 deletions(-) rename src/main/java/org/aksw/iguana/cc/{model => tasks/stresstest}/StresstestMetadata.java (86%) rename src/main/java/org/aksw/iguana/cc/{model => worker}/WorkerMetadata.java (84%) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index c2944db2..7223321c 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -2,8 +2,7 @@ import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.AbstractTask; import org.aksw.iguana.cc.worker.Worker; import org.aksw.iguana.cc.worker.WorkerFactory; @@ -337,6 +336,7 @@ public StresstestMetadata getMetadata() { } // TODO: workers might have the same queries, the following code thus adds unnecessary redundancy + // TODO: is sw used for anything? StringWriter sw = new StringWriter(); Model tripleStats = ModelFactory.createDefaultModel(); for (Worker worker : this.workers) { diff --git a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java similarity index 86% rename from src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java index 906f5854..7df35085 100644 --- a/src/main/java/org/aksw/iguana/cc/model/StresstestMetadata.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java @@ -1,5 +1,6 @@ -package org.aksw.iguana.cc.model; +package org.aksw.iguana.cc.tasks.stresstest; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.apache.jena.rdf.model.Model; import java.util.Optional; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index aecf6a6c..29d6a13e 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -1,8 +1,7 @@ package org.aksw.iguana.cc.tasks.stresstest; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.*; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.commons.rdf.IONT; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java index 9f02796e..bbce4aa4 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/ModelWritingMetric.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java index 7a360478..6995f24d 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/TaskMetric.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; import java.util.List; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java index 20373259..bc81071e 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/WorkerMetric.java @@ -1,7 +1,7 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import java.util.List; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java index c2a9027f..4374c928 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.ModelWritingMetric; import org.aksw.iguana.commons.annotation.Shorthand; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java index 032e50d0..5d56e7f9 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AvgQPS.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; @@ -19,7 +19,6 @@ public AvgQPS() { super("Average Queries per Second", "AvgQPS", "This metric calculates the average QPS between all queries."); } - // TODO: check if this is correct @Override public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { BigDecimal sum = BigDecimal.ZERO; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java index bddef57a..7af04166 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.ModelWritingMetric; import org.aksw.iguana.commons.annotation.Shorthand; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java index 8fc64d83..e1af28be 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQ.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java index bba17643..4015d3df 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/NoQPH.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java index 4441ca30..49a79875 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java index 4b624541..c3a3e01c 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/QMPH.java @@ -1,8 +1,8 @@ package org.aksw.iguana.cc.tasks.stresstest.metrics.impl; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.StresstestMetadata; -import org.aksw.iguana.cc.model.WorkerMetadata; +import org.aksw.iguana.cc.tasks.stresstest.StresstestMetadata; +import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.TaskMetric; import org.aksw.iguana.cc.tasks.stresstest.metrics.WorkerMetric; diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index ed59b357..ccb38c95 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -2,7 +2,6 @@ import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; diff --git a/src/main/java/org/aksw/iguana/cc/worker/Worker.java b/src/main/java/org/aksw/iguana/cc/worker/Worker.java index 65900bce..fb707689 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/Worker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/Worker.java @@ -1,7 +1,6 @@ package org.aksw.iguana.cc.worker; import org.aksw.iguana.cc.model.QueryExecutionStats; -import org.aksw.iguana.cc.model.WorkerMetadata; import org.aksw.iguana.cc.query.handler.QueryHandler; import org.aksw.iguana.cc.tasks.stresstest.Stresstest; diff --git a/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java b/src/main/java/org/aksw/iguana/cc/worker/WorkerMetadata.java similarity index 84% rename from src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java rename to src/main/java/org/aksw/iguana/cc/worker/WorkerMetadata.java index 0e19bacc..678306ab 100644 --- a/src/main/java/org/aksw/iguana/cc/model/WorkerMetadata.java +++ b/src/main/java/org/aksw/iguana/cc/worker/WorkerMetadata.java @@ -1,4 +1,4 @@ -package org.aksw.iguana.cc.model; +package org.aksw.iguana.cc.worker; public record WorkerMetadata( int workerID, From 724f85172f6fae1fc3d007d15a42bce54b8e77ab Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:38:04 +0200 Subject: [PATCH 22/36] code cleanup --- .../stresstest/StresstestResultProcessor.java | 48 +++++++++---------- .../stresstest/metrics/impl/PAvgQPS.java | 6 +-- .../tasks/stresstest/metrics/impl/PQPS.java | 4 +- .../org/aksw/iguana/commons/rdf/IONT.java | 4 ++ .../org/aksw/iguana/commons/rdf/IRES.java | 2 +- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index 29d6a13e..1d6a5fd5 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -16,17 +16,17 @@ public class StresstestResultProcessor { private final StresstestMetadata metadata; - private List metrics; + private final List metrics; /** * This array contains each query execution, grouped by each worker and each query. */ - private List[][] queryExecutions; + private List[][] workerQueryExecutions; /** * This map contains each query execution, grouped by each query of the task. */ - private Map> ab; + private Map> taskQueryExecutions; private final Resource taskRes; @@ -36,14 +36,14 @@ public StresstestResultProcessor(StresstestMetadata metadata) { this.metrics = MetricManager.getMetrics(); WorkerMetadata[] workers = metadata.workers(); - this.queryExecutions = new List[workers.length][]; + this.workerQueryExecutions = new List[workers.length][]; for (int i = 0; i < workers.length; i++) { - this.queryExecutions[i] = new List[workers[i].numberOfQueries()]; + this.workerQueryExecutions[i] = new List[workers[i].numberOfQueries()]; for (int j = 0; j < workers[i].numberOfQueries(); j++) { - this.queryExecutions[i][j] = new LinkedList<>(); + this.workerQueryExecutions[i][j] = new LinkedList<>(); } } - ab = new HashMap<>(); + taskQueryExecutions = new HashMap<>(); } /** @@ -56,13 +56,13 @@ public void processQueryExecutions(WorkerMetadata worker, Collection:'. int queryID = Integer.parseInt(stat.queryID().substring(stat.queryID().indexOf(":") + 1)); - queryExecutions[worker.workerID()][queryID].add(stat); + workerQueryExecutions[worker.workerID()][queryID].add(stat); - if (ab.containsKey(stat.queryID())) { - ab.get(stat.queryID()).add(stat); + if (taskQueryExecutions.containsKey(stat.queryID())) { + taskQueryExecutions.get(stat.queryID()).add(stat); } else { - ab.put(stat.queryID(), new LinkedList<>()); - ab.get(stat.queryID()).add(stat); + taskQueryExecutions.put(stat.queryID(), new LinkedList<>()); + taskQueryExecutions.get(stat.queryID()).add(stat); } } } @@ -96,8 +96,7 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { m.add(taskRes, IPROP.timeLimit, ResourceFactory.createTypedLiteral(metadata.timelimit().get())); m.add(taskRes, RDF.type, IONT.task); - // TODO: Maybe not hardcode this, instead have the classname stored inside the metadata to make this class reusable for other tasks - m.add(taskRes, RDF.type, IONT.stresstest); + m.add(taskRes, RDF.type, IONT.getClass(metadata.classname())); if (metadata.conVersion().isPresent()) m.add(connectionRes, IPROP.version, ResourceFactory.createTypedLiteral(metadata.conVersion().get())); m.add(connectionRes, RDFS.label, ResourceFactory.createTypedLiteral(metadata.conID())); @@ -115,7 +114,7 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { if (metadata.tripleStats().isPresent()) { m.add(metadata.tripleStats().get()); - // Connect task and workers to the Query objects, that store the triple stats. + // Connect task and workers to the Query nodes, that store the triple stats. for (WorkerMetadata worker : metadata.workers()) { for (String queryID : worker.queryIDs()) { Resource workerQueryRes = IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), queryID); @@ -131,16 +130,16 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { } } - // TODO: is the simple triple attribute even used for anything? - for (Metric metric : metrics) { m.add(this.createMetricModel(metric)); } + // Task to queries for (String queryID : metadata.queryIDs()) { m.add(taskRes, IPROP.query, IRES.getTaskQueryResource(metadata.taskID(), queryID)); } + // Worker to queries for (WorkerMetadata worker : metadata.workers()) { for (String queryID : worker.queryIDs()) { Resource workerRes = IRES.getWorkerResource(metadata.taskID(), worker.workerID()); @@ -172,12 +171,12 @@ private Model createMetricModel(Metric metric) { Resource metricRes = IRES.getMetricResource(metric); if (metric instanceof ModelWritingMetric) { - m.add(((ModelWritingMetric) metric).createMetricModel(metadata, queryExecutions)); - m.add(((ModelWritingMetric) metric).createMetricModel(metadata, ab)); + m.add(((ModelWritingMetric) metric).createMetricModel(metadata, workerQueryExecutions)); + m.add(((ModelWritingMetric) metric).createMetricModel(metadata, taskQueryExecutions)); } if (metric instanceof TaskMetric) { - Number metricValue = ((TaskMetric) metric).calculateTaskMetric(metadata, queryExecutions); + Number metricValue = ((TaskMetric) metric).calculateTaskMetric(metadata, workerQueryExecutions); if (metricValue != null) { Literal lit = ResourceFactory.createTypedLiteral(metricValue); m.add(taskRes, metricProp, lit); @@ -188,7 +187,7 @@ private Model createMetricModel(Metric metric) { if (metric instanceof WorkerMetric) { for (WorkerMetadata worker : metadata.workers()) { Resource workerRes = IRES.getWorkerResource(metadata.taskID(), worker.workerID()); - Number metricValue = ((WorkerMetric) metric).calculateWorkerMetric(worker, queryExecutions[worker.workerID()]); + Number metricValue = ((WorkerMetric) metric).calculateWorkerMetric(worker, workerQueryExecutions[worker.workerID()]); if (metricValue != null) { Literal lit = ResourceFactory.createTypedLiteral(metricValue); m.add(workerRes, metricProp, lit); @@ -201,7 +200,7 @@ private Model createMetricModel(Metric metric) { // queries grouped by worker for (WorkerMetadata worker : metadata.workers()) { for (int i = 0; i < worker.numberOfQueries(); i++) { - Number metricValue = ((QueryMetric) metric).calculateQueryMetric(queryExecutions[worker.workerID()][i]); + Number metricValue = ((QueryMetric) metric).calculateQueryMetric(workerQueryExecutions[worker.workerID()][i]); if (metricValue != null) { Literal lit = ResourceFactory.createTypedLiteral(metricValue); Resource queryRes = IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), worker.queryIDs()[i]); @@ -211,8 +210,8 @@ private Model createMetricModel(Metric metric) { } // queries grouped by task - for (String queryID : ab.keySet()) { - Number metricValue = ((QueryMetric) metric).calculateQueryMetric(ab.get(queryID)); + for (String queryID : taskQueryExecutions.keySet()) { + Number metricValue = ((QueryMetric) metric).calculateQueryMetric(taskQueryExecutions.get(queryID)); if (metricValue != null) { Literal lit = ResourceFactory.createTypedLiteral(metricValue); Resource queryRes = IRES.getTaskQueryResource(metadata.taskID(), queryID); @@ -222,6 +221,7 @@ private Model createMetricModel(Metric metric) { } m.add(metricRes, RDFS.label, metric.getName()); + m.add(metricRes, RDFS.label, metric.getAbbreviation()); m.add(metricRes, RDFS.comment, metric.getDescription()); m.add(metricRes, RDF.type, IONT.getMetricClass(metric)); m.add(metricRes, RDF.type, IONT.metric); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java index 49a79875..f71d42ae 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PAvgQPS.java @@ -15,10 +15,10 @@ @Shorthand("PAvgQPS") public class PAvgQPS extends Metric implements TaskMetric, WorkerMetric { - private final long penalty; + private final int penalty; - public PAvgQPS(long penalty) { - super("Penalized Average Queries per Second", "AvgQPS", "This metric calculates the average QPS between all queries. Failed executions receive a time penalty."); + public PAvgQPS(Integer penalty) { + super("Penalized Average Queries per Second", "PAvgQPS", "This metric calculates the average QPS between all queries. Failed executions receive a time penalty."); this.penalty = penalty; } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java index 09d92675..bbefdc12 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/PQPS.java @@ -15,9 +15,9 @@ @Shorthand("PQPS") public class PQPS extends Metric implements QueryMetric { - private final long penalty; + private final int penalty; - public PQPS(long penalty) { + public PQPS(Integer penalty) { super("Penalized Queries per Second", "PQPS", "This metric calculates for each query the amount of executions per second. Failed executions receive a time penalty."); this.penalty = penalty; } diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IONT.java b/src/main/java/org/aksw/iguana/commons/rdf/IONT.java index 59058d7e..b9027f9c 100644 --- a/src/main/java/org/aksw/iguana/commons/rdf/IONT.java +++ b/src/main/java/org/aksw/iguana/commons/rdf/IONT.java @@ -23,4 +23,8 @@ public static Resource getMetricClass(Metric metric) { // TODO: compare with stresstest class return ResourceFactory.createResource(NS + "metric/" + metric.getAbbreviation()); } + + public static Resource getClass(String classname) { + return ResourceFactory.createResource(NS + classname); + } } diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IRES.java b/src/main/java/org/aksw/iguana/commons/rdf/IRES.java index f98f5f25..49a01ea3 100644 --- a/src/main/java/org/aksw/iguana/commons/rdf/IRES.java +++ b/src/main/java/org/aksw/iguana/commons/rdf/IRES.java @@ -42,6 +42,6 @@ public static Resource getMetricResource(Metric metric) { } public static Resource getWorkerQueryRunResource(String taskID, int workerID, String queryID, BigInteger run) { - return ResourceFactory.createResource(NS + taskID + "/" + "workerID" + "/" + queryID + "/" + run); + return ResourceFactory.createResource(NS + taskID + "/" + workerID + "/" + queryID + "/" + run); } } From b559270c90a8118bf917fd935fdb86d979c33366 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Thu, 6 Jul 2023 18:32:31 +0200 Subject: [PATCH 23/36] fix tests --- .../aksw/iguana/cc/config/IguanaConfig.java | 24 +++++++- .../aksw/iguana/cc/worker/AbstractWorker.java | 3 +- .../iguana/cc/worker/impl/UPDATEWorker.java | 7 +++ .../aksw/iguana/cc/config/WorkflowTest.java | 55 ++++--------------- .../cc/lang/SPARQLLanguageProcessorTest.java | 2 +- .../aksw/iguana/cc/tasks/MockupStorage.java | 18 ------ .../cc/tasks/stresstest/StresstestTest.java | 5 +- .../aksw/iguana/cc/worker/HTTPWorkerTest.java | 7 +-- .../aksw/iguana/cc/worker/MockupWorker.java | 2 +- .../config/mockupworkflow-no-default.yml | 4 +- src/test/resources/querystats.nt | 26 ++++----- 11 files changed, 67 insertions(+), 86 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index 8f9109ac..580a04ce 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -5,6 +5,7 @@ import org.aksw.iguana.cc.controller.TaskController; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.MetricManager; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.*; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.commons.script.ScriptExecutor; import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; @@ -123,7 +124,28 @@ private void initResultProcessor() { } if(this.metrics == null || this.metrics.isEmpty()){ LOGGER.info("No metrics were set. Using default metrics."); - // TODO: set default metrics + metrics = new ArrayList<>(); + MetricConfig config = new MetricConfig(); + config.setClassName(QMPH.class.getCanonicalName()); + metrics.add(config); + config = new MetricConfig(); + config.setClassName(QPS.class.getCanonicalName()); + Map configMap = new HashMap<>(); + configMap.put("penalty", 180000); + config.setConfiguration(configMap); + metrics.add(config); + config = new MetricConfig(); + config.setClassName(NoQPH.class.getCanonicalName()); + metrics.add(config); + config = new MetricConfig(); + config.setClassName(AvgQPS.class.getCanonicalName()); + metrics.add(config); + config = new MetricConfig(); + config.setClassName(NoQ.class.getCanonicalName()); + metrics.add(config); + config = new MetricConfig(); + config.setClassName(AggregatedExecutionStatistics.class.getCanonicalName()); + metrics.add(config); } //Create Storages diff --git a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java index ccb38c95..9ffed99c 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/AbstractWorker.java @@ -64,7 +64,7 @@ public abstract class AbstractWorker implements Worker { protected ConnectionConfig con; protected int queryHash; protected QueryHandler queryHandler; - private Collection results = new LinkedList<>(); + protected Collection results = new LinkedList<>(); private Random latencyRandomizer; private Long endAtNOQM = null; @@ -175,6 +175,7 @@ protected HttpContext getAuthContext(String endpoint) { } public synchronized void addResults(QueryExecutionStats results) { + // TODO: check if statement for bugs, if the if line exists in the UpdateWorker, the UpdateWorker fails its tests if (!this.endSignal && !hasExecutedNoOfQueryMixes(this.endAtNOQM)) { this.results.add(results); this.executedQueries++; diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java index 1b2a6074..ece958b6 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/UPDATEWorker.java @@ -1,6 +1,7 @@ package org.aksw.iguana.cc.worker.impl; import org.aksw.iguana.cc.config.elements.ConnectionConfig; +import org.aksw.iguana.cc.model.QueryExecutionStats; import org.aksw.iguana.cc.worker.impl.update.UpdateTimer; import org.aksw.iguana.commons.annotation.Nullable; import org.aksw.iguana.commons.annotation.Shorthand; @@ -47,6 +48,12 @@ public void waitTimeMs() { super.waitTimeMs(); } + @Override + public synchronized void addResults(QueryExecutionStats result) { + this.results.add(result); + this.executedQueries++; + } + @Override public void getNextQuery(StringBuilder queryStr, StringBuilder queryID) throws IOException { // If there is no more update send end signal, as there is nothing to do anymore diff --git a/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java b/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java index 79126588..e9e10791 100644 --- a/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java +++ b/src/test/java/org/aksw/iguana/cc/config/WorkflowTest.java @@ -1,10 +1,9 @@ package org.aksw.iguana.cc.config; import org.aksw.iguana.cc.tasks.MockupStorage; -import org.aksw.iguana.cc.tasks.MockupTask; import org.aksw.iguana.cc.tasks.stresstest.metrics.Metric; import org.aksw.iguana.cc.tasks.stresstest.metrics.MetricManager; -import org.aksw.iguana.commons.constants.COMMON; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.*; import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; import org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage; @@ -66,35 +65,6 @@ public void workflowTest() throws IOException { assertEquals(1, storages.size()); Storage s = storages.iterator().next(); assertTrue(s instanceof MockupStorage); - Set meta = ((MockupStorage)s).getMeta(); - //check if suiteID eq - // check if taskID suiteID/1/1 -> 1 etc. - Set suiteID = new HashSet(); - for(Properties p : meta){ - String suite = p.getProperty(COMMON.SUITE_ID_KEY); - suiteID.add(suite); - assertEquals(MockupTask.class.getCanonicalName(),p.get(COMMON.EXPERIMENT_TASK_CLASS_ID_KEY)); - String expID = p.getProperty(COMMON.EXPERIMENT_ID_KEY); - String taskID = p.getProperty(COMMON.EXPERIMENT_TASK_ID_KEY); - assertEquals(expID, taskID.substring(0, taskID.length()-2)); - if(taskID.equals(suite+"1/1")){ - assertEquals("TestSystem", p.get(COMMON.CONNECTION_ID_KEY)); - assertEquals("DatasetName", p.get(COMMON.DATASET_ID_KEY)); - } - else if(taskID.equals(suite+"1/2")){ - assertEquals("TestSystem2", p.get(COMMON.CONNECTION_ID_KEY)); - assertEquals("DatasetName", p.get(COMMON.DATASET_ID_KEY)); - } - else if(taskID.equals(suite+"2/1")){ - assertEquals("TestSystem", p.get(COMMON.CONNECTION_ID_KEY)); - assertEquals("DatasetName2", p.get(COMMON.DATASET_ID_KEY)); - } - else if(taskID.equals(suite+"2/2")){ - assertEquals("TestSystem2", p.get(COMMON.CONNECTION_ID_KEY)); - assertEquals("DatasetName2", p.get(COMMON.DATASET_ID_KEY)); - } - } - assertEquals(1, suiteID.size()); } @Test @@ -116,9 +86,8 @@ public void noDefaultTest() throws IOException { } assertEquals(2, seen.size()); - // TODO: fix test - // assertTrue(seen.contains(QMPHMetric.class)); - // assertTrue(seen.contains(QPSMetric.class)); + assertTrue(seen.contains(QMPH.class)); + assertTrue(seen.contains(QPS.class)); } @Test @@ -136,19 +105,19 @@ public void initTest() throws IOException { del.delete(); List metrics = MetricManager.getMetrics(); - assertEquals(5, metrics.size()); + assertEquals(6, metrics.size()); Set> seen = new HashSet<>(); for(Metric m : metrics){ seen.add(m.getClass()); } - assertEquals(5, seen.size()); - - // TODO: fix test - // assertTrue(seen.contains(QMPHMetric.class)); - // assertTrue(seen.contains(QPSMetric.class)); - // assertTrue(seen.contains(AvgQPSMetric.class)); - // assertTrue(seen.contains(NoQPHMetric.class)); - // assertTrue(seen.contains(NoQMetric.class)); + assertEquals(6, seen.size()); + + assertTrue(seen.contains(QMPH.class)); + assertTrue(seen.contains(QPS.class)); + assertTrue(seen.contains(AvgQPS.class)); + assertTrue(seen.contains(NoQPH.class)); + assertTrue(seen.contains(NoQ.class)); + assertTrue(seen.contains(AggregatedExecutionStatistics.class)); } } diff --git a/src/test/java/org/aksw/iguana/cc/lang/SPARQLLanguageProcessorTest.java b/src/test/java/org/aksw/iguana/cc/lang/SPARQLLanguageProcessorTest.java index 93b1aff5..43a5da09 100644 --- a/src/test/java/org/aksw/iguana/cc/lang/SPARQLLanguageProcessorTest.java +++ b/src/test/java/org/aksw/iguana/cc/lang/SPARQLLanguageProcessorTest.java @@ -131,7 +131,7 @@ public void checkResultSize() throws IOException, ParserConfigurationException, @Test public void checkGeneratedStatsModel() throws IOException { Query q = QueryFactory.create("SELECT * {?s ?p ?o. ?o ?q ?t. FILTER(?t = \"abc\")} GROUP BY ?s"); - QueryWrapper wrapped = new QueryWrapper(q, "abc"); + QueryWrapper wrapped = new QueryWrapper(q, "abc0"); SPARQLLanguageProcessor languageProcessor = new SPARQLLanguageProcessor(); Model actual = languageProcessor.generateTripleStats(Lists.newArrayList(wrapped),"query","1/1/2"); Model expected = ModelFactory.createDefaultModel(); diff --git a/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java b/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java index 9b1aa20b..145a7257 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/MockupStorage.java @@ -4,29 +4,11 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; - public class MockupStorage implements Storage { private Model m = ModelFactory.createDefaultModel(); - private Set meta = new HashSet<>(); - @Override public void storeResult(Model data) { m.add(data); } - - public Model getModel() { - return m; - } - - public void setModel(Model m) { - this.m = m; - } - - public Set getMeta() { - return meta; - } } diff --git a/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java index 87e8c5d7..1ab15f22 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/stresstest/StresstestTest.java @@ -2,6 +2,8 @@ import org.aksw.iguana.cc.config.elements.ConnectionConfig; import org.aksw.iguana.cc.tasks.MockupStorage; +import org.aksw.iguana.cc.tasks.stresstest.metrics.MetricManager; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.EachExecutionStatistic; import org.aksw.iguana.cc.worker.MockupWorker; import org.aksw.iguana.cc.worker.Worker; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; @@ -38,8 +40,7 @@ private ConnectionConfig getConnection() { private void init(){ StorageManager storageManager = StorageManager.getInstance(); - // TODO: fix tests - // MetricManager.setMetrics(List.of(new EachQueryMetric())); + MetricManager.setMetrics(List.of(new EachExecutionStatistic())); MockupStorage storage = new MockupStorage(); storageManager.addStorage(storage); } diff --git a/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java b/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java index 7e46d206..a875295a 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java +++ b/src/test/java/org/aksw/iguana/cc/worker/HTTPWorkerTest.java @@ -124,7 +124,6 @@ public void testExecution() throws InterruptedException { assertEquals(taskID, getWorker.taskID); assertEquals(this.queryID, p.queryID()); - assertEquals(180000.0, getWorker.timeOut.doubleValue()); if (isPost) { assertEquals(200.0, p.executionTime(), 20.0); } else { @@ -132,11 +131,11 @@ public void testExecution() throws InterruptedException { } if (isFail) { assertEquals(-2L, p.responseCode()); - assertEquals(0L, p.executionTime()); + assertEquals(0L, p.resultSize()); } else { - assertEquals(1L, p.executionTime()); + assertEquals(1L, p.responseCode()); if (this.responseType != null && this.responseType.equals("text/plain")) { - assertEquals(4L, p.executionTime()); + assertEquals(4L, p.resultSize()); } if (this.responseType == null || this.responseType.equals(SPARQLLanguageProcessor.QUERY_RESULT_TYPE_JSON)) { assertEquals(2L, p.resultSize()); diff --git a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java index 5094571b..aefae5f5 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java +++ b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java @@ -50,7 +50,7 @@ public void getNextQuery(StringBuilder queryStr, StringBuilder queryID) { this.counter = 0; } queryStr.append(this.queries[this.counter]); - queryID.append("query").append(this.counter); + queryID.append("query:").append(this.counter); this.counter++; } } diff --git a/src/test/resources/config/mockupworkflow-no-default.yml b/src/test/resources/config/mockupworkflow-no-default.yml index 2a348a7f..7a2b529b 100644 --- a/src/test/resources/config/mockupworkflow-no-default.yml +++ b/src/test/resources/config/mockupworkflow-no-default.yml @@ -20,8 +20,8 @@ preScriptHook: "src/test/resources/config/pre.sh {{connection}} {{dataset.name}} postScriptHook: "src/test/resources/config/post.sh {{dataset.file}} {{dataset.name}} {{connection}}" metrics: - - className: "org.aksw.iguana.rp.metrics.impl.QMPHMetric" - - className: "org.aksw.iguana.rp.metrics.impl.QPSMetric" + - className: "org.aksw.iguana.cc.tasks.stresstest.metrics.impl.QMPH" + - className: "org.aksw.iguana.cc.tasks.stresstest.metrics.impl.QPS" storages: - className: "org.aksw.iguana.cc.tasks.MockupStorage" \ No newline at end of file diff --git a/src/test/resources/querystats.nt b/src/test/resources/querystats.nt index b0ee226e..df176f42 100644 --- a/src/test/resources/querystats.nt +++ b/src/test/resources/querystats.nt @@ -1,13 +1,13 @@ - "false"^^. - "true"^^ . - "true"^^ . - "false"^^. - "2"^^. - "false"^^. - "false"^^. - "false"^^. - "false"^^. - . - "abc". - "SELECT *\nWHERE\n { ?s ?p ?o .\n ?o ?q ?t\n FILTER ( ?t = \"abc\" )\n }\nGROUP BY ?s\n" . - . \ No newline at end of file + "false"^^. + "true"^^ . + "true"^^ . + "false"^^. + "2"^^. + "false"^^. + "false"^^. + "false"^^. + "false"^^. + . + "0"^^. + "SELECT *\nWHERE\n { ?s ?p ?o .\n ?o ?q ?t\n FILTER ( ?t = \"abc\" )\n }\nGROUP BY ?s\n" . + . \ No newline at end of file From 1db6f0ea7d07a00f72400bc722a23e452076a388 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Thu, 6 Jul 2023 21:56:40 +0200 Subject: [PATCH 24/36] Stresstest shouldn't send the worker results during execution --- .../cc/tasks/stresstest/Stresstest.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java index 7223321c..ae84cae6 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/Stresstest.java @@ -159,20 +159,27 @@ public void execute() { LOGGER.info("[TaskID: {{}}]All {{}} workers have been started", this.taskID, this.workers.size()); // wait timeLimit or noOfQueries executor.shutdown(); + + // if a time limit is set, let the task thread sleep that amount of time, otherwise sleep for 100 ms + // to periodically check if the workers are finished + long sleep = (timeLimit != null) ? timeLimit.longValue() : 100; while (!isFinished()) { - // check if worker has results yet - for (Worker worker : this.workers) { - // if so send all results buffered - sendWorkerResult(worker); + try { + Thread.sleep(sleep); + } catch (InterruptedException e) { + throw new RuntimeException(e); } - loopSleep(); } + + for (Worker worker : this.workers) { + sendWorkerResult(worker); + } + LOGGER.debug("Sending stop signal to workers"); - // tell all workers to stop sending properties, thus the await termination will - // be safe with the results for (Worker worker : this.workers) { worker.stopSending(); } + // Wait 5seconds so the workers can stop themselves, otherwise they will be // stopped try { @@ -193,15 +200,6 @@ public void execute() { this.endDate = GregorianCalendar.getInstance(); } - private void loopSleep() { - try { - TimeUnit.MILLISECONDS.sleep(100); - } catch (Exception e) { - //shouldn't be thrown except something else really went wrong - LOGGER.error("Loop sleep did not work.", e); - } - } - private void sendWorkerResult(Worker worker) { Collection props = worker.popQueryResults(); if (props == null) { From 2eb020a37394256a7ff0bb85b7fdbc2d58c469ea Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Thu, 6 Jul 2023 21:57:13 +0200 Subject: [PATCH 25/36] cleanup --- .../org/aksw/iguana/cc/config/IguanaConfig.java | 3 --- .../cc/tasks/stresstest/StresstestMetadata.java | 1 - ...ics.java => AggregatedExecutionStatistics.java} | 14 +++++++------- ...yExecution.java => EachExecutionStatistic.java} | 6 +++--- .../tasks/stresstest/storage/StorageManager.java | 4 ---- 5 files changed, 10 insertions(+), 18 deletions(-) rename src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/{AggregatedStatistics.java => AggregatedExecutionStatistics.java} (86%) rename src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/{EachQueryExecution.java => EachExecutionStatistic.java} (90%) diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index 580a04ce..6570162b 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -130,9 +130,6 @@ private void initResultProcessor() { metrics.add(config); config = new MetricConfig(); config.setClassName(QPS.class.getCanonicalName()); - Map configMap = new HashMap<>(); - configMap.put("penalty", 180000); - config.setConfiguration(configMap); metrics.add(config); config = new MetricConfig(); config.setClassName(NoQPH.class.getCanonicalName()); diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java index 7df35085..66233de8 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestMetadata.java @@ -6,7 +6,6 @@ import java.util.Optional; import java.util.Set; -// TODO: maybe extract parts to generic taskmetadata class public record StresstestMetadata( String suiteID, String expID, diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java similarity index 86% rename from src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java index 4374c928..2e5883ea 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedStatistics.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java @@ -23,11 +23,11 @@ import java.util.List; import java.util.Map; -@Shorthand("ExecutedQuery") -public class AggregatedStatistics extends Metric implements ModelWritingMetric { +@Shorthand("AES") +public class AggregatedExecutionStatistics extends Metric implements ModelWritingMetric { - public AggregatedStatistics() { - super("Aggregated Execution Statistics", "", "Sums up the statistics of each query execution for each query a worker and task has. The result size only contains the value of the last execution."); + public AggregatedExecutionStatistics() { + super("Aggregated Execution Statistics", "AES", "Sums up the statistics of each query execution for each query a worker and task has. The result size only contains the value of the last execution."); } @Override @@ -37,7 +37,7 @@ public Model createMetricModel(StresstestMetadata task, List data, Resource queryRes) { + private static Model createAggregatedModel(List data, Resource queryRes) { Model m = ModelFactory.createDefaultModel(); BigInteger succeeded = BigInteger.ZERO; BigInteger failed = BigInteger.ZERO; diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachExecutionStatistic.java similarity index 90% rename from src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java rename to src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachExecutionStatistic.java index 7af04166..f3771943 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachQueryExecution.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/EachExecutionStatistic.java @@ -19,10 +19,10 @@ import java.util.List; @Shorthand("EachQuery") -public class EachQueryExecution extends Metric implements ModelWritingMetric { +public class EachExecutionStatistic extends Metric implements ModelWritingMetric { - public EachQueryExecution() { - super("Each Query Execution", "EachQuery", "This metric saves the statistics of each query execution."); + public EachExecutionStatistic() { + super("Each Query Execution Statistic", "EachQuery", "This metric saves the statistics of each query execution."); } @Override diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java index e5e0b69f..5de7fd4e 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/StorageManager.java @@ -1,8 +1,6 @@ package org.aksw.iguana.cc.tasks.stresstest.storage; import org.apache.jena.rdf.model.Model; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.*; @@ -14,8 +12,6 @@ * */ public class StorageManager { - - private static final Logger LOGGER = LoggerFactory.getLogger(StorageManager.class); private Set storages = new HashSet<>(); From d21a7fe696e151b57bd146d9315000ae9c2e6c76 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Thu, 6 Jul 2023 21:58:48 +0200 Subject: [PATCH 26/36] fix the queryID property statements --- .../cc/tasks/stresstest/StresstestResultProcessor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index 1d6a5fd5..0b0b21ee 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -117,14 +117,16 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { // Connect task and workers to the Query nodes, that store the triple stats. for (WorkerMetadata worker : metadata.workers()) { for (String queryID : worker.queryIDs()) { + int intID = Integer.parseInt(queryID.substring(queryID.indexOf(":") + 1)); Resource workerQueryRes = IRES.getWorkerQueryResource(metadata.taskID(), worker.workerID(), queryID); - Resource queryRes = IRES.getResource(worker.queryHash() + "/" + queryID); + Resource queryRes = IRES.getResource(worker.queryHash() + "/" + intID); m.add(workerQueryRes, IPROP.queryID, queryRes); } for (String queryID : metadata.queryIDs()) { + int intID = Integer.parseInt(queryID.substring(queryID.indexOf(":") + 1)); Resource taskQueryRes = IRES.getTaskQueryResource(metadata.taskID(), queryID); - Resource queryRes = IRES.getResource(worker.queryHash() + "/" + queryID); + Resource queryRes = IRES.getResource(worker.queryHash() + "/" + intID); m.add(taskQueryRes, IPROP.queryID, queryRes); } } From 0348907b305f56da52b7d53348315bb1fb814b00 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 7 Jul 2023 15:11:49 +0200 Subject: [PATCH 27/36] update docs --- README.md | 2 +- docs/architecture.md | 1 + docs/develop/extend-metrics.md | 126 ++++++++----------------- docs/develop/extend-result-storages.md | 40 ++------ docs/download.md | 2 +- docs/shorthand-mapping.md | 21 +++-- docs/usage/configuration.md | 16 ++-- docs/usage/getting-started.md | 2 +- docs/usage/metrics.md | 61 +++++------- docs/usage/results.md | 1 - 10 files changed, 92 insertions(+), 180 deletions(-) diff --git a/README.md b/README.md index 6401ebaf..5fb12fb4 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Per query metrics: ### Prerequisites -In order to run Iguana, you need to have `Java 11`, or greater, installed on your system. +In order to run Iguana, you need to have `Java 17`, or greater, installed on your system. ### Download Download the newest release of Iguana [here](https://github.com/dice-group/IGUANA/releases/latest), or run on a unix shell: diff --git a/docs/architecture.md b/docs/architecture.md index 2ecb831a..18067357 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -51,6 +51,7 @@ Per run metrics: * Number of Queries Per Hour (NoQPH) * Number of Queries (NoQ) * Average Queries Per Second (AvgQPS) +* Penalized Average Queries Per Second (PAvgQPS) Per query metrics: * Queries Per Second (QPS) diff --git a/docs/develop/extend-metrics.md b/docs/develop/extend-metrics.md index 5c4b9833..43542dd7 100644 --- a/docs/develop/extend-metrics.md +++ b/docs/develop/extend-metrics.md @@ -1,107 +1,57 @@ # Extend Metrics -To implement a new metric, create a new class that extends the abstract class `AbstractMetric`: +To implement a new metric, create a new class that extends the abstract class `Metric`: ```java package org.benchmark.metric; @Shorthand("MyMetric") -public class MyMetric extends AbstractMetric{ +public class MyMetric extends Metric { - @Override - public void receiveData(Properties p) { - // ... - } - - @Override - public void close() { - callbackClose(); - super.close(); - - } - - protected void callbackClose() { - // your close method - } + public MyMetric() { + super("name", "abbreviation", "description"); + } } ``` -## Receive Data - -This method will receive all the results during the benchmark. - -You'll receive a few values regarding each query execution. Those values include the amount of time the execution took, if it succeeded, and if not, the reason why it failed, which can be either a timeout, a wrong HTTP Code or an unknown error. -Further on you also receive the result size of the query. - -If your metric is a single value metric, you can use the `processData` method, which will automatically add each value together. -However, if your metric is query specific, you can use the `addDataToContainter` method. (Look at the [QPSMetric](https://github.com/dice-group/IGUANA/blob/master/iguana.resultprocessor/src/main/java/org/aksw/iguana/rp/metrics/impl/QPSMetric.java)) +You can then choose if the metric is supposed to be calculated for each Query, Worker +or Task by implementing the appropriate interfaces: `QueryMetric`, `WorkerMetric`, `TaskMetric`. -Be aware that both methods will save the results for each used worker. This allows the calculation of the overall metric, as well as the metric for each worker itself. +You can also choose to implement the `ModelWritingMetric` interface, if you want your +metric to create a special RDF model, that you want to be added to the result model. -We will stick to the single-value metric for now. - - -The following shows an example, that retrieves every possible value and saves the time and success: +The following gives you an examples on how to work with the `data` parameter: ```java -@Override -public void receiveData(Properties p) { - - double time = Double.parseDouble(p.get(COMMON.RECEIVE_DATA_TIME).toString()); - long tmpSuccess = Long.parseLong(p.get(COMMON.RECEIVE_DATA_SUCCESS).toString()); - long success = (tmpSuccess > 0) ? 1 : 0; - long failure = (success == 1) ? 0 : 1; - long timeout = (tmpSuccess == COMMON.QUERY_SOCKET_TIMEOUT) ? 1 : 0; - long unknown = (tmpSuccess == COMMON.QUERY_UNKNOWN_EXCEPTION) ? 1 : 0; - long wrongCode = (tmpSuccess == COMMON.QUERY_HTTP_FAILURE) ? 1 : 0; - - if(p.containsKey(COMMON.RECEIVE_DATA_SIZE)) { - size = Long.parseLong(p.get(COMMON.RECEIVE_DATA_SIZE).toString()); + @Override + public Number calculateTaskMetric(StresstestMetadata task, List[][] data) { + for (WorkerMetadata worker : task.workers()) { + for (int i = 0; i < worker.noOfQueries(); i++) { + // This list contains every query execution statistics of one query + // from the current worker + List execs = data[worker.workerID()][i]; + } + } + return BigInteger.ZERO; } - - Properties results = new Properties(); - results.put(TOTAL_TIME, time); - results.put(TOTAL_SUCCESS, success); - - Properties extra = getExtraMeta(p); - processData(extra, results); -} -``` -## Close - -In this method you should calculate your metric and send the results. -An example: - -```java -protected void callbackClose() { - // create a model that contains the results - Model m = ModelFactory.createDefaultModel(); - - Property property = getMetricProperty(); - Double sum = 0.0; - - // Go over each worker and add metric results to model - for(Properties key : dataContainer.keySet()){ - Double totalTime = (Double) dataContainer.get(key).get(TOTAL_TIME); - Integer success = (Integer) dataContainer.get(key).get(TOTAL_SUCCESS); - - Double noOfQueriesPerHour = hourInMS * success * 1.0 / totalTime; - sum += noOfQueriesPerHour; - Resource subject = getSubject(key); - - m.add(getConnectingStatement(subject)); - m.add(subject, property, ResourceFactory.createTypedLiteral(noOfQueriesPerHour)); + @Override + public Number calculateWorkerMetric(WorkerMetadata worker, List[] data) { + for (int i = 0; i < worker.noOfQueries(); i++) { + // This list contains every query execution statistics of one query + // from the given worker + List execs = data[i]; + } + return BigInteger.ZERO; } - // Add overall metric to model - m.add(getTaskResource(), property, ResourceFactory.createTypedLiteral(sum)); - - // Send data to storage - sendData(m); -} -``` - -## Constructor - -The constructor parameters are provided the same way as for the tasks. Thus, simply look at the [Extend Task](../extend-task) page. + @Override + @Nonnull + public Model createMetricModel(StresstestMetadata task, Map> data) { + for (String queryID : task.queryIDS()) { + // This list contains every query execution statistics of one query from + // every worker that executed this querys + List execs = data.get(queryID); + } + } +``` \ No newline at end of file diff --git a/docs/develop/extend-result-storages.md b/docs/develop/extend-result-storages.md index 1632c178..d7c17d89 100644 --- a/docs/develop/extend-result-storages.md +++ b/docs/develop/extend-result-storages.md @@ -1,47 +1,23 @@ # Extend Result Storages -If you want to use a different storage other than RDF, you can implement a different storage solution. - -The current implementation of Iguana is highly optimized for RDF, thus we recommend you to work on top of the `TripleBasedStorage` class: +If you want to use a different storage other than RDF, you can implement a different storage solution. ```java package org.benchmark.storage; @Shorthand("MyStorage") -public class MyStorage extends TripleBasedStorage { - - @Override - public void commit() { - - } - - @Override - public String toString(){ - return this.getClass().getSimpleName(); - } -} -``` - -## Commit +public class MyStorage implements Storage { -This method should take all the current results, store them, and remove them from the memory. - -You can access the results at the Jena Model `this.metricResults`. - -For example: - -```java -@Override -public void commit() { - try (OutputStream os = new FileOutputStream(file.toString(), true)) { - RDFDataMgr.write(os, metricResults, RDFFormat.NTRIPLES); - metricResults.removeAll(); - } catch (IOException e) { - LOGGER.error("Could not commit to NTFileStorage.", e); + @Override + public void storeResults(Model m) { + // method for storing model } } ``` +The method `storeResults` will be called at the end of the task. The model from +the parameter contains the final result model for that task. + ## Constructor The constructor parameters are provided the same way as for the tasks. Thus, simply look at the [Extend Task](../extend-task) page. \ No newline at end of file diff --git a/docs/download.md b/docs/download.md index b2578724..8b5c4645 100644 --- a/docs/download.md +++ b/docs/download.md @@ -2,7 +2,7 @@ ## Prerequisites -You need to have Java 11 or higher installed. +You need to have Java 17 or higher installed. In Ubuntu, you can install it by executing the following command: diff --git a/docs/shorthand-mapping.md b/docs/shorthand-mapping.md index 756550dc..adf4b37c 100644 --- a/docs/shorthand-mapping.md +++ b/docs/shorthand-mapping.md @@ -15,13 +15,16 @@ | CLIInputPrefixWorker | `org.aksw.iguana.cc.worker.impl.CLIInputPrefixWorker` | | MultipleCLIInputWorker | `org.aksw.iguana.cc.worker.impl.MultipleCLIInputWorker` | | ---------- | ------- | -| NTFileStorage | `org.aksw.iguana.rp.storages.impl.NTFileStorage` | -| RDFFileStorage | `org.aksw.iguana.rp.storages.impl.RDFFileStorage` | -| TriplestoreStorage | `org.aksw.iguana.rp.storages.impl.TriplestoreStorage` | +| NTFileStorage | `org.aksw.iguana.cc.tasks.stresstest.storage.impl.NTFileStorage` | +| RDFFileStorage | `org.aksw.iguana.cc.tasks.stresstest.storage.impl.RDFFileStorage` | +| TriplestoreStorage | `org.aksw.iguana.cc.tasks.stresstest.storage.impl.TriplestoreStorage` | | ---------- | ------- | -| QPS | `org.aksw.iguana.rp.metrics.impl.QPSMetric` | -| AvgQPS | `org.aksw.iguana.rp.metrics.impl.AvgQPSMetric` | -| NoQ | `org.aksw.iguana.rp.metrics.impl.NoQMetric` | -| NoQPH | `org.aksw.iguana.rp.metrics.impl.NoQPHMetric` | -| QMPH | `org.aksw.iguana.rp.metrics.impl.QMPHMetric` | -| EachQuery | `org.aksw.iguana.rp.metrics.impl.EQEMetric` | +| QPS | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.QPS` | +| PQPS | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.PQPS` | +| AvgQPS | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.AvgQPS` | +| PAvgQPS | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.PAvgQPS` | +| NoQ | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.NoQ` | +| NoQPH | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.NoQPH` | +| QMPH | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.QMPH` | +| AES | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.AggregatedExecutionStatistics` | +| EachQuery | `org.aksw.iguana.cc.tasks.stresstest.metrics.impl.EachExecutionStatistic` | diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 851a7680..bec58f4f 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -25,7 +25,7 @@ A connection has the following items: * `updateEndpoint` - if your HTTP endpoint is an HTTP POST endpoint, you can set it with this item (optional) * `user` - for authentication purposes (optional) * `password` - for authentication purposes (optional) -* `version` - sets the version of the tested triplestore; if this is set, the resource URI will be ires:name-version (optional) +* `version` - sets the version of the tested triplestore (optional) At first, it might be confusing to set up both an `endpoint` and `updateEndpoint`, but it is used, when you want your test to perform read and write operations simultaneously, for example, to test the impact of updates on the read performance of your triple store. @@ -190,17 +190,18 @@ The `metrics` setting lets Iguana know what metrics you want to include in the r Iguana supports the following metrics: * Queries Per Second (`QPS`) +* Penalized Queries Per Second (`PQPS`) * Average Queries Per Second (`AvgQPS`) +* Penalized Average Queries Per Second (`PAvgQPS`) * Query Mixes Per Hour (`QMPH`) * Number of Queries successfully executed (`NoQ`) * Number of Queries per Hour (`NoQPH`) -* Each query execution (`EachQuery`) - experimental +* Each Execution Statistic (`EachQuery`) +* Aggregated Execution Statistics (`AES`) For more details on each of the metrics have a look at the [Metrics](../metrics) page. -The `metrics` setting is optional and the default is set to every available metric, except `EachQuery`. - -Let's look at an example: +The `metrics` setting is optional and the default is set to this: ```yaml metrics: @@ -209,11 +210,10 @@ metrics: - className: "QMPH" - className: "NoQ" - className: "NoQPH" + - className: "AES" ``` -In this case we use every metric that Iguana has implemented. This is the default. - -However, you can also just use a subset of these metrics: +You can also use a subset of these metrics: ```yaml metrics: diff --git a/docs/usage/getting-started.md b/docs/usage/getting-started.md index dcc56e08..0c07bd01 100644 --- a/docs/usage/getting-started.md +++ b/docs/usage/getting-started.md @@ -22,7 +22,7 @@ Iguana will then let every Worker execute these queries against the endpoint. ## Prerequisites -You need to have Java 11 or higher installed. +You need to have Java 17 or higher installed. In Ubuntu you can install it by executing the following command: ```bash diff --git a/docs/usage/metrics.md b/docs/usage/metrics.md index 5d832a6f..3d6f3cc2 100644 --- a/docs/usage/metrics.md +++ b/docs/usage/metrics.md @@ -1,53 +1,36 @@ # Implemented Metrics +## Global Metrics +The following metrics are calculated for each task and worker: -Every metric will be calculated globally (for one Experiment Task) and locally (for each Worker). -Hence, you are able to analyze the metrics of the whole benchmark or only of each worker. +| Metric | Description | +|---------|------------------------------------------------------------------------------------------------------------------------------------------------------| +| NoQ | The number of successfully executed Queries. | +| QMPH | The number of successfully executed Query Mixes (amount of queries inside a query source) Per Hour. | +| NoQPH | The number of successfully executed Queries Per Hour. | +| AvgQPS | The average of the QPS metric value between all queries. | +| PAvgQPS | The average of the PQPS metric value between all queries. For this metric you have to set a value for the penalty (in milliseconds) (example below). | -## NoQ -The number of successfully executed Queries -## QMPH +## Query Metrics +The following metrics are calculated for each query. -The number of executed Query Mixes Per Hour +| Metric | Description | +|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| QPS | The number of successfully executed Queries per second. | +| PQPS | The number of executed Queries per second. Each failed query execution will receive a given time penalty instead of its execution duration. | +| EachQuery | Stores for each query executions its statistics. This includes the execution duration, response code, result size and a boolean value if the execution was successful. | +| AES | This metric aggregates the values of each query execution. | -## NoQPH - -The number of successfully executed Queries Per Hour - -## QPS - -For each query, the `queries per second`, the `total time` in milliseconds (summed up time of each execution), the number of `succeeded` and `failed` executions, and the `result size` will be saved. - -Additionally, Iguana will try to tell you how many times a query has failed and for what reason (`timeout`, `wrong return code`, e.g. 400, or `unknown`). - -Further on the QPS metric provides a penalized QPS metric that penalizes queries that fail. -Some systems just return an error code, if they can't resolve a query, thus they can have a very high score, even though they were only able to handle a few queries. That would be rather unfair to the compared systems, therefore we introduced the penalty QPS. It is calculated the same as the QPS score, but for each failed query it uses the penalty instead of the actual time the failed query took. - -The default penalty is set to the `timeOut` value of the task. However, you can override it as follows: +### Configuration for PAvgQPS and QPS +An example for the configuration of both: ```yaml -metrics: - - className: "QPS" +metrics: + - className: "PAvgQPS" configuration: - #in MS penalty: 10000 -``` - -## AvgQPS - -The average of all queries per second. -It also adds a penalizedAvgQPS metric. The default penalty is set to the `timeOut` value of the task, but it can be overwritten as follows: - -```yaml -metrics: - - className: "AvgQPS" + - className: "PQPS" configuration: - # in ms penalty: 10000 ``` - -## EachQuery - -Will save every query execution. (Experimental) - diff --git a/docs/usage/results.md b/docs/usage/results.md index 837672a6..228e0dd5 100644 --- a/docs/usage/results.md +++ b/docs/usage/results.md @@ -69,7 +69,6 @@ SELECT ?taskID ?noq { } ``` -Instead of the NoQ metric you can do this for all other metrics, except `QPS`. To retrieve `QPS` look above in the results schema and let's look at an example. Let's assume the taskID is `123/1/1` again. You can retrieve the global qps values (seen above in ExecutedQueries, e.g `QPS`, `succeeded` etc.) as follows, From f7eb2871a9027d53d14e406cabe855fcf5d94be8 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Tue, 11 Jul 2023 17:32:23 +0200 Subject: [PATCH 28/36] add CSVStorage - metrics should also now be created before the storages --- pom.xml | 5 + .../aksw/iguana/cc/config/IguanaConfig.java | 23 +- .../stresstest/storage/impl/CSVStorage.java | 294 ++++++++++++++++++ 3 files changed, 313 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java diff --git a/pom.xml b/pom.xml index 471825a8..0940b7de 100644 --- a/pom.xml +++ b/pom.xml @@ -162,6 +162,11 @@ 5.9.2 test + + com.opencsv + opencsv + 5.7.1 + diff --git a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java index 6570162b..e2d16b11 100644 --- a/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/IguanaConfig.java @@ -59,6 +59,7 @@ public class IguanaConfig { @JsonProperty private List storages; + private static String suiteID = generateSuiteID(); /** * starts the config @@ -69,7 +70,7 @@ public void start() throws ExecuteException, IOException { initResultProcessor(); TaskController controller = new TaskController(); //get SuiteID - String suiteID = generateSuiteID(); + suiteID = generateSuiteID(); //generate ExpID int expID = 0; @@ -145,23 +146,27 @@ private void initResultProcessor() { metrics.add(config); } + // Create Metrics + // Metrics should be created before the Storages + List metrics = new ArrayList<>(); + for(MetricConfig config : this.metrics) { + metrics.add(config.createMetric()); + } + MetricManager.setMetrics(metrics); + //Create Storages List storages = new ArrayList<>(); for(StorageConfig config : this.storages){ storages.add(config.createStorage()); } - //Create Metrics - List metrics = new ArrayList<>(); - for(MetricConfig config : this.metrics){ - metrics.add(config.createMetric()); - } - StorageManager.getInstance().addStorages(storages); - MetricManager.setMetrics(metrics); } + public static String getSuiteID() { + return suiteID; + } - private String generateSuiteID() { + private static String generateSuiteID() { int currentTimeMillisHashCode = Math.abs(Long.valueOf(Instant.now().getEpochSecond()).hashCode()); return String.valueOf(currentTimeMillisHashCode); } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java new file mode 100644 index 00000000..03440f50 --- /dev/null +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java @@ -0,0 +1,294 @@ +package org.aksw.iguana.cc.tasks.stresstest.storage.impl; + +import com.opencsv.CSVWriter; +import com.opencsv.CSVWriterBuilder; +import org.aksw.iguana.cc.config.IguanaConfig; +import org.aksw.iguana.cc.tasks.stresstest.metrics.*; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.AggregatedExecutionStatistics; +import org.aksw.iguana.cc.tasks.stresstest.storage.Storage; +import org.aksw.iguana.commons.annotation.Shorthand; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; +import org.apache.jena.rdf.model.*; +import org.apache.jena.vocabulary.RDF; +import org.apache.jena.vocabulary.RDFS; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.function.Predicate; + +@Shorthand("CSVStorage") +public class CSVStorage implements Storage { + + private static final Logger LOGGER = LoggerFactory.getLogger(CSVStorage.class); + + private final Path folder; + private final Path taskFile; + + private List workerResources; + private Resource taskRes; + private String connection; + private String connectionVersion; + private String dataset; + + public CSVStorage(String folderPath) { + Path parentFolder; + try { + parentFolder = Paths.get(folderPath); + } catch (InvalidPathException e) { + LOGGER.error("Can't store csv files, the given path is invalid.", e); + this.folder = null; + this.taskFile = null; + return; + } + + this.folder = parentFolder.resolve(IguanaConfig.getSuiteID()); + this.taskFile = this.folder.resolve("tasks-overview.csv"); + + if (!Files.exists(parentFolder)) { + try { + Files.createDirectory(parentFolder); + } catch (IOException e) { + LOGGER.error("Can't store csv files, directory couldn't be created.", e); + return; + } + } + + if (!Files.exists(folder)) { + try { + Files.createDirectory(folder); + } catch (IOException e) { + LOGGER.error("Can't store csv files, directory couldn't be created.", e); + return; + } + } + + // write headers for the tasks.csv file + try { + Files.createFile(taskFile); + } catch (IOException e) { + LOGGER.error("Couldn't create the file: " + taskFile.toAbsolutePath(), e); + return; + } + + // This only works because the metrics are initialized sooner + try (CSVWriter csvWriter = getCSVWriter(taskFile)) { + Metric[] taskMetrics = MetricManager.getMetrics().stream().filter(x -> TaskMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); + List headerList = new LinkedList<>(); + headerList.addAll(List.of("dataset", "connection", "startDate", "endDate", "noOfWorkers")); + headerList.addAll(Arrays.stream(taskMetrics).map(Metric::getAbbreviation).toList()); + String[] header = headerList.toArray(String[]::new); + csvWriter.writeNext(header, true); + } catch (IOException e) { + LOGGER.error("Error while writing to file: " + taskFile.toAbsolutePath(), e); + } + } + + /** + * Stores the task result into the storage. This method will be executed after a task has finished. + * + * @param data the given result model + */ + @Override + public void storeResult(Model data) { + try { + setObjectAttributes(data); + } catch (NoSuchElementException e) { + LOGGER.error("Error while querying the result model. The given model is probably incorrect.", e); + return; + } + + try { + storeTaskResults(data); + } catch (IOException e) { + LOGGER.error("Error while storing the task result in a csv file.", e); + } catch (NoSuchElementException e) { + LOGGER.error("Error while storing the task result in a csv file. The given model is probably incorrect.", e); + } + + // if there is only one worker, the values are going to be the same as from the task + if (workerResources.size() > 1) { + try { + Path temp = createCSVFile(dataset, connection, connectionVersion, "worker"); + storeWorkerResults(workerResources, temp, data); + for (Resource workerRes : workerResources) { + String workerID = data.listObjectsOfProperty(workerRes, IPROP.workerID).next().asLiteral().getLexicalForm(); + try { + Path file = createCSVFile(dataset, connection, connectionVersion, "worker", "query", workerID); + storeQueryResults(workerRes, file, data); + } catch (IOException e) { + LOGGER.error("Error while storing the query results of a worker in a csv file.", e); + } catch (NoSuchElementException e) { + LOGGER.error("Error while storing the query results of a worker in a csv file. The given model is probably incorrect.", e); + } + } + } catch (IOException e) { + LOGGER.error("Error while storing the worker results in a csv file.", e); + } catch (NoSuchElementException e) { + LOGGER.error("Error while storing the worker results in a csv file. The given model is probably incorrect.", e); + } + } + + try { + Path file = createCSVFile(dataset, connection, connectionVersion, "query"); + storeQueryResults(taskRes, file, data); + } catch (IOException e) { + LOGGER.error("Error while storing the query results of a task result in a csv file.", e); + } catch (NoSuchElementException e) { + LOGGER.error("Error while storing the query results of a task result in a csv file. The given model is probably incorrect.", e); + } + } + + /** + * This method sets the objects attributes by querying the given model. + * + * @param data the result model + * @throws NoSuchElementException might be thrown if the model is incorrect + */ + private void setObjectAttributes(Model data) throws NoSuchElementException { + ResIterator resIterator = data.listSubjectsWithProperty(RDF.type, IONT.dataset); + Resource datasetRes = resIterator.nextResource(); + NodeIterator nodeIterator = data.listObjectsOfProperty(datasetRes, RDFS.label); + this.dataset = nodeIterator.next().asLiteral().getLexicalForm(); + + resIterator = data.listSubjectsWithProperty(RDF.type, IONT.connection); + Resource connectionRes = resIterator.nextResource(); + nodeIterator = data.listObjectsOfProperty(connectionRes, RDFS.label); + this.connection = nodeIterator.next().asLiteral().getLexicalForm(); + this.connectionVersion = ""; + nodeIterator = data.listObjectsOfProperty(connectionRes, IPROP.version); + if (nodeIterator.hasNext()) { + this.connectionVersion = nodeIterator.next().toString(); + } + + resIterator = data.listSubjectsWithProperty(RDF.type, IONT.task); + this.taskRes = resIterator.nextResource(); + + nodeIterator = data.listObjectsOfProperty(this.taskRes, IPROP.workerResult); + this.workerResources = nodeIterator.toList().stream().map(RDFNode::asResource).toList(); + } + + /** + * Creates a CSV file with the given name values that will be located inside the parent folder. The name value are + * joined together with the character '-'. Empty values will be ignored. + * + * @param nameValues strings that build up the name of the file + * @throws IOException if an I/O error occurs + * @return path object to the created CSV file + */ + private Path createCSVFile(String... nameValues) throws IOException { + // remove empty string values + nameValues = Arrays.stream(nameValues).filter(Predicate.not(String::isEmpty)).toArray(String[]::new); + String filename = String.join("-", nameValues) + ".csv"; + Path file = this.folder.resolve(filename); + Files.createFile(file); + return this.folder.resolve(file); + } + + private static void storeQueryResults(Resource parentRes, Path file, Model data) throws IOException, NoSuchElementException { + NodeIterator nodeIterator = data.listObjectsOfProperty(parentRes, IPROP.query); + List queryResources = nodeIterator.toList().stream().map(RDFNode::asResource).toList(); + int values = 1; + boolean containsAggrStats = !MetricManager.getMetrics().stream().filter(AggregatedExecutionStatistics.class::isInstance).toList().isEmpty(); + Metric[] queryMetrics = MetricManager.getMetrics().stream().filter(x -> QueryMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); + try (CSVWriter csvWriter = getCSVWriter(file)) { + List headerList = new LinkedList<>(); + headerList.add("queryID"); + if (containsAggrStats) { + headerList.addAll(List.of("succeeded", "failed", "totalTime", "resultSize", "wrongCodes", "timeOuts", "unknownExceptions")); + values += 7; + } + headerList.addAll(Arrays.stream(queryMetrics).map(Metric::getAbbreviation).toList()); + csvWriter.writeNext(headerList.toArray(String[]::new)); + for (Resource queryRes : queryResources) { + String[] line = new String[values + queryMetrics.length]; + line[0] = data.listObjectsOfProperty(queryRes, IPROP.queryID).next().toString(); + if (containsAggrStats) { + // might happen if queries weren't executed + try { + line[1] = data.listObjectsOfProperty(queryRes, IPROP.succeeded).next().asLiteral().getLexicalForm(); + line[2] = data.listObjectsOfProperty(queryRes, IPROP.failed).next().asLiteral().getLexicalForm(); + line[3] = data.listObjectsOfProperty(queryRes, IPROP.totalTime).next().asLiteral().getLexicalForm(); + line[4] = data.listObjectsOfProperty(queryRes, IPROP.resultSize).next().asLiteral().getLexicalForm(); + line[5] = data.listObjectsOfProperty(queryRes, IPROP.wrongCodes).next().asLiteral().getLexicalForm(); + line[6] = data.listObjectsOfProperty(queryRes, IPROP.timeOuts).next().asLiteral().getLexicalForm(); + line[7] = data.listObjectsOfProperty(queryRes, IPROP.unknownException).next().asLiteral().getLexicalForm(); + } catch (NoSuchElementException e) { + continue; + } + } + for (int i = 0; i < queryMetrics.length; i++) { + try { + line[values + i] = data.listObjectsOfProperty(queryRes, IPROP.createMetricProperty(queryMetrics[i])).next().asLiteral().getLexicalForm(); + } catch (NoSuchElementException e) { + line[values + i] = ""; + } + } + csvWriter.writeNext(line, true); + } + } + } + + private void storeTaskResults(Model data) throws IOException, NoSuchElementException { + final int values = 5; + Metric[] taskMetrics = MetricManager.getMetrics().stream().filter(x -> TaskMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); + try (CSVWriter csvWriter = getCSVWriter(this.taskFile)) { + String[] line = new String[values + taskMetrics.length]; + // taskID ? + line[0] = this.dataset; + line[1] = this.connection; + line[2] = data.listObjectsOfProperty(this.taskRes, IPROP.startDate).next().asLiteral().getLexicalForm(); + line[3] = data.listObjectsOfProperty(this.taskRes, IPROP.endDate).next().asLiteral().getLexicalForm(); + line[4] = String.valueOf(this.workerResources.size()); + for (int i = 0; i < taskMetrics.length; i++) { + try { + line[values + i] = data.listObjectsOfProperty(this.taskRes, IPROP.createMetricProperty(taskMetrics[i])).next().asLiteral().getLexicalForm(); + } catch (NoSuchElementException ignored) {} + } + csvWriter.writeNext(line, true); + } + } + + private static void storeWorkerResults(List workerResources, Path file, Model data) throws IOException, NoSuchElementException { + try (CSVWriter csvWriter = getCSVWriter(file)) { + Metric[] workerMetrics = MetricManager.getMetrics().stream().filter(x -> WorkerMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); + List headerList = new LinkedList<>(); + headerList.addAll(List.of("workerID", "workerType", "noOfQueries", "timeOut")); + headerList.addAll(Arrays.stream(workerMetrics).map(Metric::getAbbreviation).toList()); + csvWriter.writeNext(headerList.toArray(String[]::new)); + for (Resource workerRes : workerResources) { + int defaultNumber = 4; + String[] line = new String[defaultNumber + workerMetrics.length]; + line[0] = data.listObjectsOfProperty(workerRes, IPROP.workerID).next().asLiteral().getLexicalForm(); + line[1] = data.listObjectsOfProperty(workerRes, IPROP.workerType).next().asLiteral().getLexicalForm(); + line[2] = data.listObjectsOfProperty(workerRes, IPROP.noOfQueries).next().asLiteral().getLexicalForm(); + line[3] = data.listObjectsOfProperty(workerRes, IPROP.timeOut).next().asLiteral().getLexicalForm(); + for (int i = 0; i < workerMetrics.length; i++) { + // Workers might miss metrics, which is fine + try { + line[defaultNumber + i] = data.listObjectsOfProperty(workerRes, IPROP.createMetricProperty(workerMetrics[i])).next().asLiteral().getLexicalForm(); + } catch (NoSuchElementException ignored) {} + } + csvWriter.writeNext(line, true); + } + } + } + + private static CSVWriter getCSVWriter(Path file) throws IOException { + return (CSVWriter) new CSVWriterBuilder(new FileWriter(file.toAbsolutePath().toString(), true)) + .withQuoteChar('\"') + .withSeparator(',') + .withLineEnd("\n") + .build(); + } +} From afb20f0f8bc46391d0a616364f51dafea717c26a Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:31:59 +0200 Subject: [PATCH 29/36] small fix to CSVStorage --- .../iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java index 03440f50..e500d840 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java @@ -55,7 +55,7 @@ public CSVStorage(String folderPath) { this.folder = parentFolder.resolve(IguanaConfig.getSuiteID()); this.taskFile = this.folder.resolve("tasks-overview.csv"); - if (!Files.exists(parentFolder)) { + if (Files.notExists(parentFolder)) { try { Files.createDirectory(parentFolder); } catch (IOException e) { @@ -64,7 +64,7 @@ public CSVStorage(String folderPath) { } } - if (!Files.exists(folder)) { + if (Files.notExists(folder)) { try { Files.createDirectory(folder); } catch (IOException e) { @@ -192,7 +192,7 @@ private Path createCSVFile(String... nameValues) throws IOException { String filename = String.join("-", nameValues) + ".csv"; Path file = this.folder.resolve(filename); Files.createFile(file); - return this.folder.resolve(file); + return file; } private static void storeQueryResults(Resource parentRes, Path file, Model data) throws IOException, NoSuchElementException { From bc7a7579280da109a52fcd4a5dcd5e20a15bf9a8 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Tue, 18 Jul 2023 18:50:16 +0200 Subject: [PATCH 30/36] use apache jena to write csv files in the CSVStorage --- pom.xml | 5 + .../stresstest/StresstestResultProcessor.java | 11 +- .../stresstest/storage/impl/CSVStorage.java | 188 ++++++++---------- 3 files changed, 98 insertions(+), 106 deletions(-) diff --git a/pom.xml b/pom.xml index 0940b7de..bcb8e56e 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,11 @@ jena-core ${jena.version} + + org.apache.jena + jena-querybuilder + ${jena.version} + junit junit diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index 0b0b21ee..6f436f2f 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -43,7 +43,11 @@ public StresstestResultProcessor(StresstestMetadata metadata) { this.workerQueryExecutions[i][j] = new LinkedList<>(); } } + taskQueryExecutions = new HashMap<>(); + for (String queryID : metadata.queryIDs()) { + taskQueryExecutions.put(queryID, new ArrayList<>()); + } } /** @@ -58,12 +62,7 @@ public void processQueryExecutions(WorkerMetadata worker, Collection()); - taskQueryExecutions.get(stat.queryID()).add(stat); - } + taskQueryExecutions.get(stat.queryID()).add(stat); } } diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java index e500d840..f382c8e4 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/impl/CSVStorage.java @@ -1,7 +1,9 @@ package org.aksw.iguana.cc.tasks.stresstest.storage.impl; +import com.opencsv.CSVReader; import com.opencsv.CSVWriter; import com.opencsv.CSVWriterBuilder; +import com.opencsv.exceptions.CsvValidationException; import org.aksw.iguana.cc.config.IguanaConfig; import org.aksw.iguana.cc.tasks.stresstest.metrics.*; import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.AggregatedExecutionStatistics; @@ -9,14 +11,16 @@ import org.aksw.iguana.commons.annotation.Shorthand; import org.aksw.iguana.commons.rdf.IONT; import org.aksw.iguana.commons.rdf.IPROP; +import org.apache.jena.arq.querybuilder.SelectBuilder; +import org.apache.jena.query.*; import org.apache.jena.rdf.model.*; +import org.apache.jena.sparql.lang.sparql_11.ParseException; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDFS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -73,7 +77,6 @@ public CSVStorage(String folderPath) { } } - // write headers for the tasks.csv file try { Files.createFile(taskFile); } catch (IOException e) { @@ -81,11 +84,12 @@ public CSVStorage(String folderPath) { return; } + // write headers for the tasks.csv file // This only works because the metrics are initialized sooner try (CSVWriter csvWriter = getCSVWriter(taskFile)) { Metric[] taskMetrics = MetricManager.getMetrics().stream().filter(x -> TaskMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); List headerList = new LinkedList<>(); - headerList.addAll(List.of("dataset", "connection", "startDate", "endDate", "noOfWorkers")); + headerList.addAll(List.of("connection", "dataset", "startDate", "endDate", "noOfWorkers")); headerList.addAll(Arrays.stream(taskMetrics).map(Metric::getAbbreviation).toList()); String[] header = headerList.toArray(String[]::new); csvWriter.writeNext(header, true); @@ -112,31 +116,28 @@ public void storeResult(Model data) { storeTaskResults(data); } catch (IOException e) { LOGGER.error("Error while storing the task result in a csv file.", e); - } catch (NoSuchElementException e) { + } catch (NoSuchElementException | ParseException e) { LOGGER.error("Error while storing the task result in a csv file. The given model is probably incorrect.", e); } - // if there is only one worker, the values are going to be the same as from the task - if (workerResources.size() > 1) { - try { - Path temp = createCSVFile(dataset, connection, connectionVersion, "worker"); - storeWorkerResults(workerResources, temp, data); - for (Resource workerRes : workerResources) { - String workerID = data.listObjectsOfProperty(workerRes, IPROP.workerID).next().asLiteral().getLexicalForm(); - try { - Path file = createCSVFile(dataset, connection, connectionVersion, "worker", "query", workerID); - storeQueryResults(workerRes, file, data); - } catch (IOException e) { - LOGGER.error("Error while storing the query results of a worker in a csv file.", e); - } catch (NoSuchElementException e) { - LOGGER.error("Error while storing the query results of a worker in a csv file. The given model is probably incorrect.", e); - } + try { + Path temp = createCSVFile(dataset, connection, connectionVersion, "worker"); + storeWorkerResults(this.taskRes, temp, data); + for (Resource workerRes : workerResources) { + String workerID = data.listObjectsOfProperty(workerRes, IPROP.workerID).next().asLiteral().getLexicalForm(); + try { + Path file = createCSVFile(dataset, connection, connectionVersion, "worker", "query", workerID); + storeQueryResults(workerRes, file, data); + } catch (IOException e) { + LOGGER.error("Error while storing the query results of a worker in a csv file.", e); + } catch (NoSuchElementException e) { + LOGGER.error("Error while storing the query results of a worker in a csv file. The given model is probably incorrect.", e); } - } catch (IOException e) { - LOGGER.error("Error while storing the worker results in a csv file.", e); - } catch (NoSuchElementException e) { - LOGGER.error("Error while storing the worker results in a csv file. The given model is probably incorrect.", e); } + } catch (IOException e) { + LOGGER.error("Error while storing the worker results in a csv file.", e); + } catch (NoSuchElementException e) { + LOGGER.error("Error while storing the worker results in a csv file. The given model is probably incorrect.", e); } try { @@ -196,92 +197,59 @@ private Path createCSVFile(String... nameValues) throws IOException { } private static void storeQueryResults(Resource parentRes, Path file, Model data) throws IOException, NoSuchElementException { - NodeIterator nodeIterator = data.listObjectsOfProperty(parentRes, IPROP.query); - List queryResources = nodeIterator.toList().stream().map(RDFNode::asResource).toList(); - int values = 1; boolean containsAggrStats = !MetricManager.getMetrics().stream().filter(AggregatedExecutionStatistics.class::isInstance).toList().isEmpty(); Metric[] queryMetrics = MetricManager.getMetrics().stream().filter(x -> QueryMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); - try (CSVWriter csvWriter = getCSVWriter(file)) { - List headerList = new LinkedList<>(); - headerList.add("queryID"); - if (containsAggrStats) { - headerList.addAll(List.of("succeeded", "failed", "totalTime", "resultSize", "wrongCodes", "timeOuts", "unknownExceptions")); - values += 7; - } - headerList.addAll(Arrays.stream(queryMetrics).map(Metric::getAbbreviation).toList()); - csvWriter.writeNext(headerList.toArray(String[]::new)); - for (Resource queryRes : queryResources) { - String[] line = new String[values + queryMetrics.length]; - line[0] = data.listObjectsOfProperty(queryRes, IPROP.queryID).next().toString(); - if (containsAggrStats) { - // might happen if queries weren't executed - try { - line[1] = data.listObjectsOfProperty(queryRes, IPROP.succeeded).next().asLiteral().getLexicalForm(); - line[2] = data.listObjectsOfProperty(queryRes, IPROP.failed).next().asLiteral().getLexicalForm(); - line[3] = data.listObjectsOfProperty(queryRes, IPROP.totalTime).next().asLiteral().getLexicalForm(); - line[4] = data.listObjectsOfProperty(queryRes, IPROP.resultSize).next().asLiteral().getLexicalForm(); - line[5] = data.listObjectsOfProperty(queryRes, IPROP.wrongCodes).next().asLiteral().getLexicalForm(); - line[6] = data.listObjectsOfProperty(queryRes, IPROP.timeOuts).next().asLiteral().getLexicalForm(); - line[7] = data.listObjectsOfProperty(queryRes, IPROP.unknownException).next().asLiteral().getLexicalForm(); - } catch (NoSuchElementException e) { - continue; - } - } - for (int i = 0; i < queryMetrics.length; i++) { - try { - line[values + i] = data.listObjectsOfProperty(queryRes, IPROP.createMetricProperty(queryMetrics[i])).next().asLiteral().getLexicalForm(); - } catch (NoSuchElementException e) { - line[values + i] = ""; - } - } - csvWriter.writeNext(line, true); - } + + SelectBuilder sb = new SelectBuilder(); + sb.addWhere(parentRes, IPROP.query, "?eQ"); + queryProperties(sb, "?eQ", IPROP.queryID); + if (containsAggrStats) { + queryProperties(sb, "?eQ", IPROP.succeeded, IPROP.failed, IPROP.totalTime, IPROP.resultSize, IPROP.wrongCodes, IPROP.timeOuts, IPROP.unknownException); } + queryMetrics(sb, "?eQ", queryMetrics); + + executeAndStoreQuery(sb, file, data); } - private void storeTaskResults(Model data) throws IOException, NoSuchElementException { - final int values = 5; + private void storeTaskResults(Model data) throws IOException, NoSuchElementException, ParseException { Metric[] taskMetrics = MetricManager.getMetrics().stream().filter(x -> TaskMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); - try (CSVWriter csvWriter = getCSVWriter(this.taskFile)) { - String[] line = new String[values + taskMetrics.length]; - // taskID ? - line[0] = this.dataset; - line[1] = this.connection; - line[2] = data.listObjectsOfProperty(this.taskRes, IPROP.startDate).next().asLiteral().getLexicalForm(); - line[3] = data.listObjectsOfProperty(this.taskRes, IPROP.endDate).next().asLiteral().getLexicalForm(); - line[4] = String.valueOf(this.workerResources.size()); - for (int i = 0; i < taskMetrics.length; i++) { - try { - line[values + i] = data.listObjectsOfProperty(this.taskRes, IPROP.createMetricProperty(taskMetrics[i])).next().asLiteral().getLexicalForm(); - } catch (NoSuchElementException ignored) {} + + SelectBuilder sb = new SelectBuilder(); + sb.addVar("connection") + .addWhere("?taskRes", IPROP.connection, "?connRes") + .addWhere("?connRes", RDFS.label, "?connection") + .addVar("dataset") + .addWhere("?expRes", IPROP.dataset, "?datasetRes") + .addWhere("?datasetRes", RDFS.label, "?dataset"); + queryProperties(sb, String.format("<%s>", this.taskRes.toString()), IPROP.startDate, IPROP.endDate, IPROP.noOfWorkers); + queryMetrics(sb, String.format("<%s>", this.taskRes.toString()), taskMetrics); + + try(QueryExecution exec = QueryExecutionFactory.create(sb.build(), data); + CSVWriter csvWriter = getCSVWriter(taskFile); + ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + ResultSet results = exec.execSelect(); + ResultSetFormatter.outputAsCSV(baos, results); + + // workaround to remove the created header from the ResultSetFormatter + CSVReader reader = new CSVReader(new StringReader(baos.toString())); + try { + reader.readNext(); + csvWriter.writeNext(reader.readNext(), true); + } catch (CsvValidationException ignored) { + // shouldn't happen } - csvWriter.writeNext(line, true); } } - private static void storeWorkerResults(List workerResources, Path file, Model data) throws IOException, NoSuchElementException { - try (CSVWriter csvWriter = getCSVWriter(file)) { - Metric[] workerMetrics = MetricManager.getMetrics().stream().filter(x -> WorkerMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); - List headerList = new LinkedList<>(); - headerList.addAll(List.of("workerID", "workerType", "noOfQueries", "timeOut")); - headerList.addAll(Arrays.stream(workerMetrics).map(Metric::getAbbreviation).toList()); - csvWriter.writeNext(headerList.toArray(String[]::new)); - for (Resource workerRes : workerResources) { - int defaultNumber = 4; - String[] line = new String[defaultNumber + workerMetrics.length]; - line[0] = data.listObjectsOfProperty(workerRes, IPROP.workerID).next().asLiteral().getLexicalForm(); - line[1] = data.listObjectsOfProperty(workerRes, IPROP.workerType).next().asLiteral().getLexicalForm(); - line[2] = data.listObjectsOfProperty(workerRes, IPROP.noOfQueries).next().asLiteral().getLexicalForm(); - line[3] = data.listObjectsOfProperty(workerRes, IPROP.timeOut).next().asLiteral().getLexicalForm(); - for (int i = 0; i < workerMetrics.length; i++) { - // Workers might miss metrics, which is fine - try { - line[defaultNumber + i] = data.listObjectsOfProperty(workerRes, IPROP.createMetricProperty(workerMetrics[i])).next().asLiteral().getLexicalForm(); - } catch (NoSuchElementException ignored) {} - } - csvWriter.writeNext(line, true); - } - } + private static void storeWorkerResults(Resource taskRes, Path file, Model data) throws IOException, NoSuchElementException { + Metric[] workerMetrics = MetricManager.getMetrics().stream().filter(x -> WorkerMetric.class.isAssignableFrom(x.getClass())).toArray(Metric[]::new); + + SelectBuilder sb = new SelectBuilder(); + sb.addWhere(taskRes, IPROP.workerResult, "?worker"); + queryProperties(sb, "?worker", IPROP.workerID, IPROP.workerType, IPROP.noOfQueries, IPROP.timeOut); + queryMetrics(sb, "?worker", workerMetrics); + + executeAndStoreQuery(sb, file, data); } private static CSVWriter getCSVWriter(Path file) throws IOException { @@ -291,4 +259,24 @@ private static CSVWriter getCSVWriter(Path file) throws IOException { .withLineEnd("\n") .build(); } + + private static void queryProperties(SelectBuilder sb, String variable, Property... properties) { + for (Property prop : properties) { + sb.addVar(prop.getLocalName()).addWhere(variable, prop, "?" + prop.getLocalName()); + } + } + + private static void queryMetrics(SelectBuilder sb, String variable, Metric[] metrics) { + for (Metric m : metrics) { + sb.addVar(m.getAbbreviation()).addWhere(variable, IPROP.createMetricProperty(m), "?" + m.getAbbreviation()); + } + } + + private static void executeAndStoreQuery(SelectBuilder sb, Path file, Model data) throws IOException { + try(QueryExecution exec = QueryExecutionFactory.create(sb.build(), data); + FileOutputStream fos = new FileOutputStream(file.toFile())) { + ResultSet results = exec.execSelect(); + ResultSetFormatter.outputAsCSV(fos, results); + } + } } From 468004a3b9add7229dad0c53bebacc423af490e5 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Tue, 18 Jul 2023 18:51:15 +0200 Subject: [PATCH 31/36] add test for CSVStorage with simple test case --- .../cc/tasks/storage/impl/CSVStorageTest.java | 200 ++++++++++++++++++ .../dataset1-triplestore1-v1-query.csv | 2 + ...ataset1-triplestore1-v1-worker-query-1.csv | 2 + ...ataset1-triplestore1-v1-worker-query-2.csv | 1 + .../dataset1-triplestore1-v1-worker.csv | 3 + .../storage/csv_test_files/tasks-overview.csv | 2 + 6 files changed, 210 insertions(+) create mode 100644 src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java create mode 100644 src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-query.csv create mode 100644 src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-1.csv create mode 100644 src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-2.csv create mode 100644 src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker.csv create mode 100644 src/test/resources/storage/csv_test_files/tasks-overview.csv diff --git a/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java new file mode 100644 index 00000000..ae0f9515 --- /dev/null +++ b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java @@ -0,0 +1,200 @@ +package org.aksw.iguana.cc.tasks.storage.impl; + +import com.opencsv.CSVReader; +import com.opencsv.exceptions.CsvException; +import org.aksw.iguana.cc.config.IguanaConfig; +import org.aksw.iguana.cc.tasks.stresstest.metrics.*; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.AggregatedExecutionStatistics; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.NoQ; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.NoQPH; +import org.aksw.iguana.cc.tasks.stresstest.metrics.impl.QPS; +import org.aksw.iguana.cc.tasks.stresstest.storage.impl.CSVStorage; +import org.aksw.iguana.commons.rdf.IONT; +import org.aksw.iguana.commons.rdf.IPROP; +import org.aksw.iguana.commons.rdf.IRES; +import org.apache.commons.io.FileUtils; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.vocabulary.RDF; +import org.apache.jena.vocabulary.RDFS; +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.io.FileReader; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.*; + +public class CSVStorageTest { + CSVStorage storage; + Path folder; + Path suiteFolder; + + @BeforeEach + public void setup() throws IOException { + this.folder = Files.createTempDirectory("iguana-CSVStorage-test"); + this.suiteFolder = folder.resolve(IguanaConfig.getSuiteID()); + } + + public static Arguments createTestData1() { + // Entry records should store metric values in the same order as the metrics in the following list. + List metrics = List.of(new NoQ(), new NoQPH(), new QPS(), new AggregatedExecutionStatistics()); + + // First Task has 2 Worker + Resource datasetRes = IRES.getResource("dataset1"); + Resource experimentRes = IRES.getResource("suite/experiment"); + Resource taskRes = IRES.getResource("suite/experiment/task1"); + Resource conRes = IRES.getResource("triplestore1"); + Resource workerRes1 = IRES.getResource("worker1"); + Resource workerRes2 = IRES.getResource("worker2"); + Resource taskQueryRes = IRES.getResource("task-query"); + Resource workerQueryRes1 = IRES.getResource("worker-query-1"); + Resource workerQueryRes2 = IRES.getResource("worker-query-2"); + Resource queryRes1 = IRES.getResource("query1"); + Resource queryRes2 = IRES.getResource("query2"); + + Model m = ModelFactory.createDefaultModel(); + + m.add(experimentRes, RDF.type, IONT.experiment); + m.add(experimentRes, IPROP.dataset, datasetRes); + m.add(experimentRes, IPROP.task, taskRes); + m.add(datasetRes, RDFS.label, ResourceFactory.createTypedLiteral("dataset1")); + m.add(datasetRes, RDF.type, IONT.dataset); + m.add(conRes, RDF.type, IONT.connection); + m.add(conRes, RDFS.label, ResourceFactory.createTypedLiteral("triplestore1")); + m.add(conRes, IPROP.version, ResourceFactory.createTypedLiteral("v1")); + m.add(taskRes, RDF.type, IONT.task); + m.add(taskRes, IPROP.connection, conRes); + m.add(taskRes, IPROP.startDate, ResourceFactory.createTypedLiteral("now")); + m.add(taskRes, IPROP.endDate, ResourceFactory.createTypedLiteral("then")); + m.add(taskRes, IPROP.workerResult, workerRes1); + m.add(taskRes, IPROP.workerResult, workerRes2); + m.add(taskRes, IPROP.noOfWorkers, ResourceFactory.createTypedLiteral(2)); + m.add(taskRes, IPROP.createMetricProperty(new NoQ()), ResourceFactory.createTypedLiteral(BigInteger.valueOf(2))); + m.add(taskRes, IPROP.createMetricProperty(new NoQPH()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(20,2))); + m.add(taskRes, IPROP.query, taskQueryRes); + + m.add(workerRes1, RDF.type, IONT.worker); + m.add(workerRes1, IPROP.workerID, ResourceFactory.createTypedLiteral(BigInteger.valueOf(1))); + m.add(workerRes1, IPROP.workerType, ResourceFactory.createTypedLiteral("SPARQL")); + m.add(workerRes1, IPROP.noOfQueries, ResourceFactory.createTypedLiteral(BigInteger.valueOf(2))); + m.add(workerRes1, IPROP.timeOut, ResourceFactory.createTypedLiteral(BigInteger.valueOf(100))); + m.add(workerRes1, IPROP.createMetricProperty(new NoQ()), ResourceFactory.createTypedLiteral(BigInteger.valueOf(8))); + m.add(workerRes1, IPROP.createMetricProperty(new NoQPH()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(108))); + m.add(workerRes1, IPROP.query, workerQueryRes1); + + m.add(workerRes2, RDF.type, IONT.worker); + m.add(workerRes2, IPROP.workerID, ResourceFactory.createTypedLiteral(BigInteger.valueOf(2))); + m.add(workerRes2, IPROP.workerType, ResourceFactory.createTypedLiteral("LQRAPS")); + m.add(workerRes2, IPROP.noOfQueries, ResourceFactory.createTypedLiteral(BigInteger.valueOf(1))); + m.add(workerRes2, IPROP.timeOut, ResourceFactory.createTypedLiteral(BigInteger.valueOf(50))); + m.add(workerRes2, IPROP.createMetricProperty(new NoQ()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(0))); + m.add(workerRes2, IPROP.createMetricProperty(new NoQPH()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(0))); + m.add(workerRes2, IPROP.query, workerQueryRes2); + + m.add(taskQueryRes, IPROP.createMetricProperty(new QPS()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(72000, 2))); + m.add(taskQueryRes, IPROP.succeeded, ResourceFactory.createTypedLiteral(BigInteger.valueOf(2))); + m.add(taskQueryRes, IPROP.failed, ResourceFactory.createTypedLiteral(BigInteger.valueOf(0))); + m.add(taskQueryRes, IPROP.totalTime, ResourceFactory.createTypedLiteral(BigInteger.valueOf(12345))); + m.add(taskQueryRes, IPROP.resultSize, ResourceFactory.createTypedLiteral(BigInteger.valueOf(1000))); + m.add(taskQueryRes, IPROP.wrongCodes, ResourceFactory.createTypedLiteral(BigInteger.valueOf(0))); + m.add(taskQueryRes, IPROP.timeOuts, ResourceFactory.createTypedLiteral(BigInteger.valueOf(0))); + m.add(taskQueryRes, IPROP.unknownException, ResourceFactory.createTypedLiteral(BigInteger.valueOf(0))); + m.add(taskQueryRes, IPROP.queryID, queryRes1); + m.add(taskQueryRes, IPROP.createMetricProperty(new QPS()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(72000, 2))); + + m.add(workerQueryRes1, IPROP.createMetricProperty(new QPS()), ResourceFactory.createTypedLiteral(BigDecimal.valueOf(10))); + m.add(workerQueryRes1, IPROP.succeeded, ResourceFactory.createTypedLiteral(BigInteger.valueOf(1))); + m.add(workerQueryRes1, IPROP.failed, ResourceFactory.createTypedLiteral(BigInteger.valueOf(2))); + m.add(workerQueryRes1, IPROP.totalTime, ResourceFactory.createTypedLiteral(BigInteger.valueOf(100))); + m.add(workerQueryRes1, IPROP.resultSize, ResourceFactory.createTypedLiteral(BigInteger.valueOf(98))); + m.add(workerQueryRes1, IPROP.wrongCodes, ResourceFactory.createTypedLiteral(BigInteger.valueOf(3))); + m.add(workerQueryRes1, IPROP.timeOuts, ResourceFactory.createTypedLiteral(BigInteger.valueOf(4))); + m.add(workerQueryRes1, IPROP.unknownException, ResourceFactory.createTypedLiteral(BigInteger.valueOf(5))); + m.add(workerQueryRes1, IPROP.queryID, queryRes1); + + // workerQueryRes2 isn't complete, therefore won't be saved + m.add(workerQueryRes2, IPROP.queryID, queryRes2); + + Path testFileFolder = Path.of("src/test/resources/storage/csv_test_files/"); + + return Arguments.of(new Suite(List.of(m), metrics, testFileFolder)); + } + + @AfterEach + public void cleanup() throws IOException { + FileUtils.deleteDirectory(this.folder.toFile()); + } + + public static Stream data() { + return Stream.of( + createTestData1() + ); + } + + @ParameterizedTest + @MethodSource("data") + public void testCSVStorage(Suite suite) throws IOException { + for (Model m : suite.taskResults) { + // Metrics need to be set here, because the CSVStorage uses the manager to store the results + MetricManager.setMetrics(suite.metrics); + + // Test Initialisation + assertDoesNotThrow(() -> storage = new CSVStorage(this.folder.toAbsolutePath().toString())); + assertTrue(Files.exists(this.suiteFolder)); + storage.storeResult(m); + + List expectedFiles; + try (Stream s = Files.list(suite.expectedFolder)) { + expectedFiles = s.toList(); + } + + for (Path expectedFile : expectedFiles) { + Path actualFile = suiteFolder.resolve(expectedFile.getFileName()); + assertTrue(Files.exists(actualFile)); + assertDoesNotThrow(() -> compareCSVFiles(expectedFile, actualFile)); + } + } + } + + private void compareCSVFiles(Path expected, Path actual) throws IOException, CsvException { + try (CSVReader readerExpected = new CSVReader(new FileReader(expected.toFile())); + CSVReader readerActual = new CSVReader(new FileReader(actual.toFile()))) { + String[] headerExpected = readerExpected.readNext(); + String[] headerActual = readerActual.readNext(); + assertEquals(headerExpected.length, headerActual.length); + for (int i = 0; i < headerExpected.length; i++) { + assertEquals(headerExpected[i], headerActual[i]); + } + + List expectedValues = new ArrayList<>(readerExpected.readAll()); + List actualValues = new ArrayList<>(readerActual.readAll()); + + for (String[] expectedLine : expectedValues) { + List sameLines = actualValues.stream().filter(x -> { + for (int i = 0; i < expectedLine.length; i++) { + if (!expectedLine[i].equals(x[i])) return false; + } + return true; + }).toList(); + + assertFalse(sameLines.isEmpty()); + actualValues.remove(sameLines.get(0)); + } + + assertTrue(actualValues.isEmpty()); + } + } + + private record Suite(List taskResults, List metrics, Path expectedFolder) {} +} diff --git a/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-query.csv b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-query.csv new file mode 100644 index 00000000..774b809e --- /dev/null +++ b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-query.csv @@ -0,0 +1,2 @@ +queryID,succeeded,failed,totalTime,resultSize,wrongCodes,timeOuts,unknownException,QPS +http://iguana-benchmark.eu/resource/query1,2,0,12345,1000,0,0,0,720 diff --git a/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-1.csv b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-1.csv new file mode 100644 index 00000000..14cab449 --- /dev/null +++ b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-1.csv @@ -0,0 +1,2 @@ +queryID,succeeded,failed,totalTime,resultSize,wrongCodes,timeOuts,unknownException,QPS +http://iguana-benchmark.eu/resource/query1,1,2,100,98,3,4,5,10 diff --git a/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-2.csv b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-2.csv new file mode 100644 index 00000000..888ff1f2 --- /dev/null +++ b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker-query-2.csv @@ -0,0 +1 @@ +queryID,succeeded,failed,totalTime,resultSize,wrongCodes,timeOuts,unknownException,QPS diff --git a/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker.csv b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker.csv new file mode 100644 index 00000000..9d4e55d9 --- /dev/null +++ b/src/test/resources/storage/csv_test_files/dataset1-triplestore1-v1-worker.csv @@ -0,0 +1,3 @@ +workerID,workerType,noOfQueries,timeOut,NoQ,NoQPH +1,SPARQL,2,100,8,108 +2,LQRAPS,1,50,0,0 diff --git a/src/test/resources/storage/csv_test_files/tasks-overview.csv b/src/test/resources/storage/csv_test_files/tasks-overview.csv new file mode 100644 index 00000000..a3dae6eb --- /dev/null +++ b/src/test/resources/storage/csv_test_files/tasks-overview.csv @@ -0,0 +1,2 @@ +"connection","dataset","startDate","endDate","noOfWorkers","NoQ","NoQPH" +"triplestore1","dataset1","now","then","2","2","0.2" From d02c3f55652131c6934fcc77a12dab8f851d070c Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Tue, 18 Jul 2023 18:51:35 +0200 Subject: [PATCH 32/36] docs cleanup --- README.md | 10 +++------- docs/architecture.md | 1 + .../iguana/cc/tasks/stresstest/storage/Storage.java | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5fb12fb4..fb6d151e 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,6 @@ For further information visit: - [iguana-benchmark.eu](http://iguana-benchmark.eu) - [Documentation](http://iguana-benchmark.eu/docs/3.3/) -## Iguana Modules - -Iguana consists of two modules -- **corecontroller** - this will benchmark the systems -- **resultprocessor** - this will calculate the metrics and save the raw benchmark results - ### Available metrics Per run metrics: @@ -34,10 +28,12 @@ Per run metrics: * Number of Queries Per Hour (NoQPH) * Number of Queries (NoQ) * Average Queries Per Second (AvgQPS) +* Penalized Average Queries Per Second (PAvgQPS) Per query metrics: * Queries Per Second (QPS) -* number of successful and failed queries +* Penalized Queries Per Second (PQPS) +* Number of successful and failed queries * result size * queries per second * sum of execution times diff --git a/docs/architecture.md b/docs/architecture.md index 18067357..f705984e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -55,6 +55,7 @@ Per run metrics: Per query metrics: * Queries Per Second (QPS) +* Penalized Queries Per Second (PQPS) * Number of successful and failed queries * result size * queries per second diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java index a17363c8..d1b04565 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/storage/Storage.java @@ -11,7 +11,7 @@ public interface Storage { /** - * Stores the task result into the storage. + * Stores the task result into the storage. This method will be executed after a task has finished. * * @param data the given result model */ From 5248199e311a1db6c911257fbcc78b6ad9b7456d Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:02:44 +0200 Subject: [PATCH 33/36] store Duration object as XSDDuration type --- .../metrics/impl/AggregatedExecutionStatistics.java | 5 +++-- .../java/org/aksw/iguana/commons/time/TimeUtils.java | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java index 2e5883ea..a2e332cb 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/metrics/impl/AggregatedExecutionStatistics.java @@ -17,12 +17,13 @@ import org.apache.jena.vocabulary.RDF; import javax.annotation.Nonnull; -import java.math.BigDecimal; import java.math.BigInteger; import java.time.Duration; import java.util.List; import java.util.Map; +import static org.aksw.iguana.commons.time.TimeUtils.toXSDDurationInSeconds; + @Shorthand("AES") public class AggregatedExecutionStatistics extends Metric implements ModelWritingMetric { @@ -92,7 +93,7 @@ private static Model createAggregatedModel(List data, Resou m.add(queryRes, IPROP.timeOuts, ResourceFactory.createTypedLiteral(timeOuts)); m.add(queryRes, IPROP.wrongCodes, ResourceFactory.createTypedLiteral(wrongCodes)); m.add(queryRes, IPROP.unknownException, ResourceFactory.createTypedLiteral(unknownExceptions)); - m.add(queryRes, IPROP.totalTime, ResourceFactory.createTypedLiteral(new BigDecimal(BigInteger.valueOf(totalTime.toNanos()), 6))); + m.add(queryRes, IPROP.totalTime, ResourceFactory.createTypedLiteral(toXSDDurationInSeconds(totalTime))); m.add(queryRes, RDF.type, IONT.executedQuery); return m; diff --git a/src/main/java/org/aksw/iguana/commons/time/TimeUtils.java b/src/main/java/org/aksw/iguana/commons/time/TimeUtils.java index 051ddb76..46c2e13f 100644 --- a/src/main/java/org/aksw/iguana/commons/time/TimeUtils.java +++ b/src/main/java/org/aksw/iguana/commons/time/TimeUtils.java @@ -1,5 +1,10 @@ package org.aksw.iguana.commons.time; +import org.apache.jena.datatypes.xsd.XSDDuration; +import org.apache.jena.datatypes.xsd.impl.XSDDurationType; + +import java.math.BigDecimal; +import java.math.BigInteger; import java.time.Duration; import java.time.Instant; @@ -35,4 +40,8 @@ public static double durationInMilliseconds(Instant start, Instant end) { Duration duration = Duration.between(start, end); return ((long)duration.getNano() + duration.getSeconds() * 1000000000 /*ns*/) / 1000000d /*ms*/; } + + public static XSDDuration toXSDDurationInSeconds(Duration duration) { + return (XSDDuration) new XSDDurationType().parse("PT" + new BigDecimal(BigInteger.valueOf(duration.toNanos()), 9).toPlainString() + "S"); + } } From 336bd879535f083d14cb48c51ec72cc1fe4b338d Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Wed, 19 Jul 2023 15:12:50 +0200 Subject: [PATCH 34/36] add a prefix map --- .../cc/tasks/stresstest/StresstestResultProcessor.java | 6 ++---- .../java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java index 6f436f2f..c0f2dc79 100644 --- a/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java +++ b/src/main/java/org/aksw/iguana/cc/tasks/stresstest/StresstestResultProcessor.java @@ -4,6 +4,7 @@ import org.aksw.iguana.cc.worker.WorkerMetadata; import org.aksw.iguana.cc.tasks.stresstest.metrics.*; import org.aksw.iguana.cc.tasks.stresstest.storage.StorageManager; +import org.aksw.iguana.commons.rdf.IGUANA_BASE; import org.aksw.iguana.commons.rdf.IONT; import org.aksw.iguana.commons.rdf.IPROP; import org.aksw.iguana.commons.rdf.IRES; @@ -151,10 +152,7 @@ public void calculateAndSaveMetrics(Calendar start, Calendar end) { m.add(taskRes, IPROP.startDate, ResourceFactory.createTypedLiteral(start)); m.add(taskRes, IPROP.endDate, ResourceFactory.createTypedLiteral(end)); - m.setNsPrefix(IPROP.PREFIX, IPROP.NS); - m.setNsPrefix(IONT.PREFIX, IONT.NS); - m.setNsPrefix(IRES.PREFIX, IRES.NS); - m.setNsPrefix("lsqr", "http://lsq.aksw.org/res/"); + m.setNsPrefixes(IGUANA_BASE.PREFIX_MAP); StorageManager.getInstance().storeResult(m); } diff --git a/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java b/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java index b36e1faa..7dab2cb8 100644 --- a/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java +++ b/src/main/java/org/aksw/iguana/commons/rdf/IGUANA_BASE.java @@ -1,5 +1,7 @@ package org.aksw.iguana.commons.rdf; +import java.util.Map; + public class IGUANA_BASE { public static final String NS = "http://iguana-benchmark.eu" + "/"; public static final String PREFIX = "iguana"; @@ -14,4 +16,12 @@ private IGUANA_BASE() { public static String getURI() { return NS; } + + public static Map PREFIX_MAP = Map.of( + IGUANA_BASE.PREFIX, IGUANA_BASE.NS, + IONT.PREFIX, IONT.NS, + IPROP.PREFIX, IPROP.NS, + IRES.PREFIX, IRES.NS, + "lsqr", "http://lsq.aksw.org/res/" + ); } From 793dcbb2c2e026f1c15aa81c630565fd4d6afcb7 Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Wed, 19 Jul 2023 16:22:55 +0200 Subject: [PATCH 35/36] small fix --- src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java index aefae5f5..2242f7bc 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java +++ b/src/test/java/org/aksw/iguana/cc/worker/MockupWorker.java @@ -50,7 +50,7 @@ public void getNextQuery(StringBuilder queryStr, StringBuilder queryID) { this.counter = 0; } queryStr.append(this.queries[this.counter]); - queryID.append("query:").append(this.counter); + queryID.append("src/test/resources/mockupq.txt:").append(this.counter); this.counter++; } } From dac7816bab4242569c0d79f861d755eb37748a9d Mon Sep 17 00:00:00 2001 From: Nick Molcanov <32801560+nck-mlcnv@users.noreply.github.com> Date: Fri, 4 Aug 2023 17:03:00 +0200 Subject: [PATCH 36/36] add better messages to the CSVStorageTest --- .../cc/tasks/storage/impl/CSVStorageTest.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java index ae0f9515..054d6e34 100644 --- a/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java +++ b/src/test/java/org/aksw/iguana/cc/tasks/storage/impl/CSVStorageTest.java @@ -31,6 +31,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.*; +import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.*; @@ -128,7 +129,7 @@ public static Arguments createTestData1() { Path testFileFolder = Path.of("src/test/resources/storage/csv_test_files/"); - return Arguments.of(new Suite(List.of(m), metrics, testFileFolder)); + return Arguments.of(Named.of(String.format("One simple tasks with one faulty entry. | ExpectedFolder: %s | Metrics: %s", testFileFolder, metrics.stream().map(Metric::getAbbreviation).toList()), new Suite(List.of(m), metrics, testFileFolder))); } @AfterEach @@ -144,14 +145,15 @@ public static Stream data() { @ParameterizedTest @MethodSource("data") + @DisplayName("Test CSVStorage") public void testCSVStorage(Suite suite) throws IOException { for (Model m : suite.taskResults) { // Metrics need to be set here, because the CSVStorage uses the manager to store the results MetricManager.setMetrics(suite.metrics); // Test Initialisation - assertDoesNotThrow(() -> storage = new CSVStorage(this.folder.toAbsolutePath().toString())); - assertTrue(Files.exists(this.suiteFolder)); + assertDoesNotThrow(() -> storage = new CSVStorage(this.folder.toAbsolutePath().toString()), "Initialisation failed"); + assertTrue(Files.exists(this.suiteFolder), String.format("Result folder (%s) doesn't exist", this.suiteFolder)); storage.storeResult(m); List expectedFiles; @@ -161,7 +163,7 @@ public void testCSVStorage(Suite suite) throws IOException { for (Path expectedFile : expectedFiles) { Path actualFile = suiteFolder.resolve(expectedFile.getFileName()); - assertTrue(Files.exists(actualFile)); + assertTrue(Files.exists(actualFile), String.format("File (%s) doesn't exist", actualFile)); assertDoesNotThrow(() -> compareCSVFiles(expectedFile, actualFile)); } } @@ -172,9 +174,9 @@ private void compareCSVFiles(Path expected, Path actual) throws IOException, Csv CSVReader readerActual = new CSVReader(new FileReader(actual.toFile()))) { String[] headerExpected = readerExpected.readNext(); String[] headerActual = readerActual.readNext(); - assertEquals(headerExpected.length, headerActual.length); + assertEquals(headerExpected.length, headerActual.length, String.format("Headers don't match. Actual: %s, Expected: %s", Arrays.toString(headerActual), Arrays.toString(headerExpected))); for (int i = 0; i < headerExpected.length; i++) { - assertEquals(headerExpected[i], headerActual[i]); + assertEquals(headerExpected[i], headerActual[i], String.format("Headers don't match. Actual: %s, Expected: %s", Arrays.toString(headerActual), Arrays.toString(headerExpected))); } List expectedValues = new ArrayList<>(readerExpected.readAll()); @@ -188,11 +190,10 @@ private void compareCSVFiles(Path expected, Path actual) throws IOException, Csv return true; }).toList(); - assertFalse(sameLines.isEmpty()); + assertFalse(sameLines.isEmpty(), String.format("Line (%s) not found in actual file", Arrays.toString(expectedLine))); actualValues.remove(sameLines.get(0)); } - - assertTrue(actualValues.isEmpty()); + assertTrue(actualValues.isEmpty(), String.format("Actual file contains more lines than expected. Lines: %s", actualValues.stream().map(x -> "[" + String.join(", ", x) + "]").collect(Collectors.joining("\n")))); } }