Commit eff5d429 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge branch 'master' into 'cherry-pick-7698d9d7'

# Conflicts:
#   src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
#   src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
parents 1c7f20ec 37020b44
......@@ -25,7 +25,7 @@ import java.util.List;
import com.vividsolutions.jts.geom.Geometry;
import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* An obstacle (Hosts can not run through them, and communication may be either
......
......@@ -25,7 +25,7 @@ import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.Tuple;
......
......@@ -23,8 +23,8 @@ package de.tud.kom.p2psim.api.topology.placement;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/**
* Strategies and Distributions that place hosts in a {@link Topology}. These
......
......@@ -24,11 +24,13 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultWeightedEdge;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.util.geo.maps.Map;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.Tuple;
......@@ -80,7 +82,7 @@ public interface WaypointModel {
* @param waypoint
* @return
*/
public abstract List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint);
public abstract List<Tuple<Waypoint, PathEdge>> getConnectedWaypoints(Waypoint waypoint);
/**
* Returns a list of Tuple<Waypoint, Path> of a specific type that are connected to the given waypoint.
......@@ -89,14 +91,14 @@ public interface WaypointModel {
* @param type
* @return
*/
public abstract List<Tuple<Waypoint, Path>> getConnectedWaypoints(Waypoint waypoint, Class type);
public abstract List<Tuple<Waypoint, PathEdge>> getConnectedWaypoints(Waypoint waypoint, Class type);
/**
* Returns all paths that are part of the waypoint model.
*
* @return
*/
public abstract Set<Path> getPaths();
public abstract Set<PathEdge> getPaths();
/**
* Returns the shortest path between the two given waypoints.
......@@ -105,7 +107,7 @@ public interface WaypointModel {
* @param end
* @return
*/
public abstract List<Path> getShortestPath(Waypoint start, Waypoint end);
public abstract List<PathEdge> getShortestPath(Waypoint start, Waypoint end);
/**
* Returns the total number of waypoints.
......@@ -153,7 +155,7 @@ public interface WaypointModel {
/*
public abstract void setStrongWaypointStrategy(StrongWaypointStrategy strongWaypointStrategy);
*/
public DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> getGraph();
public Graph<Waypoint, PathEdge> getGraph();
/**
* Indicates if this model is scaled to the required world coordinates.
......
......@@ -20,11 +20,11 @@
package de.tud.kom.p2psim.api.topology.waypoints;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
public interface WaypointModelListener {
public void addedPath(Path path);
public void addedPath(PathEdge path);
public void addedWaypoint(Waypoint waypoint);
public void modifiedWaypoints();
}
......@@ -23,10 +23,10 @@ package de.tud.kom.p2psim.api.util.geo.maps;
import java.util.Collection;
import java.util.List;
import org.jgrapht.Graph;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener;
......@@ -39,9 +39,8 @@ public interface Map {
* @return
*/
public PositionVector getDimensions();
// TODO: Extract required functionality
public DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> getGraph();
public Graph<Waypoint, PathEdge> getGraph();
public void addWaypoint(Waypoint waypoint);
......
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.api.util.geo.maps;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public interface Node {
......
......@@ -25,6 +25,8 @@ import java.util.LinkedList;
import java.util.List;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.topology.movement.TracefileMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Oracle;
......@@ -90,7 +92,7 @@ public class MetricAnalyzer implements Analyzer {
}
for (MetricOutput outputChannel : outputs) {
outputChannel.onStop();
}
}
}
/**
......
......@@ -303,11 +303,15 @@ public abstract class AbstractFilter<M extends MetricValue<?>>
* @param blacklist
*/
public void setBlacklist(String blacklist) {
this.blacklist = blacklist.split(";");
this.blacklist = blacklist.split(";|;\\n");
for (String string : this.blacklist)
string = string.replaceAll("\\s+", "");
}
public void setWhitelist(String whitelist) {
this.whitelist = whitelist.split(";");
this.whitelist = whitelist.split(";|;\\n");
for (int i = 0; i < this.whitelist.length; i++)
this.whitelist[i] = this.whitelist[i].replaceAll("\\s+", "");
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.analyzer.metric.filter;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
/**
* calculates the delivery ratio, which is the percent of actual transferred
* messages. (1 - overhead). Uses the duplicate and message count metrics and
* merge them. Used metrics are in DELIVERY_RATIO_LIST and duplicate metric must
* end with "Dup".
*
* @author Simon Luser
* @version 1.0, 08.03.2017
*/
public class MergeDeliveryRatioFilter
extends AbstractFilter<MetricValue<Double>> {
@Override
public void onStop() {
// nothing to do
}
@Override
public String getName() {
return "DeliveryRatio";
}
@Override
protected void onInitialize(List<Metric<?>> incomingMetrics) {
// get the pairing metrics
Set<Metric<?>> duplicateMetrics = incomingMetrics.stream().filter(
m -> m.getName().endsWith("Dup") && !m.isOverallMetric())
.collect(Collectors.toSet());
Set<Metric<?>> nonDuplicateMetrics = incomingMetrics.stream().filter(
m -> !m.getName().endsWith("Dup") && !m.isOverallMetric())
.collect(Collectors.toSet());
// generate the matches and create derived metric
for (Metric<?> met : nonDuplicateMetrics) {
List<Metric<?>> matches = duplicateMetrics.stream()
.filter(m -> met.getName()
.startsWith(m.getName().substring(0,
m.getName().lastIndexOf("Dup"))))
.collect(Collectors.toList());
if (matches.size() > 1)
Monitor.log(MergeDeliveryRatioFilter.class, Level.ERROR,
"Config Error!");
else if (matches.size() == 1) {
matches.add(met);
createDerivedMetric(matches, false, met.getUnit(),
"Delivery Ratio", false);
}
}
}
@Override
protected String getNameForDerivedMetric(List<Metric<?>> inputs) {
String str = getName();
if (inputs.size() >= 1) {
str += "_";
String firstName = inputs.get(0).getName();
if (firstName.contains("Dup"))
str += firstName.substring(0, firstName.lastIndexOf("Dup"));
else
str += firstName;
}
return str;
}
@Override
protected MetricValue<Double> getDerivedMetricValueFor(
Metric<?> derivedMetric, List<Metric<?>> inputs, Host host) {
// separate the values
if (inputs.size() == 2) {
try {
MetricValue<?> duplicateVal = inputs.stream()
.filter(m -> m.getName().endsWith("Dup"))
.collect(Collectors.toList()).get(0)
.getPerHostMetric(host.getId());
MetricValue<?> receiveVal = inputs.stream()
.filter(m -> !m.getName().endsWith("Dup"))
.collect(Collectors.toList()).get(0)
.getPerHostMetric(host.getId());
if (duplicateVal == null || receiveVal == null) {
return null;
}
return new DeliveryRatioMetricValue(duplicateVal, receiveVal);
} catch (IndexOutOfBoundsException e) {
return null;
}
} else
return null;
}
/**
* calculates the delivery ratio.
*
* @author Simon Luser
* @version 1.0, 08.03.2017
*/
private class DeliveryRatioMetricValue implements MetricValue<Double> {
private MetricValue<?> duplicateVal, receiveVal;
private boolean valid;
public DeliveryRatioMetricValue(MetricValue<?> duplicateVal,
MetricValue<?> receiveVal) {
this.duplicateVal = duplicateVal;
this.receiveVal = receiveVal;
}
@Override
public Double getValue() {
Object oDup = duplicateVal.getValue();
Object oRec = receiveVal.getValue();
double nDup;
if (oDup instanceof Number) {
nDup = ((Number) oDup).doubleValue();
} else {
throw new AssertionError();
}
double nRec;
if (oRec instanceof Number) {
nRec = ((Number) oRec).doubleValue();
} else {
throw new AssertionError();
}
this.valid = duplicateVal.isValid() && receiveVal.isValid()
&& nRec > 0;
return 1 - nDup / nRec;
}
@Override
public boolean isValid() {
return valid;
}
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.analyzer.metric.filter;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
public class OnShutdownFilter extends AbstractFilter<MetricValue<?>> {
protected String description = "Shutdown Value";
private String prefix;
@Override
public void onStop() {
notifyListenersOfUpdate();
}
@Override
protected void onInitialize(List<Metric<?>> incomingMetrics) {
for (Metric metric : incomingMetrics) {
createDerivedMetric(metric, metric.isOverallMetric(), metric.getUnit(),
description + " of " + metric.getName(), true);
}
}
@Override
protected MetricValue<?> getDerivedMetricValueFor(Metric<?> derivedMetric,
List<Metric<?>> inputs, Host host) {
if (inputs.size() != 1) {
throw new AssertionError();
}
Metric input = inputs.get(0);
MetricValue inputMv = null;
if (input.isOverallMetric()) {
inputMv = input.getOverallMetric();
} else {
inputMv = input.getPerHostMetric(host.getId());
}
return inputMv;
}
@Override
protected String getNameForDerivedMetric(List<Metric<?>> inputs) {
if (inputs.size() != 1) {
throw new AssertionError();
}
if (prefix == null) {
return "OnShutdown_"
+ inputs.get(0).getName();
} else {
return prefix + "_" + inputs.get(0).getName();
}
}
/**
* Prefix to use instead of the Filtername
*
* @param prefix
* @return
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
......@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
......@@ -38,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* basic filter for more complex statistical computations on the provided
* dataset. Common functions are included as inner classes in this abstract
* filter.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -92,23 +92,22 @@ public abstract class StatisticsFilter extends
if (values == null || values.isEmpty()) {
return null;
}
LinkedList<MetricValue> mvs = new LinkedList<MetricValue>(values);
return new StatisticsMetricValue(mvs);
return new StatisticsMetricValue(values);
}
/**
* Computes statistics such as svg, sum, std...
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
private class StatisticsMetricValue implements MetricValue<Double> {
private final List<MetricValue> inputs;
private final List<? extends MetricValue<?>> inputs;
private Double result = Double.NaN;
public StatisticsMetricValue(List<MetricValue> inputs) {
public StatisticsMetricValue(List<? extends MetricValue<?>> inputs) {
this.inputs = inputs;
}
......@@ -175,7 +174,7 @@ public abstract class StatisticsFilter extends
/**
* Function that has to compute sth. on the double-list. For convenience,
* some basic statistical values are already included.
*
*
* @param incoming
* @param count
* number of values
......@@ -191,7 +190,7 @@ public abstract class StatisticsFilter extends
/**
* Standard deviation
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -208,7 +207,7 @@ public abstract class StatisticsFilter extends
/**
* Average
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -231,7 +230,7 @@ public abstract class StatisticsFilter extends
/**
* Minimum
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -250,7 +249,7 @@ public abstract class StatisticsFilter extends
/**
* Maximum
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......@@ -271,7 +270,7 @@ public abstract class StatisticsFilter extends
* The Percentile, pass a value between 0 (exclusive) and 100 (inclusive).
* The resulting metric will be called "P20_incomingmetric" in the case of
* the 20th percentile.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
......
......@@ -100,11 +100,15 @@ public abstract class AbstractOutput implements MetricOutput {
* @param blacklist
*/
public void setBlacklist(String blacklist) {
this.blacklist = blacklist.split(";");
this.blacklist = blacklist.split(";|;\\n");
for (int i = 0; i < this.blacklist.length; i++)
this.blacklist[i] = this.blacklist[i].replaceAll("\\s+", "");
}
public void setWhitelist(String whitelist) {
this.whitelist = whitelist.split(";");
this.whitelist = whitelist.split(";|;\\n");
for (int i = 0; i < this.whitelist.length; i++)
this.whitelist[i] = this.whitelist[i].replaceAll("\\s+", "");
}
}
......@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
......@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.impl.analyzer.metric.output;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
......@@ -37,6 +38,9 @@ import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription;
import de.tud.kom.p2psim.impl.util.oracle.GlobalOracle;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveMetric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric.ActiveSpatialMetricListener;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric.SpatialMetricValue;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveMetric.ActiveMetricListener;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
......@@ -45,255 +49,412 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* This class maps {@link Metric}s to calls to the DAO on regular intervals or
* special actions.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
public class MetricOutputDAO extends AbstractOutput {
protected long timeEnableDao = 0;
protected long timeStopDao = Long.MAX_VALUE;
protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected List<MetricDaoAdapter> daoAdapters = new LinkedList<>();
/**
*
* @param table
*/
@XMLConfigurableConstructor({ "table" })
public MetricOutputDAO(String table) {
DAO.database = table;
}
public void setAddress(String address) {
DAO.address = address;
}
public void setPort(String port) {
DAO.port = port;
}
public void setUser(String user) {
DAO.username = user;
}
public void setPassword(String password) {
DAO.password = password;
}
public void setTimeEnableDao(long timeEnableDao) {
this.timeEnableDao = timeEnableDao;
}
public void setTimeStopDao(long timeStopDao) {
this.timeStopDao = timeStopDao;
}
/**
* A list of PER-HOST metrics that are NOT written individually but instead
* statistical figures for a group of hosts is written. The group of hosts
* is defined by the hostGroup from the XML-config.
*
* @param metricsToAggregate
*/
public void setToAggregate(String[] metricsToAggregate) {
for (String metric : metricsToAggregate) {
this.metricsToAggregate.add(metric);
}
}
public boolean isToAggregate(Metric metric) {
for (String string : metricsToAggregate) {
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
@Override
public void onInitialize(List<Metric> metrics) {
for (Metric metric : metrics) {
/*
* Only active metrics are allowed. We register as a listener and
* wait for our call.
*/
if (metric instanceof ActiveMetric) {
ActiveMetric am = (ActiveMetric) metric;
MetricDaoAdapter adapter = new MetricDaoAdapter(am);
am.addActiveMetricListener(adapter);
daoAdapters.add(adapter);
}
}
}
@Override
public void onStop() {
for (MetricDaoAdapter adapter : daoAdapters) {
adapter.onStop();
}
/*
* Commit missing values
*/
DAO.commitQueue();
}
/**
* This class helps in persisting a metric using the {@link MeasurementDAO}
*
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
private class MetricDaoAdapter implements ActiveMetricListener {
private final ActiveMetric metric;
private final MetricDescription md;
private final MeasurementDAO dao = new MeasurementDAO();
private final List<SimHost> hosts;
private final boolean writeAggregates;
private final Map<String, List<SimHost>> hostsByGroup;
private final Map<String, DescriptiveStatistics> globalStatsByGroup;
private long timestampLastEvent = -1;
public MetricDaoAdapter(ActiveMetric metric) {
this.metric = metric;
this.md = new MetricDescription(MetricOutputDAO.class.getName(),
metric.getName(), metric.getDescription(),
metric.getUnit().toString());
this.hosts = GlobalOracle.getHosts();
this.writeAggregates = isToAggregate(metric);
this.hostsByGroup = new LinkedHashMap<>();
this.globalStatsByGroup = new LinkedHashMap<>();
for (SimHost simHost : hosts) {
String groupId = simHost.getProperties().getGroupID();
if (!this.hostsByGroup.containsKey(groupId)) {
this.hostsByGroup.put(groupId, new LinkedList<>());
this.globalStatsByGroup.put(groupId,
new DescriptiveStatistics());
}
this.hostsByGroup.get(groupId).add(simHost);
}
}
public void onStop() {
if (writeAggregates) {
for (Entry<String, DescriptiveStatistics> groupData : globalStatsByGroup
.entrySet()) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
groupData.getKey(), Time.getCurrentTime(),
groupData.getValue(),
Time.getCurrentTime() - timeEnableDao, true);
}
globalStatsByGroup.clear();
}
}
@Override
public void onMetricUpdate(ActiveMetric metric) {
long time = Time.getCurrentTime();
if (time < timeEnableDao || time > timeStopDao) {
return;
}
if (metric.isOverallMetric()) {
// global
MetricValue mv = metric.getOverallMetric();
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val).doubleValue();
dao.storeGlobalSingleMeasurement(md, time, vd);
}
}
} else {
// per-host metric
if (writeAggregates) {
/*
* Write aggregates instead of individual metric values.
* This can be improved w.r.t. performance, but currently we
* do not really care.
*/
// Iterate over groups
for (String group : hostsByGroup.keySet()) {
DescriptiveStatistics stats = new DescriptiveStatistics();
DescriptiveStatistics globalStats = globalStatsByGroup
.get(group);
for (SimHost host : hostsByGroup.get(group)) {
MetricValue mv = metric
.getPerHostMetric(host.getId());
if (mv != null) {
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val)
.doubleValue();
if (Double.isNaN(vd)) {
continue;
}
// Add value
stats.addValue(vd);
globalStats.addValue(vd);
}
}
}
}
// Write Group stats
long observationDuration = Time.getCurrentTime()
- timestampLastEvent;
if (timestampLastEvent == -1) {
observationDuration = Time.getCurrentTime()
- timeEnableDao;
}
MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats, observationDuration, false);
}
timestampLastEvent = Time.getCurrentTime();
} else {
for (SimHost host : hosts) {
MetricValue mv = metric.getPerHostMetric(host.getId());
if (mv != null) {
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val).doubleValue();
if (Double.isNaN(vd)) {
continue;
}
dao.storeSingleMeasurement(md,
host.getHostId(), time, vd);
}
}
}
}
}
}
}
}
protected long timeEnableDao = 0;
protected long timeStopDao = Long.MAX_VALUE;
protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected List<DaoAdapter> daoAdapters = new LinkedList<>();
/**
*
* @param table
*/
@XMLConfigurableConstructor({ "table" })
public MetricOutputDAO(String table) {
DAO.setDatabase(table);
}
public void setAddress(String address) {
DAO.address = address;
}
public void setPort(String port) {
DAO.port = port;
}
public void setUser(String user) {
DAO.setUsername(user);
}
public void setPassword(String password) {
DAO.setPassword(password);
}
public void setTimeEnableDao(long timeEnableDao) {
this.timeEnableDao = timeEnableDao;
}
public void setTimeStopDao(long timeStopDao) {
this.timeStopDao = timeStopDao;
}
/**
* A list of PER-HOST metrics that are NOT written individually but instead
* statistical figures for a group of hosts is written. The group of hosts
* is defined by the hostGroup from the XML-config.
*
* @param metricsToAggregate
*/
public void setToAggregate(String[] metricsToAggregate) {
for (String metric : metricsToAggregate) {
this.metricsToAggregate.add(metric);
}
}
public boolean isToAggregate(Metric metric) {
for (String string : metricsToAggregate) {
if (metric.getName().equals(string)) {
return true;
}
if (string.endsWith("*")) {
// prefix matching
String mName = metric.getName();
if (mName.startsWith(string.substring(0, string.length()-1))) {
return true;
}
}
if (string.startsWith("*")) {
// postfix matching
String mName = metric.getName();
if (mName.endsWith(string.substring(1, string.length()))) {
return true;
}
}
}
return false;
}
@Override
public void onInitialize(List<Metric> metrics) {
for (Metric metric : metrics) {
/*
* Only active metrics are allowed. We register as a listener and
* wait for our call.
*/
if (metric instanceof ActiveMetric) {
ActiveMetric am = (ActiveMetric) metric;
MetricDaoAdapter adapter = new MetricDaoAdapter(am);
am.addActiveMetricListener(adapter);
daoAdapters.add(adapter);
}
if (metric instanceof ActiveSpatialMetric) {
ActiveSpatialMetric asm = (ActiveSpatialMetric) metric;
SpatialMetricDaoAdapter adapter = new SpatialMetricDaoAdapter(asm);
asm.addActiveSpatialMetricListener(adapter);
daoAdapters.add(adapter);
}
}
}
@Override
public void onStop() {
for (DaoAdapter adapter : daoAdapters) {
adapter.onStop();
}
/*
* Commit missing values
*/
DAO.commitQueue();
}
private interface DaoAdapter {
void onStop();
}
/**
* This class helps in persisting a metric using the {@link MeasurementDAO}
*
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
private class MetricDaoAdapter implements ActiveMetricListener, DaoAdapter {
private final ActiveMetric metric;
private final MetricDescription md;
private final MeasurementDAO dao = new MeasurementDAO();
private final List<SimHost> hosts;
private final boolean writeAggregates;
private final Map<String, List<SimHost>> hostsByGroup;
private final Map<String, DescriptiveStatistics> globalStatsByGroup;
private long timestampLastEvent = -1;
public MetricDaoAdapter(ActiveMetric metric) {
this.metric = metric;
this.md = new MetricDescription(MetricOutputDAO.class.getName(),
metric.getName(), metric.getDescription(),
metric.getUnit().toString());
this.hosts = GlobalOracle.getHosts();
this.writeAggregates = isToAggregate(metric);
this.hostsByGroup = new LinkedHashMap<>();
this.globalStatsByGroup = new LinkedHashMap<>();
for (SimHost simHost : hosts) {
String groupId = simHost.getProperties().getGroupID();
if (!this.hostsByGroup.containsKey(groupId)) {
this.hostsByGroup.put(groupId, new LinkedList<>());
this.globalStatsByGroup.put(groupId,
new DescriptiveStatistics());
}
this.hostsByGroup.get(groupId).add(simHost);
}
}
public void onStop() {
if (writeAggregates) {
for (Entry<String, DescriptiveStatistics> groupData : globalStatsByGroup
.entrySet()) {
MeasurementDAO.storeGroupStatisticsMeasurement(md,
groupData.getKey(), Time.getCurrentTime(),
groupData.getValue(),
Time.getCurrentTime() - timeEnableDao, true);
}
globalStatsByGroup.clear();
}
}
@Override
public void onMetricUpdate(ActiveMetric metric) {
long time = Time.getCurrentTime();
if (time < timeEnableDao || time > timeStopDao) {
return;
}
if (metric.isOverallMetric()) {
// global
MetricValue mv = metric.getOverallMetric();
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val).doubleValue();
dao.storeGlobalSingleMeasurement(md, time, vd);
}
}
} else {
// per-host metric
if (writeAggregates) {
/*
* Write aggregates instead of individual metric values.
* This can be improved w.r.t. performance, but currently we
* do not really care.
*/
// Iterate over groups
for (String group : hostsByGroup.keySet()) {
DescriptiveStatistics stats = new DescriptiveStatistics();
DescriptiveStatistics globalStats = globalStatsByGroup
.get(group);
for (SimHost host : hostsByGroup.get(group)) {
MetricValue mv = metric
.getPerHostMetric(host.getId());
if (mv != null) {
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val)
.doubleValue();
if (Double.isNaN(vd)) {
continue;
}
// Add valuer
if(stats != null)
stats.addValue(vd);
if(globalStats != null)
globalStats.addValue(vd);
}
}
}
}
// Write Group stats
long observationDuration = Time.getCurrentTime()
- timestampLastEvent;
if (timestampLastEvent == -1) {
observationDuration = Time.getCurrentTime()
- timeEnableDao;
}
MeasurementDAO.storeGroupStatisticsMeasurement(md,
group, time, stats, observationDuration, false);
}
timestampLastEvent = Time.getCurrentTime();
} else {
for (SimHost host : hosts) {
MetricValue mv = metric.getPerHostMetric(host.getId());
if (mv != null) {
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val).doubleValue();
if (Double.isNaN(vd)) {
continue;
}
dao.storeSingleMeasurement(md,
host.getHostId(), time, vd);
}
}
}
}
}
}
}
}
/**
* This class helps in persisting a spatial metric using the
* {@link MeasurementDAO}
*
* @author Tobias Meuser
* @version 1.0, 10.10.2018
*/
private class SpatialMetricDaoAdapter implements ActiveSpatialMetricListener, DaoAdapter {
private final MetricDescription md;
private final MeasurementDAO dao = new MeasurementDAO();
private final List<SimHost> hosts;
private final Map<String, List<SimHost>> hostsByGroup;
private final Map<String, DescriptiveStatistics> globalStatsByGroup;
private Map<GridKey, Double> values = new HashMap<>();
private long lastUpdate = -1;
private final double spatialResolution;
private ActiveSpatialMetric<?> metric;
public SpatialMetricDaoAdapter(ActiveSpatialMetric metric) {
this.metric = metric;
this.md = new MetricDescription(MetricOutputDAO.class.getName(), metric.getName(), metric.getDescription(),
metric.getUnit().toString());
this.hosts = GlobalOracle.getHosts();
this.hostsByGroup = new LinkedHashMap<>();
this.globalStatsByGroup = new LinkedHashMap<>();
for (SimHost simHost : hosts) {
String groupId = simHost.getProperties().getGroupID();
if (!this.hostsByGroup.containsKey(groupId)) {
this.hostsByGroup.put(groupId, new LinkedList<>());
this.globalStatsByGroup.put(groupId, new DescriptiveStatistics());
}
this.hostsByGroup.get(groupId).add(simHost);
}
spatialResolution = metric.getResolution();
}
@Override
public void onStop() {
store();
}
private void store() {
for (Entry<GridKey, Double> entry : values.entrySet()) {
dao.storeGlobalSpatialMeasurement(md, lastUpdate, entry.getValue(), entry.getKey().getX(),
entry.getKey().getY());
}
values.clear();
lastUpdate = Time.getCurrentTime();
}
@Override
public void onMetricUpdate(ActiveSpatialMetric<?> metric) {
long time = Time.getCurrentTime();
if (time < timeEnableDao || time > timeStopDao) {
return;
}
if (metric.isOverallMetric()) {
if (!metric.isAggregated() || Time.getCurrentTime() != lastUpdate) {
store();
}
// global
SpatialMetricValue mv = metric.getOverallMetric();
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val).doubleValue();
GridKey key = new GridKey((int) (mv.getLocation().getLongitudeOrX() / spatialResolution),
(int) (mv.getLocation().getLatitudeOrY() / spatialResolution));
if (!values.containsKey(key)) {
values.put(key, vd);
} else {
double storedValue = values.get(key);
if (storedValue < vd) {
values.put(key, vd);
}
}
}
}
} else {
for (SimHost host : hosts) {
SpatialMetricValue mv = metric.getPerHostMetric(host.getId());
if (mv != null) {
Object val = mv.getValue();
if (mv.isValid()) {
if (val instanceof Number) {
double vd = ((Number) val).doubleValue();
if (Double.isNaN(vd)) {
continue;
}
dao.storeSpatialMeasurement(md, host.getId().value(), time, vd,
(int) (mv.getLocation().getLongitudeOrX() / spatialResolution),
(int) (mv.getLocation().getLatitudeOrY() / spatialResolution));
}
}
}
}
}
}
}
private class GridKey {
private final int x;
private final int y;
public GridKey(int pX, int pY) {
x = pX;
y = pY;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
@Override
public int hashCode() {
return Integer.hashCode(x) << 16 + Integer.hashCode(y);
}
@Override
public boolean equals(Object pObj) {
if (pObj instanceof GridKey) {
return x == ((GridKey) pObj).x && y == ((GridKey) pObj).y;
}
return false;
}
}
}
......@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
......@@ -31,7 +31,7 @@ import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
/**
* Live Monitoring of all configured {@link Metric}s
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.08.2012
*/
......@@ -55,7 +55,7 @@ public class MetricOutputLive extends AbstractOutput {
/**
* Just matching the {@link ProgressValue}-interface to the
* {@link TransitMetric} interface.
*
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.08.2012
*/
......
......@@ -24,12 +24,14 @@ import java.util.LinkedList;
import java.util.List;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.DisasterMetricChartAdapter;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.MetricCDFAdapter;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.MetricChartAdapter;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.MetricPlotAdapter;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.PlottingView;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.MessageWithDisasterType.MessageDisasterType;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
......@@ -41,6 +43,13 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class MetricOutputLivePlot extends AbstractOutput implements
EventHandler {
/**
* appended in metric description to separate from normal metrics, these
* metrics have a {@link MessageDisasterType} to plot, which are visualized
* in only one graph.
*/
public static final String DRAW_ONCE = "_DRAW_ONCE_";
private List<MetricPlotAdapter> charts = new LinkedList<MetricPlotAdapter>();
protected int upperPercentile = -1;
......@@ -70,8 +79,28 @@ public class MetricOutputLivePlot extends AbstractOutput implements
if (pView == null) {
pView = VisualizationInjector.createPlottingView("Metrics");
}
MetricChartAdapter mca = new MetricChartAdapter(metric, pView,
lowerPercentile, upperPercentile, maxItemCount);
// extended by choosing disaster adapter, if it is a disaster metric
boolean isMessageDisasterMetric = false;
for (MessageDisasterType type : MessageDisasterType.values())
if (metric.getName().contains(DRAW_ONCE)
&& metric.getName().contains(type.name())) {
isMessageDisasterMetric = true;
break;
}
if (isMessageDisasterMetric)
continue;
MetricPlotAdapter mca;
if (metric.getName().contains(DRAW_ONCE))
mca = new DisasterMetricChartAdapter(metric, pView,
maxItemCount);
else
mca = new MetricChartAdapter(metric, pView, lowerPercentile,
upperPercentile, maxItemCount);
charts.add(mca);
if (enableCDF && !metric.isOverallMetric()) {
if (pViewCdf == null) {
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.analyzer.metric.spatial;
import java.util.ArrayList;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.common.metric.AbstractMetric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
public abstract class AbstractSpatialMetric<T extends AbstractSpatialMetricValue<?>> extends AbstractMetric<T> implements Metric<T>, ActiveSpatialMetric<T> {
protected boolean aggregate = false;
public AbstractSpatialMetric(String pDescription, MetricUnit pUnit) {
super(pDescription, pUnit);
}
public AbstractSpatialMetric(String pName, String pDescription, MetricUnit pUnit) {
super(pName, pDescription, pUnit);
}
protected void setOverallMetric(T aggregate) {
super.setOverallMetric(aggregate);
}
@Override
public boolean isAggregated() {
return aggregate;
}
private List<ActiveSpatialMetricListener> _listeners = new ArrayList<>();
@Override
public void addActiveSpatialMetricListener(ActiveSpatialMetricListener pListener) {
_listeners.add(pListener);
}
@Override
public void notifyListeners() {
for (ActiveSpatialMetricListener activeSpatialMetricListener : _listeners) {
activeSpatialMetricListener.onMetricUpdate(this);
}
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.analyzer.metric.spatial;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveSpatialMetric.SpatialMetricValue;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public abstract class AbstractSpatialMetricValue<S extends Object> implements SpatialMetricValue<S> {
private S value;
private Location location;
private ActiveSpatialMetric<?> metric;
public AbstractSpatialMetricValue(ActiveSpatialMetric<?> pMetric) {
metric = pMetric;
}
public AbstractSpatialMetricValue(ActiveSpatialMetric<?> pMetric, S pValue) {
metric = pMetric;
value = pValue;
}
public void setValue(S pValue, Location pLocation) {
value = pValue;
location = pLocation;
metric.notifyListeners();
}
@Override
public S getValue() {
return value;
}
@Override
public Location getLocation() {
return location;
}
}
\ No newline at end of file
......@@ -114,8 +114,17 @@ public class MaxPeerCountChurnGenerator
@XMLConfigurableConstructor({ "file", "maxNumberOfNodes" })
public MaxPeerCountChurnGenerator(String file, int maxNumberOfNodes) {
this.maxNumberOfNodes = maxNumberOfNodes;
parseTrace(file);
parseTrace(file);
}
@XMLConfigurableConstructor({ "churnStart", "maxNumberOfNodes", "burstLength" })
public MaxPeerCountChurnGenerator(long churnStart, int maxNumberOfNodes, long burstLength) {
this.maxNumberOfNodes = maxNumberOfNodes;
churnInfos.add(new ChurnInfo(churnStart, burstLength, maxNumberOfNodes));
this.setChurnStart(churnStart);
}
/**
* A class that implements the {@link LifecycleComponent}-interface and can
......@@ -361,8 +370,6 @@ public class MaxPeerCountChurnGenerator
// Insanity Checks
assert startTime >= previousEndTime : "Start time for next fluctuation must be greater than previous end time.";
assert burstLength >= _minBurstLength : "The minimal length of the burst must be at least 1m.";
assert numberOfClients > 0 : "Number of nodes must be positive.";
assert numberOfClients <= maxNumberOfNodes : "Cannot configure more nodes than configured in configuration.";
......
......@@ -231,6 +231,6 @@ public class DefaultHost implements SimHost {
throw new AssertionError(
"This host was configured without any components!");
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment