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; ...@@ -25,7 +25,7 @@ import java.util.List;
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Geometry;
import de.tud.kom.p2psim.api.topology.views.TopologyView; 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 * An obstacle (Hosts can not run through them, and communication may be either
......
...@@ -25,7 +25,7 @@ import java.util.List; ...@@ -25,7 +25,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; 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; import de.tud.kom.p2psim.impl.util.Tuple;
......
...@@ -23,8 +23,8 @@ package de.tud.kom.p2psim.api.topology.placement; ...@@ -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.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent; import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle; 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.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/** /**
* Strategies and Distributions that place hosts in a {@link Topology}. These * Strategies and Distributions that place hosts in a {@link Topology}. These
......
...@@ -24,11 +24,13 @@ import java.util.Collection; ...@@ -24,11 +24,13 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; 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.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.util.geo.maps.Map; 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.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph; import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint; import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.Tuple; import de.tud.kom.p2psim.impl.util.Tuple;
...@@ -80,7 +82,7 @@ public interface WaypointModel { ...@@ -80,7 +82,7 @@ public interface WaypointModel {
* @param waypoint * @param waypoint
* @return * @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. * 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 { ...@@ -89,14 +91,14 @@ public interface WaypointModel {
* @param type * @param type
* @return * @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. * Returns all paths that are part of the waypoint model.
* *
* @return * @return
*/ */
public abstract Set<Path> getPaths(); public abstract Set<PathEdge> getPaths();
/** /**
* Returns the shortest path between the two given waypoints. * Returns the shortest path between the two given waypoints.
...@@ -105,7 +107,7 @@ public interface WaypointModel { ...@@ -105,7 +107,7 @@ public interface WaypointModel {
* @param end * @param end
* @return * @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. * Returns the total number of waypoints.
...@@ -153,7 +155,7 @@ public interface WaypointModel { ...@@ -153,7 +155,7 @@ public interface WaypointModel {
/* /*
public abstract void setStrongWaypointStrategy(StrongWaypointStrategy strongWaypointStrategy); 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. * Indicates if this model is scaled to the required world coordinates.
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
package de.tud.kom.p2psim.api.topology.waypoints; 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; import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
public interface WaypointModelListener { public interface WaypointModelListener {
public void addedPath(Path path); public void addedPath(PathEdge path);
public void addedWaypoint(Waypoint waypoint); public void addedWaypoint(Waypoint waypoint);
public void modifiedWaypoints(); public void modifiedWaypoints();
} }
...@@ -23,10 +23,10 @@ package de.tud.kom.p2psim.api.util.geo.maps; ...@@ -23,10 +23,10 @@ package de.tud.kom.p2psim.api.util.geo.maps;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import org.jgrapht.Graph;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle; import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph; import de.tud.kom.p2psim.impl.topology.waypoints.graph.PathEdge;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint; import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener; import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener;
...@@ -40,8 +40,7 @@ public interface Map { ...@@ -40,8 +40,7 @@ public interface Map {
*/ */
public PositionVector getDimensions(); public PositionVector getDimensions();
// TODO: Extract required functionality public Graph<Waypoint, PathEdge> getGraph();
public DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> getGraph();
public void addWaypoint(Waypoint waypoint); public void addWaypoint(Waypoint waypoint);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.api.util.geo.maps; 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 { public interface Node {
......
...@@ -25,6 +25,8 @@ import java.util.LinkedList; ...@@ -25,6 +25,8 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; 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.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Oracle; import de.tudarmstadt.maki.simonstrator.api.Oracle;
......
...@@ -303,11 +303,15 @@ public abstract class AbstractFilter<M extends MetricValue<?>> ...@@ -303,11 +303,15 @@ public abstract class AbstractFilter<M extends MetricValue<?>>
* @param blacklist * @param blacklist
*/ */
public void setBlacklist(String 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) { 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;
}
}
...@@ -92,8 +92,7 @@ public abstract class StatisticsFilter extends ...@@ -92,8 +92,7 @@ public abstract class StatisticsFilter extends
if (values == null || values.isEmpty()) { if (values == null || values.isEmpty()) {
return null; return null;
} }
LinkedList<MetricValue> mvs = new LinkedList<MetricValue>(values); return new StatisticsMetricValue(values);
return new StatisticsMetricValue(mvs);
} }
/** /**
...@@ -104,11 +103,11 @@ public abstract class StatisticsFilter extends ...@@ -104,11 +103,11 @@ public abstract class StatisticsFilter extends
*/ */
private class StatisticsMetricValue implements MetricValue<Double> { private class StatisticsMetricValue implements MetricValue<Double> {
private final List<MetricValue> inputs; private final List<? extends MetricValue<?>> inputs;
private Double result = Double.NaN; private Double result = Double.NaN;
public StatisticsMetricValue(List<MetricValue> inputs) { public StatisticsMetricValue(List<? extends MetricValue<?>> inputs) {
this.inputs = inputs; this.inputs = inputs;
} }
......
...@@ -100,11 +100,15 @@ public abstract class AbstractOutput implements MetricOutput { ...@@ -100,11 +100,15 @@ public abstract class AbstractOutput implements MetricOutput {
* @param blacklist * @param blacklist
*/ */
public void setBlacklist(String 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) { 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+", "");
} }
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package de.tud.kom.p2psim.impl.analyzer.metric.output; package de.tud.kom.p2psim.impl.analyzer.metric.output;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -37,6 +38,9 @@ import de.tud.kom.p2psim.impl.util.db.metric.MetricDescription; ...@@ -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.tud.kom.p2psim.impl.util.oracle.GlobalOracle;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.metric.ActiveMetric; 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.ActiveMetric.ActiveMetricListener;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric; import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue; import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
...@@ -51,13 +55,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; ...@@ -51,13 +55,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
*/ */
public class MetricOutputDAO extends AbstractOutput { public class MetricOutputDAO extends AbstractOutput {
protected long timeEnableDao = 0; protected long timeEnableDao = 0;
protected long timeStopDao = Long.MAX_VALUE; protected long timeStopDao = Long.MAX_VALUE;
protected Set<String> metricsToAggregate = new LinkedHashSet<>(); protected Set<String> metricsToAggregate = new LinkedHashSet<>();
protected List<MetricDaoAdapter> daoAdapters = new LinkedList<>(); protected List<DaoAdapter> daoAdapters = new LinkedList<>();
/** /**
* *
...@@ -65,7 +70,7 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -65,7 +70,7 @@ public class MetricOutputDAO extends AbstractOutput {
*/ */
@XMLConfigurableConstructor({ "table" }) @XMLConfigurableConstructor({ "table" })
public MetricOutputDAO(String table) { public MetricOutputDAO(String table) {
DAO.database = table; DAO.setDatabase(table);
} }
public void setAddress(String address) { public void setAddress(String address) {
...@@ -77,11 +82,11 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -77,11 +82,11 @@ public class MetricOutputDAO extends AbstractOutput {
} }
public void setUser(String user) { public void setUser(String user) {
DAO.username = user; DAO.setUsername(user);
} }
public void setPassword(String password) { public void setPassword(String password) {
DAO.password = password; DAO.setPassword(password);
} }
public void setTimeEnableDao(long timeEnableDao) { public void setTimeEnableDao(long timeEnableDao) {
...@@ -141,12 +146,18 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -141,12 +146,18 @@ public class MetricOutputDAO extends AbstractOutput {
am.addActiveMetricListener(adapter); am.addActiveMetricListener(adapter);
daoAdapters.add(adapter); daoAdapters.add(adapter);
} }
if (metric instanceof ActiveSpatialMetric) {
ActiveSpatialMetric asm = (ActiveSpatialMetric) metric;
SpatialMetricDaoAdapter adapter = new SpatialMetricDaoAdapter(asm);
asm.addActiveSpatialMetricListener(adapter);
daoAdapters.add(adapter);
}
} }
} }
@Override @Override
public void onStop() { public void onStop() {
for (MetricDaoAdapter adapter : daoAdapters) { for (DaoAdapter adapter : daoAdapters) {
adapter.onStop(); adapter.onStop();
} }
/* /*
...@@ -155,13 +166,17 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -155,13 +166,17 @@ public class MetricOutputDAO extends AbstractOutput {
DAO.commitQueue(); DAO.commitQueue();
} }
private interface DaoAdapter {
void onStop();
}
/** /**
* This class helps in persisting a metric using the {@link MeasurementDAO} * This class helps in persisting a metric using the {@link MeasurementDAO}
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012 * @version 1.0, 13.08.2012
*/ */
private class MetricDaoAdapter implements ActiveMetricListener { private class MetricDaoAdapter implements ActiveMetricListener, DaoAdapter {
private final ActiveMetric metric; private final ActiveMetric metric;
...@@ -255,8 +270,10 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -255,8 +270,10 @@ public class MetricOutputDAO extends AbstractOutput {
if (Double.isNaN(vd)) { if (Double.isNaN(vd)) {
continue; continue;
} }
// Add value // Add valuer
if(stats != null)
stats.addValue(vd); stats.addValue(vd);
if(globalStats != null)
globalStats.addValue(vd); globalStats.addValue(vd);
} }
} }
...@@ -296,4 +313,148 @@ public class MetricOutputDAO extends AbstractOutput { ...@@ -296,4 +313,148 @@ public class MetricOutputDAO extends AbstractOutput {
} }
/**
* 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;
}
}
} }
...@@ -24,12 +24,14 @@ import java.util.LinkedList; ...@@ -24,12 +24,14 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; 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.MetricCDFAdapter;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.MetricChartAdapter; 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.MetricPlotAdapter;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.PlottingView; import de.tud.kom.p2psim.impl.topology.views.visualization.ui.PlottingView;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; 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.common.metric.Metric;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
...@@ -41,6 +43,13 @@ 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 public class MetricOutputLivePlot extends AbstractOutput implements
EventHandler { 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>(); private List<MetricPlotAdapter> charts = new LinkedList<MetricPlotAdapter>();
protected int upperPercentile = -1; protected int upperPercentile = -1;
...@@ -70,8 +79,28 @@ public class MetricOutputLivePlot extends AbstractOutput implements ...@@ -70,8 +79,28 @@ public class MetricOutputLivePlot extends AbstractOutput implements
if (pView == null) { if (pView == null) {
pView = VisualizationInjector.createPlottingView("Metrics"); 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); charts.add(mca);
if (enableCDF && !metric.isOverallMetric()) { if (enableCDF && !metric.isOverallMetric()) {
if (pViewCdf == null) { 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
...@@ -117,6 +117,15 @@ public class MaxPeerCountChurnGenerator ...@@ -117,6 +117,15 @@ public class MaxPeerCountChurnGenerator
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 * A class that implements the {@link LifecycleComponent}-interface and can
* then be controlled by this generator. * then be controlled by this generator.
...@@ -361,8 +370,6 @@ public class MaxPeerCountChurnGenerator ...@@ -361,8 +370,6 @@ public class MaxPeerCountChurnGenerator
// Insanity Checks // Insanity Checks
assert startTime >= previousEndTime : "Start time for next fluctuation must be greater than previous end time."; 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 > 0 : "Number of nodes must be positive.";
assert numberOfClients <= maxNumberOfNodes : "Cannot configure more nodes than configured in configuration."; assert numberOfClients <= maxNumberOfNodes : "Cannot configure more nodes than configured in configuration.";
......
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