Merge "Issue #2545 - Get bandwidth graph data by network" into development

Former-commit-id: a31695805478d27e072d069d5d3b369001c1d80d
This commit is contained in:
Richard Peter 2013-12-05 14:54:46 -06:00 committed by Gerrit Code Review
commit 6fde307f0a
14 changed files with 875 additions and 332 deletions

View file

@ -45,6 +45,7 @@ import com.raytheon.uf.common.time.util.TimeUtil;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Nov 28, 2012 1269 lvenable Initial creation. * Nov 28, 2012 1269 lvenable Initial creation.
* Dec 13, 2012 1269 lvenable Fixes and updates. * Dec 13, 2012 1269 lvenable Fixes and updates.
* Nov 25, 2013 2545 mpduff Data sorted by network.
* *
* </pre> * </pre>
* *
@ -213,18 +214,19 @@ public abstract class AbstractCanvasImage {
switch (imageMgr.getSortBy()) { switch (imageMgr.getSortBy()) {
case NAME_ASC: case NAME_ASC:
return graphData.getSortedNames(true); return graphData.getSortedNames(true, imageMgr.getNetwork());
case NAME_DESC: case NAME_DESC:
return graphData.getSortedNames(false); return graphData.getSortedNames(false, imageMgr.getNetwork());
case CURRENT_TIME: case CURRENT_TIME:
return graphData.getSubscriptionsSortedByTime( return graphData.getSubscriptionsSortedByTime(
imageMgr.getCurrentTimeMillis(), true); imageMgr.getNetwork(), imageMgr.getCurrentTimeMillis(),
true);
case SELECTED_INTERSECT: case SELECTED_INTERSECT:
return graphData.getSubscriptionsSortedByTime( return graphData.getSubscriptionsSortedByTime(
imageMgr.getSortTimeMillis(), true); imageMgr.getNetwork(), imageMgr.getSortTimeMillis(), true);
case SELECTED_START: case SELECTED_START:
return graphData.getSubscriptionsSortedByTime( return graphData.getSubscriptionsSortedByTime(
imageMgr.getSortTimeMillis(), false); imageMgr.getNetwork(), imageMgr.getSortTimeMillis(), false);
default: default:
return new ArrayList<String>(); return new ArrayList<String>();
} }

View file

@ -101,6 +101,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
* Jan 28, 2013 1529 djohnson Disable menu items if no subscriptions selected. * Jan 28, 2013 1529 djohnson Disable menu items if no subscriptions selected.
* Oct 28, 2013 2430 mpduff Add % of bandwidth utilized graph. * Oct 28, 2013 2430 mpduff Add % of bandwidth utilized graph.
* Nov 19, 2013 1531 mpduff Made graph resizable. * Nov 19, 2013 1531 mpduff Made graph resizable.
* Nov 25, 2013 2545 mpduff Default to Opsnet if Network not available yet.
* </pre> * </pre>
* *
* @author lvenable * @author lvenable
@ -445,7 +446,12 @@ public class BandwidthCanvasComp extends Composite implements IDialogClosed,
int totalHeight = 0; int totalHeight = 0;
if (bgd != null) { if (bgd != null) {
numOfSubs = bgd.getNumberOfSubscriptions(); if (imageMgr == null) {
// Default to OPSNET
numOfSubs = bgd.getNumberOfSubscriptions(Network.OPSNET);
} else {
numOfSubs = bgd.getNumberOfSubscriptions(imageMgr.getNetwork());
}
totalHeight = AbstractCanvasImage.TEXT_OFFSET * numOfSubs; totalHeight = AbstractCanvasImage.TEXT_OFFSET * numOfSubs;
} }

View file

@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Composite;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthGraphData; import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthGraphData;
import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData; import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority; import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.datadelivery.bandwidth.ui.BandwidthImageMgr.SortBy; import com.raytheon.uf.viz.datadelivery.bandwidth.ui.BandwidthImageMgr.SortBy;
@ -53,6 +54,7 @@ import com.raytheon.uf.viz.datadelivery.bandwidth.ui.BandwidthImageMgr.SortBy;
* Jan 04, 2013 1420 mpduff Change default priority to normal priority. * Jan 04, 2013 1420 mpduff Change default priority to normal priority.
* Jan 25, 2013 1528 djohnson Subscription priority is now an enum, remove incorrect use of ordinal values. * Jan 25, 2013 1528 djohnson Subscription priority is now an enum, remove incorrect use of ordinal values.
* Oct 28, 2013 2430 mpduff Add % of bandwidth utilized graph. * Oct 28, 2013 2430 mpduff Add % of bandwidth utilized graph.
* Nov 25, 2013 2545 mpduff Data organized by network.
* *
* </pre> * </pre>
* *
@ -154,6 +156,10 @@ public class GraphImage extends AbstractCanvasImage {
* Graphics Context * Graphics Context
*/ */
private void drawData(GC gc) { private void drawData(GC gc) {
if (graphData == null) {
return;
}
windowTimeInfoMap.clear(); windowTimeInfoMap.clear();
int offset = 22; int offset = 22;
@ -161,30 +167,26 @@ public class GraphImage extends AbstractCanvasImage {
Color c = null; Color c = null;
gc.setForeground(display.getSystemColor(SWT.COLOR_GRAY)); gc.setForeground(display.getSystemColor(SWT.COLOR_GRAY));
if (graphData == null) { Network network = imageMgr.getNetwork();
return;
}
long currentTimeMillis = imageMgr.getCurrentTimeMillis(); long currentTimeMillis = imageMgr.getCurrentTimeMillis();
// Loop over data and draw // Loop over data and draw
Map<String, List<TimeWindowData>> dataMap = graphData.getDataMap();
List<String> subscriptionList = getSortedData(); List<String> subscriptionList = getSortedData();
for (String subName : subscriptionList) { for (String subName : subscriptionList) {
if (imageMgr.isColorByPriority()) { if (imageMgr.isColorByPriority()) {
if (graphData.getPriority(subName) == SubscriptionPriority.NORMAL) { if (graphData.getPriority(network, subName) == SubscriptionPriority.NORMAL) {
c = new Color( c = new Color(
display, display,
imageMgr.getPriorityColor(SubscriptionPriority.NORMAL)); imageMgr.getPriorityColor(SubscriptionPriority.NORMAL));
gc.setBackground(c); gc.setBackground(c);
} else if (graphData.getPriority(subName) == SubscriptionPriority.HIGH) { } else if (graphData.getPriority(network, subName) == SubscriptionPriority.HIGH) {
c = new Color( c = new Color(
display, display,
imageMgr.getPriorityColor(SubscriptionPriority.HIGH)); imageMgr.getPriorityColor(SubscriptionPriority.HIGH));
gc.setBackground(c); gc.setBackground(c);
} else if (graphData.getPriority(subName) == SubscriptionPriority.LOW) { } else if (graphData.getPriority(network, subName) == SubscriptionPriority.LOW) {
c = new Color(display, c = new Color(display,
imageMgr.getPriorityColor(SubscriptionPriority.LOW)); imageMgr.getPriorityColor(SubscriptionPriority.LOW));
gc.setBackground(c); gc.setBackground(c);
@ -204,7 +206,8 @@ public class GraphImage extends AbstractCanvasImage {
} }
long startTime = 0; long startTime = 0;
List<TimeWindowData> timeWindows = dataMap.get(subName); List<TimeWindowData> timeWindows = graphData.getTimeWindowArray(
imageMgr.getNetwork(), subName);
for (TimeWindowData data : timeWindows) { for (TimeWindowData data : timeWindows) {
startTime = data.getTimeWindowStartTime(); startTime = data.getTimeWindowStartTime();
if (data.getTimeWindowEndTime() < currentTimeMillis) { if (data.getTimeWindowEndTime() < currentTimeMillis) {
@ -221,7 +224,8 @@ public class GraphImage extends AbstractCanvasImage {
int xCoord2 = 0; int xCoord2 = 0;
long endTime = data.getTimeWindowEndTime(); long endTime = data.getTimeWindowEndTime();
if (endTime == startTime) { if (endTime == startTime) {
endTime = startTime + graphData.getBinTimeInMins() endTime = startTime
+ graphData.getBinTimeInMinutes(network)
* TimeUtil.MILLIS_PER_MINUTE; * TimeUtil.MILLIS_PER_MINUTE;
} }
@ -324,7 +328,6 @@ public class GraphImage extends AbstractCanvasImage {
return; return;
} }
Map<String, List<TimeWindowData>> dataMap = graphData.getDataMap();
long startTime = 0; long startTime = 0;
long currentTimeMillis = imageMgr.getCurrentTimeMillis(); long currentTimeMillis = imageMgr.getCurrentTimeMillis();
List<String> subscriptionList = getSortedData(); List<String> subscriptionList = getSortedData();
@ -332,7 +335,8 @@ public class GraphImage extends AbstractCanvasImage {
int yCoord = cs.getImageHeight() - offset; int yCoord = cs.getImageHeight() - offset;
for (String subName : subscriptionList) { for (String subName : subscriptionList) {
List<TimeWindowData> timeWindows = dataMap.get(subName); List<TimeWindowData> timeWindows = graphData.getTimeWindowArray(
imageMgr.getNetwork(), subName);
for (TimeWindowData data : timeWindows) { for (TimeWindowData data : timeWindows) {
startTime = data.getTimeWindowStartTime(); startTime = data.getTimeWindowStartTime();
if (data.getTimeWindowEndTime() < currentTimeMillis) { if (data.getTimeWindowEndTime() < currentTimeMillis) {
@ -349,8 +353,9 @@ public class GraphImage extends AbstractCanvasImage {
int xCoord2 = 0; int xCoord2 = 0;
long endTime = data.getTimeWindowEndTime(); long endTime = data.getTimeWindowEndTime();
if (endTime == startTime) { if (endTime == startTime) {
endTime = startTime + graphData.getBinTimeInMins() endTime = startTime
* TimeUtil.MILLIS_PER_MINUTE; + graphData.getBinTimeInMinutes(imageMgr
.getNetwork()) * TimeUtil.MILLIS_PER_MINUTE;
} }

View file

@ -34,7 +34,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 20, 2013 2397 bgonzale Initial creation * Sep 20, 2013 2397 bgonzale Initial creation.
* Nov 25, 2545 2545 mpduff Added bucketTimeInMinutes.
* *
* </pre> * </pre>
* *
@ -60,6 +61,9 @@ public class BandwidthBucketDescription implements
@DynamicSerializeElement @DynamicSerializeElement
private long bucketStartTime; private long bucketStartTime;
@DynamicSerializeElement
private int bucketTimeMinutes;
/** /**
* Default Constructor. * Default Constructor.
*/ */
@ -154,4 +158,44 @@ public class BandwidthBucketDescription implements
this.bucketStartTime = bucketStartTime; this.bucketStartTime = bucketStartTime;
} }
/**
* @return the bucketTimeMinutes
*/
public int getBucketTimeMinutes() {
return bucketTimeMinutes;
}
/**
* @param bucketTimeMinutes
* the bucketTimeMinutes to set
*/
public void setBucketTimeMinutes(int bucketTimeMinutes) {
this.bucketTimeMinutes = bucketTimeMinutes;
}
/**
* Get any data that is leftover after filling the bucket.
*
* @return The amount of data overage
*/
public long getLeftovers() {
long leftover = 0;
if (this.usedBytes > this.bucketSize) {
leftover = usedBytes - bucketSize;
usedBytes = bucketSize;
}
return leftover;
}
/**
* Add any leftovers from the previous buckets.
*
* @param leftovers
* data overage from previous buckets
*/
public void addLeftovers(long leftovers) {
this.usedBytes += leftovers;
}
} }

View file

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
@ -49,6 +50,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* Jan 25, 2013 1528 djohnson Subscription priority is now an enum. * Jan 25, 2013 1528 djohnson Subscription priority is now an enum.
* Sep 20, 2013 2397 bgonzale Added Map of Bucket Descriptions. * Sep 20, 2013 2397 bgonzale Added Map of Bucket Descriptions.
* Nov 19, 2013 2545 bgonzale Added 'add' method stub. Still work to do. * Nov 19, 2013 2545 bgonzale Added 'add' method stub. Still work to do.
* Nov 25, 2013 2545 mpduff Finished implementing 2545.
* *
* </pre> * </pre>
* *
@ -57,84 +59,34 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
*/ */
@DynamicSerialize @DynamicSerialize
public class BandwidthGraphData { public class BandwidthGraphData {
/** Subscription Name -> TimeWindowData list */ /** Network -> List of SubscriptionWindowData */
@DynamicSerializeElement @DynamicSerializeElement
private Map<String, List<TimeWindowData>> dataMap; private Map<Network, List<SubscriptionWindowData>> networkDataMap;
/** Subscription Name -> Subscription Priority */
@DynamicSerializeElement
private Map<String, SubscriptionPriority> priorityMap;
/** Network -> Bandwidth Bucket Descriptions */ /** Network -> Bandwidth Bucket Descriptions */
@DynamicSerializeElement @DynamicSerializeElement
private Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap; private Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap;
/** Bin duration in minutes */
@DynamicSerializeElement
private int binTimeInMins;
/** /**
* Constructor. * Constructor.
*
* @deprecated Required by dynamic serialization, use
* {@link #BandwidthGraphData(int)} instead.
*/ */
@Deprecated
public BandwidthGraphData() { public BandwidthGraphData() {
this(3); networkDataMap = new HashMap<Network, List<SubscriptionWindowData>>(2);
networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>(
2);
} }
/** /**
* Constructor. * Save the bucket descriptions.
* *
* @param binTimeMins * @param network
* bin duration in minutes * The network the buckets belong to
* @param buckets
* The buckets to save
*/ */
public BandwidthGraphData(int binTimeMins) { public void addBucketDescriptions(Network network,
this.binTimeInMins = binTimeMins; SortedSet<BandwidthBucketDescription> buckets) {
dataMap = new HashMap<String, List<TimeWindowData>>(); networkBucketMap.put(network, buckets);
priorityMap = new HashMap<String, SubscriptionPriority>();
}
/**
* Add the other BandwidthGraphData data to this object.
*
* @param other
*/
public void add(BandwidthGraphData other) {
/*
* TODO merge SBN and OPSNET data into on Bandwidth Graph Data
*/
}
/**
* @return the dataMap
*/
public Map<String, List<TimeWindowData>> getDataMap() {
return dataMap;
}
/**
* @param dataMap
* the dataMap to set
*/
public void setDataMap(Map<String, List<TimeWindowData>> dataMap) {
this.dataMap = dataMap;
}
/**
* @return the priorityMap
*/
public Map<String, SubscriptionPriority> getPriorityMap() {
return priorityMap;
}
/**
* @param priorityMap
* the priorityMap to set
*/
public void setPriorityMap(Map<String, SubscriptionPriority> priorityMap) {
this.priorityMap = priorityMap;
} }
/** /**
@ -160,124 +112,115 @@ public class BandwidthGraphData {
this.networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>(); this.networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>();
for (Entry<Network, SortedSet<BandwidthBucketDescription>> descEntry : networkBucketMap for (Entry<Network, SortedSet<BandwidthBucketDescription>> descEntry : networkBucketMap
.entrySet()) { .entrySet()) {
this.networkBucketMap.put(descEntry.getKey(), this.networkBucketMap.put(
descEntry.getKey(),
new TreeSet<BandwidthBucketDescription>( new TreeSet<BandwidthBucketDescription>(
(Collection<BandwidthBucketDescription>) descEntry (Collection<BandwidthBucketDescription>) descEntry
.getValue())); .getValue()));
} }
} }
/**
* @return the binTimeInMins
*/
public int getBinTimeInMins() {
return binTimeInMins;
}
/**
* @param binTimeInMins
* the binTimeInMins to set
*/
public void setBinTimeInMins(int binTimeInMins) {
this.binTimeInMins = binTimeInMins;
}
/**
* Get the bin time in minutes
*
* @return bin time
*/
public int getBinTimeInMinutes() {
return binTimeInMins;
}
/**
* Add a Graph Data Array.
*
* @param subscriptionName
* @param priority
* @param dataArray
*/
public void addGraphDataArray(String subscriptionName,
SubscriptionPriority priority,
List<TimeWindowData> dataArray) {
dataMap.put(subscriptionName, dataArray);
priorityMap.put(subscriptionName, priority);
}
/** /**
* Get the sorted names. * Get the sorted names.
* *
* @param ascending * @param ascending
* sort in ascending or descending, true for ascending * sort in ascending or descending, true for ascending
* @param network
* The network type requested
* @return List of names * @return List of names
*/ */
public List<String> getSortedNames(boolean ascending) { public List<String> getSortedNames(boolean ascending, Network network) {
ArrayList<String> keyArray = new ArrayList<String>(); List<SubscriptionWindowData> subList = this.networkDataMap.get(network);
List<String> subNameList = new ArrayList<String>(subList.size());
for (String s : dataMap.keySet()) { for (SubscriptionWindowData s : subList) {
keyArray.add(s); subNameList.add(s.getSubscriptionName());
} }
Collections.sort(keyArray);
/* /*
* Since the data will be drawn from the bottom up, ascending is * Since the data will be drawn from the bottom up, ascending is
* actually reverse order of the sort. * actually reverse order of the sort.
*/ */
if (ascending) { if (ascending) {
Collections.reverse(keyArray); Collections.reverse(subNameList);
} else {
Collections.sort(subNameList);
} }
return keyArray; return subNameList;
} }
/** /**
* Sort the graph data * Sort the graph data
*/ */
public void sortGraphData() { public void sortGraphData() {
for (Entry<String, List<TimeWindowData>> entry : dataMap.entrySet()) { for (Entry<Network, List<SubscriptionWindowData>> entry : networkDataMap
Collections.sort(entry.getValue()); .entrySet()) {
for (SubscriptionWindowData swd : entry.getValue()) {
Collections.sort(swd.getWindowDataList());
}
} }
} }
/** /**
* Get the time window array for the subscription * Get the time window array for the subscription
* *
* @param network
* The Network
*
* @param subName * @param subName
* Subscription name * Subscription name
* *
* @return List of TimeWindowData objects * @return List of TimeWindowData objects
*/ */
public List<TimeWindowData> getTimeWindowArray(String subName) { public List<TimeWindowData> getTimeWindowArray(Network network,
return dataMap.get(subName); String subName) {
for (Entry<Network, List<SubscriptionWindowData>> entry : networkDataMap
.entrySet()) {
for (SubscriptionWindowData swd : entry.getValue()) {
if (swd.getSubscriptionName().equals(subName)) {
return swd.getWindowDataList();
}
}
}
return new ArrayList<TimeWindowData>(0);
} }
/** /**
* Get the priority for the subscription name. * Get the priority for the subscription name.
* *
* @param subscriptionName * @param network
* The network to check for the subscription name
*
* @param subName
* The subscription name. * The subscription name.
* @return The priority number. * @return The priority number.
*/ */
public SubscriptionPriority getPriority(String subscriptionName) { public SubscriptionPriority getPriority(Network network, String subName) {
if (priorityMap.containsKey(subscriptionName)) { for (Entry<Network, List<SubscriptionWindowData>> entry : networkDataMap
return priorityMap.get(subscriptionName); .entrySet()) {
for (SubscriptionWindowData swd : entry.getValue()) {
if (swd.getSubscriptionName().equals(subName)) {
return swd.getPriority();
}
}
} }
// This should never occur. // This should never occur.
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Unable to find a priority for subscription [" "Unable to find a priority for subscription [" + subName + "]");
+ subscriptionName + "]");
} }
/** /**
* Get the number of subscriptions * Get the number of subscriptions
* *
* @param network
* The network to check
*
* @return Number of subscriptions * @return Number of subscriptions
*/ */
public int getNumberOfSubscriptions() { public int getNumberOfSubscriptions(Network network) {
return dataMap.keySet().size(); return networkDataMap.get(network).size();
} }
/** /**
@ -285,10 +228,17 @@ public class BandwidthGraphData {
* window time. If two subscription share the same time window time then the * window time. If two subscription share the same time window time then the
* subscription names will be in alphabetical order. * subscription names will be in alphabetical order.
* *
* @param network
* The network
* @param currentTime
* The time
* @param intersect
* True if current time intesects the download window
*
* @return List of subscription names. * @return List of subscription names.
*/ */
public List<String> getSubscriptionsSortedByTime(long currentTime, public List<String> getSubscriptionsSortedByTime(Network network,
boolean intersect) { long currentTime, boolean intersect) {
/* /*
* Sort each of the subscriptions array time windows so they are in * Sort each of the subscriptions array time windows so they are in
* order by time window start time. * order by time window start time.
@ -302,9 +252,8 @@ public class BandwidthGraphData {
Map<Long, List<String>> sortedTimeMap = new TreeMap<Long, List<String>>(); Map<Long, List<String>> sortedTimeMap = new TreeMap<Long, List<String>>();
long startTime = 0L; long startTime = 0L;
for (Entry<String, List<TimeWindowData>> entry : dataMap.entrySet()) { for (SubscriptionWindowData swd : networkDataMap.get(network)) {
if (!entry.getValue().isEmpty()) { for (TimeWindowData data : swd.getWindowDataList()) {
for (TimeWindowData data : entry.getValue()) {
if (intersect) { if (intersect) {
if (data.getTimeWindowEndTime() > currentTime) { if (data.getTimeWindowEndTime() > currentTime) {
startTime = data.getTimeWindowStartTime(); startTime = data.getTimeWindowStartTime();
@ -317,15 +266,15 @@ public class BandwidthGraphData {
} }
} }
} }
if (sortedTimeMap.containsKey(startTime)) { if (sortedTimeMap.containsKey(startTime)) {
sortedTimeMap.get(startTime).add(entry.getKey()); sortedTimeMap.get(startTime).add(swd.getSubscriptionName());
} else { } else {
List<String> tmpArray = new ArrayList<String>(); List<String> tmpArray = new ArrayList<String>();
tmpArray.add(entry.getKey()); tmpArray.add(swd.getSubscriptionName());
sortedTimeMap.put(startTime, tmpArray); sortedTimeMap.put(startTime, tmpArray);
} }
} }
}
/* /*
* Take the sorted map of time window start times and subscription names * Take the sorted map of time window start times and subscription names
@ -341,4 +290,73 @@ public class BandwidthGraphData {
return sortedSubscriptionNames; return sortedSubscriptionNames;
} }
/**
* Get a list of available networks
*
* @return List of available Networks
*/
public List<String> getAvailableNetworks() {
List<String> networkList = new ArrayList<String>(3);
for (Network network : networkDataMap.keySet()) {
networkList.add(network.name());
}
return networkList;
}
/**
* @return the networkDataMap
*/
public Map<Network, List<SubscriptionWindowData>> getNetworkDataMap() {
return networkDataMap;
}
/**
* @param networkDataMap
* the networkDataMap to set
*/
public void setNetworkDataMap(
Map<Network, List<SubscriptionWindowData>> networkDataMap) {
this.networkDataMap = networkDataMap;
}
/**
* Get the bin time in minutes.
*
* @param network
* The network to check
* @return The bin time in minutes
*/
public int getBinTimeInMinutes(Network network) {
Set<BandwidthBucketDescription> bucketSet = this.networkBucketMap
.get(network);
return bucketSet.iterator().next().getBucketTimeMinutes();
}
/**
* Merge another Bandwidth graph data into this object.
*
* @param data2
* The other data set to merge
*/
public void merge(BandwidthGraphData data2) {
Map<Network, SortedSet<BandwidthBucketDescription>> nbm = data2
.getNetworkBucketMap();
for (Network network : nbm.keySet()) {
if (!networkBucketMap.containsKey(network)) {
networkBucketMap.put(network, nbm.get(network));
}
}
Map<Network, List<SubscriptionWindowData>> ndm = data2
.getNetworkDataMap();
for (Network network : ndm.keySet()) {
if (!networkDataMap.containsKey(network)) {
networkDataMap.put(network, ndm.get(network));
}
}
}
} }

View file

@ -0,0 +1,242 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.datadelivery.bandwidth.data;
import java.util.ArrayList;
import java.util.List;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* Subscription object holding the download window information.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 21, 2013 2545 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
@DynamicSerialize
public class SubscriptionWindowData {
/** The network this subscription is associate with */
@DynamicSerializeElement
private Network network;
/** The registry id of the subscription */
@DynamicSerializeElement
private String registryId;
/** The subscription name */
@DynamicSerializeElement
private String subscriptionName;
/** The list of download window data */
@DynamicSerializeElement
private List<TimeWindowData> windowDataList;
/** The subscription's priority */
@DynamicSerializeElement
private SubscriptionPriority priority;
/**
* Default Constructor.
*/
public SubscriptionWindowData() {
windowDataList = new ArrayList<TimeWindowData>();
}
/**
* Constructor.
*
* @param subscriptionName
* The subscription's name
* @param windowsDataList
* The list of download window data
* @param priority
* The subscription's priority
*/
public SubscriptionWindowData(String subscriptionName,
List<TimeWindowData> windowsDataList, SubscriptionPriority priority) {
this.subscriptionName = subscriptionName;
this.windowDataList = windowsDataList;
this.priority = priority;
}
/**
* @return the subscriptionName
*/
public String getSubscriptionName() {
return subscriptionName;
}
/**
* @param subscriptionName
* the subscriptionName to set
*/
public void setSubscriptionName(String subscriptionName) {
this.subscriptionName = subscriptionName;
}
/**
* @return the windowDataList
*/
public List<TimeWindowData> getWindowDataList() {
return windowDataList;
}
/**
* @param windowDataList
* the windowDataList to set
*/
public void setWindowDataList(List<TimeWindowData> windowDataList) {
this.windowDataList = windowDataList;
}
/**
* Add a TimeWindowData object
*/
public void addTimeWindow(TimeWindowData windowData) {
this.windowDataList.add(windowData);
}
/**
* @return the priority
*/
public SubscriptionPriority getPriority() {
return priority;
}
/**
* @param priority
* the priority to set
*/
public void setPriority(SubscriptionPriority priority) {
this.priority = priority;
}
/**
* @return the network
*/
public Network getNetwork() {
return network;
}
/**
* @param network
* the network to set
*/
public void setNetwork(Network network) {
this.network = network;
}
/**
* @return the registryId
*/
public String getRegistryId() {
return registryId;
}
/**
* @param registryId
* the registryId to set
*/
public void setRegistryId(String registryId) {
this.registryId = registryId;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((network == null) ? 0 : network.hashCode());
result = prime * result
+ ((priority == null) ? 0 : priority.hashCode());
result = prime * result
+ ((registryId == null) ? 0 : registryId.hashCode());
result = prime
* result
+ ((subscriptionName == null) ? 0 : subscriptionName.hashCode());
result = prime * result
+ ((windowDataList == null) ? 0 : windowDataList.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof SubscriptionWindowData)) {
return false;
}
SubscriptionWindowData other = (SubscriptionWindowData) obj;
if (network != other.network) {
return false;
}
if (priority != other.priority) {
return false;
}
if (registryId == null) {
if (other.registryId != null) {
return false;
}
} else if (!registryId.equals(other.registryId)) {
return false;
}
if (subscriptionName == null) {
if (other.subscriptionName != null) {
return false;
}
} else if (!subscriptionName.equals(other.subscriptionName)) {
return false;
}
if (windowDataList == null) {
if (other.windowDataList != null) {
return false;
}
} else if (!windowDataList.equals(other.windowDataList)) {
return false;
}
return true;
}
}

View file

@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
@ -42,6 +43,7 @@ import com.raytheon.uf.common.time.util.TimeUtil;
* Nov 25, 2012 1269 lvenable Initial creation. * Nov 25, 2012 1269 lvenable Initial creation.
* Dec 06, 2012 1397 djohnson Add dynamic serialize class annotation. * Dec 06, 2012 1397 djohnson Add dynamic serialize class annotation.
* Jan 07, 2013 1451 djohnson Use TimeUtil.newGmtCalendar(). * Jan 07, 2013 1451 djohnson Use TimeUtil.newGmtCalendar().
* Nov 25, 2013 2545 mpduff Add Network.
* *
* </pre> * </pre>
* *
@ -62,6 +64,10 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
@DynamicSerializeElement @DynamicSerializeElement
private List<Long> binStartTimes; private List<Long> binStartTimes;
/** The network for the data */
@DynamicSerializeElement
private Network network;
/** /**
* Constructor. * Constructor.
* *
@ -88,16 +94,10 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
* already be at the minute so this maybe redundant but we need to * already be at the minute so this maybe redundant but we need to
* remove the seconds and millisecond to graph properly. * remove the seconds and millisecond to graph properly.
*/ */
this.timeWindowStartTime = (windowStartTime / TimeUtil.MILLIS_PER_MINUTE) * TimeUtil.MILLIS_PER_MINUTE; this.timeWindowStartTime = (windowStartTime / TimeUtil.MILLIS_PER_MINUTE)
this.timeWindowEndTime = (windowEndTime / TimeUtil.MILLIS_PER_MINUTE) * TimeUtil.MILLIS_PER_MINUTE; * TimeUtil.MILLIS_PER_MINUTE;
this.timeWindowEndTime = (windowEndTime / TimeUtil.MILLIS_PER_MINUTE)
init(); * TimeUtil.MILLIS_PER_MINUTE;
}
/**
* Initialize.
*/
private void init() {
binStartTimes = new ArrayList<Long>(); binStartTimes = new ArrayList<Long>();
} }
@ -108,7 +108,7 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
*/ */
public void setBinTimes(List<Long> binTimesArray) { public void setBinTimes(List<Long> binTimesArray) {
binStartTimes = binTimesArray; binStartTimes = binTimesArray;
Collections.sort(binStartTimes); sortBinStartTimes();
} }
/** /**
@ -118,8 +118,10 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
*/ */
public void addBinTime(Long binStartTime) { public void addBinTime(Long binStartTime) {
if (validBinStartTime(binStartTime)) { if (validBinStartTime(binStartTime)) {
long roundedBinTime = (binStartTime / TimeUtil.MILLIS_PER_MINUTE) * TimeUtil.MILLIS_PER_MINUTE; long roundedBinTime = (binStartTime / TimeUtil.MILLIS_PER_MINUTE)
* TimeUtil.MILLIS_PER_MINUTE;
binStartTimes.add(roundedBinTime); binStartTimes.add(roundedBinTime);
sortBinStartTimes();
return; return;
} }
} }
@ -131,7 +133,8 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
* @return true if bin time is within the time window * @return true if bin time is within the time window
*/ */
private boolean validBinStartTime(Long binStartTime) { private boolean validBinStartTime(Long binStartTime) {
return binStartTime >= timeWindowStartTime && binStartTime <= timeWindowEndTime; return binStartTime >= timeWindowStartTime
&& binStartTime <= timeWindowEndTime;
} }
/** /**
@ -183,26 +186,44 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
} }
/** /**
* @param timeWindowStartTime the timeWindowStartTime to set * @param timeWindowStartTime
* the timeWindowStartTime to set
*/ */
public void setTimeWindowStartTime(long timeWindowStartTime) { public void setTimeWindowStartTime(long timeWindowStartTime) {
this.timeWindowStartTime = timeWindowStartTime; this.timeWindowStartTime = timeWindowStartTime;
} }
/** /**
* @param timeWindowEndTime the timeWindowEndTime to set * @param timeWindowEndTime
* the timeWindowEndTime to set
*/ */
public void setTimeWindowEndTime(long timeWindowEndTime) { public void setTimeWindowEndTime(long timeWindowEndTime) {
this.timeWindowEndTime = timeWindowEndTime; this.timeWindowEndTime = timeWindowEndTime;
} }
/** /**
* @param binStartTimes the binStartTimes to set * @param binStartTimes
* the binStartTimes to set
*/ */
public void setBinStartTimes(List<Long> binStartTimes) { public void setBinStartTimes(List<Long> binStartTimes) {
this.binStartTimes = binStartTimes; this.binStartTimes = binStartTimes;
} }
/**
* @return the network
*/
public Network getNetwork() {
return network;
}
/**
* @param network
* the network to set
*/
public void setNetwork(Network network) {
this.network = network;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -214,7 +235,8 @@ public class TimeWindowData implements Comparable<TimeWindowData> {
cal.setTimeInMillis(this.timeWindowStartTime); cal.setTimeInMillis(this.timeWindowStartTime);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Start Time:\t").append(sdf.format(cal.getTime())).append(" Z"); sb.append("Start Time:\t").append(sdf.format(cal.getTime()))
.append(" Z");
sb.append("\n"); sb.append("\n");
cal.setTimeInMillis(this.timeWindowEndTime); cal.setTimeInMillis(this.timeWindowEndTime);
sb.append("End Time:\t").append(sdf.format(cal.getTime())).append(" Z"); sb.append("End Time:\t").append(sdf.format(cal.getTime())).append(" Z");

View file

@ -24,14 +24,13 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import com.google.common.collect.ArrayListMultimap; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Multimap;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthBucketDescription; import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthBucketDescription;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthGraphData; import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthGraphData;
import com.raytheon.uf.common.datadelivery.bandwidth.data.SubscriptionWindowData;
import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData; import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData;
import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority; import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority;
@ -61,6 +60,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
* Jun 24, 2013 2106 djohnson Access bucket allocations through RetrievalPlan. * Jun 24, 2013 2106 djohnson Access bucket allocations through RetrievalPlan.
* Jul 11, 2013 2106 djohnson Use priority straight from the BandwidthSubscription. * Jul 11, 2013 2106 djohnson Use priority straight from the BandwidthSubscription.
* Sep 20, 2013 2397 bgonzale Add Map of Bucket Descriptions to BandwidthGraphData. * Sep 20, 2013 2397 bgonzale Add Map of Bucket Descriptions to BandwidthGraphData.
* Nov 27, 2013 2545 mpduff Get data by network
* *
* </pre> * </pre>
* *
@ -79,8 +79,6 @@ class BandwidthGraphDataAdapter {
* *
* @param retrievalManager * @param retrievalManager
* the bucket time in minutes * the bucket time in minutes
* @param bandwidthDao
* the bandwidth dao
*/ */
public BandwidthGraphDataAdapter(RetrievalManager retrievalManager) { public BandwidthGraphDataAdapter(RetrievalManager retrievalManager) {
this.retrievalManager = retrievalManager; this.retrievalManager = retrievalManager;
@ -92,37 +90,33 @@ class BandwidthGraphDataAdapter {
* @return the data * @return the data
*/ */
public BandwidthGraphData get() { public BandwidthGraphData get() {
// Technically this is wrong, because different Networks can have final BandwidthGraphData bandwidthGraphData = new BandwidthGraphData();
// different bucket minutes. The BandwidthGraphData object should be
// changed later to reflect this
final BandwidthGraphData bandwidthGraphData = new BandwidthGraphData(
retrievalManager.getRetrievalPlans().values().iterator().next()
.getBucketMinutes());
Map<String, List<TimeWindowData>> dataMap = new HashMap<String, List<TimeWindowData>>();
Map<String, SubscriptionPriority> priorityMap = new HashMap<String, SubscriptionPriority>();
Map<Long, SubscriptionRetrieval> retrievals = new HashMap<Long, SubscriptionRetrieval>();
Multimap<Long, BandwidthReservation> reservations = ArrayListMultimap
.create();
Multimap<String, SubscriptionRetrieval> subNameToRetrievals = ArrayListMultimap
.create();
Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>();
Collection<RetrievalPlan> retrievalPlans = retrievalManager Collection<RetrievalPlan> retrievalPlans = retrievalManager
.getRetrievalPlans().values(); .getRetrievalPlans().values();
Map<Long, SubscriptionRetrieval> retrievals = new HashMap<Long, SubscriptionRetrieval>();
Map<Long, List<BandwidthReservation>> reservations = new HashMap<Long, List<BandwidthReservation>>();
Map<Network, List<SubscriptionWindowData>> networkMap = new HashMap<Network, List<SubscriptionWindowData>>();
// One retrieval plan per network
for (RetrievalPlan retrievalPlan : retrievalPlans) { for (RetrievalPlan retrievalPlan : retrievalPlans) {
Network network = retrievalPlan.getNetwork();
if (!networkMap.containsKey(network)) {
networkMap
.put(network, new ArrayList<SubscriptionWindowData>());
}
// Get all buckets that are in the retrieval plan from the current // Get all buckets that are in the retrieval plan from the current
// time forward // time forward
final SortedSet<BandwidthBucket> bandwidthBuckets = retrievalPlan final SortedSet<BandwidthBucket> bandwidthBuckets = retrievalPlan
.getBucketsInWindow(TimeUtil.currentTimeMillis(), .getBucketsInWindow(TimeUtil.currentTimeMillis(),
Long.MAX_VALUE); Long.MAX_VALUE);
networkBucketMap.put(retrievalPlan.getNetwork(), // % utilized graph data
toDescriptions(bandwidthBuckets)); SortedSet<BandwidthBucketDescription> buckets = toDescriptions(bandwidthBuckets);
// Add all subscription retrievals to a collection keyed by sub bandwidthGraphData.addBucketDescriptions(network, buckets);
// name, and associate all of the bandwidth reservations with their
// associated retrievals // Latency window data - accumulate all the reservations
for (BandwidthBucket bucket : bandwidthBuckets) { for (BandwidthBucket bucket : bandwidthBuckets) {
final List<BandwidthAllocation> requests = retrievalPlan final List<BandwidthAllocation> requests = retrievalPlan
.getBandwidthAllocationsForBucket(bucket); .getBandwidthAllocationsForBucket(bucket);
@ -130,9 +124,6 @@ class BandwidthGraphDataAdapter {
if (allocation instanceof SubscriptionRetrieval) { if (allocation instanceof SubscriptionRetrieval) {
final SubscriptionRetrieval subRetrieval = (SubscriptionRetrieval) allocation; final SubscriptionRetrieval subRetrieval = (SubscriptionRetrieval) allocation;
retrievals.put(allocation.getId(), subRetrieval); retrievals.put(allocation.getId(), subRetrieval);
subNameToRetrievals.put(subRetrieval
.getBandwidthSubscription().getName(),
subRetrieval);
} }
} }
@ -140,61 +131,83 @@ class BandwidthGraphDataAdapter {
.getBandwidthReservationsForBucket(bucket); .getBandwidthReservationsForBucket(bucket);
for (BandwidthReservation reservation : bandwidthReservations) { for (BandwidthReservation reservation : bandwidthReservations) {
reservations.put(reservation.getId(), reservation); if (!reservations.containsKey(reservation.getId())) {
reservations.put(reservation.getId(),
new ArrayList<BandwidthReservation>());
}
reservations.get(reservation.getId()).add(reservation);
} }
} }
} }
// Create time windows for each subscription retrieval by aggregating // Create time windows for each subscription retrieval by aggregating
// them with an reservations they have // them with any reservations they have
for (Entry<Long, SubscriptionRetrieval> entry : retrievals.entrySet()) { for (Long key : retrievals.keySet()) {
final SubscriptionRetrieval value = entry.getValue(); final SubscriptionRetrieval retrieval = retrievals.get(key);
BandwidthSubscription dao = value.getBandwidthSubscription(); BandwidthSubscription dao = retrieval.getBandwidthSubscription();
final String subName = dao.getName(); String subName = dao.getName();
priorityMap.put(subName, dao.getPriority()); SubscriptionPriority priority = dao.getPriority();
String registryId = retrieval.getBandwidthSubscription()
.getRegistryId();
Network network = retrieval.getNetwork();
List<TimeWindowData> timeWindows = dataMap.get(subName); SubscriptionWindowData windowData = null;
if (timeWindows == null) { List<SubscriptionWindowData> subList = networkMap.get(network);
timeWindows = new ArrayList<TimeWindowData>(); for (SubscriptionWindowData subData : subList) {
dataMap.put(subName, timeWindows); if (subData.getRegistryId().equals(registryId)) {
windowData = subData;
break;
}
} }
final long startMillis = value.getStartTime().getTimeInMillis(); if (windowData == null) {
windowData = new SubscriptionWindowData();
windowData.setNetwork(network);
windowData.setPriority(priority);
windowData.setRegistryId(registryId);
windowData.setSubscriptionName(subName);
networkMap.get(network).add(windowData);
}
final long startMillis = retrieval.getStartTime().getTimeInMillis();
final long endMillis = startMillis final long endMillis = startMillis
+ (value.getSubscriptionLatency() * TimeUtil.MILLIS_PER_MINUTE); + (retrieval.getSubscriptionLatency() * TimeUtil.MILLIS_PER_MINUTE);
TimeWindowData window = new TimeWindowData(startMillis, endMillis); TimeWindowData window = new TimeWindowData(startMillis, endMillis);
List<Long> binStartTimes = new ArrayList<Long>(); List<Long> binStartTimes = new ArrayList<Long>();
binStartTimes.add(value.getStartTime().getTimeInMillis()); binStartTimes.add(retrieval.getStartTime().getTimeInMillis());
for (BandwidthReservation reservation : reservations.get(value for (BandwidthReservation reservation : reservations.get(retrieval
.getIdentifier())) { .getIdentifier())) {
binStartTimes.add(reservation.getBandwidthBucket()); binStartTimes.add(reservation.getBandwidthBucket());
} }
window.setBinStartTimes(binStartTimes); window.setBinStartTimes(binStartTimes);
timeWindows.add(window); windowData.addTimeWindow(window);
} }
bandwidthGraphData.setDataMap(dataMap); bandwidthGraphData.setNetworkDataMap(networkMap);
bandwidthGraphData.setPriorityMap(priorityMap);
bandwidthGraphData.setNetworkBucketMap(networkBucketMap);
return bandwidthGraphData; return bandwidthGraphData;
} }
/* /**
* Return BandwithBucketDescription objects for the given BandwidthBuckets. * Return BandwithBucketDescription objects for the given BandwidthBuckets.
*/ */
private SortedSet<BandwidthBucketDescription> toDescriptions( @VisibleForTesting
SortedSet<BandwidthBucketDescription> toDescriptions(
SortedSet<BandwidthBucket> bandwidthBuckets) { SortedSet<BandwidthBucket> bandwidthBuckets) {
SortedSet<BandwidthBucketDescription> descriptions = new TreeSet<BandwidthBucketDescription>(); SortedSet<BandwidthBucketDescription> descriptions = new TreeSet<BandwidthBucketDescription>();
long leftovers = 0;
for (BandwidthBucket bucket : bandwidthBuckets) { for (BandwidthBucket bucket : bandwidthBuckets) {
BandwidthBucketDescription desc = new BandwidthBucketDescription( BandwidthBucketDescription desc = new BandwidthBucketDescription(
bucket.getNetwork(), bucket.getBucketSize(), bucket.getNetwork(), bucket.getBucketSize(),
bucket.getCurrentSize(), bucket.getBucketStartTime()); bucket.getCurrentSize(), bucket.getBucketStartTime());
desc.addLeftovers(leftovers);
leftovers = desc.getLeftovers();
descriptions.add(desc); descriptions.add(desc);
} }
return descriptions; return descriptions;
} }
} }

View file

@ -64,18 +64,21 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
* Nov 19, 2013 2545 bgonzale Added registryEventListener method for update events. * Nov 19, 2013 2545 bgonzale Added registryEventListener method for update events.
* Added getBandwidthGraphData. * Added getBandwidthGraphData.
* Reschedule updated local subscriptions. * Reschedule updated local subscriptions.
* Nov 27, 2013 2545 mpduff Get data by network
* *
* </pre> * </pre>
* *
* @author djohnson * @author djohnson
* @version 1.0 * @version 1.0
*/ */
public class WfoBandwidthManagerCreator<T extends Time, C extends Coverage> implements IEdexBandwidthManagerCreator { public class WfoBandwidthManagerCreator<T extends Time, C extends Coverage>
implements IEdexBandwidthManagerCreator {
/** /**
* WFO {@link BandwidthManager} implementation. * WFO {@link BandwidthManager} implementation.
*/ */
static class WfoBandwidthManager<T extends Time, C extends Coverage> extends EdexBandwidthManager<T, C> { static class WfoBandwidthManager<T extends Time, C extends Coverage>
extends EdexBandwidthManager<T, C> {
private static final String[] WFO_BANDWIDTH_MANAGER_FILES = new String[] { private static final String[] WFO_BANDWIDTH_MANAGER_FILES = new String[] {
JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo-edex-impl.xml"), JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo-edex-impl.xml"),
@ -125,8 +128,7 @@ public class WfoBandwidthManagerCreator<T extends Time, C extends Coverage> impl
Subscription<T, C> subscription = getRegistryObjectById( Subscription<T, C> subscription = getRegistryObjectById(
getSubscriptionHandler(), event.getId()); getSubscriptionHandler(), event.getId());
boolean isLocalOrigination = subscription.getOriginatingSite() boolean isLocalOrigination = subscription.getOriginatingSite()
.equals( .equals(SiteUtil.getSite());
SiteUtil.getSite());
if (isLocalOrigination) { if (isLocalOrigination) {
subscriptionUpdated(subscription); subscriptionUpdated(subscription);
@ -164,18 +166,26 @@ public class WfoBandwidthManagerCreator<T extends Time, C extends Coverage> impl
*/ */
@Override @Override
protected Set<String> scheduleSbnSubscriptions( protected Set<String> scheduleSbnSubscriptions(
List<Subscription<T, C>> subscriptions) throws SerializationException { List<Subscription<T, C>> subscriptions)
throws SerializationException {
return ncfBandwidthService.schedule(subscriptions); return ncfBandwidthService.schedule(subscriptions);
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected BandwidthGraphData getBandwidthGraphData() { protected BandwidthGraphData getBandwidthGraphData() {
BandwidthGraphData data = super.getBandwidthGraphData(); BandwidthGraphData data = super.getBandwidthGraphData();
data.add(ncfBandwidthService.getBandwidthGraphData()); BandwidthGraphData data2 = ncfBandwidthService
return data; .getBandwidthGraphData();
if (data2 != null) {
data.merge(data2);
} }
return data;
}
} }
/** /**
@ -192,5 +202,4 @@ public class WfoBandwidthManagerCreator<T extends Time, C extends Coverage> impl
retrievalManager, bandwidthDaoUtil, dataSetMetaDataHandler, retrievalManager, bandwidthDaoUtil, dataSetMetaDataHandler,
subscriptionHandler, subscriptionNotificationService); subscriptionHandler, subscriptionNotificationService);
} }
} }

View file

@ -24,6 +24,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* Jun 24, 2013 2106 djohnson Add copy constructor. * Jun 24, 2013 2106 djohnson Add copy constructor.
* Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum.
* Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil.
* Dec 02, 2013 2545 mpduff Set size in bytes.
* *
* </pre> * </pre>
* *
@ -41,6 +42,7 @@ public class BandwidthReservation implements Serializable,
private SubscriptionPriority priority; private SubscriptionPriority priority;
/** Size of the reservation in bytes */
private long size; private long size;
private final RetrievalStatus status = RetrievalStatus.RESERVED; private final RetrievalStatus status = RetrievalStatus.RESERVED;
@ -65,8 +67,8 @@ public class BandwidthReservation implements Serializable,
* BandwidthReservation. * BandwidthReservation.
* *
* @param bandwidthRequired * @param bandwidthRequired
* The amount of bandwidth this BandwidthReservation should * The amount of bandwidth in bytes this BandwidthReservation
* reserve in a {@link RetrievalPlan}. * should reserve in a {@link RetrievalPlan}.
*/ */
public BandwidthReservation(BandwidthAllocation allocation, public BandwidthReservation(BandwidthAllocation allocation,
long bandwidthRequired) { long bandwidthRequired) {
@ -101,7 +103,7 @@ public class BandwidthReservation implements Serializable,
sb.append("reserve id: [").append(getId()).append("] "); sb.append("reserve id: [").append(getId()).append("] ");
sb.append("path [").append(getNetwork()).append("] "); sb.append("path [").append(getNetwork()).append("] ");
sb.append("priority [").append(getPriority()).append("] "); sb.append("priority [").append(getPriority()).append("] ");
sb.append("size (bytes) [").append(getSizeInBytes()).append("] "); sb.append("size (bytes) [").append(getSize()).append("] ");
sb.append("status [").append(getStatus()).append("] "); sb.append("status [").append(getStatus()).append("] ");
sb.append("startTime [").append(BandwidthUtil.format(getStartTime())) sb.append("startTime [").append(BandwidthUtil.format(getStartTime()))
.append("] "); .append("] ");
@ -141,27 +143,20 @@ public class BandwidthReservation implements Serializable,
} }
/** /**
* @param estimatedSize * @param size
* the estimatedSize to set, in kilobytes * the estimatedSize to set, in bytes
*/ */
public void setSize(long size) { public void setSize(long size) {
this.size = size; this.size = size;
} }
/** /**
* @return the estimatedSize, in kilobytes * @return the estimatedSize, in bytes
*/ */
public long getSize() { public long getSize() {
return size; return size;
} }
/**
* @return the estimatedSize, in bytes
*/
public long getSizeInBytes() {
return getSize() * BandwidthUtil.BYTES_PER_KILOBYTE;
}
/** /**
* @return the status * @return the status
*/ */

View file

@ -44,6 +44,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* Jun 25, 2013 2106 djohnson Separate state into other classes, promote BandwidthBucket to a class proper. * Jun 25, 2013 2106 djohnson Separate state into other classes, promote BandwidthBucket to a class proper.
* Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil.
* Nov 16, 2013 1736 dhladky Alter size of available bandwidth by subtracting that used by registry. * Nov 16, 2013 1736 dhladky Alter size of available bandwidth by subtracting that used by registry.
* Dec 05, 2013 2545 mpduff BandwidthReservation now stored in bytes.
* *
* </pre> * </pre>
* *
@ -115,7 +116,8 @@ public class RetrievalPlan {
if (found) { if (found) {
// create registry bandwidth service // create registry bandwidth service
RegistryBandwidthService rbs = new RegistryBandwidthService(bucketsDao, network, bucketMinutes); RegistryBandwidthService rbs = new RegistryBandwidthService(
bucketsDao, network, bucketMinutes);
long bucketMillis = bucketMinutes * TimeUtil.MILLIS_PER_MINUTE; long bucketMillis = bucketMinutes * TimeUtil.MILLIS_PER_MINUTE;
Calendar currentBucket = BandwidthUtil.now(); Calendar currentBucket = BandwidthUtil.now();
planStart = BandwidthUtil.now(); planStart = BandwidthUtil.now();
@ -136,8 +138,8 @@ public class RetrievalPlan {
.convertKilobytesPerSecondToBytesPerSpecifiedMinutes( .convertKilobytesPerSecondToBytesPerSpecifiedMinutes(
bw, bucketMinutes); bw, bucketMinutes);
bucketsDao.create(new BandwidthBucket(currentMillis, bytesPerBucket, bucketsDao.create(new BandwidthBucket(currentMillis,
network)); bytesPerBucket, network));
currentMillis += bucketMillis; currentMillis += bucketMillis;
} }
@ -145,8 +147,10 @@ public class RetrievalPlan {
// subtract registry traffic from total available bytes/per second // subtract registry traffic from total available bytes/per second
for (BandwidthBucket bucket : bucketsDao.getAll(network)) { for (BandwidthBucket bucket : bucketsDao.getAll(network)) {
long startMillis = bucket.getBucketStartTime(); long startMillis = bucket.getBucketStartTime();
int registryBytesPerSecond = rbs.getRegistryBandwidth(startMillis); int registryBytesPerSecond = rbs
bucket.setBucketSize(bucket.getBucketSize() - (registryBytesPerSecond * TimeUtil.SECONDS_PER_MINUTE * bucketMinutes)); .getRegistryBandwidth(startMillis);
bucket.setBucketSize(bucket.getBucketSize()
- (registryBytesPerSecond * TimeUtil.SECONDS_PER_MINUTE * bucketMinutes));
} }
} else { } else {
@ -241,13 +245,16 @@ public class RetrievalPlan {
// buckets until we have the new plan size. // buckets until we have the new plan size.
currentBucketMillis += bucketMillis; currentBucketMillis += bucketMillis;
// create Registry Bandwidth Service // create Registry Bandwidth Service
RegistryBandwidthService rbs = new RegistryBandwidthService(bucketsDao, network, bucketMinutes); RegistryBandwidthService rbs = new RegistryBandwidthService(
bucketsDao, network, bucketMinutes);
while (!(currentBucketMillis > newPlanEndMillis)) { while (!(currentBucketMillis > newPlanEndMillis)) {
int bw = map.getBandwidth(network, currentBucket); int bw = map.getBandwidth(network, currentBucket);
// subtract registry traffic from total available bytes/per second // subtract registry traffic from total available bytes/per
int registryBytesPerSecond = rbs.getRegistryBandwidth(currentBucketMillis); // second
int registryBytesPerSecond = rbs
.getRegistryBandwidth(currentBucketMillis);
bw = bw - registryBytesPerSecond; bw = bw - registryBytesPerSecond;
// Get the bucket size.. // Get the bucket size..
// buckets are (bandwidth * kilobytes/second * 60 seconds * // buckets are (bandwidth * kilobytes/second * 60 seconds *
@ -428,7 +435,7 @@ public class RetrievalPlan {
for (Long bucketId : bucketIds) { for (Long bucketId : bucketIds) {
BandwidthBucket bucket = getBucket(bucketId); BandwidthBucket bucket = getBucket(bucketId);
bucket.setCurrentSize(bucket.getCurrentSize() bucket.setCurrentSize(bucket.getCurrentSize()
- reservation.getSizeInBytes()); - reservation.getSize());
associator.removeFromBucket(bucket, reservation); associator.removeFromBucket(bucket, reservation);
} }
} }
@ -555,7 +562,7 @@ public class RetrievalPlan {
synchronized (bucketsLock) { synchronized (bucketsLock) {
BandwidthBucket actualBucket = getBucket(bucketStartTime); BandwidthBucket actualBucket = getBucket(bucketStartTime);
actualBucket.setCurrentSize(actualBucket.getCurrentSize() actualBucket.setCurrentSize(actualBucket.getCurrentSize()
+ reservation.getSizeInBytes()); + reservation.getSize());
associator.addToBucket(actualBucket, reservation); associator.addToBucket(actualBucket, reservation);
} }
} }

View file

@ -75,6 +75,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
* Nov 12, 2013 2448 dhladky Fixed stop/start subscription scheduling problem. * Nov 12, 2013 2448 dhladky Fixed stop/start subscription scheduling problem.
* Nov 20, 2013 2448 bgonzale Fix for subscription start time set to first cycle time. * Nov 20, 2013 2448 bgonzale Fix for subscription start time set to first cycle time.
* Fix for subscription end time set to end of day. * Fix for subscription end time set to end of day.
* Dec 02, 2013 2545 mpduff Fix for delay starting retrievals, execute adhoc upon subscribing.
* *
* </pre> * </pre>
* *
@ -113,8 +114,8 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
* @param cycles * @param cycles
* @return * @return
*/ */
public SortedSet<Calendar> getRetrievalTimes(Subscription<T,C> subscription, public SortedSet<Calendar> getRetrievalTimes(
SortedSet<Integer> cycles) { Subscription<T, C> subscription, SortedSet<Integer> cycles) {
return getRetrievalTimes(subscription, cycles, return getRetrievalTimes(subscription, cycles,
Sets.newTreeSet(Arrays.asList(0))); Sets.newTreeSet(Arrays.asList(0)));
} }
@ -128,8 +129,8 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
* the retrieval interval * the retrieval interval
* @return the retrieval times * @return the retrieval times
*/ */
public SortedSet<Calendar> getRetrievalTimes(Subscription<T,C> subscription, public SortedSet<Calendar> getRetrievalTimes(
int retrievalInterval) { Subscription<T, C> subscription, int retrievalInterval) {
// Add all hours of the days // Add all hours of the days
final SortedSet<Integer> hours = Sets.newTreeSet(); final SortedSet<Integer> hours = Sets.newTreeSet();
for (int i = 0; i < TimeUtil.HOURS_PER_DAY; i++) { for (int i = 0; i < TimeUtil.HOURS_PER_DAY; i++) {
@ -155,8 +156,9 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
* @param minutes * @param minutes
* @return * @return
*/ */
private SortedSet<Calendar> getRetrievalTimes(Subscription<T,C> subscription, private SortedSet<Calendar> getRetrievalTimes(
SortedSet<Integer> hours, SortedSet<Integer> minutes) { Subscription<T, C> subscription, SortedSet<Integer> hours,
SortedSet<Integer> minutes) {
SortedSet<Calendar> subscriptionTimes = new TreeSet<Calendar>(); SortedSet<Calendar> subscriptionTimes = new TreeSet<Calendar>();
@ -179,7 +181,8 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
.getActivePeriodStart()); .getActivePeriodStart());
// Substitute the active periods month and day for the // Substitute the active periods month and day for the
// plan start month and day. // plan start month and day.
Calendar start = BandwidthUtil.planToPeriodCompareCalendar(planStart, activePeriodStart); Calendar start = BandwidthUtil.planToPeriodCompareCalendar(
planStart, activePeriodStart);
// If the active period start is outside the plan bounds, // If the active period start is outside the plan bounds,
// there is no intersection - just return an empty set. // there is no intersection - just return an empty set.
if (start.after(planEnd)) { if (start.after(planEnd)) {
@ -187,10 +190,12 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
} }
// Do the same for active plan end.. // Do the same for active plan end..
activePeriodEnd = TimeUtil.newCalendar(subscription.getActivePeriodEnd()); activePeriodEnd = TimeUtil.newCalendar(subscription
.getActivePeriodEnd());
// Substitute the active periods month and day for the // Substitute the active periods month and day for the
// plan ends month and day. // plan ends month and day.
Calendar end = BandwidthUtil.planToPeriodCompareCalendar(planStart, activePeriodEnd); Calendar end = BandwidthUtil.planToPeriodCompareCalendar(planStart,
activePeriodEnd);
// If the active period end is before the start of the plan, // If the active period end is before the start of the plan,
// there is no intersection - just return an empty set. // there is no intersection - just return an empty set.
if (end.before(planStart)) { if (end.before(planStart)) {
@ -222,7 +227,8 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
// setup active period checks if necessary // setup active period checks if necessary
if (activePeriodStart != null && activePeriodEnd != null) { if (activePeriodStart != null && activePeriodEnd != null) {
// need to add the current year in order to make the checks relevant // need to add the current year in order to make the checks relevant
activePeriodStart = TimeUtil.addCurrentYearCalendar(activePeriodStart); activePeriodStart = TimeUtil
.addCurrentYearCalendar(activePeriodStart);
activePeriodEnd = TimeUtil.addCurrentYearCalendar(activePeriodEnd); activePeriodEnd = TimeUtil.addCurrentYearCalendar(activePeriodEnd);
// Create a Set of Calendars for all the baseReferenceTimes that a // Create a Set of Calendars for all the baseReferenceTimes that a
@ -377,7 +383,8 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
if (dataSetMetaDatas != null && !dataSetMetaDatas.isEmpty()) { if (dataSetMetaDatas != null && !dataSetMetaDatas.isEmpty()) {
// No guarantee on ordering, have to find most recent time // No guarantee on ordering, have to find most recent time
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
DataSetMetaData<PointTime> selectedDataSet = dataSetMetaDatas.get(0); DataSetMetaData<PointTime> selectedDataSet = dataSetMetaDatas
.get(0);
Date checkDate = selectedDataSet.getDate(); Date checkDate = selectedDataSet.getDate();
for (DataSetMetaData<PointTime> dsmd : dataSetMetaDatas) { for (DataSetMetaData<PointTime> dsmd : dataSetMetaDatas) {
@ -411,9 +418,11 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
Time adhocTime = adhoc.getTime(); Time adhocTime = adhoc.getTime();
for (BandwidthDataSetUpdate current : dataSetMetaDataUpdates) { for (BandwidthDataSetUpdate current : dataSetMetaDataUpdates) {
if (mostRecent if (mostRecent
|| ((GriddedTime)adhocTime).getCycleTimes().contains( || ((GriddedTime) adhocTime)
current.getDataSetBaseTime().get( .getCycleTimes()
Calendar.HOUR_OF_DAY))) { .contains(
current.getDataSetBaseTime()
.get(Calendar.HOUR_OF_DAY))) {
daoToUse = current; daoToUse = current;
break; break;
} }
@ -442,6 +451,8 @@ public class BandwidthDaoUtil<T extends Time, C extends Coverage> {
retVal = adhoc; retVal = adhoc;
} }
} }
} else {
retVal = adhoc;
} }
} else { } else {
throw new IllegalArgumentException("DataType: " throw new IllegalArgumentException("DataType: "

View file

@ -32,7 +32,6 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
@ -88,7 +87,8 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum.
* Jul 18, 2013 1653 mpduff Added test for sub status summary. * Jul 18, 2013 1653 mpduff Added test for sub status summary.
* Sept 25, 2013 1797 dhladky separated time from gridded time * Sept 25, 2013 1797 dhladky separated time from gridded time
* Oct 21, 2013 2292 mpduff Implement multiple data types * Oct 21, 2013 2292 mpduff Implement multiple data types.
* Dec 02, 2013 2545 mpduff Get data by network.
* </pre> * </pre>
* *
* @author djohnson * @author djohnson
@ -526,7 +526,7 @@ public class BandwidthServiceIntTest<T extends Time, C extends Coverage>
BandwidthGraphData graphData = service.getBandwidthGraphData(); BandwidthGraphData graphData = service.getBandwidthGraphData();
assertEquals("Incorrect number of subscriptions returned!", 2, assertEquals("Incorrect number of subscriptions returned!", 2,
graphData.getNumberOfSubscriptions()); graphData.getNumberOfSubscriptions(Network.OPSNET));
} }
@Test @Test
@ -549,7 +549,8 @@ public class BandwidthServiceIntTest<T extends Time, C extends Coverage>
RetrievalPlan opsnetPlan = retrievalManager.getPlan(Network.OPSNET); RetrievalPlan opsnetPlan = retrievalManager.getPlan(Network.OPSNET);
assertEquals("Incorrect number of subscriptions returned!", assertEquals("Incorrect number of subscriptions returned!",
opsnetPlan.getBucketMinutes(), graphData.getBinTimeInMinutes()); opsnetPlan.getBucketMinutes(),
graphData.getBinTimeInMinutes(Network.OPSNET));
SortedSet<BandwidthBucketDescription> descs = graphData SortedSet<BandwidthBucketDescription> descs = graphData
.getNetworkBucketMap().get(Network.OPSNET); .getNetworkBucketMap().get(Network.OPSNET);
long earliestTime = descs.first().getBucketStartTime(); long earliestTime = descs.first().getBucketStartTime();
@ -575,11 +576,9 @@ public class BandwidthServiceIntTest<T extends Time, C extends Coverage>
bandwidthManager.schedule(subscription); bandwidthManager.schedule(subscription);
BandwidthGraphData graphData = service.getBandwidthGraphData(); BandwidthGraphData graphData = service.getBandwidthGraphData();
final Map<String, List<TimeWindowData>> dataMap = graphData
.getDataMap();
final List<TimeWindowData> subscriptionOneTimeWindows = dataMap final List<TimeWindowData> subscriptionOneTimeWindows = graphData
.get(subscription.getName()); .getTimeWindowArray(Network.OPSNET, subscription.getName());
assertEquals( assertEquals(
"Expected there to be two time windows for this subscription over 2 days", "Expected there to be two time windows for this subscription over 2 days",
@ -656,13 +655,11 @@ public class BandwidthServiceIntTest<T extends Time, C extends Coverage>
service.schedule(subscription2); service.schedule(subscription2);
BandwidthGraphData graphData = service.getBandwidthGraphData(); BandwidthGraphData graphData = service.getBandwidthGraphData();
final Map<String, List<TimeWindowData>> dataMap = graphData
.getDataMap();
final List<TimeWindowData> subscriptionOneTimeWindows = dataMap final List<TimeWindowData> subscriptionOneTimeWindows = graphData
.get(subscription.getName()); .getTimeWindowArray(Network.OPSNET, subscription.getName());
final List<TimeWindowData> subscriptionTwoTimeWindows = dataMap final List<TimeWindowData> subscriptionTwoTimeWindows = graphData
.get(subscription2.getName()); .getTimeWindowArray(Network.OPSNET, subscription2.getName());
assertEquals( assertEquals(
"Expected there to be four retrievals for this subscription over 2 days", "Expected there to be four retrievals for this subscription over 2 days",
@ -691,13 +688,12 @@ public class BandwidthServiceIntTest<T extends Time, C extends Coverage>
service.schedule(subscription2); service.schedule(subscription2);
BandwidthGraphData graphData = service.getBandwidthGraphData(); BandwidthGraphData graphData = service.getBandwidthGraphData();
final Map<String, SubscriptionPriority> priorityMap = graphData assertThat(
.getPriorityMap(); graphData.getPriority(Network.OPSNET, subscription.getName()),
assertThat(priorityMap.get(subscription.getName()),
is(equalTo(subscription.getPriority()))); is(equalTo(subscription.getPriority())));
assertThat(priorityMap.get(subscription2.getName()), assertThat(
graphData.getPriority(Network.OPSNET, subscription2.getName()),
is(equalTo(subscription2.getPriority()))); is(equalTo(subscription2.getPriority())));
} }

View file

@ -0,0 +1,173 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.datadelivery.bandwidth;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
import org.junit.Before;
import org.junit.Test;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthBucketDescription;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
/**
* Test class for {@link BandwidthGraphdataAdapter}.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 25, 2013 mpduff Initial creation
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class BandwidthGraphDataAdapterTest {
private static final int BUCKET_SIZE = 100;
private static final RetrievalManager retrievalManagerMock = mock(RetrievalManager.class);
private static final RetrievalPlan retrievalPlan = new RetrievalPlan();
private static final SortedSet<BandwidthBucket> bucketSet = new TreeSet<BandwidthBucket>();
private static final BandwidthGraphDataAdapter adapter = new BandwidthGraphDataAdapter(
retrievalManagerMock);
@Before
public void classSetup() {
bucketSet.clear();
long bucketSizeMinutes = 3 * TimeUtil.MILLIS_PER_MINUTE;
long bucketStart = bucketSizeMinutes;
// Create 10 buckets
for (int i = 0; i < 10; i++) {
BandwidthBucket bucket = new BandwidthBucket(bucketStart,
BUCKET_SIZE, Network.OPSNET);
bucketSet.add(bucket);
bucketStart += bucketSizeMinutes;
}
}
@Test
public void testAdapterCreatesTheCorrectNumberObjects() {
SortedSet<BandwidthBucketDescription> descriptions = adapter
.toDescriptions(bucketSet);
assertTrue("Incorrect number of descriptions created",
descriptions.size() == bucketSet.size());
}
@Test
public void testToDescriptionFillsOneBucketOnly() {
Iterator<BandwidthBucket> iter = bucketSet.iterator();
// Get the first bucket and fill it full
BandwidthBucket bucket = iter.next();
bucket.setCurrentSize(BUCKET_SIZE);
int idx = 0;
SortedSet<BandwidthBucketDescription> descriptions = adapter
.toDescriptions(bucketSet);
Iterator<BandwidthBucketDescription> it = descriptions.iterator();
while (it.hasNext()) {
BandwidthBucketDescription bbd = it.next();
if (idx == 0) {
assertTrue("First bucket should be full",
bbd.getUsedBytes() == bucket.getBucketSize());
idx++;
} else {
assertTrue("Bucket should be empty", bbd.getUsedBytes() == 0);
}
}
}
@Test
public void testToDescriptionFillsTwoBucketsFull() {
Iterator<BandwidthBucket> iter = bucketSet.iterator();
// Get the first 2 buckets and fill them full
BandwidthBucket bucket = iter.next();
bucket.setCurrentSize(BUCKET_SIZE);
bucket = iter.next();
bucket.setCurrentSize(BUCKET_SIZE);
int idx = 0;
SortedSet<BandwidthBucketDescription> descriptions = adapter
.toDescriptions(bucketSet);
Iterator<BandwidthBucketDescription> it = descriptions.iterator();
while (it.hasNext()) {
BandwidthBucketDescription bbd = it.next();
if (idx == 0 || idx == 1) {
assertTrue("First two buckets should be full",
bbd.getUsedBytes() == bucket.getBucketSize());
idx++;
} else {
assertTrue("Bucket should be empty", bbd.getUsedBytes() == 0);
}
}
}
@Test
public void testOverfilledBucketsOverflowToLaterBuckets() {
Iterator<BandwidthBucket> iter = bucketSet.iterator();
// Get the first bucket and fill it 4.5 buckets worth
BandwidthBucket bucket = iter.next();
bucket.setCurrentSize((BUCKET_SIZE * 4) + (BUCKET_SIZE / 2));
int idx = 0;
SortedSet<BandwidthBucketDescription> descriptions = adapter
.toDescriptions(bucketSet);
Iterator<BandwidthBucketDescription> it = descriptions.iterator();
while (it.hasNext()) {
BandwidthBucketDescription bbd = it.next();
if (idx <= 3) {
assertTrue("First four buckets should be full",
bbd.getUsedBytes() == bucket.getBucketSize());
idx++;
} else if (idx == 4) {
assertTrue("Bucket should be half full",
bbd.getUsedBytes() == bucket.getBucketSize() / 2);
idx++;
} else {
assertTrue("Bucket should be empty", bbd.getUsedBytes() == 0);
}
}
}
}