Merge "Issue #2397 Added Bandwidth Bucket usage information to BandwidthGraphData." into development

Former-commit-id: 62b38d25b1 [formerly a55a0b51ef] [formerly 5eb46b42dc [formerly ff7411c7b560bec7e21c125c3ed9b65678ae429c]]
Former-commit-id: 5eb46b42dc
Former-commit-id: 75163db16f
This commit is contained in:
Richard Peter 2013-09-23 17:38:28 -05:00 committed by Gerrit Code Review
commit 37c9094014
4 changed files with 230 additions and 1 deletions

View file

@ -0,0 +1,157 @@
/**
* 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 com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* Describes a bucket, especially the total bytes available and bytes used. Used
* by the UI to display information about buckets. Comparable by startime and
* bucketSize
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 20, 2013 2397 bgonzale Initial creation
*
* </pre>
*
* @author bgonzale
* @version 1.0
*/
@DynamicSerialize
public class BandwidthBucketDescription implements
Comparable<BandwidthBucketDescription> {
@DynamicSerializeElement
private Network network;
// Number of bytes of bandwidth;
@DynamicSerializeElement
private long bucketSize;
// Number of allocated bytes
@DynamicSerializeElement
private long usedBytes;
@DynamicSerializeElement
private long bucketStartTime;
/**
* Default Constructor.
*/
public BandwidthBucketDescription() {
}
/**
* Initialize all fields Constructor.
*
* @param network
* @param bucketSize
* @param usedBytes
* @param bucketStartTime
*/
public BandwidthBucketDescription(Network network, long bucketSize,
long usedBytes, long bucketStartTime) {
this.network = network;
this.bucketSize = bucketSize;
this.usedBytes = usedBytes;
this.bucketStartTime = bucketStartTime;
}
/**
* Compare by bucket start time. If bucket start times are equal, then
* compare by bucket size.
*/
@Override
public int compareTo(BandwidthBucketDescription o) {
long compStart = this.bucketStartTime - o.getBucketStartTime();
int retval = (int) (compStart == 0 ? this.bucketSize - o.bucketSize
: compStart);
return retval;
}
/**
* @return the network
*/
public Network getNetwork() {
return network;
}
/**
* @param network
* the network to set
*/
public void setNetwork(Network network) {
this.network = network;
}
/**
* @return the bucketSize
*/
public long getBucketSize() {
return bucketSize;
}
/**
* @param bucketSize
* the bucketSize to set
*/
public void setBucketSize(long bucketSize) {
this.bucketSize = bucketSize;
}
/**
* @return the usedBytes
*/
public long getUsedBytes() {
return usedBytes;
}
/**
* @param usedBytes
* the usedBytes to set
*/
public void setUsedBytes(long usedBytes) {
this.usedBytes = usedBytes;
}
/**
* @return the bucketStartTime
*/
public long getBucketStartTime() {
return bucketStartTime;
}
/**
* @param bucketStartTime
* the bucketStartTime to set
*/
public void setBucketStartTime(long bucketStartTime) {
this.bucketStartTime = bucketStartTime;
}
}

View file

@ -20,13 +20,17 @@
package com.raytheon.uf.common.datadelivery.bandwidth.data; package com.raytheon.uf.common.datadelivery.bandwidth.data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
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.Map.Entry;
import java.util.SortedSet;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet;
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.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;
@ -43,6 +47,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* 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 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.
* *
* </pre> * </pre>
* *
@ -59,6 +64,10 @@ public class BandwidthGraphData {
@DynamicSerializeElement @DynamicSerializeElement
private Map<String, SubscriptionPriority> priorityMap; private Map<String, SubscriptionPriority> priorityMap;
/** Network -> Bandwidth Bucket Descriptions */
@DynamicSerializeElement
private Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap;
/** Bin duration in minutes */ /** Bin duration in minutes */
@DynamicSerializeElement @DynamicSerializeElement
private int binTimeInMins; private int binTimeInMins;
@ -116,6 +125,36 @@ public class BandwidthGraphData {
this.priorityMap = priorityMap; this.priorityMap = priorityMap;
} }
/**
* @return the networkBucketMap
*/
public Map<Network, SortedSet<BandwidthBucketDescription>> getNetworkBucketMap() {
return networkBucketMap;
}
/**
* @param networkBucketMap
* the networkBucketMap to set
*/
public void setNetworkBucketMap(
Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap) {
/*
* Ensure bucket description set sorting. This is done like this because
* the thrift version we are using is recreating the SortedSet as a
* HashSet on deserialization and causing
* getNetworkBucketMap().get(Network) to throw
* "java.lang.ClassCastException: java.util.HashSet cannot be cast to java.util.SortedSet"
*/
this.networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>();
for (Entry<Network, SortedSet<BandwidthBucketDescription>> descEntry : networkBucketMap
.entrySet()) {
this.networkBucketMap.put(descEntry.getKey(),
new TreeSet<BandwidthBucketDescription>(
(Collection<BandwidthBucketDescription>) descEntry
.getValue()));
}
}
/** /**
* @return the binTimeInMins * @return the binTimeInMins
*/ */

View file

@ -26,11 +26,14 @@ 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.SortedSet; import java.util.SortedSet;
import java.util.TreeSet;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
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.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.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
@ -57,6 +60,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
* Jan 25, 2013 1528 djohnson Subscription priority is now an enum. * Jan 25, 2013 1528 djohnson Subscription priority is now an enum.
* 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.
* *
* </pre> * </pre>
* *
@ -103,6 +107,7 @@ class BandwidthGraphDataAdapter {
.create(); .create();
Multimap<String, SubscriptionRetrieval> subNameToRetrievals = ArrayListMultimap Multimap<String, SubscriptionRetrieval> subNameToRetrievals = ArrayListMultimap
.create(); .create();
Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>();
Collection<RetrievalPlan> retrievalPlans = retrievalManager Collection<RetrievalPlan> retrievalPlans = retrievalManager
.getRetrievalPlans().values(); .getRetrievalPlans().values();
@ -113,6 +118,8 @@ class BandwidthGraphDataAdapter {
.getBucketsInWindow(TimeUtil.currentTimeMillis(), .getBucketsInWindow(TimeUtil.currentTimeMillis(),
Long.MAX_VALUE); Long.MAX_VALUE);
networkBucketMap.put(retrievalPlan.getNetwork(),
toDescriptions(bandwidthBuckets));
// Add all subscription retrievals to a collection keyed by sub // Add all subscription retrievals to a collection keyed by sub
// name, and associate all of the bandwidth reservations with their // name, and associate all of the bandwidth reservations with their
// associated retrievals // associated retrievals
@ -170,8 +177,24 @@ class BandwidthGraphDataAdapter {
bandwidthGraphData.setDataMap(dataMap); bandwidthGraphData.setDataMap(dataMap);
bandwidthGraphData.setPriorityMap(priorityMap); bandwidthGraphData.setPriorityMap(priorityMap);
bandwidthGraphData.setNetworkBucketMap(networkBucketMap);
return bandwidthGraphData; return bandwidthGraphData;
} }
/*
* Return BandwithBucketDescription objects for the given BandwidthBuckets.
*/
private SortedSet<BandwidthBucketDescription> toDescriptions(
SortedSet<BandwidthBucket> bandwidthBuckets) {
SortedSet<BandwidthBucketDescription> descriptions = new TreeSet<BandwidthBucketDescription>();
for (BandwidthBucket bucket : bandwidthBuckets) {
BandwidthBucketDescription desc = new BandwidthBucketDescription(
bucket.getNetwork(), bucket.getBucketSize(),
bucket.getCurrentSize(), bucket.getBucketStartTime());
descriptions.add(desc);
}
return descriptions;
}
} }

View file

@ -42,6 +42,7 @@ import com.raytheon.uf.common.datadelivery.bandwidth.BandwidthService;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest; import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest;
import com.raytheon.uf.common.datadelivery.bandwidth.IProposeScheduleResponse; import com.raytheon.uf.common.datadelivery.bandwidth.IProposeScheduleResponse;
import com.raytheon.uf.common.datadelivery.bandwidth.WfoBandwidthService; import com.raytheon.uf.common.datadelivery.bandwidth.WfoBandwidthService;
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.SubscriptionStatusSummary; import com.raytheon.uf.common.datadelivery.bandwidth.data.SubscriptionStatusSummary;
import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData; import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData;
@ -59,6 +60,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
/** /**
@ -529,10 +531,18 @@ public class BandwidthServiceIntTest extends AbstractWfoBandwidthManagerIntTest
service.schedule(subscription2); service.schedule(subscription2);
BandwidthGraphData graphData = service.getBandwidthGraphData(); BandwidthGraphData graphData = service.getBandwidthGraphData();
RetrievalPlan opsnetPlan = retrievalManager.getPlan(Network.OPSNET);
assertEquals("Incorrect number of subscriptions returned!", assertEquals("Incorrect number of subscriptions returned!",
retrievalManager.getPlan(Network.OPSNET).getBucketMinutes(), opsnetPlan.getBucketMinutes(),
graphData.getBinTimeInMinutes()); graphData.getBinTimeInMinutes());
SortedSet<BandwidthBucketDescription> descs = graphData
.getNetworkBucketMap().get(Network.OPSNET);
long earliestTime = descs.first().getBucketStartTime();
long latestTime = descs.last().getBucketStartTime();
assertEquals("Incorrect number of buckets returned", opsnetPlan
.getBucketsInWindow(earliestTime, latestTime).size(),
descs.size());
} }
@Test @Test