diff --git a/deltaScripts/14.2.1/createRegistryBandwidthRecord.sh b/deltaScripts/14.2.1/createRegistryBandwidthRecord.sh new file mode 100644 index 0000000000..109e95258c --- /dev/null +++ b/deltaScripts/14.2.1/createRegistryBandwidthRecord.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +PSQL=/awips2/psql/bin/psql +DIR=`dirname $0` +${PSQL} -U awips -d metadata -f ${DIR}/registryBandwidth.sql \ No newline at end of file diff --git a/deltaScripts/14.2.1/registryBandwidth.sql b/deltaScripts/14.2.1/registryBandwidth.sql new file mode 100644 index 0000000000..e9556cdb37 --- /dev/null +++ b/deltaScripts/14.2.1/registryBandwidth.sql @@ -0,0 +1,11 @@ +CREATE TABLE datadeliveryregistrybandwidth +( + timeperiod integer NOT NULL, + bytes integer NOT NULL, + CONSTRAINT datadeliveryregistrybandwidth_pkey PRIMARY KEY (timeperiod) +) +WITH ( + OIDS=FALSE +); +ALTER TABLE datadeliveryregistrybandwidth + OWNER TO awips; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/AvailableBandwidth.java b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/AvailableBandwidth.java similarity index 96% rename from edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/AvailableBandwidth.java rename to edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/AvailableBandwidth.java index af6a8baa9e..793fad0755 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/AvailableBandwidth.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/AvailableBandwidth.java @@ -1,10 +1,12 @@ -package com.raytheon.uf.edex.datadelivery.bandwidth.retrieval; +package com.raytheon.uf.common.datadelivery.bandwidth.data; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; + + /** * Class to describe available bandwidth for {@link BandwidthRoute} to generate * a profile of available network resources for any given time. diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthMap.java b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/BandwidthMap.java similarity index 96% rename from edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthMap.java rename to edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/BandwidthMap.java index 244a371213..bef8a8feb2 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthMap.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/BandwidthMap.java @@ -1,4 +1,4 @@ -package com.raytheon.uf.edex.datadelivery.bandwidth.retrieval; +package com.raytheon.uf.common.datadelivery.bandwidth.data; import java.io.File; import java.util.ArrayList; @@ -16,19 +16,21 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import com.raytheon.uf.common.datadelivery.registry.Network; -import com.raytheon.uf.common.serialization.ISerializableObject; +import com.raytheon.uf.common.serialization.JAXBManager; import com.raytheon.uf.common.serialization.SerializationException; -import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.util.TimeUtil; + /** * Class generates a profile of available bandwidth for edex to manage using * {@link BandwidthRoute} entries. Each BandwidthRoute describes the network @@ -44,6 +46,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; * Sep 27, 2012 726 jspinks Initial release. * Oct 10, 2012 0726 djohnson Overload the load method to support files. * Oct 23, 2012 1286 djohnson Add ability to save changes to the map. + * Nov 27, 2013 1736 dhladky Moved to common plugin * * * @@ -51,8 +54,14 @@ import com.raytheon.uf.common.time.util.TimeUtil; */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class BandwidthMap implements ISerializableObject { +public class BandwidthMap { + private static final Class[] clazzess = new Class[] { + BandwidthMap.class, BandwidthRoute.class, RelativeTime.class, + AvailableBandwidth.class }; + + private static JAXBManager jaxb = null; + private static final int DEFAULT_BUCKET_SIZE = 3; private static final int DEFAULT_PLAN_DAYS = 2; @@ -60,6 +69,19 @@ public class BandwidthMap implements ISerializableObject { private static final IUFStatusHandler statusHandler = UFStatus .getHandler(BandwidthMap.class); + /** + * marshall and unmarshall Bandwidth Map objects + * + * @return + */ + private static JAXBManager getJaxb() throws JAXBException { + + if (jaxb == null) { + jaxb = new JAXBManager(clazzess); + } + return jaxb; + } + /** * Load an XML serialized BandwidthMap from the specified file. * @@ -68,15 +90,24 @@ public class BandwidthMap implements ISerializableObject { * @return the map */ public static BandwidthMap load(File file) { + + BandwidthMap map = null; + try { - BandwidthMap map = SerializationUtil.jaxbUnmarshalFromXmlFile( - BandwidthMap.class, file); + map = getJaxb().unmarshalFromXmlFile(BandwidthMap.class, file); map.initialize(); map.setFile(file); - return map; - } catch (SerializationException e) { + + } catch (JAXBException e) { throw new IllegalArgumentException(e); + } catch (SerializationException e) { + statusHandler.handle( + Priority.ERROR, + "Can not de-serialize the Bandwidth Map file! " + + file.getAbsolutePath(), e); } + + return map; } // Map to track days of the year (int) to bandwidthBucket id (long) @@ -804,7 +835,11 @@ public class BandwidthMap implements ISerializableObject { * on error serializing changes */ public void save(File file) throws SerializationException { - SerializationUtil.jaxbMarshalToXmlFile(this, file.getAbsolutePath()); + try { + getJaxb().marshalToXmlFile(this, file.getAbsolutePath()); + } catch (JAXBException e) { + statusHandler.handle(Priority.PROBLEM, "Can not serialize Bandwidth Map to file", e); + } } /** diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthRoute.java b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/BandwidthRoute.java similarity index 95% rename from edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthRoute.java rename to edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/BandwidthRoute.java index 3041e4dd94..e036050942 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/BandwidthRoute.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/BandwidthRoute.java @@ -1,4 +1,4 @@ -package com.raytheon.uf.edex.datadelivery.bandwidth.retrieval; +package com.raytheon.uf.common.datadelivery.bandwidth.data; import java.util.List; @@ -8,7 +8,6 @@ import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import com.raytheon.uf.common.datadelivery.registry.Network; -import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager; /** * Class to describe available bandwidth for edex to manage network load using @@ -25,6 +24,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 27, 2012 726 jspinks Initial release. + * Nov 27, 2013 1736 dhladky Moved to common plugin. * * * diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RelativeTime.java b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/RelativeTime.java similarity index 97% rename from edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RelativeTime.java rename to edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/RelativeTime.java index eadc26a931..40c5d7479a 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RelativeTime.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.bandwidth/src/com/raytheon/uf/common/datadelivery/bandwidth/data/RelativeTime.java @@ -1,4 +1,4 @@ -package com.raytheon.uf.edex.datadelivery.bandwidth.retrieval; +package com.raytheon.uf.common.datadelivery.bandwidth.data; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/DataDeliveryRegistryObjectTypes.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/DataDeliveryRegistryObjectTypes.java index 4ba8bd7327..3ce94af116 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/DataDeliveryRegistryObjectTypes.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/DataDeliveryRegistryObjectTypes.java @@ -35,6 +35,7 @@ import com.raytheon.uf.common.registry.ebxml.RegistryUtil; * May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription. * Oct 11, 2013 2460 dhladky Restored Adhoc to registry store, WFO only. * Nov 12, 2013 2506 bgonzale Added is recurring subscription method. + * Nov 18, 2013 1736 dhladky Data Set helper method. * * * @@ -81,4 +82,16 @@ public final class DataDeliveryRegistryObjectTypes { || DataDeliveryRegistryObjectTypes.SITE_SUBSCRIPTION .equals(objectType); } + + /** + * Is the object type a datasetmeta type. + * + * @param objectType + * @return true if the objectType is a datasetmeta type; false + * otherwise. + */ + public static final boolean isDataSetMetaData(String objectType) { + return DataDeliveryRegistryObjectTypes.DATASETMETADATA + .equals(objectType); + } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/MANIFEST.MF index 04f2b4394c..01d5c2195a 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/MANIFEST.MF @@ -31,12 +31,18 @@ Require-Bundle: com.raytheon.uf.common.status;bundle-version="1.12.1174", com.raytheon.uf.common.util, com.raytheon.uf.common.datadelivery.request;bundle-version="1.0.0", com.raytheon.uf.edex.registry.ebxml;bundle-version="1.0.0", - com.raytheon.uf.common.datadelivery.service;bundle-version="1.0.0" + com.raytheon.uf.common.datadelivery.service;bundle-version="1.0.0", + org.eclipse.jetty.io;bundle-version="8.1.3", + org.eclipse.jetty.server;bundle-version="8.1.3", + com.raytheon.uf.common.serialization.comm;bundle-version="1.12.1174", + org.quartz;bundle-version="1.8.6" Export-Package: com.raytheon.uf.edex.datadelivery.bandwidth, com.raytheon.uf.edex.datadelivery.bandwidth.dao, com.raytheon.uf.edex.datadelivery.bandwidth.interfaces, com.raytheon.uf.edex.datadelivery.bandwidth.processing, + com.raytheon.uf.edex.datadelivery.bandwidth.registry, com.raytheon.uf.edex.datadelivery.bandwidth.retrieval, + com.raytheon.uf.edex.datadelivery.bandwidth.registry, com.raytheon.uf.edex.datadelivery.bandwidth.util Import-Package: com.raytheon.uf.common.datadelivery.event.retrieval, com.raytheon.uf.common.datadelivery.registry, diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject index 82e349cc98..ad59954f75 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/META-INF/services/com.raytheon.uf.common.serialization.ISerializableObject @@ -2,5 +2,4 @@ com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthDataSetUpdate com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation -com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrievalAttributes \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml index ae6fa98860..1b40381388 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml @@ -67,7 +67,7 @@ @@ -88,6 +88,15 @@ + + + + + + + * @@ -321,4 +322,21 @@ public class InMemoryBandwidthBucketDao implements IBandwidthBucketDao { BandwidthBucket bucket = buckets.get(bucketId); return bucket; } + + /** + * {@inheritDoc} + */ + @Override + public BandwidthBucket getBucketContainingTime(long millis, + Network network) { + + List buckets = getWhereStartTimeIsLessThanOrEqualTo( + millis, network); + // last bucket. + if (!buckets.isEmpty()) { + return buckets.get(buckets.size() -1); + } else { + return null; + } + } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthContextFactory.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthContextFactory.java index e3030d094a..3396acc151 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthContextFactory.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthContextFactory.java @@ -21,6 +21,7 @@ package com.raytheon.uf.edex.datadelivery.bandwidth; import java.io.File; +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthMap; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -30,7 +31,6 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializer; -import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthContextFactory.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthContextFactory.java index d821fc3822..fd16ca21d1 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthContextFactory.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthContextFactory.java @@ -21,11 +21,11 @@ package com.raytheon.uf.edex.datadelivery.bandwidth.dao; import java.io.File; +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthMap; import com.raytheon.uf.edex.datadelivery.bandwidth.BandwidthManager; import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager; import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDbInit; import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializer; -import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/IBandwidthBucketDao.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/IBandwidthBucketDao.java index 694413ea1f..920a31dcb9 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/IBandwidthBucketDao.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/IBandwidthBucketDao.java @@ -35,6 +35,7 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jun 18, 2013 2106 djohnson Initial creation + * Dec 2, 2013 1736 dhladky Needed to add registry bandwidth utilization attenuation. * * * @@ -141,4 +142,13 @@ public interface IBandwidthBucketDao { * @param bucketsDao */ void copyState(IBandwidthBucketDao bucketsDao); + + /** + * Finds the Bandwidth Bucket that contains the given time, null if none exists. + * @param millis + * @param Network + * @return + */ + public BandwidthBucket getBucketContainingTime(long millis, Network network); + } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/BandwidthBucketDao.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/BandwidthBucketDao.java index a4c798aaaa..7a8570acbd 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/BandwidthBucketDao.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/BandwidthBucketDao.java @@ -39,6 +39,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jun 25, 2013 2106 djohnson Initial creation + * Dec 3, 2013 1736 dhladky Bandwidth bucket size attenuation. * * * @@ -150,4 +151,20 @@ public class BandwidthBucketDao extends return BandwidthBucket.class; } -} + /** + * {@inheritDoc} + */ + @Override + public BandwidthBucket getBucketContainingTime(long millis, + Network network) { + + List buckets = getWhereStartTimeIsLessThanOrEqualTo( + millis, network); + // last bucket. + if (!buckets.isEmpty()) { + return buckets.get(buckets.size() -1); + } else { + return null; + } + } +} \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/BandwidthUtilizationProcessor.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/BandwidthUtilizationProcessor.java new file mode 100644 index 0000000000..8c6cbda098 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/BandwidthUtilizationProcessor.java @@ -0,0 +1,142 @@ +package com.raytheon.uf.edex.datadelivery.bandwidth.registry; + +/** + * 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. + **/ + +import java.util.Calendar; +import java.util.concurrent.atomic.AtomicInteger; + +import org.quartz.Job; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao; + +/** + * Process the totals gathered by the BandwidthUtilizationListener class + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 27, 2013 1736       dhladky     Initial creation
+ * 
+ * 
+ * + * @author dhladky + * @version 1.0 + */ + +public class BandwidthUtilizationProcessor implements Job { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(BandwidthUtilizationProcessor.class); + + /** total bytes saved in map */ + private AtomicInteger totalBytes = null; + /** long last run time */ + private long lastRun = 0l; + /** job data map pertinent to this execution */ + private JobDataMap map = null; + /** network of the traffic be tracked */ + private Network network = null; + /** bucket Dao class */ + private IBandwidthBucketDao bucketDao = null; + /** bucket size in mins */ + private int bucketSize = 0; + + public BandwidthUtilizationProcessor() { + + } + + @Override + public void execute(JobExecutionContext context) throws JobExecutionException { + + this.map = context.getJobDetail().getJobDataMap(); + this.network = (Network) map.get("network"); + this.lastRun = map.getLongValue("lastRun"); + this.totalBytes = (AtomicInteger) map.get("totalBytes"); + this.bucketDao = (IBandwidthBucketDao) map.get("bucketDao"); + this.bucketSize = map.getInt("bucketSize"); + + // do the processing + processRecord(); + } + + /** + * Gets the bytes per second for the interval run + * @return bytesPerSec + */ + private int getBytesPerSecondAndReset() { + + long now = TimeUtil.currentTimeMillis(); + int diffSeconds = (int) (now - lastRun)/1000; + int bytesPerSec = totalBytes.getAndSet(0)/diffSeconds; + // reset time + map.put("lastRun", now); + + return bytesPerSec; + } + + /** + * Process the record and save to DB + */ + private synchronized void processRecord() { + + RegistryBandwidthService service = new RegistryBandwidthService(bucketDao, network, bucketSize); + RegistryBandwidthRecord rbr = null; + + try { + rbr = service.getCurrentRegistryBandwidthRecord(); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, "Could not lookup previous Registry Bandwidth Record! ", e); + } + + int nowBytes = getBytesPerSecondAndReset(); + + if (rbr != null) { + // get the previous bytes/per second value + int previousBytes = rbr.getBytes(); + int averageBytes = (previousBytes + nowBytes)/2; + rbr.setBytes(averageBytes); + + } else { + // brand spanking new + Calendar cal = TimeUtil.newGmtCalendar(); + Long timePeriodKey = service.getTimePeriodKey(cal); + + if (timePeriodKey != null) { + rbr = new RegistryBandwidthRecord(timePeriodKey, nowBytes); + } + } + + service.addorUpdateRecord(rbr); + } + + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthDao.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthDao.java new file mode 100644 index 0000000000..291bc02737 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthDao.java @@ -0,0 +1,104 @@ +package com.raytheon.uf.edex.datadelivery.bandwidth.registry; + +/** + * 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. + **/ + +import java.util.ArrayList; +import java.util.List; + +import com.raytheon.uf.edex.database.DataAccessLayerException; +import com.raytheon.uf.edex.database.dao.CoreDao; +import com.raytheon.uf.edex.database.dao.DaoConfig; + +/** + * Provider Key Dao + * + *
+ * 
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 15, 2013 1736       dhladky     Dao for registry bandwidth gathering
+ * 
+ * 
+ * + * @author dhladky + * @version 1.0 + */ + +public class RegistryBandwidthDao extends CoreDao { + + private static final String FIELD = "timePeriod"; + + private static final String GREATERTHANEQUAL = ">="; + + private static final String LESSTHAN = "<"; + + /** + * Creates a new RegistryBandwidthDao + */ + public RegistryBandwidthDao() { + super(DaoConfig.forClass(RegistryBandwidthRecord.class)); + } + + /** + * Retrieves a RegistryBandwidthRecord with the timePeriod + * All times are in seconds since 0 GMT of each day + * returns null if none exists + * @param startTime + * @param endTime + * @return The Record with the corresponding timePeriod + */ + + public RegistryBandwidthRecord queryByTimeRange(long startMillis, long endMillis) + throws DataAccessLayerException { + + List fields = new ArrayList(2); + List values = new ArrayList(2); + List operands = new ArrayList(2); + fields.add(FIELD); + values.add(startMillis); + operands.add(GREATERTHANEQUAL); + fields.add(FIELD); + values.add(endMillis); + operands.add(LESSTHAN); + + List timePeriods = queryByCriteria(fields, values, operands, 1, FIELD, false); + if (timePeriods.isEmpty()) { + return null; + } else { + return (RegistryBandwidthRecord)timePeriods.get(0); + } + } + + /** + * Add or update an existing RegistryBandwidthRecord + * + * @param record + */ + public void addOrUpdateRecord(RegistryBandwidthRecord record) + throws Exception { + + // only persist records we have an active period for + if (record.getTimePeriod() != null) { + persist(record); + } + } +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthRecord.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthRecord.java new file mode 100644 index 0000000000..a5f34f0262 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthRecord.java @@ -0,0 +1,96 @@ +package com.raytheon.uf.edex.datadelivery.bandwidth.registry; + +/** + * 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. + **/ + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject; +import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; +import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; + +/** + * Provider Key Record + * + *
+ * 
+ * SOFTWARE HISTORY
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 15, 2013 1736       dhladky     Store bandwidth entries
+ *
+ * 
+ * 
+ * + * @author dhladky + * @version 1.0 + */ +@Entity +@Table(name = "dataDeliveryRegistryBandwidth") +@DynamicSerialize +public class RegistryBandwidthRecord implements IPersistableDataObject, + Serializable { + + private static final long serialVersionUID = 177884683888461814L; + + @Id + @DynamicSerializeElement + private Long timePeriod; + + @Column(nullable = false) + @DynamicSerializeElement + private int bytes; + + public RegistryBandwidthRecord() { + + } + + public RegistryBandwidthRecord(long timePeriod, int bytes) { + this.timePeriod = timePeriod; + this.bytes = bytes; + } + + public int getBytes() { + return bytes; + } + + public void setBytes(int bytes) { + this.bytes = bytes; + } + + @Override + public Long getIdentifier() { + return timePeriod; + } + + public Long getTimePeriod() { + return timePeriod; + } + + public void setTimePeriod(long timePeriod) { + this.timePeriod = timePeriod; + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthService.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthService.java new file mode 100644 index 0000000000..5e18c1915a --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthService.java @@ -0,0 +1,256 @@ +package com.raytheon.uf.edex.datadelivery.bandwidth.registry; +/** + * 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. + **/ +import java.util.Calendar; + +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.edex.database.DataAccessLayerException; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao; +/** + * Registry Bandwidth Service. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 16, 2013  1736     dhladky      Initial creation
+ * 
+ * 
+ * + * @author dhladky + * @version 1.0 + */ +public class RegistryBandwidthService { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(RegistryBandwidthService.class); + + public static final int BYTES_PER_KILOBYTE = 1024; + + private Network network; + + private IBandwidthBucketDao bucketDao; + + private int bucketSize; + + public RegistryBandwidthService() { + + } + + /** + * Construct an instance + * @param bucketDao + * @param network + */ + public RegistryBandwidthService(IBandwidthBucketDao bucketDao, Network network, int bucketSize) { + this.bucketDao = bucketDao; + this.network = network; + this.bucketSize = bucketSize; + } + + /** + * Gives a time averaged bandwidth for the current time. + * @return + */ + public Integer getCurrentRegistryBandwidth() { + + if (network == Network.OPSNET) { + + RegistryBandwidthRecord rbr = getCurrentRegistryBandwidthRecord(); + + if (rbr != null) { + // convert to kb per/second + return convertBytesToKilobytes(rbr.getBytes()); + } else { + statusHandler + .handle(Priority.WARN, + "No active registry bandwidth information for current time."); + } + } + + return 0; + + } + + /** + * Gives the current full record. Which is the previous record time wise + * because the query is back one full bucketSize in millis. + * @return + */ + public RegistryBandwidthRecord getCurrentRegistryBandwidthRecord() { + + RegistryBandwidthRecord rbr = null; + + if (network == Network.OPSNET) { + + RegistryBandwidthDao rbd = new RegistryBandwidthDao(); + Calendar cal = TimeUtil.newGmtCalendar(); + Long timePeriodKey = getTimePeriodKey(cal); + + if (timePeriodKey != null) { + try { + long startMillis = timePeriodKey - bucketSize; + long endMillis = timePeriodKey; + rbr = rbd.queryByTimeRange(startMillis, endMillis); + } catch (DataAccessLayerException dale) { + statusHandler.handle(Priority.PROBLEM, + "Could not lookup Registry Bandwidth Record! ", + dale); + } + } + } + + return rbr; + } + + /** + * Gives a time averaged bandwidth utilization for the registry, time passed + * in. + * + * @param cal + * @return + */ + public Integer getRegistryBandwidth(long millis) { + + if (network == Network.OPSNET) { + + Calendar cal = TimeUtil.newGmtCalendar(); + cal.setTimeInMillis(millis); + RegistryBandwidthRecord rbr = getRegistryBandwidthRecord(cal); + + if (rbr != null) { + return convertBytesToKilobytes(rbr.getBytes()); + } else { + // No record for this bucket, + // try current + return getCurrentRegistryBandwidth(); + } + } + + return 0; + } + + /** + * Retrieve a registry bandwidth record + * @param cal + * @return + */ + public RegistryBandwidthRecord getRegistryBandwidthRecord(Calendar cal) { + + RegistryBandwidthDao rbd = new RegistryBandwidthDao(); + Long timePeriodKey = getTimePeriodKey(cal); + RegistryBandwidthRecord rbr = null; + + if (timePeriodKey != null) { + try { + long startMillis = timePeriodKey - bucketSize/2; + long endMillis = timePeriodKey + bucketSize/2; + rbr = rbd.queryByTimeRange(startMillis, endMillis); + } catch (DataAccessLayerException dale) { + statusHandler.handle(Priority.PROBLEM, + "Could not lookup Registry Bandwidth Record! ", dale); + } + } + + return rbr; + } + + /** + * Retrieve a registry bandwidth record + * @param cal + * @return + */ + public RegistryBandwidthRecord getRegistryBandwidthRecord(long millis) { + + Calendar cal = TimeUtil.newGmtCalendar(); + cal.setTimeInMillis(millis); + + return getRegistryBandwidthRecord(cal); + } + + /** + * Get time period key for some other determined time + * @param cal + * @return + */ + public Long getTimePeriodKey(Calendar cal) { + + long millis = cal.getTimeInMillis(); + BandwidthBucket bucket = bucketDao.getBucketContainingTime(millis, + network); + + if (bucket != null) { + return getTimeKey(bucket.getBucketStartTime()); + } + + // in the off chance a bucket doesn't exist anywhere near this time. + return null; + } + + /** + * conversion + * @param bytes + * @return + */ + public static int convertBytesToKilobytes(int bytes) { + return bytes / BYTES_PER_KILOBYTE; + } + + /** + * Add or update the record + * @param rbr + */ + public void addorUpdateRecord(RegistryBandwidthRecord rbr) { + RegistryBandwidthDao rbd = new RegistryBandwidthDao(); + + try { + if (rbr != null) { + rbd.addOrUpdateRecord(rbr); + } + } catch (Exception e) { + statusHandler.handle(Priority.ERROR, + "Could not write Registry Bandwidth Record! ", e); + } + } + + /** + * Records in the DB are kept by millis on a one day cycle + * @param current + * @return + */ + private long getTimeKey(long current) { + + long value = current % TimeUtil.MILLIS_PER_DAY; + + if (value < 0) { + return 0; + } else { + return value; + } + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthUtilizationListener.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthUtilizationListener.java new file mode 100644 index 0000000000..4635d0673f --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/registry/RegistryBandwidthUtilizationListener.java @@ -0,0 +1,254 @@ +package com.raytheon.uf.edex.datadelivery.bandwidth.registry; + +/** + * 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. + **/ + +import java.net.InetAddress; +import java.net.Socket; +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.io.NetworkTrafficListener; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector; +import org.quartz.CronTrigger; +import org.quartz.JobDetail; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.SchedulerFactory; + +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthMap; +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthRoute; +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao; + +/** + * {@link RegistryBandwidthUtilizationListener} Keeps track of network traffic for registry + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 06, 2013 1736       dhladky     Initial creation
+ * 
+ * 
+ * + * @author dhladky + * @version 1.0 + */ + +public class RegistryBandwidthUtilizationListener implements NetworkTrafficListener { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(RegistryBandwidthUtilizationListener.class); + + /* Is this registry federated or not */ + private boolean isFederated = false; + + /* Total bytes collected since last run */ + private AtomicInteger totalBytes = new AtomicInteger(0); + + /* The millis of the last run */ + private Long lastRun; + + /** network for data traffic */ + private Network network = Network.OPSNET;; + + /** size of bucket in minutes */ + private int bucketSize = 0; + + /** bucket dao class */ + private IBandwidthBucketDao bucketDao; + + /** + * Construct the listener + * @param server + * @param isFederated + * @param BandwidthMap + */ + public RegistryBandwidthUtilizationListener(Server server, Boolean isFederated, BandwidthMap map, IBandwidthBucketDao bucketDao) { + + // We only care about OPSNET in this listener + this.setFederated(isFederated); + this.lastRun = TimeUtil.currentTimeMillis(); + BandwidthRoute route = map.getRoute(network); + this.bucketSize = route.getBucketSizeMinutes(); + this.bucketDao = bucketDao; + String cron = getCronString(route.getBucketSizeMinutes()); + createQuartzCron(cron, network.name()); + + for (Connector connector: server.getConnectors()) { + if (connector instanceof NetworkTrafficSelectChannelConnector) { + NetworkTrafficSelectChannelConnector nconnector = ((NetworkTrafficSelectChannelConnector)connector); + nconnector.addNetworkTrafficListener(this); + statusHandler.debug(nconnector.toString()+ " on Network: "+network); + } + } + } + + + @Override + public void opened(Socket socket) { + if (statusHandler.isPriorityEnabled(Priority.DEBUG)) { + statusHandler.debug("Socket Open!"); + } + } + + @Override + public void incoming(Socket socket, Buffer bytes) { + + // Ignore local traffic if federated + if (isFilteredTraffic(socket)) { + return; + } + + // add bytes to total + addBytes(bytes); + } + + @Override + public void outgoing(Socket socket, Buffer bytes) { + + // Ignore local traffic if federated + if (isFilteredTraffic(socket)) { + return; + } + + // add bytes to total + addBytes(bytes); + } + + @Override + public void closed(Socket socket) { + if (statusHandler.isPriorityEnabled(Priority.DEBUG)) { + statusHandler.debug("Socket Closed!"); + } + } + + /** + * Add the bytes + * @param bytes + */ + private void addBytes(Buffer bytes) { + totalBytes.getAndAdd(bytes.length()); + } + + + public boolean isFederated() { + return isFederated; + } + + + public void setFederated(boolean isFederated) { + this.isFederated = isFederated; + } + + /** + * Filter un-needed traffic + * @param socket + * @return + */ + private boolean isFilteredTraffic(Socket socket) { + + if (isFederated()) { + + InetAddress address = socket.getInetAddress(); + + if (address.isLoopbackAddress()) { + // ignore this traffic + return true; + } + } + + return false; + } + + /** + * Get the string to submit as the cron + * @param minutes + * @return + */ + private String getCronString(int minutes) { + return new String("0 0/"+minutes+" * * * ?"); + } + + /** + * Creates a dynamic quartz cron for the Bandwidth Utilization based on the + * size of the Bandwidth Bucket in minutes. + * @param cron + * @param name + */ + private void createQuartzCron(String cron, String name) { + + try { + + SchedulerFactory schedFactory = new org.quartz.impl.StdSchedulerFactory(); + Scheduler schedular = schedFactory.getScheduler(); + JobDetail jobDetail = null; + + try { + jobDetail = schedular.getJobDetail(name, "BandwidthUtilization"); + } catch (SchedulerException se) { + statusHandler.info("Job doesn't exist!"); + } + + if (jobDetail != null) { + // reschedule + CronTrigger trigger = (CronTrigger) schedular.getTrigger(name, + "BandwidthUtilization"); + String cronEx = trigger.getCronExpression(); + if (!cron.equals(cronEx)) { + trigger.setCronExpression(cron); + schedular.rescheduleJob(name, "BandwidthUtilization", trigger); + statusHandler.info("Rescheduling Job: " + name); + } + } else { + jobDetail = new JobDetail(name, "BandwidthUtilization", BandwidthUtilizationProcessor.class); + jobDetail.getJobDataMap().put(name, "FULL"); + // add the atomic int to the map + jobDetail.getJobDataMap().put("totalBytes", totalBytes); + jobDetail.getJobDataMap().put("network", network); + jobDetail.getJobDataMap().put("lastRun", lastRun); + jobDetail.getJobDataMap().put("bucketDao", bucketDao); + jobDetail.getJobDataMap().put("bucketSize", bucketSize); + CronTrigger trigger = new CronTrigger(name, "BandwidthUtilization"); + trigger.setCronExpression(cron); + schedular.scheduleJob(jobDetail, trigger); + statusHandler.info("Scheduling Job: " + name); + } + + if (!schedular.isStarted()) { + schedular.start(); + } + + } catch (Exception e) { + statusHandler.error("Unable to schedule job: " + name + " error: " + + e); + } + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java index 4c7befba90..456981262d 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalPlan.java @@ -11,6 +11,8 @@ import java.util.TreeSet; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthMap; +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthRoute; import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.serialization.SerializationException; import com.raytheon.uf.common.status.IUFStatusHandler; @@ -22,6 +24,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.IBandwidthBucketDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; +import com.raytheon.uf.edex.datadelivery.bandwidth.registry.RegistryBandwidthService; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; /** @@ -40,6 +43,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Nov 20, 2012 1286 djohnson Handle null bucketIds being returned. * 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. + * Nov 16, 2013 1736 dhladky Alter size of available bandwidth by subtracting that used by registry. * * * @@ -102,6 +106,7 @@ public class RetrievalPlan { void init() { boolean found = false; BandwidthRoute route = map.getRoute(network); + if (route != null) { found = true; this.planDays = route.getPlanDays(); @@ -109,28 +114,41 @@ public class RetrievalPlan { } if (found) { + // create registry bandwidth service + RegistryBandwidthService rbs = new RegistryBandwidthService(bucketsDao, network, bucketMinutes); + long bucketMillis = bucketMinutes * TimeUtil.MILLIS_PER_MINUTE; Calendar currentBucket = BandwidthUtil.now(); planStart = BandwidthUtil.now(); planEnd = TimeUtil.newCalendar(planStart); planEnd.add(Calendar.DAY_OF_YEAR, planDays); - + long currentMillis = currentBucket.getTimeInMillis(); + long planEndMillis = planEnd.getTimeInMillis(); // Make the buckets... - long bucket = 0; - while (!currentBucket.after(planEnd)) { + + while (!(currentMillis > planEndMillis)) { + int bw = map.getBandwidth(network, currentBucket); - bucket = currentBucket.getTimeInMillis(); // Get the bucket size.. - // buckets are (bandwidth [kilobits/second] * milliseconds per + // buckets are (bandwidth [kilobytes/second] * milliseconds per // minute * // bucket minutes)/bits per byte) ... bytesPerBucket = BandwidthUtil .convertKilobytesPerSecondToBytesPerSpecifiedMinutes( bw, bucketMinutes); - bucketsDao.create(new BandwidthBucket(bucket, bytesPerBucket, + bucketsDao.create(new BandwidthBucket(currentMillis, bytesPerBucket, network)); - currentBucket.add(Calendar.MINUTE, bucketMinutes); + + currentMillis += bucketMillis; } + + // subtract registry traffic from total available bytes/per second + for (BandwidthBucket bucket: bucketsDao.getAll(network)) { + long startMillis = bucket.getBucketStartTime(); + int registryBytesPerSecond = rbs.getRegistryBandwidth(startMillis); + bucket.setBucketSize(bucket.getBucketSize() - (registryBytesPerSecond * TimeUtil.SECONDS_PER_MINUTE * bucketMinutes)); + } + } else { // Can't proceed, throw an Exception throw new IllegalArgumentException( @@ -212,33 +230,41 @@ public class RetrievalPlan { // Get the last bucket and add buckets to make up the // difference.. // Make the buckets... + long bucketMillis = bucketMinutes * TimeUtil.MILLIS_PER_MINUTE; + long newPlanEndMillis = newEndOfPlan.getTimeInMillis(); BandwidthBucket bucket = bucketsDao.getLastBucket(network); Calendar currentBucket = BandwidthUtil.now(); currentBucket.setTimeInMillis(bucket.getBucketStartTime()); + long currentBucketMillis = bucket.getBucketStartTime(); // Add the buckets minutes to the last bucket and add // buckets until we have the new plan size. - currentBucket.add(Calendar.MINUTE, bucketMinutes); - - while (!currentBucket.after(newEndOfPlan)) { + currentBucketMillis += bucketMillis; + // create Registry Bandwidth Service + RegistryBandwidthService rbs = new RegistryBandwidthService(bucketsDao, network, bucketMinutes); + + while (!(currentBucketMillis > newPlanEndMillis)) { + int bw = map.getBandwidth(network, currentBucket); - long bucketStartTime = currentBucket.getTimeInMillis(); + // subtract registry traffic from total available bytes/per second + int registryBytesPerSecond = rbs.getRegistryBandwidth(currentBucketMillis); + bw = bw - registryBytesPerSecond; // Get the bucket size.. - // buckets are (bandwidth * kilobits/second * 60 seconds * + // buckets are (bandwidth * kilobytes/second * 60 seconds * // bucket minutes)/bits per byte) ... bytesPerBucket = BandwidthUtil .convertKilobytesPerSecondToBytesPerSpecifiedMinutes( bw, bucketMinutes); - bucketsDao.create(new BandwidthBucket(bucketStartTime, + bucketsDao.create(new BandwidthBucket(currentBucketMillis, bytesPerBucket, network)); - currentBucket.add(Calendar.MINUTE, bucketMinutes); + + currentBucketMillis += bucketMillis; statusHandler.info("resize() - Adding bucket [" + bucket + "] bandwidth = [" + bw + "]"); } } - } - // Now remove buckets from the front of the map whos time slot + // Now remove buckets from the front of the map who's time slot // is past and are empty long newStart = newStartOfPlan.getTimeInMillis(); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/META-INF/MANIFEST.MF index 5853e0db16..67f14aed98 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.registry/META-INF/MANIFEST.MF @@ -23,3 +23,7 @@ Require-Bundle: com.raytheon.uf.common.registry.schemas.ebxml;bundle-version="1. com.raytheon.uf.common.datadelivery.registry;bundle-version="1.0.0", org.apache.commons.lang;bundle-version="2.3.0", com.raytheon.uf.common.registry.event;bundle-version="1.0.0" +Export-Package: com.raytheon.uf.edex.datadelivery.registry.availability, + com.raytheon.uf.edex.datadelivery.registry.federation, + com.raytheon.uf.edex.datadelivery.registry.replication, + com.raytheon.uf.edex.datadelivery.registry.web diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml index ac83bf6582..36c7c08d7f 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/res/spring/ebxml-webserver.xml @@ -14,7 +14,7 @@ - + diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java index a0d4415a87..57ca7c7e95 100644 --- a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java @@ -44,6 +44,7 @@ import com.raytheon.uf.common.datadelivery.bandwidth.IProposeScheduleResponse; 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.BandwidthMap; import com.raytheon.uf.common.datadelivery.bandwidth.data.SubscriptionStatusSummary; import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData; import com.raytheon.uf.common.datadelivery.registry.AdhocSubscription; @@ -63,7 +64,6 @@ import com.raytheon.uf.common.time.util.TimeUtil; 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.SubscriptionRetrieval; -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; diff --git a/tests/unit/com/raytheon/uf/common/serialization/TestJaxbableClassesLocator.java b/tests/unit/com/raytheon/uf/common/serialization/TestJaxbableClassesLocator.java index 8f166c7a47..4328a5cc6b 100644 --- a/tests/unit/com/raytheon/uf/common/serialization/TestJaxbableClassesLocator.java +++ b/tests/unit/com/raytheon/uf/common/serialization/TestJaxbableClassesLocator.java @@ -95,7 +95,7 @@ public class TestJaxbableClassesLocator implements IJaxbableClassesLocator { com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthDataSetUpdate.class, com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription.class, com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation.class, - com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap.class, + com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthMap.class, com.raytheon.uf.common.datadelivery.retrieval.xml.ServiceConfig.class, com.raytheon.uf.common.datadelivery.retrieval.xml.UnitLookup.class, com.raytheon.uf.common.datadelivery.retrieval.xml.LevelLookup.class, diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtilTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtilTest.java index 86e18030a2..0b6cbe927f 100644 --- a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtilTest.java +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/BandwidthDaoUtilTest.java @@ -44,6 +44,7 @@ import org.junit.Before; import org.junit.Test; import com.google.common.collect.Maps; +import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthMap; import com.raytheon.uf.common.datadelivery.registry.GriddedTime; import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription; @@ -61,7 +62,6 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.InMemoryBandwidthBucketDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; -import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.InMemoryBandwidthBucketAllocationAssociator; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;